From 01764d005f85167278474bf1720546eff1899589 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Tue, 5 Sep 2023 21:23:46 +0800 Subject: [PATCH] Add new settings displayAd --- lib/components/gallery_info.dart | 8 +++++--- lib/components/thumbnail_gridview.dart | 7 +++++-- lib/globals.dart | 18 ++++++++++++++++++ lib/l10n/app_en.arb | 3 ++- lib/l10n/app_zh.arb | 3 ++- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/components/gallery_info.dart b/lib/components/gallery_info.dart index b86d541..4f6844b 100644 --- a/lib/components/gallery_info.dart +++ b/lib/components/gallery_info.dart @@ -18,13 +18,14 @@ class GalleryInfo extends StatefulWidget { class _GalleryInfo extends State with ThemeModeWidget { final ScrollController controller = ScrollController(); - void showNsfwChanged(dynamic _) { + void stateChanged(dynamic _) { setState(() {}); } @override void initState() { - listener.on("showNsfwChanged", showNsfwChanged); + listener.on("showNsfwChanged", stateChanged); + listener.on("displayAdChanged", stateChanged); super.initState(); } @@ -76,7 +77,8 @@ class _GalleryInfo extends State with ThemeModeWidget { @override void dispose() { controller.dispose(); - listener.removeEventListener("showNsfwChanged", showNsfwChanged); + listener.removeEventListener("showNsfwChanged", stateChanged); + listener.removeEventListener("displayAdChanged", stateChanged); super.dispose(); } } diff --git a/lib/components/thumbnail_gridview.dart b/lib/components/thumbnail_gridview.dart index 795c7fb..9f321e5 100644 --- a/lib/components/thumbnail_gridview.dart +++ b/lib/components/thumbnail_gridview.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import '../api/file.dart'; import '../api/gallery.dart'; +import '../globals.dart'; import 'thumbnail.dart'; class ThumbnailGridView extends StatelessWidget { @@ -12,11 +13,13 @@ class ThumbnailGridView extends StatelessWidget { @override Widget build(BuildContext context) { + final displayAd = prefs.getBool("displayAd") ?? false; + final npages = displayAd ? pages : pages.where((e) => !e.isAd).toList(); return SliverGrid.builder( gridDelegate: gridDelegate, - itemCount: pages.length, + itemCount: npages.length, itemBuilder: (context, index) { - final page = pages[index]!; + final page = npages[index]!; final fileId = files != null ? files!.files[page.token]!.first.id : null; return Container( diff --git a/lib/globals.dart b/lib/globals.dart index b71b1ab..9ba55b9 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -181,6 +181,24 @@ List> buildMoreVertSettings( title: Text(AppLocalizations.of(context)!.showNsfw), ), ))); + var displayAd = prefs.getBool("displayAd") ?? false; + list.add(PopupMenuItem( + child: StatefulBuilder( + builder: (context, setState) => CheckboxListTile( + controlAffinity: ListTileControlAffinity.leading, + value: displayAd, + onChanged: (value) { + if (value != null) { + prefs.setBool("displayAd", value); + listener.emit("displayAdChanged", null); + setState(() { + displayAd = value; + }); + } + }, + title: Text(AppLocalizations.of(context)!.displayAd), + ), + ))); return list; } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index d39601d..186635d 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -29,5 +29,6 @@ "colon": ":", "copyImage": "Copy image to clipboard", "copyImgUrl": "Copy image URL to clipboard", - "retry": "Retry" + "retry": "Retry", + "displayAd": "Display Ad pages" } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 6295968..13de168 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -29,5 +29,6 @@ "colon": ":", "copyImage": "复制图片到剪贴板", "copyImgUrl": "复制图片链接到剪贴板", - "retry": "重试" + "retry": "重试", + "displayAd": "显示广告页面" }