diff --git a/lib/constants.dart b/lib/constants.dart index d69342b8c..93923fbe8 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -14,6 +14,7 @@ const String kSharedPrefUrl = 'url'; const String kSharedPrefSecret = 'secret'; const String kSharedPrefEnableDarkMode = 'enable_dark_mode'; const String kSharedPrefEmailPayment = 'email_payment'; +const String kSharedPrefManualTimer = 'manual_timer'; const String kSharedPrefAppVersion = 'app_version'; const String kSharedPrefRequireAuthentication = 'require_authentication'; diff --git a/lib/data/models/task_model.dart b/lib/data/models/task_model.dart index 8221306d0..1153aaa54 100644 --- a/lib/data/models/task_model.dart +++ b/lib/data/models/task_model.dart @@ -69,7 +69,7 @@ class TaskTime { abstract class TaskEntity extends Object with BaseEntity, SelectableEntity implements Built { - factory TaskEntity() { + factory TaskEntity({bool isRunning = false}) { return _$TaskEntity._( id: --TaskEntity.counter, description: '', @@ -77,7 +77,9 @@ abstract class TaskEntity extends Object invoiceId: null, clientId: null, projectId: null, - timeLog: '[[${(DateTime.now().millisecondsSinceEpoch / 1000).floor()},0]]', + timeLog: isRunning + ? '[[${(DateTime.now().millisecondsSinceEpoch / 1000).floor()},0]]' + : '', isRunning: false, customValue1: '', customValue2: '', diff --git a/lib/redux/app/app_actions.dart b/lib/redux/app/app_actions.dart index a193f476e..d83fba6f1 100644 --- a/lib/redux/app/app_actions.dart +++ b/lib/redux/app/app_actions.dart @@ -27,11 +27,15 @@ class LoadStaticSuccess { class UserSettingsChanged implements PersistUI { UserSettingsChanged( - {this.enableDarkMode, this.emailPayment, this.requireAuthentication}); + {this.enableDarkMode, + this.emailPayment, + this.requireAuthentication, + this.manualTimer}); final bool enableDarkMode; final bool emailPayment; final bool requireAuthentication; + final bool manualTimer; } class LoadDataSuccess { diff --git a/lib/redux/auth/auth_middleware.dart b/lib/redux/auth/auth_middleware.dart index 9731139d7..9a6226c63 100644 --- a/lib/redux/auth/auth_middleware.dart +++ b/lib/redux/auth/auth_middleware.dart @@ -47,13 +47,15 @@ void _loadAuthLocal(Store store, dynamic action) async { final bool enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode) ?? false; final bool emailPayment = prefs.getBool(kSharedPrefEmailPayment) ?? false; + final bool manualTimer = prefs.getBool(kSharedPrefManualTimer) ?? false; final bool requireAuthentication = prefs.getBool(kSharedPrefRequireAuthentication) ?? false; store.dispatch(UserSettingsChanged( enableDarkMode: enableDarkMode, emailPayment: emailPayment, - requireAuthentication: requireAuthentication)); + requireAuthentication: requireAuthentication, + manualTimer: manualTimer)); } Middleware _createLoginInit() { diff --git a/lib/redux/ui/ui_state.dart b/lib/redux/ui/ui_state.dart index af7d0c673..5733eb854 100644 --- a/lib/redux/ui/ui_state.dart +++ b/lib/redux/ui/ui_state.dart @@ -27,15 +27,14 @@ abstract class UIState implements Built { enableDarkMode: enableDarkMode ?? false, requireAuthentication: requireAuthentication ?? false, emailPayment: false, + manualTimer: false, dashboardUIState: DashboardUIState(), productUIState: ProductUIState(), clientUIState: ClientUIState(), invoiceUIState: InvoiceUIState(), // STARTER: constructor - do not remove comment -taskUIState: TaskUIState(), - -projectUIState: ProjectUIState(), - + taskUIState: TaskUIState(), + projectUIState: ProjectUIState(), paymentUIState: PaymentUIState(company), quoteUIState: QuoteUIState(), ); @@ -53,6 +52,8 @@ projectUIState: ProjectUIState(), bool get emailPayment; + bool get manualTimer; + DashboardUIState get dashboardUIState; ProductUIState get productUIState; @@ -65,9 +66,9 @@ projectUIState: ProjectUIState(), String get filter; // STARTER: properties - do not remove comment -TaskUIState get taskUIState; + TaskUIState get taskUIState; -ProjectUIState get projectUIState; + ProjectUIState get projectUIState; PaymentUIState get paymentUIState; diff --git a/lib/redux/ui/ui_state.g.dart b/lib/redux/ui/ui_state.g.dart index 517fdffe8..b27f4cbbb 100644 --- a/lib/redux/ui/ui_state.g.dart +++ b/lib/redux/ui/ui_state.g.dart @@ -46,6 +46,9 @@ class _$UIStateSerializer implements StructuredSerializer { 'emailPayment', serializers.serialize(object.emailPayment, specifiedType: const FullType(bool)), + 'manualTimer', + serializers.serialize(object.manualTimer, + specifiedType: const FullType(bool)), 'dashboardUIState', serializers.serialize(object.dashboardUIState, specifiedType: const FullType(DashboardUIState)), @@ -112,6 +115,10 @@ class _$UIStateSerializer implements StructuredSerializer { result.emailPayment = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; break; + case 'manualTimer': + result.manualTimer = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + break; case 'dashboardUIState': result.dashboardUIState.replace(serializers.deserialize(value, specifiedType: const FullType(DashboardUIState)) @@ -168,6 +175,8 @@ class _$UIState extends UIState { @override final bool emailPayment; @override + final bool manualTimer; + @override final DashboardUIState dashboardUIState; @override final ProductUIState productUIState; @@ -195,6 +204,7 @@ class _$UIState extends UIState { this.enableDarkMode, this.requireAuthentication, this.emailPayment, + this.manualTimer, this.dashboardUIState, this.productUIState, this.clientUIState, @@ -220,6 +230,9 @@ class _$UIState extends UIState { if (emailPayment == null) { throw new BuiltValueNullFieldError('UIState', 'emailPayment'); } + if (manualTimer == null) { + throw new BuiltValueNullFieldError('UIState', 'manualTimer'); + } if (dashboardUIState == null) { throw new BuiltValueNullFieldError('UIState', 'dashboardUIState'); } @@ -262,6 +275,7 @@ class _$UIState extends UIState { enableDarkMode == other.enableDarkMode && requireAuthentication == other.requireAuthentication && emailPayment == other.emailPayment && + manualTimer == other.manualTimer && dashboardUIState == other.dashboardUIState && productUIState == other.productUIState && clientUIState == other.clientUIState && @@ -289,13 +303,18 @@ class _$UIState extends UIState { $jc( $jc( $jc( - 0, - selectedCompanyIndex + $jc( + 0, + selectedCompanyIndex + .hashCode), + currentRoute .hashCode), - currentRoute.hashCode), - enableDarkMode.hashCode), - requireAuthentication.hashCode), - emailPayment.hashCode), + enableDarkMode + .hashCode), + requireAuthentication + .hashCode), + emailPayment.hashCode), + manualTimer.hashCode), dashboardUIState.hashCode), productUIState.hashCode), clientUIState.hashCode), @@ -315,6 +334,7 @@ class _$UIState extends UIState { ..add('enableDarkMode', enableDarkMode) ..add('requireAuthentication', requireAuthentication) ..add('emailPayment', emailPayment) + ..add('manualTimer', manualTimer) ..add('dashboardUIState', dashboardUIState) ..add('productUIState', productUIState) ..add('clientUIState', clientUIState) @@ -354,6 +374,10 @@ class UIStateBuilder implements Builder { bool get emailPayment => _$this._emailPayment; set emailPayment(bool emailPayment) => _$this._emailPayment = emailPayment; + bool _manualTimer; + bool get manualTimer => _$this._manualTimer; + set manualTimer(bool manualTimer) => _$this._manualTimer = manualTimer; + DashboardUIStateBuilder _dashboardUIState; DashboardUIStateBuilder get dashboardUIState => _$this._dashboardUIState ??= new DashboardUIStateBuilder(); @@ -415,6 +439,7 @@ class UIStateBuilder implements Builder { _enableDarkMode = _$v.enableDarkMode; _requireAuthentication = _$v.requireAuthentication; _emailPayment = _$v.emailPayment; + _manualTimer = _$v.manualTimer; _dashboardUIState = _$v.dashboardUIState?.toBuilder(); _productUIState = _$v.productUIState?.toBuilder(); _clientUIState = _$v.clientUIState?.toBuilder(); @@ -453,6 +478,7 @@ class UIStateBuilder implements Builder { enableDarkMode: enableDarkMode, requireAuthentication: requireAuthentication, emailPayment: emailPayment, + manualTimer: manualTimer, dashboardUIState: dashboardUIState.build(), productUIState: productUIState.build(), clientUIState: clientUIState.build(), diff --git a/lib/ui/app/app_drawer.dart b/lib/ui/app/app_drawer.dart index d88da4623..29e70e3d2 100644 --- a/lib/ui/app/app_drawer.dart +++ b/lib/ui/app/app_drawer.dart @@ -235,7 +235,9 @@ class AppDrawer extends StatelessWidget { onTap: () => store.dispatch(ViewTaskList(context)), onCreateTap: () { navigator.pop(); - store.dispatch(EditTask(task: TaskEntity(), context: context)); + store.dispatch(EditTask( + task: TaskEntity(isRunning: !state.uiState.manualTimer), + context: context)); }, ), ListTile( diff --git a/lib/ui/client/view/client_view.dart b/lib/ui/client/view/client_view.dart index 36dfb667f..3521a142e 100644 --- a/lib/ui/client/view/client_view.dart +++ b/lib/ui/client/view/client_view.dart @@ -141,7 +141,9 @@ class _ClientViewState extends State onTap: () { Navigator.of(context).pop(); store.dispatch(EditTask( - task: TaskEntity() + task: TaskEntity( + isRunning: + !store.state.uiState.manualTimer) .rebuild((b) => b.clientId = client.id), context: context)); }, diff --git a/lib/ui/project/view/project_view_vm.dart b/lib/ui/project/view/project_view_vm.dart index 215cb2db1..717d4d861 100644 --- a/lib/ui/project/view/project_view_vm.dart +++ b/lib/ui/project/view/project_view_vm.dart @@ -83,9 +83,10 @@ class ProjectViewVM { }, onAddTaskPressed: (context) => store.dispatch(EditTask( context: context, - task: TaskEntity().rebuild((b) => b - ..projectId = project.id - ..clientId = project.clientId))), + task: TaskEntity(isRunning: !state.uiState.manualTimer) + .rebuild((b) => b + ..projectId = project.id + ..clientId = project.clientId))), onBackPressed: () { if (state.uiState.currentRoute.contains(ProjectScreen.route)) { store.dispatch(UpdateCurrentRoute(ProjectScreen.route)); diff --git a/lib/ui/task/task_screen.dart b/lib/ui/task/task_screen.dart index 7961745ce..92dd0f7fd 100644 --- a/lib/ui/task/task_screen.dart +++ b/lib/ui/task/task_screen.dart @@ -71,8 +71,10 @@ class TaskScreen extends StatelessWidget { //key: Key(TaskKeys.taskScreenFABKeyString), backgroundColor: Theme.of(context).primaryColorDark, onPressed: () { - store.dispatch( - EditTask(task: TaskEntity(), context: context)); + store.dispatch(EditTask( + task: TaskEntity( + isRunning: !store.state.uiState.manualTimer), + context: context)); }, child: Icon( Icons.add,