Skip to content

Commit

Permalink
Merge pull request #357 from its-me-abhishek/main
Browse files Browse the repository at this point in the history
Add CCSync/Taskchampion support to the app
  • Loading branch information
Pavel401 authored Jul 7, 2024
2 parents 3d8aaa6 + 2d73068 commit 86727d6
Show file tree
Hide file tree
Showing 40 changed files with 3,241 additions and 175 deletions.
509 changes: 509 additions & 0 deletions lib/api_service.dart

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: depend_on_referenced_packages

import 'package:built_collection/built_collection.dart';
import 'package:get/get.dart';
import 'package:taskwarrior/app/modules/home/controllers/home_controller.dart';
Expand Down Expand Up @@ -46,7 +48,7 @@ class DetailRouteController extends GetxController {
// 'status': controller.modify.draft.status,
// 'entry': controller.modify.draft.entry,
// 'modified': controller.modify.draft.modified,
// 'start': controller.modify.draft.start,
// 'start': controller.modify.draft.start,
// 'end': controller.modify.draft.end,
// 'due': controller.dueValue.value,
// 'wait': controller.modify.draft.wait,
Expand Down
2 changes: 2 additions & 0 deletions lib/app/modules/detailRoute/views/detail_route_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: depend_on_referenced_packages, deprecated_member_use

import 'package:built_collection/built_collection.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand Down
55 changes: 52 additions & 3 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:get/get.dart';
import 'package:home_widget/home_widget.dart';
import 'package:loggy/loggy.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:taskwarrior/api_service.dart';
import 'package:taskwarrior/app/models/filters.dart';

import 'package:taskwarrior/app/models/json/task.dart';
Expand All @@ -22,6 +23,7 @@ import 'package:taskwarrior/app/tour/filter_drawer_tour.dart';
import 'package:taskwarrior/app/tour/home_page_tour.dart';
import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart';
import 'package:taskwarrior/app/utils/language/supported_language.dart';
import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart';
import 'package:taskwarrior/app/utils/taskfunctions/comparator.dart';
import 'package:taskwarrior/app/utils/taskfunctions/projects.dart';
import 'package:taskwarrior/app/utils/taskfunctions/query.dart';
Expand Down Expand Up @@ -49,6 +51,8 @@ class HomeController extends GetxController {
final Rx<SupportedLanguage> selectedLanguage = SupportedLanguage.english.obs;
final ScrollController scrollController = ScrollController();
final RxBool showbtn = false.obs;
late TaskDatabase taskdb;
var tasks = <Tasks>[].obs;

@override
void onInit() {
Expand All @@ -66,6 +70,45 @@ class HomeController extends GetxController {
if (Platform.isAndroid) {
handleHomeWidgetClicked();
}
taskdb = TaskDatabase();
taskdb.open();
getUniqueProjects();
_loadTaskChampion();
fetchTasksFromDB();
}

Future<List<String>> getUniqueProjects() async {
var taskDatabase = TaskDatabase();
List<String> uniqueProjects = await taskDatabase.fetchUniqueProjects();
debugPrint('Unique projects: $uniqueProjects');
return uniqueProjects;
}

Future<void> deleteAllTasksInDB() async {
var taskDatabase = TaskDatabase();
await taskDatabase.deleteAllTasksInDB();
debugPrint('Deleted all tasks from db');
}

Future<void> refreshTasks(String clientId, String encryptionSecret) async {
TaskDatabase taskDatabase = TaskDatabase();
await taskDatabase.open();
List<Tasks> tasksFromServer = await fetchTasks(clientId, encryptionSecret);
await updateTasksInDatabase(tasksFromServer);
List<Tasks> fetchedTasks = await taskDatabase.fetchTasksFromDatabase();
tasks.value = fetchedTasks;
}

Future<void> fetchTasksFromDB() async {
TaskDatabase taskDatabase = TaskDatabase();
await taskDatabase.open();
List<Tasks> fetchedTasks = await taskDatabase.fetchTasksFromDatabase();
tasks.value = fetchedTasks;
}

Future<void> _loadTaskChampion() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
taskchampion.value = prefs.getBool('taskchampion') ?? false;
}

void addListenerToScrollController() {
Expand Down Expand Up @@ -425,21 +468,25 @@ class HomeController extends GetxController {
final SharedPreferences prefs = await SharedPreferences.getInstance();
bool? value;
value = prefs.getBool('sync-onStart') ?? false;

String? clientId, encryptionSecret;
clientId = await CredentialsStorage.getClientId();
encryptionSecret = await CredentialsStorage.getEncryptionSecret();
if (value) {
synchronize(context, false);
refreshTasks(clientId!, encryptionSecret!);
} else {}
}

RxBool syncOnStart = false.obs;
RxBool syncOnTaskCreate = false.obs;
RxBool delaytask = false.obs;
RxBool change24hr = false.obs;
RxBool taskchampion = false.obs;

// dialogue box

final formKey = GlobalKey<FormState>();
final namecontroller = TextEditingController();
final projectcontroller = TextEditingController();
var due = Rxn<DateTime>();
RxString dueString = ''.obs;
RxString priority = 'M'.obs;
Expand Down Expand Up @@ -505,7 +552,7 @@ class HomeController extends GetxController {
void initLanguageAndDarkMode() {
isDarkModeOn.value = AppSettings.isDarkMode;
selectedLanguage.value = AppSettings.selectedLanguage;
print("called and value is${isDarkModeOn.value}");
// print("called and value is${isDarkModeOn.value}");
}

final addKey = GlobalKey();
Expand Down Expand Up @@ -557,6 +604,7 @@ class HomeController extends GetxController {

final GlobalKey statusKey = GlobalKey();
final GlobalKey projectsKey = GlobalKey();
final GlobalKey projectsKeyTaskc = GlobalKey();
final GlobalKey filterTagKey = GlobalKey();
final GlobalKey sortByKey = GlobalKey();

Expand All @@ -565,6 +613,7 @@ class HomeController extends GetxController {
targets: filterDrawer(
statusKey: statusKey,
projectsKey: projectsKey,
projectsKeyTaskc: projectsKeyTaskc,
filterTagKey: filterTagKey,
sortByKey: sortByKey,
),
Expand Down
11 changes: 5 additions & 6 deletions lib/app/modules/home/views/add_task_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,21 @@ class AddTaskBottomSheet extends StatelessWidget {
initialTime: TimeOfDay.fromDateTime(
homeController.due.value ?? DateTime.now()),
);
print("date$date Time : $time");
// print("date$date Time : $time");
if (time != null) {
var dateTime = date.add(
Duration(
hours: time.hour,
minutes: time.minute,
),
);
print(dateTime);
// print(dateTime);
homeController.due.value = dateTime.toUtc();

print("due value ${homeController.due}");
// print("due value ${homeController.due}");
homeController.dueString.value =
DateFormat("dd-MM-yyyy HH:mm").format(dateTime);
print(homeController.dueString.value);
// print(homeController.dueString.value);
if (dateTime.isBefore(DateTime.now())) {
//Try changing the color. in the settings and Due display.

Expand Down Expand Up @@ -391,7 +391,6 @@ class AddTaskBottomSheet extends StatelessWidget {
);

Widget buildAddButton(BuildContext context) {

return TextButton(
child: Text(
"Add",
Expand All @@ -402,7 +401,7 @@ class AddTaskBottomSheet extends StatelessWidget {
),
),
onPressed: () async {
print(homeController.formKey.currentState);
// print(homeController.formKey.currentState);
if (homeController.formKey.currentState!.validate()) {
try {
var task = taskParser(homeController.namecontroller.text)
Expand Down
Loading

0 comments on commit 86727d6

Please sign in to comment.