Syncing issue fixed, Bridge established to server
This commit is contained in:
@@ -36,7 +36,7 @@ class _ActivitiesState extends State<Activities> {
|
|||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
super.initState();
|
super.initState();
|
||||||
_focus.addListener(_onFocusChange);
|
_focus.addListener(_onFocusChange);
|
||||||
UpdateList();
|
//UpdateList();
|
||||||
//init(context);
|
//init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class _CategoriesState extends State<Categories> {
|
|||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
super.initState();
|
super.initState();
|
||||||
//init(context);
|
//init(context);
|
||||||
UpdateList();
|
// UpdateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override void dispose() {
|
@override void dispose() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@@ -137,6 +138,9 @@ class Settings{
|
|||||||
}else{
|
}else{
|
||||||
var uuid = Uuid();
|
var uuid = Uuid();
|
||||||
String _uuid = uuid.v4();
|
String _uuid = uuid.v4();
|
||||||
|
if(Platform.isAndroid){
|
||||||
|
|
||||||
|
}
|
||||||
await prefs.setString('uuid',_uuid);
|
await prefs.setString('uuid',_uuid);
|
||||||
return Future.value(_uuid);
|
return Future.value(_uuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class _TasksState extends State<Tasks> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
super.initState();
|
super.initState();
|
||||||
UpdateList();
|
// UpdateList();
|
||||||
// init(context);
|
// init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@@ -32,7 +31,7 @@ List<Project> projects = [];
|
|||||||
|
|
||||||
bool offline = true;
|
bool offline = true;
|
||||||
bool registered = false;
|
bool registered = false;
|
||||||
StreamController<bool> refreshStream = StreamController<bool>();
|
StreamController<bool> refreshStream = StreamController.broadcast();
|
||||||
Future<http.Response> login(String _username, String password) async {
|
Future<http.Response> login(String _username, String password) async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
@@ -64,28 +63,68 @@ Future<void> initUserData() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await refreshUserData();
|
await refreshUserData();
|
||||||
|
BuildBridgeToServer();
|
||||||
print('Initializing UserData...');
|
print('Initializing UserData...');
|
||||||
|
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
if (Platform.isAndroid || Platform.isIOS) {
|
// if (Platform.isAndroid || Platform.isIOS) {
|
||||||
Connectivity().onConnectivityChanged.listen((result) {
|
// Connectivity().onConnectivityChanged.listen((result) {
|
||||||
offline = (result == ConnectivityResult.none);
|
// offline = (result == ConnectivityResult.none);
|
||||||
if (!offline) {
|
// if (!offline) {
|
||||||
UserOperations.executeQueries();
|
// UserOperations.executeQueries();
|
||||||
refreshUserData();
|
// refreshUserData();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> BuildBridgeToServer() async{
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
|
||||||
|
try {
|
||||||
|
http.Response response = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/bridge.php'),
|
||||||
|
body: <String, String>{"username": username}));
|
||||||
|
|
||||||
|
print("bridge retreive (try): ${response.body}");
|
||||||
|
List<String> data = response.body.split(",");
|
||||||
|
print('Update :\nactivities_rev=${data[0]} tasks_rev=${data[1]} cats_rev=${data[2]} projects_rev=${data[3]}');
|
||||||
|
|
||||||
|
if(prefs.containsKey('rev')){
|
||||||
|
if(prefs.getString('rev') == response.body){
|
||||||
|
print('We are on the same page');
|
||||||
|
}else{
|
||||||
|
print('Gotta update');
|
||||||
|
await refreshUserData();
|
||||||
|
prefs.setString('rev',response.body);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
prefs.setString('rev', response.body);
|
||||||
|
await refreshUserData();
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
print("Error with bridge : $e");
|
||||||
|
}
|
||||||
|
|
||||||
|
await Future.delayed(Duration(seconds: 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool m_refreshing = false;
|
||||||
Future<void> refreshUserData() async {
|
Future<void> refreshUserData() async {
|
||||||
|
print('refreshing user data');
|
||||||
|
if(m_refreshing){
|
||||||
|
print('Called while refreshing. Return');return;
|
||||||
|
}
|
||||||
|
m_refreshing=true;
|
||||||
refreshStream.add(true);
|
refreshStream.add(true);
|
||||||
await updateCatsList();
|
await updateCatsList();
|
||||||
await updateTasksList();
|
await updateTasksList();
|
||||||
await updateActList();
|
await updateActList();
|
||||||
await updateProjectsList();
|
await updateProjectsList();
|
||||||
refreshStream.add(false);
|
refreshStream.add(false);
|
||||||
|
m_refreshing=false;
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
NotificationManager.RescheduleNotifications();
|
NotificationManager.RescheduleNotifications();
|
||||||
}
|
}
|
||||||
@@ -710,7 +749,7 @@ class UserOperations {
|
|||||||
Category.colProductive: productive
|
Category.colProductive: productive
|
||||||
};
|
};
|
||||||
await cacheDb.insert('Categories', data);
|
await cacheDb.insert('Categories', data);
|
||||||
await refreshUserData();
|
// await refreshUserData();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_category.php'), body: queryBody));
|
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_category.php'), body: queryBody));
|
||||||
@@ -749,7 +788,7 @@ class UserOperations {
|
|||||||
//update Cache
|
//update Cache
|
||||||
Map<String, Object> data = {TaskType.colId: username + name, Category.colName: name, Category.colCatId: username + category};
|
Map<String, Object> data = {TaskType.colId: username + name, Category.colName: name, Category.colCatId: username + category};
|
||||||
await cacheDb.insert('TaskTypes', data);
|
await cacheDb.insert('TaskTypes', data);
|
||||||
await refreshUserData();
|
//await refreshUserData();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_taskType.php'), body: queryBody));
|
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_taskType.php'), body: queryBody));
|
||||||
@@ -805,7 +844,7 @@ class UserOperations {
|
|||||||
Activity.colMetadata: metadata
|
Activity.colMetadata: metadata
|
||||||
};
|
};
|
||||||
await cacheDb.insert('Activities', data);
|
await cacheDb.insert('Activities', data);
|
||||||
await refreshUserData();
|
// await refreshUserData();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_activity.php'), body: queryBody));
|
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_activity.php'), body: queryBody));
|
||||||
@@ -859,7 +898,7 @@ class UserOperations {
|
|||||||
// Map<String, Object> data = {Activity.colType: username + type, Activity.colStartTime: dFormat.format(sTime), Activity.colEndTime: dFormat.format(eTime), Activity.colMetadata: metadata};
|
// Map<String, Object> data = {Activity.colType: username + type, Activity.colStartTime: dFormat.format(sTime), Activity.colEndTime: dFormat.format(eTime), Activity.colMetadata: metadata};
|
||||||
// String updateActQuery = "UPDATE Activities SET ${Activity.colType}=";
|
// String updateActQuery = "UPDATE Activities SET ${Activity.colType}=";
|
||||||
// await cacheDb.insert('Activities', data);
|
// await cacheDb.insert('Activities', data);
|
||||||
await refreshUserData();
|
// await refreshUserData();
|
||||||
} else {
|
} else {
|
||||||
// queries.add(Queries('edit_activity', jsonEncode(queryBody)));
|
// queries.add(Queries('edit_activity', jsonEncode(queryBody)));
|
||||||
try {
|
try {
|
||||||
@@ -899,7 +938,7 @@ class UserOperations {
|
|||||||
//update Cache
|
//update Cache
|
||||||
Map<String, Object> data = {Project.colName: username+name, Project.colCat: category, Project.colSteps: jsonEncode(steps), Project.colDeadline: deadline.toString()};
|
Map<String, Object> data = {Project.colName: username+name, Project.colCat: category, Project.colSteps: jsonEncode(steps), Project.colDeadline: deadline.toString()};
|
||||||
await cacheDb.insert('Projects', data);
|
await cacheDb.insert('Projects', data);
|
||||||
await refreshUserData();
|
//await refreshUserData();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_project.php'), body: queryBody));
|
http.Response queryResponse = (await http.post(Uri.parse('http://161.97.127.136/task_tracker/add_project.php'), body: queryBody));
|
||||||
@@ -935,7 +974,7 @@ class UserOperations {
|
|||||||
};
|
};
|
||||||
await cacheDb.rawDelete("DELETE FROM TaskTypes WHERE id='${username + name}'");
|
await cacheDb.rawDelete("DELETE FROM TaskTypes WHERE id='${username + name}'");
|
||||||
|
|
||||||
await refreshUserData();
|
// await refreshUserData();
|
||||||
//Add to server and refresh Cache
|
//Add to server and refresh Cache
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -972,7 +1011,7 @@ class UserOperations {
|
|||||||
Category.colName: name,
|
Category.colName: name,
|
||||||
};
|
};
|
||||||
await cacheDb.rawDelete("DELETE FROM Categories WHERE ${Category.colCatId}='${username + name}'");
|
await cacheDb.rawDelete("DELETE FROM Categories WHERE ${Category.colCatId}='${username + name}'");
|
||||||
await refreshUserData();
|
//await refreshUserData();
|
||||||
//Add to server and refresh Cache
|
//Add to server and refresh Cache
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -1011,7 +1050,7 @@ class UserOperations {
|
|||||||
print("delteQuery : $deleteQuery");
|
print("delteQuery : $deleteQuery");
|
||||||
|
|
||||||
await cacheDb.rawDelete(deleteQuery);
|
await cacheDb.rawDelete(deleteQuery);
|
||||||
await refreshUserData();
|
// await refreshUserData();
|
||||||
//Add to server and refresh Cache
|
//Add to server and refresh Cache
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -1060,8 +1099,9 @@ class UserOperations {
|
|||||||
print("Error while query $e");
|
print("Error while query $e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await refreshUserData();
|
//await refreshUserData();
|
||||||
} else {
|
} else {
|
||||||
|
await refreshUserData();
|
||||||
print('Trying to execute queries in no cahce mode, We dont do that here');
|
print('Trying to execute queries in no cahce mode, We dont do that here');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import 'Tasks.dart';
|
|||||||
import 'Activities.dart';
|
import 'Activities.dart';
|
||||||
import 'User.dart' as User;
|
import 'User.dart' as User;
|
||||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
||||||
import 'Dialogs.dart';
|
import 'Dialogs.dart';
|
||||||
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
|
||||||
showAlertDialog(BuildContext context, String title, String message) {
|
showAlertDialog(BuildContext context, String title, String message) {
|
||||||
@@ -148,6 +147,7 @@ class MyHomePage extends StatefulWidget {
|
|||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
var connectivitySub;
|
var connectivitySub;
|
||||||
|
var refreshSub;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -157,28 +157,33 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
print("Initializing refresh stream on main dart");
|
print("Initializing refresh stream on main dart");
|
||||||
|
|
||||||
connectivitySub=Connectivity().onConnectivityChanged.listen((result) {
|
// connectivitySub=Connectivity().onConnectivityChanged.listen((result) {
|
||||||
if (this.mounted) {
|
// if (this.mounted) {
|
||||||
setState(() {});
|
// setState(() {});
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
refreshSub = User.refreshStream.stream.listen((event) {
|
||||||
|
if(event==false){
|
||||||
|
//Update done, Lets go update data
|
||||||
|
LoadStats();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
LoadStats();
|
LoadStats();
|
||||||
// User.progressDialog=progressDialog;
|
// User.progressDialog=progressDialog;
|
||||||
}
|
}
|
||||||
var refreshSub;
|
|
||||||
void init(BuildContext context) async{
|
void init(BuildContext context) async{
|
||||||
await Future.delayed(Duration(seconds: 1));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
refreshSub = User.refreshStream.stream.listen((value) {
|
refreshSub = User.refreshStream.stream.listen((value) {
|
||||||
print("Streaming refresh : $value");
|
print("Streaming refresh : $value");
|
||||||
if(value){
|
if(value){
|
||||||
Dialogs.waiting("Syncing...");
|
// Dialogs.waiting("Syncing...");
|
||||||
print("Opening progress dialog");
|
print("Opening progress dialog");
|
||||||
}else{
|
}else{
|
||||||
Dialogs.hide();
|
// Dialogs.hide();
|
||||||
print("Closing progress dialog");
|
print("Closing progress dialog");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await User.refreshUserData();
|
//await User.refreshUserData();
|
||||||
|
|
||||||
}
|
}
|
||||||
DateTime? lastProductive = null;
|
DateTime? lastProductive = null;
|
||||||
@@ -187,6 +192,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
// TODO: implement dispose
|
// TODO: implement dispose
|
||||||
super.dispose();
|
super.dispose();
|
||||||
connectivitySub?.cancel();
|
connectivitySub?.cancel();
|
||||||
|
refreshSub?.closeSteam();
|
||||||
}
|
}
|
||||||
void LoadStats() async {
|
void LoadStats() async {
|
||||||
// return;
|
// return;
|
||||||
@@ -348,7 +354,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewActivity())).then((value) => {User.refreshUserData().then((va) => LoadStats())});
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewActivity()));
|
||||||
},
|
},
|
||||||
label: Text("New Activity"),
|
label: Text("New Activity"),
|
||||||
icon: Icon(Icons.add)),
|
icon: Icon(Icons.add)),
|
||||||
@@ -369,7 +375,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
: InkWell(
|
: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() async {
|
setState(() async {
|
||||||
await User.refreshUserData();
|
//await User.refreshUserData();
|
||||||
LoadStats();
|
LoadStats();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
49
pubspec.lock
49
pubspec.lock
@@ -50,48 +50,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.15.0"
|
version: "1.15.0"
|
||||||
connectivity_plus:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: connectivity_plus
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "2.2.1"
|
|
||||||
connectivity_plus_linux:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: connectivity_plus_linux
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.3.0"
|
|
||||||
connectivity_plus_macos:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: connectivity_plus_macos
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.2.1"
|
|
||||||
connectivity_plus_platform_interface:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: connectivity_plus_platform_interface
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.2.0"
|
|
||||||
connectivity_plus_web:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: connectivity_plus_web
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.2.0"
|
|
||||||
connectivity_plus_windows:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: connectivity_plus_windows
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.2.0"
|
|
||||||
crypto:
|
crypto:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -310,13 +268,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
nm:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: nm
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "0.5.0"
|
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ dependencies:
|
|||||||
|
|
||||||
flutter_switch: ^0.3.2
|
flutter_switch: ^0.3.2
|
||||||
sqflite_common_ffi: ^2.1.0+2
|
sqflite_common_ffi: ^2.1.0+2
|
||||||
connectivity_plus: ^2.2.1
|
|
||||||
flutter_spinkit: ^5.1.0
|
flutter_spinkit: ^5.1.0
|
||||||
flutter_local_notifications: ^9.3.3
|
flutter_local_notifications: ^9.3.3
|
||||||
rxdart: ^0.27.1
|
rxdart: ^0.27.1
|
||||||
|
|||||||
@@ -6,9 +6,6 @@
|
|||||||
|
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
|
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
|
|
||||||
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
connectivity_plus_windows
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||||
|
|||||||
Reference in New Issue
Block a user