Skip to content

Commit c85e714

Browse files
authored
Merge pull request #96 from Vito0912/feat/seriesSorting
Series sorting and fixed caching
2 parents 4dd9d9b + 51dd6af commit c85e714

File tree

13 files changed

+177
-95
lines changed

13 files changed

+177
-95
lines changed

lib/features/home/home.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,18 @@ class Home extends HookConsumerWidget {
6262
],
6363
if (MediaQuery.of(context).size.width >= 900 &&
6464
(currentIndex.value == 0 || currentIndex.value == 2)) ...[
65-
const Expanded(
65+
Expanded(
6666
flex: 3,
6767
child: Padding(
68-
padding: EdgeInsets.only(left: 16),
68+
padding: const EdgeInsets.only(left: 16),
6969
child: Padding(
70-
padding: EdgeInsets.symmetric(horizontal: 32),
71-
child: Center(child: NotchContent())),
70+
padding: const EdgeInsets.symmetric(horizontal: 32),
71+
child: Center(
72+
child: NotchContent(
73+
disableFilter: currentIndex.value == 2,
74+
sortKeys:
75+
currentIndex.value == 2 ? seriesSortKeys : null,
76+
))),
7277
))
7378
]
7479
],
@@ -142,6 +147,7 @@ class Home extends HookConsumerWidget {
142147
search: previousSort?.search ?? '',
143148
filter: previousSort?.filter,
144149
filterKey: previousSort?.filterKey,
150+
sort: previousSort?.sort ?? (index == 2 ? 'name' : null),
145151
previous: [
146152
...?sortList.previous?.where((LibrarySort sort) {
147153
return sort.index != index;

lib/features/library/item_components/item_series.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:abs_api/abs_api.dart';
55
import 'package:abs_flutter/features/library/item_components/top_label.dart';
66
import 'package:abs_flutter/generated/l10n.dart';
77
import 'package:abs_flutter/models/library_series_preview.dart';
8-
import 'package:abs_flutter/provider/library_items_provider.dart';
98
import 'package:abs_flutter/provider/progress_provider.dart';
109
import 'package:abs_flutter/provider/settings_provider.dart';
1110
import 'package:abs_flutter/util/constants.dart';
@@ -29,17 +28,7 @@ class ItemSeries extends ConsumerWidget {
2928
return InkWell(
3029
onTap: clickable
3130
? () {
32-
ref.read(libraryItemSearchProvider.notifier).state = ref
33-
.read(libraryItemSearchProvider.notifier)
34-
.state
35-
.copyWith(
36-
filterKey: 'series',
37-
filter: series.id,
38-
sort: 'sequence',
39-
desc:
40-
settings[Constants.SORT_SERIES_ASC] == true ? 1 : 0,
41-
search: '');
42-
context.push('/series-view/${series.name}');
31+
context.push('/series-view/${series.name}/${series.id}');
4332
}
4433
: null,
4534
child: Padding(

lib/features/library/library_items_wrapper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class LibraryItemsWrapper extends StatelessWidget {
1111
return Stack(
1212
children: [
1313
const LibraryItems(),
14-
if(MediaQuery.of(context).size.width < 900) const LibraryNotch(),
14+
if (MediaQuery.of(context).size.width < 900) const LibraryNotch(),
1515
],
1616
);
1717
}

lib/features/library/notch.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
21
import 'package:abs_flutter/features/library/notch/notch_content.dart';
32
import 'package:flutter/material.dart';
43

5-
6-
74
class LibraryNotch extends StatelessWidget {
8-
const LibraryNotch({super.key});
5+
final bool disableFilter;
6+
final bool disableSearch;
7+
final Map<String, String>? sortKeys;
8+
const LibraryNotch(
9+
{super.key,
10+
this.disableFilter = false,
11+
this.disableSearch = false,
12+
this.sortKeys});
913

1014
@override
1115
Widget build(BuildContext context) {
@@ -24,10 +28,13 @@ class LibraryNotch extends StatelessWidget {
2428
bottomRight: Radius.circular(32.0),
2529
),
2630
),
27-
child: const Padding(
28-
padding: EdgeInsets.only(left: 8, right: 8, top: 8, bottom: 8),
29-
child: NotchContent()
30-
),
31+
child: Padding(
32+
padding: const EdgeInsets.only(left: 8, right: 8, top: 8, bottom: 8),
33+
child: NotchContent(
34+
disableFilter: disableFilter,
35+
disableSearch: disableSearch,
36+
sortKeys: sortKeys,
37+
)),
3138
);
3239
}
3340
}

lib/features/library/notch/notch_content.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
1111
class NotchContent extends ConsumerStatefulWidget {
1212
final bool disableFilter;
1313
final bool disableSearch;
14+
final Map<String, String>? sortKeys;
1415
const NotchContent(
15-
{super.key, this.disableFilter = false, this.disableSearch = false});
16+
{super.key,
17+
this.disableFilter = false,
18+
this.disableSearch = false,
19+
this.sortKeys});
1620

1721
@override
1822
_NotchContentState createState() => _NotchContentState();
@@ -93,7 +97,9 @@ class _NotchContentState extends ConsumerState<NotchContent> {
9397
},
9498
),
9599
),
96-
SortButton(),
100+
SortButton(
101+
overwriteSortOptions: widget.sortKeys,
102+
),
97103
if (!widget.disableFilter) const FilterButton(),
98104
if (librarySort.search == null ||
99105
librarySort.search!.isNotEmpty)

lib/features/library/notch/sort_button.dart

Lines changed: 77 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
77
import 'package:flutter_riverpod/flutter_riverpod.dart';
88

99
class SortButton extends ConsumerWidget {
10-
SortButton({super.key});
11-
12-
final Map<String, String> sortOptions = {
13-
"media.metadata.title": S.current.title,
14-
"media.metadata.seriesName": S.current.series,
15-
"media.metadata.authorName": S.current.author,
16-
"media.metadata.publisher": S.current.publisher,
17-
"media.metadata.language": S.current.language,
18-
"media.duration": S.current.duration,
19-
"sequence": S.current.sequence,
20-
};
10+
final Map<String, String>? overwriteSortOptions;
11+
late final Map<String, String> sortOptions;
12+
SortButton({super.key, this.overwriteSortOptions}) {
13+
sortOptions = overwriteSortOptions ??
14+
{
15+
"media.metadata.title": S.current.title,
16+
"media.metadata.seriesName": S.current.series,
17+
"media.metadata.authorName": S.current.author,
18+
"media.metadata.publisher": S.current.publisher,
19+
"media.metadata.language": S.current.language,
20+
"media.duration": S.current.duration,
21+
"sequence": S.current.sequence,
22+
};
23+
}
2124

2225
@override
2326
Widget build(BuildContext context, WidgetRef ref) {
@@ -57,11 +60,19 @@ class SortButton extends ConsumerWidget {
5760
Navigator.of(context).pop();
5861
}
5962

63+
void onItemLongPress() {
64+
sort.state = sort.state.copyWith(
65+
sort: sortKey,
66+
desc: isSelected ? (isDescending ? 1 : 0) : 1,
67+
);
68+
Navigator.of(context).pop();
69+
}
70+
6071
return PlatformWidget(
61-
material: (_, __) => _buildMaterialListTile(
62-
sortValue, isSelected, isDescending, onItemTap),
63-
cupertino: (_, __) => _buildCupertinoListTile(
64-
sortValue, isSelected, isDescending, onItemTap),
72+
material: (_, __) => _buildMaterialListTile(sortValue, isSelected,
73+
isDescending, onItemTap, onItemLongPress),
74+
cupertino: (_, __) => _buildCupertinoListTile(sortValue,
75+
isSelected, isDescending, onItemTap, onItemLongPress),
6576
);
6677
},
6778
);
@@ -70,55 +81,62 @@ class SortButton extends ConsumerWidget {
7081
}
7182

7283
Widget _buildMaterialListTile(String sortValue, bool isSelected,
73-
bool isDescending, VoidCallback onTap) {
74-
return ListTile(
75-
title: Row(
76-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
77-
children: [
78-
Text(sortValue),
79-
if (isSelected)
80-
Row(
81-
children: [
82-
Tooltip(
83-
message: isDescending
84-
? S.current.ascending
85-
: S.current.descending,
86-
child: Icon(isDescending
87-
? Icons.arrow_upward
88-
: Icons.arrow_downward)),
89-
const SizedBox(width: 8),
90-
const Icon(Icons.check),
91-
],
92-
),
93-
],
84+
bool isDescending, VoidCallback onTap, VoidCallback onLongPress) {
85+
return GestureDetector(
86+
onLongPress: onLongPress,
87+
child: ListTile(
88+
title: Row(
89+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
90+
children: [
91+
Text(sortValue),
92+
if (isSelected)
93+
Row(
94+
children: [
95+
Tooltip(
96+
message: isDescending
97+
? S.current.ascending
98+
: S.current.descending,
99+
child: Icon(isDescending
100+
? Icons.arrow_upward
101+
: Icons.arrow_downward)),
102+
const SizedBox(width: 8),
103+
const Icon(Icons.check),
104+
],
105+
),
106+
],
107+
),
108+
onTap: onTap,
94109
),
95-
onTap: onTap,
96110
);
97111
}
98112

99113
Widget _buildCupertinoListTile(String sortValue, bool isSelected,
100-
bool isDescending, VoidCallback onTap) {
101-
return CupertinoListTile(
102-
title: Text(sortValue),
103-
trailing: isSelected
104-
? Row(
105-
mainAxisSize: MainAxisSize.min,
106-
children: [
107-
Tooltip(
108-
message:
109-
isDescending ? S.current.ascending : S.current.descending,
110-
child: Icon(
111-
isDescending
112-
? CupertinoIcons.arrow_up
113-
: CupertinoIcons.arrow_down,
114-
size: 16),
115-
),
116-
const SizedBox(width: 8),
117-
const Icon(CupertinoIcons.check_mark),
118-
],
119-
)
120-
: null,
121-
onTap: onTap,
114+
bool isDescending, VoidCallback onTap, VoidCallback onLongPress) {
115+
return GestureDetector(
116+
onLongPress: onLongPress,
117+
child: CupertinoListTile(
118+
title: Text(sortValue),
119+
trailing: isSelected
120+
? Row(
121+
mainAxisSize: MainAxisSize.min,
122+
children: [
123+
Tooltip(
124+
message: isDescending
125+
? S.current.ascending
126+
: S.current.descending,
127+
child: Icon(
128+
isDescending
129+
? CupertinoIcons.arrow_up
130+
: CupertinoIcons.arrow_down,
131+
size: 16),
132+
),
133+
const SizedBox(width: 8),
134+
const Icon(CupertinoIcons.check_mark),
135+
],
136+
)
137+
: null,
138+
onTap: onTap,
139+
),
122140
);
123141
}
124142
}

lib/features/library/series/series_view_wrapper.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:abs_flutter/features/library/notch.dart';
22
import 'package:abs_flutter/features/library/series/series_view.dart';
3+
import 'package:abs_flutter/globals.dart';
34
import 'package:flutter/material.dart';
45

56
class SeriesViewWrapper extends StatelessWidget {
@@ -10,7 +11,8 @@ class SeriesViewWrapper extends StatelessWidget {
1011
return Stack(
1112
children: [
1213
const SeriesView(),
13-
if (MediaQuery.of(context).size.width < 900) const LibraryNotch(),
14+
if (MediaQuery.of(context).size.width < 900)
15+
LibraryNotch(disableFilter: true, sortKeys: seriesSortKeys),
1416
],
1517
);
1618
}

lib/features/library/series/single_series_view.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ class _SingleSeriesViewState extends ConsumerState<SingleSeriesView> {
4141
sort: 'sequence',
4242
desc: (ref.read(settingsProvider)[Constants.SORT_SERIES_ASC])
4343
? 1
44-
: 0);
44+
: 0,
45+
previous: [
46+
ref.read(libraryItemSearchProvider).copyWith(previous: null),
47+
...?ref.read(libraryItemSearchProvider).previous
48+
]);
4549
}
50+
print(ref.read(libraryItemSearchProvider));
4651
}
4752
});
4853

@@ -122,11 +127,15 @@ class _SingleSeriesViewState extends ConsumerState<SingleSeriesView> {
122127
icon: const Icon(Icons.arrow_back),
123128
onPressed: () {
124129
// Reset filter on back
125-
final sortNotifier = ref.read(libraryItemSearchProvider.notifier);
126-
sortNotifier.state = sortNotifier.state.copyWith(
127-
filter: null,
128-
filterKey: null,
129-
);
130+
ref.read(libraryItemSearchProvider.notifier).state = ref
131+
.read(libraryItemSearchProvider)
132+
.previous!
133+
.first
134+
.copyWith(
135+
previous: ref
136+
.read(libraryItemSearchProvider)
137+
.previous
138+
?.sublist(1));
130139
Navigator.pop(context);
131140
},
132141
)),

