Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/IamMuuo/academia into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMuuo committed Sep 23, 2024
2 parents fbb8ee7 + efb37c1 commit bcf7d41
Show file tree
Hide file tree
Showing 27 changed files with 2,226 additions and 2 deletions.
Binary file added assets/images/left_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/right_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/constants/tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ final List<Map<String, dynamic>> allTools = [
},
{
"id": 10,
"name": "Academia Anki",
"action": "Lets Up That Grade",
"image": "assets/images/tasks_manager.png",
"ontap": () {
Get.to(const AnkiHomePage());
},
"description":
"Ready to revolutionize your study habits?\nLet's help you master courses effortlessly",
},
{
"id": 11,
"name": "Ask Me",
"action": "Ask Me",
"image": "assets/images/think.jpeg",
Expand Down
24 changes: 22 additions & 2 deletions lib/storage/schemas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const schemas = <String, String>{
end_date TEXT NOT NULL
);
""",

"course_topics": """
CREATE TABLE IF NOT EXISTS course_topics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand All @@ -133,6 +132,28 @@ const schemas = <String, String>{
description TEXT NOT NULL
);
""",
// Anki
// Topic
"ankiTopics": """
CREATE TABLE IF NOT EXISTS ankiTopics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE NOT NULL,
desc TEXT NOT NULL,
is_favourite INTEGER DEFAULT 0 NOT NULL,
num_cards INTERGER DEFAULT 0 NOT NULL
);
""",
// AnkiCard
"ankiCards": """
CREATE TABLE IF NOT EXISTS ankiCards (
id INTEGER PRIMARY KEY AUTOINCREMENT,
topic_id INTERGER NOT NULL,
question TEXT NOT NULL,
answer TEXT NOT NULL,
FOREIGN KEY(topic_id) REFERENCES ankiTopics(id)
);
""",

//Ask Me
//Files from Ask Me from which questions are being generated
"askme_files": """
Expand All @@ -143,7 +164,6 @@ const schemas = <String, String>{
avgScore INTEGER NOT NULL
);
""",

//AskMe Scores
"askme_scores": """
CREATE TABLE IF NOT EXISTS askme_scores (
Expand Down
1 change: 1 addition & 0 deletions lib/tools/anki/anki.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'pages/anki_home.dart';
52 changes: 52 additions & 0 deletions lib/tools/anki/controllers/ankicard_controller.dart
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;
}
}
7 changes: 7 additions & 0 deletions lib/tools/anki/controllers/answer_controller.dart
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;
}
3 changes: 3 additions & 0 deletions lib/tools/anki/controllers/controllers.dart
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';
96 changes: 96 additions & 0 deletions lib/tools/anki/controllers/topic_controller.dart
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;
}
}
28 changes: 28 additions & 0 deletions lib/tools/anki/models/ankicard_model.dart
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,
};
}
63 changes: 63 additions & 0 deletions lib/tools/anki/models/ankicard_model_helper.dart
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');
}
}
4 changes: 4 additions & 0 deletions lib/tools/anki/models/models.dart
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';
32 changes: 32 additions & 0 deletions lib/tools/anki/models/topic_model.dart
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,
};
}
Loading

0 comments on commit bcf7d41

Please sign in to comment.