Commit 0e93ebed authored by wonko's avatar wonko

storing and retrieving likes

parent e2cb40f2
......@@ -20,13 +20,10 @@ class Assets {
}
}
class LectureData extends Assets {
static final LectureData _instance = LectureData._internal();
factory LectureData() => _instance;
factory LectureData() => _instance;
Lectures _data;
......@@ -45,7 +42,7 @@ class LectureData extends Assets {
_dataFuture.then(_storeSchedule);
}
Future<Lectures> reload() async{
Future<Lectures> reload() async {
print('reloading');
DefaultCacheManager().emptyCache();
return getData();
......@@ -137,20 +134,61 @@ class Room {
}
class Lecture {
final String fs, name, teaser, time, room, id;
final String fs, name, teaser, time, room;
String _id;
final bool aufz;
bool like = false;
bool _like = false;
SharedPreferences prefs;
bool get like => _like;
set like(bool liked) {
_like = liked;
saveBoolPref(id, _like);
}
void readLike(String prefId, {bool valDefault = false}) {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
prefs.then((SharedPreferences p) {
if (p.containsKey(prefId)) {
_like = p.getBool(prefId);
} else {
_like = valDefault;
}
});
}
void saveBoolPref(String prefId, dynamic prefValue) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
print('saving $prefId $prefValue');
prefs.setBool(prefId, prefValue);
}
String get id => _id;
set id(String lectureID) {
if (lectureID != null && lectureID != "") {
_id = lectureID;
} else if (teaser != null) {
_id =
teaser.toLowerCase().replaceAll(new RegExp(r"\s+\b|\b\s|\s|\b"), "");
}
}
Lecture(final this.fs, final this.name, final this.teaser, final this.aufz,
final this.time, final this.room, final this.id);
final this.time, final this.room, lectureID) {
this.id = lectureID;
readLike(id);
}
factory Lecture.fromJSON(Map<String, dynamic> json) {
if (json != null) {
return Lecture(json['fs'], json['name'], json['teaser'], json['aufz'],
json['time'], json['room'], json['id']);
Lecture l = Lecture(json['fs'], json['name'], json['teaser'],
json['aufz'], json['time'], json['room'], json['id']);
return l;
} else {
return null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment