1
+ import 'package:collection/collection.dart' ;
1
2
import 'package:dantotsu/DataClass/Media.dart' ;
2
3
import 'package:dantotsu/Screens/Info/Tabs/Watch/BaseParser.dart' ;
3
4
import 'package:dantotsu/Screens/Info/Tabs/Watch/BaseWatchScreen.dart' ;
@@ -6,9 +7,10 @@ import 'package:get/get.dart';
6
7
7
8
import '../../../../../Adaptor/Episode/EpisodeAdaptor.dart' ;
8
9
import '../../../../../DataClass/Episode.dart' ;
10
+ import '../../../../../Theme/LanguageSwitcher.dart' ;
11
+ import 'AnimeParser.dart' ;
9
12
import 'Widget/BuildChunkSelector.dart' ;
10
13
import 'Widget/ContinueCard.dart' ;
11
- import 'AnimeParser.dart' ;
12
14
13
15
class AnimeWatchScreen extends StatefulWidget {
14
16
final Media mediaData;
@@ -49,17 +51,22 @@ class AnimeWatchScreenState extends BaseWatchScreen<AnimeWatchScreen> {
49
51
if (episodeList == null || episodeList.isEmpty) {
50
52
return const Center (child: CircularProgressIndicator ());
51
53
}
52
-
53
54
if (! _viewModel.episodeDataLoaded.value) {
54
55
return const Center (child: CircularProgressIndicator ());
55
56
}
56
-
57
57
updateEpisodeDetails (episodeList);
58
58
59
- var (chunks, selectedChunkIndex ) = buildChunks (
59
+ var (chunks, initChunkIndex ) = buildChunks (
60
60
context, episodeList, widget.mediaData.userProgress.toString ());
61
61
62
- var selectedEpisode = episodeList[((widget.mediaData.userProgress ?? 0 ) + 1 ).toString ()];
62
+ var selectedEpisode = episodeList.values.firstWhereOrNull ((element) =>
63
+ element.number ==
64
+ ((widget.mediaData.userProgress ?? 0 ) + 1 ).toString ());
65
+
66
+ RxInt selectedChunkIndex = (- 1 ).obs;
67
+
68
+ selectedChunkIndex =
69
+ selectedChunkIndex.value == - 1 ? initChunkIndex : selectedChunkIndex;
63
70
return Column (
64
71
mainAxisSize: MainAxisSize .min,
65
72
crossAxisAlignment: CrossAxisAlignment .start,
@@ -70,15 +77,26 @@ class AnimeWatchScreenState extends BaseWatchScreen<AnimeWatchScreen> {
70
77
episode: selectedEpisode,
71
78
source: _viewModel.source.value! ,
72
79
),
73
- buildChunkSelector (context, chunks, selectedChunkIndex),
80
+ ChunkSelector (
81
+ context,
82
+ chunks,
83
+ selectedChunkIndex,
84
+ _viewModel.reversed,
85
+ ),
74
86
Container (
75
87
margin: const EdgeInsets .symmetric (horizontal: 18 , vertical: 4 ),
76
- child: Obx (() => EpisodeAdaptor (
77
- type: _viewModel.viewType.value,
78
- source: _viewModel.source.value! ,
79
- episodeList: chunks[selectedChunkIndex.value],
80
- mediaData: widget.mediaData,
81
- )),
88
+ child: Obx (() {
89
+ List <List <Episode >> reversed = _viewModel.reversed.value
90
+ ? chunks.map ((element) => element.reversed.toList ())
91
+ .toList ()
92
+ : chunks;
93
+ return EpisodeAdaptor (
94
+ type: _viewModel.viewType.value,
95
+ source: _viewModel.source.value! ,
96
+ episodeList: reversed[selectedChunkIndex.value],
97
+ mediaData: widget.mediaData,
98
+ );
99
+ }),
82
100
)
83
101
],
84
102
);
@@ -91,63 +109,30 @@ class AnimeWatchScreenState extends BaseWatchScreen<AnimeWatchScreen> {
91
109
child: Row (
92
110
mainAxisAlignment: MainAxisAlignment .spaceBetween,
93
111
children: [
94
- const Text (
95
- 'Episodes' ,
96
- style: TextStyle (
97
- fontFamily: 'Poppins' ,
98
- fontWeight: FontWeight .bold,
99
- fontSize: 16 ,
112
+ Expanded (
113
+ child: Text (
114
+ getString.episodes,
115
+ style: TextStyle (
116
+ fontFamily: 'Poppins' ,
117
+ fontWeight: FontWeight .bold,
118
+ fontSize: 16 ,
119
+ ),
120
+ overflow: TextOverflow .ellipsis,
121
+ maxLines: 1 ,
122
+ ),
123
+ ),
124
+ IconButton (
125
+ onPressed: () => _viewModel.settingsDialog (context, mediaData),
126
+ icon: Icon (
127
+ Icons .menu_rounded,
128
+ color: Theme .of (context).colorScheme.onSurface,
100
129
),
101
- overflow: TextOverflow .ellipsis,
102
- maxLines: 1 ,
103
130
),
104
- _buildIconButtons (),
105
131
],
106
132
),
107
133
);
108
134
}
109
135
110
- Widget _buildIconButtons () {
111
- final theme = Theme .of (context).colorScheme;
112
- final icons = [
113
- Icons .view_list_sharp,
114
- Icons .grid_view_rounded,
115
- Icons .view_comfy_rounded,
116
- ];
117
- var viewType = _viewModel.viewType;
118
-
119
- return Obx (() {
120
- return Row (
121
- children: List .generate (icons.length, (index) {
122
- return Padding (
123
- padding: const EdgeInsets .only (left: 10 ),
124
- child: IconButton (
125
- icon: Transform (
126
- alignment: Alignment .center,
127
- transform: index == 0
128
- ? Matrix4 .rotationY (3.14159 )
129
- : Matrix4 .identity (),
130
- child: Icon (icons[index]),
131
- ),
132
- iconSize: 24 ,
133
- color: viewType.value == index
134
- ? theme.onSurface
135
- : theme.onSurface.withValues (alpha: 0.33 ),
136
- onPressed: () => changeViewType (viewType, index),
137
- ),
138
- );
139
- }),
140
- );
141
- });
142
- }
143
-
144
- void changeViewType (RxInt viewType, int index) {
145
- var type = _viewModel.loadSelected (mediaData);
146
- viewType.value = index;
147
- type.recyclerStyle = index;
148
- _viewModel.saveSelected (mediaData.id, type);
149
- }
150
-
151
136
void updateEpisodeDetails (Map <String , Episode > episodeList) {
152
137
widget.mediaData.anime? .episodes = episodeList;
153
138
widget.mediaData.anime? .fillerEpisodes =
0 commit comments