Skip to content

Commit 90f56ba

Browse files
committed
feat: hide private media
1 parent 1f132e6 commit 90f56ba

File tree

8 files changed

+97
-164
lines changed

8 files changed

+97
-164
lines changed

lib/Adaptor/Media/MediaAdaptor.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
77
import '../../Animation/ScaleAnimation.dart';
88
import '../../DataClass/Media.dart';
99
import '../../Functions/Function.dart';
10+
import '../../Preferences/PrefManager.dart';
11+
import '../../Preferences/Preferences.dart';
1012
import '../../Screens/Info/MediaScreen.dart';
1113
import '../../Widgets/ScrollConfig.dart';
1214
import 'MediaLargeViewHolder.dart';
@@ -93,6 +95,12 @@ class MediaGridState extends State<MediaAdaptor> {
9395
duration: const Duration(milliseconds: 200),
9496
child: GestureDetector(
9597
onTap: () => _handleMediaTap(index, _mediaList[index], tag),
98+
onLongPress: () {
99+
snackString('Added to hidden');
100+
var removeList = List<int>.from(PrefManager.getVal(PrefName.malRemoveList));
101+
removeList.add(_mediaList[index].id);
102+
PrefManager.setVal(PrefName.malRemoveList, removeList);
103+
},
96104
child: child,
97105
),
98106
);

lib/Adaptor/Settings/SettingsItem.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@ class SettingSwitchItem extends StatefulWidget {
6868
}
6969

