Renamed all Timer named things to TimeProgress

Signed-off-by: Andreas Fahrecker <AndreasFahrecker@gmail.com>
This commit is contained in:
Andreas Fahrecker
2020-10-16 14:25:15 +02:00
parent 7f6eec43de
commit 976fbec455
16 changed files with 198 additions and 188 deletions

View File

@ -1,9 +1,9 @@
class TimerEntity {
class TimeProgressEntity {
final String id;
final DateTime startTime;
final DateTime endTime;
TimerEntity(this.id, this.startTime, this.endTime);
TimeProgressEntity(this.id, this.startTime, this.endTime);
@override
int get hashCode => id.hashCode ^ startTime.hashCode ^ endTime.hashCode;
@ -11,7 +11,7 @@ class TimerEntity {
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is TimerEntity &&
other is TimeProgressEntity &&
runtimeType == other.runtimeType &&
id == other.id &&
startTime == other.startTime &&
@ -25,12 +25,12 @@ class TimerEntity {
};
}
static TimerEntity fromJson(Map<String, Object> json) {
static TimeProgressEntity fromJson(Map<String, Object> json) {
final String id = json["id"] as String;
final DateTime startTime =
DateTime.fromMillisecondsSinceEpoch(json["startTime"] as int);
final DateTime endTime =
DateTime.fromMillisecondsSinceEpoch(json["endTime"] as int);
return TimerEntity(id, startTime, endTime);
return TimeProgressEntity(id, startTime, endTime);
}
}

View File

@ -0,0 +1,27 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:time_progress_calculator/persistence/time_progress_entity.dart';
class TimeProgressRepository {
static const String _key = "time_progress_repo";
final SharedPreferences prefs;
final JsonCodec codec;
TimeProgressRepository(this.prefs, {this.codec = json});
Future<List<TimeProgressEntity>> loadTimeProgressList() {
final String jsonString = this.prefs.getString(_key);
return codec
.decode(jsonString)["timers"]
.cast<Map<String, Object>>()
.map<TimeProgressEntity>(TimeProgressEntity.fromJson)
.toList(growable: false);
}
Future<bool> saveTimeProgressList(List<TimeProgressEntity> timeProgressList) {
final String jsonString = codec
.encode({"timers": timeProgressList.map((timer) => timer.toJson()).toList()});
return this.prefs.setString(_key, jsonString);
}
}

View File

@ -1,27 +0,0 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:time_progress_calculator/persistence/timer_entity.dart';
class TimersRepository {
static const String _key = "timers_repo";
final SharedPreferences prefs;
final JsonCodec codec;
TimersRepository(this.prefs, {this.codec = json});
Future<List<TimerEntity>> loadTimers() {
final String jsonString = this.prefs.getString(_key);
return codec
.decode(jsonString)["timers"]
.cast<Map<String, Object>>()
.map<TimerEntity>(TimerEntity.fromJson)
.toList(growable: false);
}
Future<bool> saveTimers(List<TimerEntity> timers) {
final String jsonString = codec
.encode({"timers": timers.map((timer) => timer.toJson()).toList()});
return this.prefs.setString(_key, jsonString);
}
}