Feature/bugfix 02 past time progresses (#5)

* Replaced startedTimeProgressSelectors with currentTimeProgressSelector.
* Added pastTimeProgressSelector.
* Fixed ProgressDetailScreen for PastProgresses.
* Fixed ProgressDashBoard for PastProgresses.
* Fixed AppDrawer for PastProgresses.
* Increased Version Number

Signed-off-by: Andreas Fahrecker <AndreasFahrecker@gmail.com>
This commit is contained in:
Andreas Fahrecker 2021-01-28 23:14:45 +01:00 committed by GitHub
parent 319f539b48
commit 58bc713227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 46 deletions

View File

@ -43,8 +43,8 @@ class ProgressDashboardScreen extends StatelessWidget {
} }
List<Widget> startedProgressesTileList = List<Widget>(); List<Widget> startedProgressesTileList = List<Widget>();
if (vm.hasStartedProgresses) { if (vm.hasCurrentProgresses) {
for (TimeProgress tp in vm.startedTimeProgreses) { for (TimeProgress tp in vm.currentTimeProgresses) {
startedProgressesTileList.add( startedProgressesTileList.add(
Card( Card(
child: ListTile( child: ListTile(
@ -87,44 +87,78 @@ class ProgressDashboardScreen extends StatelessWidget {
} }
} }
List<Widget> pastProgressesTileList = List<Widget>();
if (vm.pastTimeProgresses.length > 0) {
for (TimeProgress tp in vm.pastTimeProgresses) {
pastProgressesTileList.add(
Card(
child: ListTile(
title: Text(tp.name),
subtitle: Text(
"Ended ${DateTime.now().difference(tp.endTime).inDays} Days ago."),
onTap: () {
Navigator.pushNamed(context, ProgressDetailScreen.routeName,
arguments: ProgressDetailScreenArguments(tp.id));
},
)),
);
}
}
double dividerHeight = 1; double dividerHeight = 1;
double screenHeight = MediaQuery.of(context).size.height - double screenHeight = MediaQuery.of(context).size.height -
appBar.preferredSize.height - appBar.preferredSize.height -
24 - 24 -
dividerHeight; //Divider dividerHeight -
1; //Divider
List<Widget> columnChildren = List<Widget>(); List<Widget> columnChildren = List<Widget>();
int tpCount = int tpCount = vm.currentTimeProgresses.length +
vm.startedTimeProgreses.length + vm.futureTimeProgresses.length; vm.futureTimeProgresses.length +
if (vm.hasStartedProgresses) { vm.pastTimeProgresses.length;
if (vm.hasCurrentProgresses) {
columnChildren.add(Container( columnChildren.add(Container(
height: vm.hasFutureProgresses height:
? (screenHeight / tpCount) * vm.startedTimeProgreses.length (screenHeight / tpCount) * vm.currentTimeProgresses.length,
: screenHeight,
child: ListView( child: ListView(
padding: EdgeInsets.all(8), padding: EdgeInsets.all(8),
children: startedProgressesTileList, children: startedProgressesTileList,
), ),
)); ));
} }
if (vm.hasStartedProgresses && vm.hasFutureProgresses) { if (vm.hasCurrentProgresses && vm.hasFutureProgresses) {
columnChildren.add(Divider( columnChildren.add(Divider(
height: dividerHeight, height: dividerHeight,
)); ));
} }
if (vm.hasFutureProgresses) { if (vm.hasFutureProgresses) {
columnChildren.add(Container( columnChildren.add(Container(
height: vm.hasStartedProgresses height: (screenHeight / tpCount) * vm.futureTimeProgresses.length,
? (screenHeight / tpCount) * vm.futureTimeProgresses.length
: screenHeight,
child: ListView( child: ListView(
padding: EdgeInsets.all(8), padding: EdgeInsets.all(8),
children: futureProgressesTileList, children: futureProgressesTileList,
), ),
)); ));
} }
if ((vm.hasCurrentProgresses || vm.hasFutureProgresses) &&
vm.pastTimeProgresses.length > 0) {
columnChildren.add(Divider(
height: dividerHeight,
));
}
if (vm.pastTimeProgresses.length > 0) {
columnChildren.add(Container(
height: (screenHeight / tpCount) * vm.pastTimeProgresses.length,
child: ListView(
padding: EdgeInsets.all(8),
children: pastProgressesTileList,
),
));
}
if (!vm.hasStartedProgresses && !vm.hasFutureProgresses) { if (!vm.hasCurrentProgresses &&
!vm.hasFutureProgresses &&
vm.pastTimeProgresses.length < 1) {
columnChildren.add(Container( columnChildren.add(Container(
margin: EdgeInsets.all(16), margin: EdgeInsets.all(16),
child: Center( child: Center(
@ -151,30 +185,31 @@ class ProgressDashboardScreen extends StatelessWidget {
} }
class _ViewModel { class _ViewModel {
final List<TimeProgress> startedTimeProgreses; final List<TimeProgress> currentTimeProgresses;
final bool hasStartedProgresses; final bool hasCurrentProgresses;
final List<TimeProgress> futureTimeProgresses; final List<TimeProgress> futureTimeProgresses;
final bool hasFutureProgresses; final bool hasFutureProgresses;
final List<TimeProgress> pastTimeProgresses;
final bool hasLoaded; final bool hasLoaded;
_ViewModel({ _ViewModel({
@required this.startedTimeProgreses, @required this.currentTimeProgresses,
@required this.hasStartedProgresses, @required this.hasCurrentProgresses,
@required this.futureTimeProgresses, @required this.futureTimeProgresses,
@required this.hasFutureProgresses, @required this.hasFutureProgresses,
@required this.pastTimeProgresses,
@required this.hasLoaded, @required this.hasLoaded,
}); });
static _ViewModel fromStore(Store<AppState> store) { static _ViewModel fromStore(Store<AppState> store) {
List<TimeProgress> startedTPList = List<TimeProgress> currentTPList = currentTimeProgressSelector(store.state);
startedTimeProgressesSelector(store.state); List<TimeProgress> futureTPList = futureTimeProgressesSelector(store.state);
List<TimeProgress> furtureTPList =
futureTimeProgressesSelector(store.state);
return _ViewModel( return _ViewModel(
startedTimeProgreses: startedTPList, currentTimeProgresses: currentTPList,
hasStartedProgresses: startedTPList.length > 0, hasCurrentProgresses: currentTPList.length > 0,
futureTimeProgresses: furtureTPList, futureTimeProgresses: futureTPList,
hasFutureProgresses: furtureTPList.length > 0, hasFutureProgresses: futureTPList.length > 0,
pastTimeProgresses: pastTimeProgressesSelector(store.state),
hasLoaded: store.state.hasLoaded, hasLoaded: store.state.hasLoaded,
); );
} }

View File

@ -179,7 +179,7 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
: "The Name of the Time Progress has to be set.", : "The Name of the Time Progress has to be set.",
), ),
) )
: vm.hasProgressStarted : (vm.hasProgressStarted && !vm.hasEnded)
? FittedBox( ? FittedBox(
fit: BoxFit.fitWidth, fit: BoxFit.fitWidth,
child: Text( child: Text(
@ -205,7 +205,7 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
), ),
), ),
), ),
vm.hasProgressStarted (vm.hasProgressStarted && !vm.hasEnded)
? Expanded( ? Expanded(
flex: 2, flex: 2,
child: ProgressDetailCircularPercent( child: ProgressDetailCircularPercent(
@ -216,10 +216,13 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
) )
: Expanded( : Expanded(
flex: 2, flex: 2,
child: Text( child: !vm.hasEnded
"Starts in ${vm.timeProgress.startTime.difference(DateTime.now()).inDays} Days."), ? Text(
"Starts in ${vm.timeProgress.startTime.difference(DateTime.now()).inDays} Days.")
: Text(
"Ended ${DateTime.now().difference(vm.timeProgress.endTime).inDays} Days ago."),
), ),
vm.hasProgressStarted (vm.hasProgressStarted && !vm.hasEnded)
? Expanded( ? Expanded(
flex: 1, flex: 1,
child: ProgressDetailLinearPercent( child: ProgressDetailLinearPercent(
@ -278,18 +281,21 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
class _ViewModel { class _ViewModel {
final TimeProgress timeProgress; final TimeProgress timeProgress;
final bool hasProgressStarted; final bool hasProgressStarted;
final bool hasEnded;
_ViewModel({ _ViewModel({
@required this.timeProgress, @required this.timeProgress,
@required this.hasProgressStarted, @required this.hasProgressStarted,
@required this.hasEnded,
}); });
static _ViewModel fromStoreAndArg( static _ViewModel fromStoreAndArg(
Store<AppState> store, ProgressDetailScreenArguments args) { Store<AppState> store, ProgressDetailScreenArguments args) {
int currentTime = DateTime.now().millisecondsSinceEpoch;
TimeProgress tp = timeProgressByIdSelector(store.state, args.id); TimeProgress tp = timeProgressByIdSelector(store.state, args.id);
return _ViewModel( return _ViewModel(
timeProgress: tp, timeProgress: tp,
hasProgressStarted: DateTime.now().millisecondsSinceEpoch > hasProgressStarted: currentTime > tp.startTime.millisecondsSinceEpoch,
tp.startTime.millisecondsSinceEpoch); hasEnded: tp.endTime.millisecondsSinceEpoch < currentTime);
} }
} }

View File

@ -4,12 +4,14 @@ import 'package:time_progress_tracker/models/time_progress.dart';
List<TimeProgress> timeProgressListSelector(AppState state) => List<TimeProgress> timeProgressListSelector(AppState state) =>
state.timeProgressList; state.timeProgressList;
List<TimeProgress> startedTimeProgressesSelector(AppState state) => List<TimeProgress> currentTimeProgressSelector(AppState state) {
state.timeProgressList int currentTime = DateTime.now().millisecondsSinceEpoch;
.where((timeProgress) => return state.timeProgressList
DateTime.now().millisecondsSinceEpoch >= .where((tp) =>
timeProgress.startTime.millisecondsSinceEpoch) currentTime >= tp.startTime.millisecondsSinceEpoch &&
.toList(); tp.endTime.millisecondsSinceEpoch >= currentTime)
.toList();
}
List<TimeProgress> futureTimeProgressesSelector(AppState state) => List<TimeProgress> futureTimeProgressesSelector(AppState state) =>
state.timeProgressList state.timeProgressList
@ -18,6 +20,13 @@ List<TimeProgress> futureTimeProgressesSelector(AppState state) =>
timeProgress.startTime.millisecondsSinceEpoch) timeProgress.startTime.millisecondsSinceEpoch)
.toList(); .toList();
List<TimeProgress> pastTimeProgressesSelector(AppState state) =>
state.timeProgressList
.where((tp) =>
tp.endTime.millisecondsSinceEpoch <
DateTime.now().millisecondsSinceEpoch)
.toList();
TimeProgress timeProgressByIdSelector(AppState state, String id) { TimeProgress timeProgressByIdSelector(AppState state, String id) {
if (state.timeProgressList.length < 1) return null; if (state.timeProgressList.length < 1) return null;
return state.timeProgressList return state.timeProgressList

View File

@ -49,8 +49,8 @@ class AppDrawer extends StatelessWidget {
}, },
), ),
)); ));
if (vm.startedTimeProgresses.length > 0) { if (vm.currentTimeProgresses.length > 0) {
for (TimeProgress tp in vm.startedTimeProgresses) { for (TimeProgress tp in vm.currentTimeProgresses) {
drawerTileList.add(ListTile( drawerTileList.add(ListTile(
title: Text(tp.name), title: Text(tp.name),
trailing: CircularPercentIndicator( trailing: CircularPercentIndicator(
@ -73,7 +73,7 @@ class AppDrawer extends StatelessWidget {
); );
}, },
)); ));
if (vm.startedTimeProgresses.last != tp) { if (vm.currentTimeProgresses.last != tp) {
drawerTileList.add(Divider( drawerTileList.add(Divider(
color: Colors.black12, color: Colors.black12,
)); ));
@ -110,17 +110,17 @@ class AppDrawer extends StatelessWidget {
} }
class _ViewModel { class _ViewModel {
final List<TimeProgress> startedTimeProgresses; final List<TimeProgress> currentTimeProgresses;
final bool hasLoaded; final bool hasLoaded;
_ViewModel({ _ViewModel({
@required this.startedTimeProgresses, @required this.currentTimeProgresses,
@required this.hasLoaded, @required this.hasLoaded,
}); });
static _ViewModel fromStore(Store<AppState> store) { static _ViewModel fromStore(Store<AppState> store) {
return _ViewModel( return _ViewModel(
startedTimeProgresses: startedTimeProgressesSelector(store.state), currentTimeProgresses: currentTimeProgressSelector(store.state),
hasLoaded: store.state.hasLoaded, hasLoaded: store.state.hasLoaded,
); );
} }

View File

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.0.3+3 version: 0.0.4+4
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"