7070
class SettingSwitchItemState extends State<SettingSwitchItem> {
71+
late bool _isChecked; // Local state for the switch
7172
bool _isHovered = false;
7273

74+
@override
75+
void initState() {
76+
super.initState();
77+
_isChecked = widget.setting.isChecked; // Initialize local state
78+
}
79+
7380
@override
7481
Widget build(BuildContext context) {
7582
if (!widget.setting.isVisible) return const SizedBox.shrink();
@@ -78,7 +85,11 @@ class SettingSwitchItemState extends State<SettingSwitchItem> {
7885
onEnter: (_) => setState(() => _isHovered = true),
7986
onExit: (_) => setState(() => _isHovered = false),
8087
child: GestureDetector(
81-
onTap: () => widget.setting.onSwitchChange!(!widget.setting.isChecked),
88+
onTap: () {
89+
final newValue = !_isChecked;
90+
setState(() => _isChecked = newValue);
91+
widget.setting.onSwitchChange?.call(newValue);
92+
},
8293
onLongPress: widget.setting.onLongClick,
8394
child: AnimatedContainer(
8495
duration: const Duration(milliseconds: 200),
@@ -113,8 +124,11 @@ class SettingSwitchItemState extends State<SettingSwitchItem> {
113124
GestureDetector(
114125
behavior: HitTestBehavior.translucent,
115126
child: Switch(
116-
value: widget.setting.isChecked,
117-
onChanged: widget.setting.onSwitchChange,
127+
value: _isChecked, // Use local state
128+
onChanged: (value) {
129+
setState(() => _isChecked = value); // Update local state
130+
widget.setting.onSwitchChange?.call(value); // Trigger callback
131+
},
118132
),
119133
),
120134
],

lib/Preferences/Preferences.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ class PrefName {
4343
'Dropped Manga': false,
4444
});
4545
static const Pref<List<int>> anilistRemoveList =
46-
Pref(Location.General, 'removeList', []);
46+
Pref(Location.General, 'anilistRemoveList', []);
4747
static const Pref<List<int>> malRemoveList =
48-
Pref(Location.General, 'removeList', []);
48+
Pref(Location.General, 'malRemoveList', []);
49+
static const Pref<bool> anilistHidePrivate =
50+
Pref(Location.General, 'anilistHidePrivate', false);
51+
4952
//anime page
5053
static const Pref<Map<String, bool>> anilistAnimeLayout =
5154
Pref(Location.General, 'animeLayoutOrder', {

lib/Screens/Home/HomeScreen.dart

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -194,123 +194,6 @@ class HomeScreenState extends State<HomeScreen> {
194194
);
195195
}
196196

197-
void contactPage(BuildContext context) {
198-
var theme = Theme.of(context).colorScheme;
199-
var t = CustomBottomDialog(
200-
title: 'Contact Us',
201-
viewList: [
202-
Padding(
203-
padding: const EdgeInsets.all(16.0),
204-
child: Column(
205-
crossAxisAlignment: CrossAxisAlignment.start,
206-
children: [
207-
Text(
208-
'Name',
209-
style: TextStyle(
210-
fontWeight: FontWeight.bold,
211-
color: theme.onPrimaryContainer,
212-
fontFamily: 'Poppins',
213-
),
214-
),
215-
const SizedBox(height: 8.0),
216-
TextField(
217-
decoration: InputDecoration(
218-
hintText: 'Enter your name',
219-
hintStyle: const TextStyle(
220-
fontWeight: FontWeight.w600,
221-
fontFamily: 'Poppins',
222-
),
223-
border: OutlineInputBorder(
224-
borderRadius: BorderRadius.circular(16.0),
225-
),
226-
prefixIcon: const Icon(Icons.person),
227-
),
228-
),
229-
const SizedBox(height: 16.0),
230-
Text(
231-
'Email',
232-
style: TextStyle(
233-
fontWeight: FontWeight.bold,
234-
color: theme.onPrimaryContainer,
235-
),
236-
),
237-
const SizedBox(height: 8.0),
238-
TextField(
239-
decoration: InputDecoration(
240-
hintText: 'Enter your email',
241-
hintStyle: const TextStyle(
242-
fontWeight: FontWeight.w600,
243-
fontFamily: 'Poppins',
244-
),
245-
border: OutlineInputBorder(
246-
borderRadius: BorderRadius.circular(16.0),
247-
),
248-
prefixIcon: const Icon(Icons.email),
249-
),
250-
),
251-
const SizedBox(height: 16.0),
252-
Text(
253-
'Message',
254-
style: TextStyle(
255-
fontWeight: FontWeight.bold,
256-
color: theme.onPrimaryContainer,
257-
),
258-
),
259-
const SizedBox(height: 8.0),
260-
TextField(
261-
maxLines: 4,
262-
decoration: InputDecoration(
263-
hintText: 'Write your message here...',
264-
hintStyle: const TextStyle(
265-
fontWeight: FontWeight.w600,
266-
fontFamily: 'Poppins',
267-
),
268-
border: OutlineInputBorder(
269-
borderRadius: BorderRadius.circular(16.0),
270-
),
271-
//prefixIcon: const Icon(Icons.message),
272-
),
273-
),
274-
const SizedBox(height: 24.0),
275-
Center(
276-
child: ElevatedButton.icon(
277-
onPressed: () {},
278-
icon: const Padding(
279-
padding: EdgeInsets.only(left: 6.0),
280-
child: Icon(Icons.send),
281-
),
282-
iconAlignment: IconAlignment.end,
283-
label: Text(
284-
'Submit',
285-
style: TextStyle(
286-
fontFamily: 'Poppins',
287-
color: theme.onPrimaryContainer,
288-
fontWeight: FontWeight.bold,
289-
),
290-
),
291-
style: ElevatedButton.styleFrom(
292-
backgroundColor: theme.primaryContainer,
293-
padding: const EdgeInsets.only(
294-
top: 26,
295-
bottom: 26,
296-
left: 24,
297-
right: 42,
298-
),
299-
shape: RoundedRectangleBorder(
300-
borderRadius: BorderRadius.circular(16),
301-
),
302-
),
303-
),
304-
),
305-
],
306-
),
307-
),
308-
],
309-
);
310-
311-
showCustomBottomDialog(context, t);
312-
}
313-
314197
Widget _buildUserInfo(BaseServiceData data) {
315198
final theme = Theme.of(context).colorScheme;
316199
final isDarkMode = Provider.of<ThemeNotifier>(context).isDarkMode;
@@ -321,7 +204,7 @@ class HomeScreenState extends State<HomeScreen> {
321204
child: SlideUpAnimation(
322205
child: Row(children: [
323206
GestureDetector(
324-
onTap: () => contactPage(context),
207+
onTap: () {},
325208
child: CircleAvatar(
326209
backgroundColor: Colors.transparent,
327210
radius: 26.0,

lib/Screens/Settings/SettingsCommonScreen.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ class SettingsCommonScreenState extends BaseSettingsScreen {
4343
),
4444
SettingsAdaptor(
4545
settings: [
46+
Setting(
47+
type: SettingType.switchType,
48+
name: 'Hide Private',
49+
description: 'Hide private media from the home page',
50+
icon: Icons.visibility_off,
51+
isChecked: PrefManager.getVal(PrefName.anilistHidePrivate),
52+
onSwitchChange: (value) {
53+
PrefManager.setVal(PrefName.anilistHidePrivate, value);
54+
Refresh.activity[RefreshId.Anilist.homePage]?.value = true;
55+
},
56+
),
4657
Setting(
4758
type: SettingType.normal,
4859
name: getString.manageHomeLayouts,

lib/api/Anilist/AnilistQueries/GetHomePageData.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension on AnilistQueries {
44
Future<Map<String, List<Media>>> _initHomePage() async {
55
try {
66
final removeList = PrefManager.getVal(PrefName.anilistRemoveList);
7-
const hidePrivate = true;
7+
final hidePrivate = PrefManager.getVal(PrefName.anilistHidePrivate);
88
List<Media> removedMedia = [];
99
final homeLayoutMap = PrefManager.getVal(PrefName.anilistHomeLayout);
1010

lib/api/Anilist/Screen/AnilistHomeScreen.dart

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class AnilistHomeScreen extends BaseHomeScreen {
9696
emptyMessage: 'All caught up, when New?',
9797
emptyButtonText: 'Browse\nAnime',
9898
emptyButtonOnPressed: () => navbar?.onClick(0),
99-
onLongPressTitle: () => showHidden.value = !showHidden.value,
10099
),
101100
MediaSectionData(
102101
type: 0,
@@ -159,22 +158,30 @@ class AnilistHomeScreen extends BaseHomeScreen {
159158
.where((entry) => entry.value)
160159
.map((entry) => sectionMap[entry.key])
161160
.whereType<MediaSectionData>()
162-
.map((section) => MediaSection(
163-
context: context,
164-
type: section.type,
165-
title: section.title,
166-
mediaList: section.list,
167-
isLarge: section.isLarge,
168-
onLongPressTitle: section.onLongPressTitle,
169-
customNullListIndicator: _buildNullIndicator(
170-
context,
171-
section.emptyIcon,
172-
section.emptyMessage,
173-
section.emptyButtonText,
174-
section.emptyButtonOnPressed,
175-
),
176-
))
177-
.toList()
161+
.toList();
162+
163+
if (sectionWidgets.isNotEmpty) {
164+
sectionWidgets.first.onLongPressTitle =
165+
() => showHidden.value = !showHidden.value;
166+
}
167+
168+
final result = sectionWidgets.map((section) {
169+
return MediaSection(
170+
context: context,
171+
type: section.type,
172+
title: section.title,
173+
mediaList: section.list,
174+
isLarge: section.isLarge,
175+
onLongPressTitle: section.onLongPressTitle,
176+
customNullListIndicator: _buildNullIndicator(
177+
context,
178+
section.emptyIcon,
179+
section.emptyMessage,
180+
section.emptyButtonText,
181+
section.emptyButtonOnPressed,
182+
),
183+
);
184+
}).toList()
178185
..add(const SizedBox(height: 128));
179186

180187
var hiddenMedia = MediaSection(
@@ -195,12 +202,12 @@ class AnilistHomeScreen extends BaseHomeScreen {
195202
return [
196203
Obx(() {
197204
if (showHidden.value) {
198-
sectionWidgets.insert(0, hiddenMedia);
205+
result.insert(0, hiddenMedia);
199206
} else {
200-
sectionWidgets.remove(hiddenMedia);
207+
result.remove(hiddenMedia);
201208
}
202209
return Column(
203-
children: sectionWidgets,
210+
children: result,
204211
);
205212
}),
206213
];

lib/api/MyAnimeList/Screen/MalHomeScreen.dart

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,34 @@ class MalHomeScreen extends BaseHomeScreen {
164164
final sectionMap = {
165165
for (var section in mediaSections) section.title: section
166166
};
167-
168167
final sectionWidgets = homeLayoutMap.entries
169168
.where((entry) => entry.value)
170169
.map((entry) => sectionMap[entry.key])
171170
.whereType<MediaSectionData>()
172-
.map((section) => MediaSection(
173-
context: context,
174-
type: section.type,
175-
title: section.title,
176-
mediaList: section.list,
177-
isLarge: section.isLarge,
178-
onLongPressTitle: section.onLongPressTitle,
179-
customNullListIndicator: _buildNullIndicator(
180-
context,
181-
section.emptyIcon,
182-
section.emptyMessage,
183-
section.emptyButtonText,
184-
section.emptyButtonOnPressed,
185-
),
186-
))
187-
.toList()
171+
.toList();
172+
173+
if (sectionWidgets.isNotEmpty) {
174+
sectionWidgets.first.onLongPressTitle =
175+
() => showHidden.value = !showHidden.value;
176+
}
177+
178+
final result = sectionWidgets.map((section) {
179+
return MediaSection(
180+
context: context,
181+
type: section.type,
182+
title: section.title,
183+
mediaList: section.list,
184+
isLarge: section.isLarge,
185+
onLongPressTitle: section.onLongPressTitle,
186+
customNullListIndicator: _buildNullIndicator(
187+
context,
188+
section.emptyIcon,
189+
section.emptyMessage,
190+
section.emptyButtonText,
191+
section.emptyButtonOnPressed,
192+
),
193+
);
194+
}).toList()
188195
..add(const SizedBox(height: 128));
189196

190197
var hiddenMedia = MediaSection(
@@ -205,12 +212,12 @@ class MalHomeScreen extends BaseHomeScreen {
205212
return [
206213
Obx(() {
207214
if (showHidden.value) {
208-
sectionWidgets.insert(0, hiddenMedia);
215+
result.insert(0, hiddenMedia);
209216
} else {
210-
sectionWidgets.remove(hiddenMedia);
217+
result.remove(hiddenMedia);
211218
}
212219
return Column(
213-
children: sectionWidgets,
220+
children: result,
214221
);
215222
}),
216223
];

0 commit comments

Comments
 (0)