-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Hiding of Calendar Events (#282)
- Loading branch information
1 parent
bcbd3cc
commit 024d834
Showing
30 changed files
with
449 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
description: This file stores settings for Dart & Flutter DevTools. | ||
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states | ||
extensions: | ||
- drift: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'calendar_preferences.g.dart'; | ||
|
||
@JsonSerializable() | ||
class CalendarPreferences { | ||
final Map<String, int> colorPreferences; | ||
final Map<String, bool> visibilityPreferences; | ||
|
||
CalendarPreferences( | ||
this.colorPreferences, | ||
this.visibilityPreferences, | ||
); | ||
|
||
factory CalendarPreferences.fromJson(Map<String, dynamic> json) => | ||
_$CalendarPreferencesFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$CalendarPreferencesToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
lib/calendarComponent/services/calendar_color_service.dart
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
lib/calendarComponent/services/calendar_preference_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:campus_flutter/calendarComponent/model/calendar_preferences.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class CalendarPreferenceService { | ||
static const key = "calendar"; | ||
|
||
final SharedPreferences sharedPreferences; | ||
|
||
Map<String, int> colorPreferences = {}; | ||
Map<String, bool> visibilityPreferences = {}; | ||
|
||
CalendarPreferenceService(this.sharedPreferences); | ||
|
||
void saveColorPreference(String id, Color color) { | ||
colorPreferences[id] = color.value; | ||
try { | ||
sharedPreferences.setString( | ||
key, | ||
jsonEncode( | ||
CalendarPreferences( | ||
colorPreferences, | ||
visibilityPreferences, | ||
).toJson(), | ||
), | ||
); | ||
} catch (_) {} | ||
} | ||
|
||
Color? getColorPreference(String key) { | ||
if (colorPreferences.isEmpty) { | ||
loadPreferences(); | ||
} | ||
|
||
final color = colorPreferences[key]; | ||
return color != null ? Color(color) : null; | ||
} | ||
|
||
void saveVisibilityPreference(String id, bool isVisible) { | ||
visibilityPreferences[id] = isVisible; | ||
try { | ||
sharedPreferences.setString( | ||
key, | ||
jsonEncode( | ||
CalendarPreferences( | ||
colorPreferences, | ||
visibilityPreferences, | ||
).toJson(), | ||
), | ||
); | ||
} catch (_) {} | ||
} | ||
|
||
bool? getVisibilityPreference(String key) { | ||
if (visibilityPreferences.isEmpty) { | ||
loadPreferences(); | ||
} | ||
|
||
return visibilityPreferences[key]; | ||
} | ||
|
||
void loadPreferences() { | ||
try { | ||
final data = sharedPreferences.getString(key); | ||
if (data != null) { | ||
final json = jsonDecode(data); | ||
final calendarPreferences = CalendarPreferences.fromJson( | ||
json as Map<String, dynamic>, | ||
); | ||
colorPreferences = calendarPreferences.colorPreferences; | ||
visibilityPreferences = calendarPreferences.visibilityPreferences; | ||
} | ||
} catch (_) {} | ||
} | ||
|
||
void resetPreferences() { | ||
sharedPreferences.remove(key); | ||
} | ||
} |
Oops, something went wrong.