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
49
lib/persistence/app_settings.dart
Normal file
49
lib/persistence/app_settings.dart
Normal file
@ -0,0 +1,49 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:time_progress_tracker/models/app_settings.dart';
|
||||
|
||||
class AppSettingsRepository {
|
||||
static const String _key = "app_settings";
|
||||
final SharedPreferences prefs;
|
||||
final JsonCodec codec;
|
||||
|
||||
AppSettingsRepository(this.prefs, {this.codec = json});
|
||||
|
||||
Future<AppSettingsEntity> loadAppSettings() {
|
||||
final String jsonString = this.prefs.getString(_key);
|
||||
if (jsonString == null)
|
||||
return Future<AppSettingsEntity>.value(AppSettingsEntity.defaults());
|
||||
return Future<AppSettingsEntity>.value(
|
||||
AppSettingsEntity.fromJson(codec.decode(jsonString)));
|
||||
}
|
||||
|
||||
Future<bool> saveAppSettings(AppSettingsEntity appSettings) =>
|
||||
this.prefs.setString(_key, codec.encode(appSettings));
|
||||
}
|
||||
|
||||
class AppSettingsEntity {
|
||||
static const String _doneKey = "doneColorValue", _leftKey = "leftColorValue";
|
||||
final int doneColorValue, leftColorValue;
|
||||
|
||||
AppSettingsEntity(this.doneColorValue, this.leftColorValue);
|
||||
|
||||
factory AppSettingsEntity.defaults() => AppSettings.defaults().toEntity();
|
||||
|
||||
@override
|
||||
int get hashCode => doneColorValue.hashCode ^ leftColorValue.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is AppSettingsEntity &&
|
||||
runtimeType == other.runtimeType &&
|
||||
doneColorValue == other.doneColorValue &&
|
||||
leftColorValue == other.leftColorValue;
|
||||
|
||||
Map<String, Object> toJson() =>
|
||||
{_doneKey: doneColorValue, _leftKey: leftColorValue};
|
||||
|
||||
static AppSettingsEntity fromJson(Map<String, Object> json) =>
|
||||
AppSettingsEntity(json[_doneKey], json[_leftKey]);
|
||||
}
|
@ -2,8 +2,6 @@ import 'dart:convert';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:time_progress_tracker/persistence/time_progress_entity.dart';
|
||||
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
class TimeProgressRepository {
|
||||
static const String _key = "time_progress_repo";
|
||||
final SharedPreferences prefs;
|
||||
|
Reference in New Issue
Block a user