Skip to content

Ccsync integrate latest #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 115 additions & 27 deletions lib/app/modules/home/views/show_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import 'package:taskwarrior/app/utils/constants/utilites.dart';
import 'package:taskwarrior/app/utils/themes/theme_extension.dart';
import 'package:taskwarrior/app/utils/language/sentence_manager.dart';
import 'package:taskwarrior/app/v3/db/task_database.dart';
import 'package:taskwarrior/app/v3/models/task.dart';
import 'package:taskwarrior/app/v3/net/modify.dart';
import 'package:taskwarrior/app/v3/models/annotation.dart';
import 'package:taskwarrior/app/v3/models/task.dart'; // Ensure this path is correct for your new model
// import 'package:taskwarrior/app/v3/net/modify.dart';

class TaskDetails extends StatefulWidget {
final TaskForC task;
Expand All @@ -25,6 +26,14 @@ class _TaskDetailsState extends State<TaskDetails> {
late String status;
late String priority;
late String due;
late String start;
late String wait;
late List<String> tags;
late List<String> depends;
late String rtype;
late String recur;
late List<Annotation> annotations;

late TaskDatabase taskDatabase;

bool hasChanges = false;
Expand All @@ -33,11 +42,22 @@ class _TaskDetailsState extends State<TaskDetails> {
void initState() {
super.initState();
description = widget.task.description;
project = widget.task.project!;
project = widget.task.project ?? '-';
status = widget.task.status;
priority = widget.task.priority!;
priority = widget.task.priority ?? '-';
due = widget.task.due ?? '-';
due = _buildDate(due);
start = widget.task.start ?? '-';
wait = widget.task.wait ?? '-';
tags = widget.task.tags ?? [];
depends = widget.task.depends ?? [];
rtype = widget.task.rtype ?? '-';
recur = widget.task.recur ?? '-';
annotations = widget.task.annotations ?? [];

due = _buildDate(due); // Format the date for display
start = _buildDate(start);
wait = _buildDate(wait);

setState(() {
taskDatabase = TaskDatabase();
taskDatabase.open();
Expand All @@ -47,6 +67,10 @@ class _TaskDetailsState extends State<TaskDetails> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
// This part seems redundant if taskDatabase.open() is already in initState
// and ideally, the database connection should be managed more robustly
// (e.g., singleton, provider, or passed down).
// However, keeping it as per original logic, but be aware of potential multiple openings.
taskDatabase = TaskDatabase();
taskDatabase.open();
}
Expand Down Expand Up @@ -109,7 +133,7 @@ class _TaskDetailsState extends State<TaskDetails> {
_buildSelectableDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPagePriority}:',
priority,
['H', 'M', 'L'], (value) {
['H', 'M', 'L', '-'], (value) {
setState(() {
priority = value;
hasChanges = true;
Expand All @@ -123,10 +147,52 @@ class _TaskDetailsState extends State<TaskDetails> {
hasChanges = true;
});
}),
_buildDetail('UUID:', widget.task.uuid!),
_buildDatePickerDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPageStart}:',
start, (value) {
setState(() {
start = value;
hasChanges = true;
});
}),
_buildDatePickerDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPageWait}:',
wait, (value) {
setState(() {
wait = value;
hasChanges = true;
});
}),
_buildEditableDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPageTags}:',
tags.join(', '), (value) {
setState(() {
tags = value.split(',').map((e) => e.trim()).toList();
hasChanges = true;
});
}),
_buildEditableDetail('Depends:', depends.join(', '), (value) {
setState(() {
depends = value.split(',').map((e) => e.trim()).toList();
hasChanges = true;
});
}),
_buildEditableDetail('Rtype:', rtype, (value) {
setState(() {
rtype = value;
hasChanges = true;
});
}),
_buildEditableDetail('Recur:', recur, (value) {
setState(() {
recur = value;
hasChanges = true;
});
}),
_buildDetail('UUID:', widget.task.uuid ?? '-'),
_buildDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPageUrgency}:',
widget.task.urgency.toString()),
widget.task.urgency?.toStringAsFixed(2) ?? '-'),
_buildDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPageEnd}:',
_buildDate(widget.task.end)),
Expand All @@ -136,6 +202,11 @@ class _TaskDetailsState extends State<TaskDetails> {
_buildDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPageModified}:',
_buildDate(widget.task.modified)),
_buildDetail(
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences}:',
annotations.isNotEmpty
? annotations.map((e) => e.description).join('\n')
: '-'),
],
),
),
Expand Down Expand Up @@ -183,7 +254,9 @@ class _TaskDetailsState extends State<TaskDetails> {
onTap: () async {
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: value != '-' ? DateTime.parse(value) : DateTime.now(),
initialDate: value != '-'
? DateTime.tryParse(value) ?? DateTime.now()
: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2101),
builder: (BuildContext context, Widget? child) {
Expand All @@ -196,8 +269,9 @@ class _TaskDetailsState extends State<TaskDetails> {
if (pickedDate != null) {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: TimeOfDay.fromDateTime(
value != '-' ? DateTime.parse(value) : DateTime.now()),
initialTime: TimeOfDay.fromDateTime(value != '-'
? DateTime.tryParse(value) ?? DateTime.now()
: DateTime.now()),
);
if (pickedTime != null) {
final DateTime fullDateTime = DateTime(
Expand All @@ -207,6 +281,9 @@ class _TaskDetailsState extends State<TaskDetails> {
pickedTime.hour,
pickedTime.minute);
onChanged(DateFormat('yyyy-MM-dd HH:mm:ss').format(fullDateTime));
} else {
// If only date is picked, use current time
onChanged(DateFormat('yyyy-MM-dd HH:mm:ss').format(pickedDate));
}
}
},
Expand Down Expand Up @@ -414,25 +491,36 @@ class _TaskDetailsState extends State<TaskDetails> {
}

Future<void> _saveTask() async {
await taskDatabase.saveEditedTaskInDB(
widget.task.uuid!,
description,
project,
status,
priority,
due,
);
// Update the TaskForC object with the new values
// final updatedTask = TaskForC(
// id: widget.task.id,
// description: description,
// project: project == '-' ? null : project,
// status: status,
// uuid: widget.task.uuid,
// urgency: widget
// .task.urgency, // Urgency is typically calculated, not edited directly
// priority: priority == '-' ? null : priority,
// due: due == '-' ? null : due,
// start: start == '-' ? null : start,
// end: widget
// .task.end, // 'end' is usually set when completed, not edited directly
// entry: widget.task.entry, // 'entry' is static
// wait: wait == '-' ? null : wait,
// modified: DateFormat('yyyy-MM-dd HH:mm:ss')
// .format(DateTime.now()), // Update modified time
// tags: tags.isEmpty ? null : tags,
// depends: depends.isEmpty ? null : depends,
// rtype: rtype == '-' ? null : rtype,
// recur: recur == '-' ? null : recur,
// annotations: annotations.isEmpty ? null : annotations,
// );

setState(() {
hasChanges = false;
});
modifyTaskOnTaskwarrior(
description,
project,
due,
priority,
status,
widget.task.uuid!,
);
// Assuming modifyTaskOnTaskwarrior takes the updated TaskForC object
// await modifyTaskOnTaskwarrior(updatedTask);
}
}

Expand Down
Loading