-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4eb70b6
commit 69d0004
Showing
11 changed files
with
402 additions
and
10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
lib/state_notifier/installed_themes_page/misskey_theme_codes_notifier.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,77 @@ | ||
import "package:json5/json5.dart"; | ||
import "package:miria/model/color_theme.dart"; | ||
import "package:miria/model/misskey_theme.dart"; | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
import "package:shared_preferences/shared_preferences.dart"; | ||
|
||
part "misskey_theme_codes_notifier.g.dart"; | ||
|
||
@riverpod | ||
class MisskeyThemeCodesNotifier extends _$MisskeyThemeCodesNotifier { | ||
@override | ||
List<String> build() { | ||
Future(_load); | ||
return []; | ||
} | ||
|
||
static const _key = "themes"; | ||
|
||
Future<void> _load() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
final themes = prefs.getStringList(_key); | ||
if (themes == null) { | ||
return; | ||
} | ||
state = themes; | ||
} | ||
|
||
Future<void> _save() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
await prefs.setStringList(_key, state); | ||
} | ||
|
||
Future<void> install(String code) async { | ||
state = [...state, code]; | ||
await _save(); | ||
} | ||
|
||
Future<void> uninstall(int index) async { | ||
state = [ | ||
...state.sublist(0, index), | ||
...state.sublist(index + 1), | ||
]; | ||
await _save(); | ||
} | ||
|
||
Future<void> import(List<String> codes) async { | ||
state = codes; | ||
await _save(); | ||
} | ||
} | ||
|
||
@riverpod | ||
List<MisskeyTheme?> misskeyThemes(MisskeyThemesRef ref) { | ||
final codes = ref.watch(misskeyThemeCodesNotifierProvider); | ||
return codes.map((code) { | ||
try { | ||
return MisskeyTheme.fromJson(json5Decode(code) as Map<String, dynamic>); | ||
} catch (_) { | ||
return null; | ||
} | ||
}).toList(); | ||
} | ||
|
||
@riverpod | ||
List<ColorTheme> installedColorThemes(InstalledColorThemesRef ref) { | ||
final themes = ref.watch(misskeyThemesProvider); | ||
return themes.nonNulls | ||
.map((theme) { | ||
try { | ||
return ColorTheme.misskey(theme); | ||
} catch (_) { | ||
return null; | ||
} | ||
}) | ||
.nonNulls | ||
.toList(); | ||
} |
59 changes: 59 additions & 0 deletions
59
lib/state_notifier/installed_themes_page/misskey_theme_codes_notifier.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
lib/state_notifier/note_create_page/note_create_state_notifier.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.