Feature/change progress colors (#6)
* Added Settings Actions * Created App Settings and Repo + Entity * Code cleanup Time Progress * Created App Settings Middleware * Has Progresses ad has Settings loaded * Created Load and Update Settings reducers * Added Settings store middleware to renamed store middleware * Load Default Settings if not Saved. Use Redux AppState to showprogress colors. Colors are not yet changeable. * Added ColorPicker for Done and Left Color Fixed Loading App Settings Bug * Fixed Version Number * Fixed Android App Logo * Extracted Color Settings into Widget * Fixed Home Settings Tab Layout and Color Settings Button now show Text in complementary color
This commit is contained in:
committed by
GitHub
parent
c580e45361
commit
b520d56d1a
44
lib/models/app_settings.dart
Normal file
44
lib/models/app_settings.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:time_progress_tracker/persistence/app_settings.dart';
|
||||
|
||||
@immutable
|
||||
class AppSettings {
|
||||
final Color doneColor;
|
||||
final Color leftColor;
|
||||
final Duration duration;
|
||||
|
||||
AppSettings({
|
||||
this.doneColor,
|
||||
this.leftColor,
|
||||
this.duration,
|
||||
});
|
||||
|
||||
factory AppSettings.defaults() =>
|
||||
AppSettings(doneColor: Colors.green, leftColor: Colors.red);
|
||||
|
||||
AppSettings copyWith({
|
||||
Color doneColor,
|
||||
Color leftColor,
|
||||
}) =>
|
||||
AppSettings(
|
||||
doneColor: doneColor ?? this.doneColor,
|
||||
leftColor: leftColor ?? this.leftColor);
|
||||
|
||||
@override
|
||||
int get hashCode => doneColor.hashCode ^ leftColor.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is AppSettings &&
|
||||
runtimeType == other.runtimeType &&
|
||||
doneColor == other.doneColor &&
|
||||
leftColor == other.leftColor;
|
||||
|
||||
AppSettingsEntity toEntity() =>
|
||||
AppSettingsEntity(doneColor.value, leftColor.value);
|
||||
|
||||
static AppSettings fromEntity(AppSettingsEntity entity) => AppSettings(
|
||||
doneColor: Color(entity.doneColorValue),
|
||||
leftColor: Color(entity.leftColorValue));
|
||||
}
|
@ -1,36 +1,40 @@
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:time_progress_tracker/models/app_settings.dart';
|
||||
import 'package:time_progress_tracker/models/time_progress.dart';
|
||||
|
||||
@immutable
|
||||
class AppState {
|
||||
final bool hasLoaded;
|
||||
final bool hasProgressesLoaded, hasSettingsLoaded;
|
||||
final List<TimeProgress> timeProgressList;
|
||||
final AppSettings appSettings;
|
||||
|
||||
AppState({
|
||||
this.hasLoaded = false,
|
||||
this.timeProgressList = const [],
|
||||
});
|
||||
AppState(
|
||||
{this.hasProgressesLoaded = false,
|
||||
this.hasSettingsLoaded = false,
|
||||
this.timeProgressList = const [],
|
||||
this.appSettings});
|
||||
|
||||
factory AppState.initial() => AppState(hasLoaded: false);
|
||||
factory AppState.initial() =>
|
||||
AppState(hasProgressesLoaded: false, appSettings: AppSettings.defaults());
|
||||
|
||||
AppState copyWith({
|
||||
bool hasLoaded,
|
||||
List<TimeProgress> timeProgressList,
|
||||
}) {
|
||||
return AppState(
|
||||
hasLoaded: hasLoaded ?? this.hasLoaded,
|
||||
hasProgressesLoaded: hasLoaded ?? this.hasProgressesLoaded,
|
||||
timeProgressList: timeProgressList ?? this.timeProgressList,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => hasLoaded.hashCode ^ timeProgressList.hashCode;
|
||||
int get hashCode => hasProgressesLoaded.hashCode ^ timeProgressList.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is AppState &&
|
||||
runtimeType == other.runtimeType &&
|
||||
hasLoaded == other.hasLoaded &&
|
||||
hasProgressesLoaded == other.hasProgressesLoaded &&
|
||||
timeProgressList == other.timeProgressList;
|
||||
}
|
||||
|
@ -20,26 +20,19 @@ class TimeProgress {
|
||||
}
|
||||
|
||||
TimeProgress copyWith(
|
||||
{String id, String name, DateTime startTime, DateTime endTime}) {
|
||||
return TimeProgress(
|
||||
name ?? this.name,
|
||||
startTime ?? this.startTime,
|
||||
endTime ?? this.endTime,
|
||||
id: id ?? this.id,
|
||||
);
|
||||
}
|
||||
{String id, String name, DateTime startTime, DateTime endTime}) =>
|
||||
TimeProgress(
|
||||
name ?? this.name,
|
||||
startTime ?? this.startTime,
|
||||
endTime ?? this.endTime,
|
||||
id: id ?? this.id,
|
||||
);
|
||||
|
||||
int daysBehind() {
|
||||
return DateTime.now().difference(startTime).inDays;
|
||||
}
|
||||
int daysBehind() => DateTime.now().difference(startTime).inDays;
|
||||
|
||||
int daysLeft() {
|
||||
return endTime.difference(DateTime.now()).inDays;
|
||||
}
|
||||
int daysLeft() => endTime.difference(DateTime.now()).inDays;
|
||||
|
||||
int allDays() {
|
||||
return endTime.difference(startTime).inDays;
|
||||
}
|
||||
int allDays() => endTime.difference(startTime).inDays;
|
||||
|
||||
double percentDone() {
|
||||
double percent = this.daysBehind() / (this.allDays() / 100) / 100;
|
||||
@ -48,15 +41,11 @@ class TimeProgress {
|
||||
return percent;
|
||||
}
|
||||
|
||||
bool hasStarted() {
|
||||
return DateTime.now().millisecondsSinceEpoch >
|
||||
startTime.millisecondsSinceEpoch;
|
||||
}
|
||||
bool hasStarted() =>
|
||||
DateTime.now().millisecondsSinceEpoch > startTime.millisecondsSinceEpoch;
|
||||
|
||||
bool hasEnded() {
|
||||
return DateTime.now().millisecondsSinceEpoch >
|
||||
endTime.millisecondsSinceEpoch;
|
||||
}
|
||||
bool hasEnded() =>
|
||||
DateTime.now().millisecondsSinceEpoch > endTime.millisecondsSinceEpoch;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
@ -73,9 +62,8 @@ class TimeProgress {
|
||||
endTime == other.endTime;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "TimeProgress{id: $id, name: $name, startTime: $startTime, endTime: $endTime}";
|
||||
}
|
||||
String toString() =>
|
||||
"TimeProgress{id: $id, name: $name, startTime: $startTime, endTime: $endTime}";
|
||||
|
||||
TimeProgressEntity toEntity() {
|
||||
if (!TimeProgress.isNameValid(name))
|
||||
@ -86,25 +74,17 @@ class TimeProgress {
|
||||
return TimeProgressEntity(id, name, startTime, endTime);
|
||||
}
|
||||
|
||||
static TimeProgress fromEntity(TimeProgressEntity entity) {
|
||||
return TimeProgress(
|
||||
entity.name,
|
||||
entity.startTime,
|
||||
entity.endTime,
|
||||
id: entity.id ?? Uuid().generateV4(),
|
||||
);
|
||||
}
|
||||
static TimeProgress fromEntity(TimeProgressEntity entity) =>
|
||||
TimeProgress(entity.name, entity.startTime, entity.endTime,
|
||||
id: entity.id ?? Uuid().generateV4());
|
||||
|
||||
static bool isValid(TimeProgress tp) {
|
||||
return TimeProgress.isNameValid(tp.name) &&
|
||||
TimeProgress.areTimesValid(tp.startTime, tp.endTime);
|
||||
}
|
||||
static bool isValid(TimeProgress tp) =>
|
||||
TimeProgress.isNameValid(tp.name) &&
|
||||
TimeProgress.areTimesValid(tp.startTime, tp.endTime);
|
||||
|
||||
static bool isNameValid(String name) {
|
||||
return name != null && name != "" && name.length > 2 && name.length < 21;
|
||||
}
|
||||
static bool isNameValid(String name) =>
|
||||
name != null && name != "" && name.length > 2 && name.length < 21;
|
||||
|
||||
static bool areTimesValid(DateTime startTime, DateTime endTime) {
|
||||
return startTime.isBefore(endTime);
|
||||
}
|
||||
static bool areTimesValid(DateTime startTime, DateTime endTime) =>
|
||||
startTime.isBefore(endTime);
|
||||
}
|
||||
|
Reference in New Issue
Block a user