Skip to content

Commit

Permalink
Feat: NSFW toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Aug 23, 2023
1 parent f4222f0 commit 0dab731
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/pages/extension_repo/controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:get/get.dart';
import 'package:miru_app/utils/miru_storage.dart';

Expand Down Expand Up @@ -37,10 +38,14 @@ class ExtensionRepoPageController extends GetxController {
final res = await dio.get<String>(
'${MiruStorage.getSetting(SettingKey.miruRepoUrl)}/index.json');
extensions = jsonDecode(res.data!);
if (!MiruStorage.getSetting(SettingKey.enableNSFW)) {
extensions.removeWhere((element) => element['nsfw'] == "true");
}
extensionsTemp.clear();
extensionsTemp.addAll(extensions);
} catch (e) {
isError.value = true;
debugPrint(e.toString());
} finally {
isLoading.value = false;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/search/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:miru_app/utils/extension_runtime.dart';
import 'package:miru_app/utils/miru_storage.dart';

class SearchPageController extends GetxController {
Rx<ExtensionType?> cuurentExtensionType = Rx(null);
Expand All @@ -28,6 +29,9 @@ class SearchPageController extends GetxController {
if (type != null) {
exts.removeWhere((element) => element.extension.type != type);
}
if (!MiruStorage.getSetting(SettingKey.enableNSFW)) {
exts.removeWhere((element) => element.extension.nsfw);
}
searchResultList.clear();
for (var element in exts) {
searchResultList.add(SearchResult(runitme: element));
Expand Down
15 changes: 15 additions & 0 deletions lib/pages/settings/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ class _SettingsPageState extends State<SettingsPage> {
},
),
const SizedBox(height: 8),
SettingsSwitchTile(
icon: const PlatformWidget(
androidWidget: Icon(Icons.warning_amber_rounded),
desktopWidget: Icon(fluent.FluentIcons.warning, size: 24),
),
title: 'settings.nsfw'.i18n,
buildSubtitle: () => "settings.nsfw-subtitle".i18n,
buildValue: () {
return MiruStorage.getSetting(SettingKey.enableNSFW);
},
onChanged: (value) {
MiruStorage.setSetting(SettingKey.enableNSFW, value);
},
),
const SizedBox(height: 8),
SettingsRadiosTile(
icon: const PlatformWidget(
androidWidget: Icon(Icons.color_lens),
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/miru_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MiruStorage {
await _initSetting(SettingKey.language, 'en');
await _initSetting(SettingKey.novelFontSize, 18.0);
await _initSetting(SettingKey.theme, 'system');
await _initSetting(SettingKey.enableNSFW, false);
}

static _initSetting(String key, dynamic value) async {
Expand All @@ -58,4 +59,5 @@ class SettingKey {
static String autoCheckUpdate = 'AutoCheckUpdate';
static String language = 'Language';
static String novelFontSize = 'NovelFontSize';
static String enableNSFW = 'EnableNSFW';
}

0 comments on commit 0dab731

Please sign in to comment.