Ongoing online

This commit is contained in:
Sewmina
2022-03-21 19:43:49 +05:30
parent 211e1b70b4
commit ee678fcc88
10 changed files with 408 additions and 12 deletions

View File

@@ -4,8 +4,10 @@ import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tasktracker/Categories.dart';
import 'package:tasktracker/Projects.dart';
import 'package:tasktracker/Todo.dart';
@@ -169,8 +171,24 @@ class _MyHomePageState extends State<MyHomePage> {
}
});
LoadStats();
startLoadStatRefresher();
// User.progressDialog=progressDialog;
}
void startLoadStatRefresher() async{
int lastMinute = 0;
while(true){
if(DateTime.now().minute != lastMinute){
lastMinute = DateTime.now().minute;
LoadStats();
}
await Refresh();
await Future.delayed(Duration(seconds: 1));
}
}
void init(BuildContext context) async{
await Future.delayed(Duration(seconds: 1));
refreshSub = User.refreshStream.stream.listen((value) {
@@ -194,9 +212,35 @@ class _MyHomePageState extends State<MyHomePage> {
connectivitySub?.cancel();
refreshSub?.closeSteam();
}
String ongoingActName = "";
DateTime ongoingActStime=DateTime.now();
Future<void> Refresh() async{
final prefs = await SharedPreferences.getInstance();
if(prefs.containsKey('current_activity')){
List<String> data = [];
try{
data = prefs.getString('current_activity')!.split('<td>');
ongoingActName=data[0];
ongoingActStime = DateTime.parse(data[2]);
}catch(e){
ongoingActName = "";
}
}else{
ongoingActName = "";
}
setState(() {
});
}
void LoadStats() async {
// return;
// await User.refreshUserData();
await Refresh();
DateFormat dFormat = DateFormat("MM/dd");
Map<Category, int> catTimeMap = <Category, int>{};
Map<Category, int> catBriefMap = <Category, int>{};
@@ -430,6 +474,59 @@ class _MyHomePageState extends State<MyHomePage> {
),
)
: Container(),
//Ongoing activity card
(ongoingActName == "") ? Container():
Container(
padding: EdgeInsets.all(10),
child: Card(
color: Colors.white12,
elevation: 20,
shadowColor: Colors.green,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
SpinKitPouringHourGlass(color: Colors.amber),
SizedBox(width: 20,),
Flexible(child: Text("You are engaged in '$ongoingActName' since ${DateFormat("hh:mm").format(ongoingActStime)}.", style: TextStyle(fontSize: 19),textAlign: TextAlign.center,)),
],
),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child:Text(MinutesToTimeString(DateTime.now().difference(ongoingActStime).inMinutes))
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
InkWell(
onTap: (){
Dialogs.ongoing();
},
child: Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(10)
),
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8,horizontal: 15),
child:Text('Take Action')
)
)
),
],
),
],
)
],
),
)),
),
Container(
height: 350,
padding: EdgeInsets.all(10),
@@ -446,6 +543,7 @@ class _MyHomePageState extends State<MyHomePage> {
width: 10,
),
Text("Productivity", style: TextStyle(color: Colors.green, fontWeight: FontWeight.bold)),
],
),
Divider(),
@@ -484,6 +582,9 @@ class _MyHomePageState extends State<MyHomePage> {
yValueMapper: (ProductivityMapData sales, _) => sales.productivity,
dataLabelMapper: (ProductivityMapData sales, _) => sales.productivity.toStringAsFixed(1) + "%",
dataLabelSettings: DataLabelSettings(overflowMode: OverflowMode.hide, showZeroValue: false, isVisible: true),
onPointTap: (ChartPointDetails point){
showAlertDialog(context, productivityData[point.pointIndex!].day, "I'll show you detailed info about this day in future, When my master creates the feature");
},
color: Colors.green)
]),
),