lib/generated/intl/messages_en.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class MessageLookup extends MessageLookupByLibrary {
107107
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
108108
"addANewUser": MessageLookupByLibrary.simpleMessage("Add a New User"),
109109
"addUser": MessageLookupByLibrary.simpleMessage("Add User"),
110+
"added": MessageLookupByLibrary.simpleMessage("Added"),
110111
"aggressiveCaching":
111112
MessageLookupByLibrary.simpleMessage("Aggressive Caching"),
112113
"aggressiveCachingDescription": MessageLookupByLibrary.simpleMessage(
@@ -284,6 +285,7 @@ class MessageLookup extends MessageLookupByLibrary {
284285
"If you want to use multiple server addresses, you can add them later"),
285286
"mustEnterValidAddress": MessageLookupByLibrary.simpleMessage(
286287
"You must enter a valid server address"),
288+
"name": MessageLookupByLibrary.simpleMessage("Name"),
287289
"narrators": MessageLookupByLibrary.simpleMessage("Narrators"),
288290
"newestEpisodes":
289291
MessageLookupByLibrary.simpleMessage("Newest Episodes"),
@@ -305,6 +307,8 @@ class MessageLookup extends MessageLookupByLibrary {
305307
"notificationHeading": MessageLookupByLibrary.simpleMessage(
306308
"Notifications should be enabled"),
307309
"numBooksInSeries": m30,
310+
"numberOfBooks":
311+
MessageLookupByLibrary.simpleMessage("Number of Books"),
308312
"offlineProgress":
309313
MessageLookupByLibrary.simpleMessage("Offline Progress"),
310314
"offlineSavedProgress":

0 commit comments

Comments
 (0)