Summary page done

This commit is contained in:
warlock
2022-03-02 09:24:26 +05:30
parent 8c7ea9b86e
commit 4576957b4c
16 changed files with 974 additions and 409 deletions

View File

@@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'main.dart';
@@ -6,15 +7,15 @@ import 'Data.dart';
import 'User.dart' as User;
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
class Activities extends StatefulWidget {
const Activities({Key? key}) : super(key: key);
@override
_ActivitiesState createState() => _ActivitiesState();
}
late ProgressDialog progressDialog;
class _ActivitiesState extends State<Activities> {
@override
void initState() {
@@ -26,9 +27,8 @@ class _ActivitiesState extends State<Activities> {
@override
Widget build(BuildContext context) {
progressDialog=ProgressDialog(context: context);
progressDialog = ProgressDialog(context: context);
return Scaffold(
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Navigator.of(context)
@@ -39,7 +39,7 @@ class _ActivitiesState extends State<Activities> {
icon: Icon(Icons.add)),
appBar: AppBar(
title: Row(
mainAxisSize: MainAxisSize.max,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(children: [
@@ -47,15 +47,29 @@ class _ActivitiesState extends State<Activities> {
SizedBox(width: 10),
Text('Activities')
]),
(selecting)?Row(children: [
InkWell(onTap: (){
DeleteSelectedTasks();
}, child: Icon(Icons.delete,size: 30,)),
SizedBox(width: 20,),
InkWell(onTap: (){setState(() {
selecting=false;
});}, child: Icon(Icons.close,size: 30),)
]) : Container(),
(selecting)
? Row(children: [
InkWell(
onTap: () {
DeleteSelectedTasks();
},
child: Icon(
Icons.delete,
size: 30,
)),
SizedBox(
width: 20,
),
InkWell(
onTap: () {
setState(() {
selecting = false;
});
},
child: Icon(Icons.close, size: 30),
)
])
: Container(),
],
)),
drawer: navDrawer(context, 2),
@@ -68,10 +82,14 @@ class _ActivitiesState extends State<Activities> {
}
void UpdateList() async {
try{progressDialog.show(max:100,msg: 'Loading Activities');}catch(e){}
try {
progressDialog.show(max: 100, msg: 'Loading Activities');
} catch (e) {}
await User.updateActList();
setState(() {});
try{progressDialog.update(value: 100);}catch(e){}
try {
progressDialog.update(value: 100);
} catch (e) {}
}
List<Widget> PrintTasks() {
@@ -79,19 +97,52 @@ class _ActivitiesState extends State<Activities> {
print('Priting cats : ' + User.taskTypes.length.toString());
String lastDate = "";
DateFormat dFormat = DateFormat("MM/dd");
Map<String, int> productivtyActs = <String, int>{};
Map<String, int> unproductivtyActs = <String, int>{};
Map<String, int> totalMinutes = <String, int>{};
for (var element in User.activities) {
String thisDate = dFormat.format(element.startTime);
if(thisDate != lastDate){
_tasks.add(DateSeperator(thisDate));
lastDate=thisDate;
int thisMinutes= element.endTime.difference(element.startTime).inMinutes;
if(totalMinutes.containsKey(thisDate)){
if((totalMinutes[thisDate]??0) < thisMinutes){
totalMinutes[thisDate] = thisMinutes;
}
}else{
totalMinutes.putIfAbsent(thisDate, () => thisMinutes);
}
if (element.taskType.cat?.productive ?? false) {
if (productivtyActs.containsKey(thisDate)) {
productivtyActs[thisDate] = (productivtyActs[thisDate]! + thisMinutes);
} else {
productivtyActs.putIfAbsent(thisDate, () => thisMinutes);
}
} else {
if (unproductivtyActs.containsKey(thisDate)) {
unproductivtyActs[thisDate] = (unproductivtyActs[thisDate]! + thisMinutes);
} else {
unproductivtyActs.putIfAbsent(thisDate, () => thisMinutes);
}
}
}
print(productivtyActs);
for (var element in User.activities) {
String thisDate = dFormat.format(element.startTime);
if (thisDate != lastDate) {
int prodActs = productivtyActs[thisDate] ?? 0;
int unProdActs = unproductivtyActs[thisDate] ?? 0;
_tasks.add(DateSeperator(thisDate, prodActs, unProdActs));
lastDate = thisDate;
}
String name = element.taskType.name;
if (element.taskType.cat == null) {
print('Got some null cat : ${element.taskType.name}');
} else {
Color color = HexColor.fromHex(element.taskType.cat?.color ?? '#000000');
Color color =
HexColor.fromHex(element.taskType.cat?.color ?? '#000000');
bool productive = element.taskType.cat?.productive ?? true;
Widget task = ActivityCard(context, name,element.startTime,element.endTime, productive, color,element);
Widget task = ActivityCard(context, name, element.startTime,
element.endTime, productive, color, element, totalMinutes[thisDate] ?? 0);
_tasks.add(task);
}
}
@@ -99,23 +150,65 @@ class _ActivitiesState extends State<Activities> {
return _tasks;
}
Widget DateSeperator(date){
Widget DateSeperator(date, prodActs, unprodActs) {
double prodPercentage = (prodActs / (prodActs + unprodActs)) * 100;
return Padding(
padding: const EdgeInsets.fromLTRB(10, 20, 10, 0),
child: Column(children: [
Row(children: [
Text(date,style: TextStyle(fontSize: 18),)
],)
],),
child: Column(
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
date,
style: TextStyle(fontSize: 18),
),
Row(children: [
Row(
children: [
Container(child:Align(child:Text(MinutesToTimeString(prodActs)), alignment: Alignment.center,),width: (prodPercentage) * 1.7, height: 25,decoration: BoxDecoration(color: Colors.green,borderRadius: BorderRadius.horizontal(left: Radius.circular(10))),),
Container(child:Align(child:Text(MinutesToTimeString(unprodActs)), alignment: Alignment.center,),width: (100-prodPercentage)* 1.7,height: 25,decoration: BoxDecoration(color: Colors.red,borderRadius: BorderRadius.horizontal(right: Radius.circular(10))),),
],
),
SizedBox(width: 10,),
Text(prodPercentage.toStringAsFixed(1) + "%",style: TextStyle(color: Colors.green, fontWeight: FontWeight.bold,fontSize: 20))
],)
// CustomPaint(
// painter: MyPlayerBar(100, prodPercentage.toInt(),
// background: Colors.green, fill: Colors.deepOrange),
// child: Container(
// alignment: Alignment.center,
// height: 25.0,
// width: 200,
// child: Text(
// "Productivity : ${prodPercentage.toStringAsFixed(1)}%",
// style: TextStyle(fontWeight: FontWeight.bold),),
//
// ),
// ),
],
)
],
),
);
}
bool selecting = false;
Widget ActivityCard(
BuildContext context, String name,DateTime sTime, DateTime eTime, bool productive, Color color, Activity activity) {
Widget ActivityCard(BuildContext context, String name, DateTime sTime,
DateTime eTime, bool productive, Color color, Activity activity,int totalMinutes) {
DateFormat dateFormat = DateFormat("HH:mm");
int thisMinutes = (activity.endTime.difference(activity.startTime).inMinutes);
int timePercentage = ((thisMinutes / totalMinutes) * 100).toInt();
// print("$thisMinutes / $totalMinutes");
bool containsMetadata = ((activity.metadata ?? 'null') != 'null') &&
((activity.metadata ?? '').isNotEmpty);
var _timeSpan = eTime.difference(sTime);
String timeSpan = ((_timeSpan.inHours > 0) ? _timeSpan.inHours.toString()+'h ' : '') + ((_timeSpan.inMinutes %60 > 0) ? (_timeSpan.inMinutes%60).toString()+'m ' : '');
String timeSpan =
((_timeSpan.inHours > 0) ? _timeSpan.inHours.toString() + 'h ' : '') +
((_timeSpan.inMinutes % 60 > 0)
? (_timeSpan.inMinutes % 60).toString() + 'm'
: '');
return Row(children: [
// Container(),
(selecting)
@@ -132,54 +225,84 @@ class _ActivitiesState extends State<Activities> {
Card(
// color: color,
elevation:20,
elevation: 20,
shadowColor: color,
child: InkWell(
onTap: () {
//Open Respective Category
if(selecting){
if (selecting) {
OnItemSelected(activity);
}
setState(() {
});
setState(() {});
},
onLongPress: () {
print('gonna delete');
selecting = !selecting;
selectedActivities = [activity];
setState(() {});
},
child: Container(
padding: EdgeInsets.all(10),
padding: EdgeInsets.all(15),
child: Column(
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(name + " ($timeSpan)",
style: TextStyle(color: Colors.white)),
Text(dateFormat.format(sTime) + " - " + dateFormat.format(eTime)),
Row(children: [
Text(name + " [$timeSpan]",
style: TextStyle( fontSize: 17)),
if (containsMetadata)
Icon(Icons.arrow_forward_outlined, size: 20,),
if (containsMetadata)
Text(activity.metadata ?? '',overflow: TextOverflow.clip,)
]),
// Icon(Icons.analytics, color: color, size: 20,),
Icon(Icons.circle,
color: (productive)
? Colors.green
: Colors.red)
]),
SizedBox(
height: 5,
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(dateFormat.format(sTime) +
" - " +
dateFormat.format(eTime)),
SizedBox(
width: 20,
),
Container(
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: (productive)
? Colors.green
: Colors.red),
child: Text(
activity.taskType.cat?.name ?? 'n/a'))
// Icon(Icons.circle,
// color: (productive)
// ? Colors.green
// : Colors.red)
])
],
)))),
Container(
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
height: 2,
color: color)
child:Row(children: [
Expanded(flex:timePercentage ,child: Container(color:color)),
Expanded(flex:100-timePercentage,child:Container())
],)),
]),
),
]);
}
void OnItemSelected(Activity activity){
void OnItemSelected(Activity activity) {
if (!selectedActivities.contains(activity)) {
selectedActivities.add(activity);
} else {
@@ -187,23 +310,25 @@ class _ActivitiesState extends State<Activities> {
}
}
void DeleteSelectedTasks() async{
progressDialog.show(max: 100, msg: 'Deleteing ${selectedActivities.length} Task Types');
void DeleteSelectedTasks() async {
progressDialog.show(
max: 100, msg: 'Deleteing ${selectedActivities.length} Activities');
selectedActivities.forEach((element) async {
await User.UserOperations.deleteActivity(element, bulk:true);
await User.UserOperations.deleteActivity(element, bulk: true);
});
await Future.delayed(Duration(seconds: 2));
await User.UserOperations.executeQueries();
await User.updateActList();
selectedActivities=[];
selecting=false;
selectedActivities = [];
selecting = false;
setState(() {
progressDialog.update(value: 100);
});
}
}
List<Activity> selectedActivities = [];