-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/IamMuuo/academia into dev
- Loading branch information
Showing
27 changed files
with
2,226 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'pages/anki_home.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:academia/tools/anki/models/models.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
class AnkiCardController extends GetxController { | ||
AnkiCardController({ | ||
required this.topicId, | ||
}); | ||
|
||
final RxList<AnkiCard> allCards = <AnkiCard>[].obs; | ||
final int topicId; | ||
|
||
@override | ||
void onInit() { | ||
super.onInit(); | ||
getAllTopicCards().then((value) { | ||
debugPrint("[+] Anki Topic Cards Loaded"); | ||
}); | ||
} | ||
|
||
// returns the number of topics | ||
int numAnkiCards() { | ||
return allCards.length; | ||
} | ||
|
||
Future<bool> addAnkiCard(AnkiCard ankiCard) async { | ||
int value = await AnkiCardModelHelper().create(ankiCard.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
Future<bool> updateAnkiCard(AnkiCard ankiCard) async { | ||
int value = await AnkiCardModelHelper().update(ankiCard.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
Future<List<AnkiCard>> getAllTopicCards() async { | ||
AnkiCardModelHelper().queryAnkiCardsByTopic(topicId).then((values) { | ||
allCards.clear(); | ||
values = values.reversed.toList(); | ||
for (final val in values) { | ||
allCards.add(AnkiCard.fromJson(val)); | ||
} | ||
}); | ||
return allCards; | ||
} | ||
|
||
Future<bool> deleteCard(AnkiCard ankiCard) async { | ||
int value = await AnkiCardModelHelper().delete(ankiCard.toJson()); | ||
getAllTopicCards(); | ||
return value == 0 ? false : true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// import 'package:academia/exports/barrel.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
class AnswerCardController extends GetxController { | ||
var ansCard = "".obs; | ||
var ansSwitch = true.obs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'answer_controller.dart'; | ||
export 'topic_controller.dart'; | ||
export 'ankicard_controller.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:academia/tools/anki/models/models.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
class TopicController extends GetxController { | ||
final RxList<AnkiTopic> allTopics = <AnkiTopic>[].obs; | ||
final RxList<AnkiTopic> allFavourites = <AnkiTopic>[].obs; | ||
|
||
@override | ||
void onInit() { | ||
super.onInit(); | ||
getAllTopics().then((value) { | ||
debugPrint("[+] Topics Loaded"); | ||
}); | ||
getAllFavourites().then((value) { | ||
debugPrint("[+] Favourite Topics Loaded"); | ||
}); | ||
} | ||
|
||
// returns the number of topics | ||
int numTopics() { | ||
return allTopics.length; | ||
} | ||
|
||
Future<bool> addTopic(AnkiTopic topic) async { | ||
int value = await TopicModelHelper().create(topic.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
// Marking topic as favourite and vice versa | ||
Future<bool> favouriteTopic(AnkiTopic topic) async { | ||
topic.isFavourite = !topic.isFavourite; | ||
// update topic list | ||
if (allFavourites.length >= 5) { | ||
updateFavourites(); | ||
} | ||
int value = await TopicModelHelper().update(topic.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
// updating favourite lists by popping one | ||
void updateFavourites() async { | ||
// pops the last favourited topic when more than five | ||
AnkiTopic removedTopic = allFavourites.removeAt(0); | ||
removedTopic.isFavourite = false; | ||
// update the topic in db | ||
await updateTopic(removedTopic); | ||
} | ||
|
||
// increments topics number of cards by one | ||
Future<bool> incTopicNumCards(AnkiTopic topic) async { | ||
topic.numCards++; | ||
int value = await TopicModelHelper().update(topic.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
// decrements topics number of cards by one | ||
Future<bool> descTopicNumCards(AnkiTopic topic) async { | ||
topic.numCards--; | ||
int value = await TopicModelHelper().update(topic.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
Future<bool> updateTopic(AnkiTopic topic) async { | ||
int value = await TopicModelHelper().update(topic.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
Future<List<AnkiTopic>> getAllFavourites() async { | ||
TopicModelHelper().getFavourites().then((values) { | ||
allFavourites.clear(); | ||
values = values.reversed.toList(); | ||
for (final val in values) { | ||
allFavourites.add(AnkiTopic.fromJson(val)); | ||
} | ||
}); | ||
return allFavourites.reversed.toList(); | ||
} | ||
|
||
Future<List<AnkiTopic>> getAllTopics() async { | ||
TopicModelHelper().queryAll().then((values) { | ||
allTopics.clear(); | ||
values = values.reversed.toList(); | ||
for (final val in values) { | ||
allTopics.add(AnkiTopic.fromJson(val)); | ||
} | ||
}); | ||
return allTopics; | ||
} | ||
|
||
Future<bool> deleteTopic(AnkiTopic topic) async { | ||
int value = await TopicModelHelper().delete(topic.toJson()); | ||
getAllTopics(); | ||
return value == 0 ? false : true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ankiTCard model | ||
|
||
class AnkiCard { | ||
int? id; | ||
int topicId; | ||
String question; | ||
String answer; | ||
|
||
AnkiCard({ | ||
this.id, | ||
required this.topicId, | ||
required this.question, | ||
required this.answer, | ||
}); | ||
|
||
AnkiCard.fromJson(Map<String, dynamic> json) | ||
: id = json['id'], | ||
topicId = json['topic_id'], | ||
question = json['question'], | ||
answer = json['answer']; | ||
|
||
Map<String, dynamic> toJson() => { | ||
'id': id, | ||
'topic_id': topicId, | ||
'question': question, | ||
'answer': answer, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:academia/storage/storage.dart'; | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
class AnkiCardModelHelper implements DatabaseOperations { | ||
static final AnkiCardModelHelper _instance = AnkiCardModelHelper._internal(); | ||
|
||
factory AnkiCardModelHelper() { | ||
return _instance; | ||
} | ||
|
||
AnkiCardModelHelper._internal(); | ||
|
||
@override | ||
Future<int> create(Map<String, dynamic> data) async { | ||
final db = await DatabaseHelper().database; | ||
final id = await db.insert( | ||
'ankiCards', | ||
data, | ||
conflictAlgorithm: ConflictAlgorithm.replace, | ||
); | ||
|
||
debugPrint("[+] Anki Card Created Succcessfuly"); | ||
return id; | ||
} | ||
|
||
@override | ||
Future<List<Map<String, dynamic>>> queryAll() async { | ||
final db = await DatabaseHelper().database; | ||
final ankiCards = await db.query('ankiCards'); | ||
return ankiCards; | ||
} | ||
|
||
@override | ||
Future<int> delete(Map<String, dynamic> data) async { | ||
final db = await DatabaseHelper().database; | ||
return await db | ||
.delete('ankiCards', where: 'id = ?', whereArgs: [data["id"]]); | ||
} | ||
|
||
@override | ||
Future<int> update(Map<String, dynamic> data) async { | ||
final db = await DatabaseHelper().database; | ||
return await db | ||
.update('ankiCards', data, where: 'id = ?', whereArgs: [data['id']]); | ||
} | ||
|
||
Future<List<Map<String, dynamic>>> queryAnkiCardsByTopic(int topicId) async { | ||
final db = await DatabaseHelper().database; | ||
return await db.query( | ||
'ankiCards', | ||
where: 'topic_id = ?', | ||
whereArgs: [topicId], | ||
); | ||
} | ||
|
||
// make sure to call in the logout function | ||
@override | ||
Future<void> truncate() async { | ||
final db = await DatabaseHelper().database; | ||
await db.execute('DELETE FROM ankiCards'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'topic_model.dart'; | ||
export 'topic_model_helper.dart'; | ||
export 'ankicard_model.dart'; | ||
export 'ankicard_model_helper.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// ankiTopic model | ||
|
||
class AnkiTopic { | ||
int? id; | ||
String name; | ||
String desc; | ||
bool isFavourite; | ||
int numCards; | ||
|
||
AnkiTopic({ | ||
this.id, | ||
required this.name, | ||
required this.desc, | ||
this.isFavourite = false, | ||
this.numCards = 0, | ||
}); | ||
|
||
AnkiTopic.fromJson(Map<String, dynamic> json) | ||
: id = json['id'], | ||
name = json['name'], | ||
desc = json['desc'], | ||
isFavourite = json['is_favourite'] == 0 ? false : true, | ||
numCards = json['num_cards']; | ||
|
||
Map<String, dynamic> toJson() => { | ||
'id': id, | ||
'name': name, | ||
'desc': desc, | ||
'is_favourite': isFavourite ? 1 : 0, | ||
'num_cards': numCards, | ||
}; | ||
} |
Oops, something went wrong.