Skip to content

Commit b8610a2

Browse files
committed
fix bugs & change history logic
1 parent 4c419ad commit b8610a2

File tree

5 files changed

+55
-73
lines changed

5 files changed

+55
-73
lines changed

lib/core/bloc/history_bloc/history_bloc.dart

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,61 +26,36 @@ class HistoryBloc extends Bloc<HistoryEvent, HistoryState> {
2626
) async* {
2727
if (event is AddHistory)
2828
yield* insertHistoryToState(event);
29-
else if (event is UpdateHistory)
30-
yield* updateHistoryToState(event);
3129
else if (event is DeleteHistory) yield* deleteHistoryToState(event);
3230
}
3331

3432
Stream<HistoryState> insertHistoryToState(AddHistory event) async* {
3533
try {
3634
final data = event.historyModel;
37-
3835
final result = await _moorDBRepository.getHistory(
3936
event.historyModel.title, event.historyModel.mangaEndpoint);
40-
41-
if (result == null) {
42-
_moorDBRepository.insertHistory(History(
43-
title: data.title,
44-
mangaEndpoint: data.mangaEndpoint,
45-
image: data.image,
46-
author: data.author,
47-
type: data.type,
48-
rating: data.rating,
49-
selectedIndex: data.selectedIndex,
50-
chapterReached: data.chapterReached,
51-
totalChapter: data.totalChapter,
52-
chapterReachedName: data.chapterReachedName));
53-
54-
yield HistorySuccess();
55-
} else {
56-
yield* updateHistoryToState(UpdateHistory(historyModel: data));
57-
}
58-
} catch (e) {
59-
yield HistoryError(error: e.toString());
60-
}
61-
}
62-
63-
Stream<HistoryState> updateHistoryToState(UpdateHistory event) async* {
64-
try {
65-
final data = event.historyModel;
66-
final result =
67-
await _moorDBRepository.getHistory(data.title, data.mangaEndpoint);
68-
69-
_moorDBRepository.updateHistory(History(
37+
final historyModel = History(
7038
title: data.title,
7139
mangaEndpoint: data.mangaEndpoint,
7240
image: data.image,
7341
author: data.author,
7442
type: data.type,
7543
rating: data.rating,
76-
selectedIndex: data.totalChapter > result.totalChapter
77-
? data.selectedIndex + 1
78-
: data.selectedIndex,
44+
selectedIndex: data.selectedIndex,
7945
chapterReached: data.chapterReached,
8046
totalChapter: data.totalChapter,
81-
chapterReachedName: data.chapterReachedName));
47+
chapterReachedName: data.chapterReachedName);
8248

83-
yield HistorySuccess();
49+
if (result == null) {
50+
_moorDBRepository.insertHistory(historyModel);
51+
52+
yield HistorySuccess();
53+
} else {
54+
_moorDBRepository.deleteHistory(data.title, data.mangaEndpoint);
55+
56+
_moorDBRepository.insertHistory(historyModel);
57+
yield HistorySuccess();
58+
}
8459
} catch (e) {
8560
yield HistoryError(error: e.toString());
8661
}

lib/screen/ui/chapter/chapter_placholder.dart

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,54 @@ Widget chapterAppbarPlaceholder(BuildContext context) {
1616
offset: Offset(0, 2),
1717
color: Colors.grey)
1818
]),
19-
child: Row(
20-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
21-
children: [
22-
Container(
23-
height: ScreenUtil().setHeight(110),
24-
width: ScreenUtil().setHeight(110),
25-
color: Colors.transparent,
26-
),
27-
ContentPlaceholder(
28-
child: Column(
29-
mainAxisAlignment: MainAxisAlignment.center,
30-
crossAxisAlignment: CrossAxisAlignment.center,
31-
children: [
32-
ContentPlaceholder.block(
33-
topSpacing: ScreenUtil().setHeight(40),
34-
height: ScreenUtil().setHeight(40),
35-
width: ScreenUtil().setWidth(500),
19+
child: Padding(
20+
padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(30)),
21+
child: Row(
22+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
23+
children: [
24+
Container(
25+
height: ScreenUtil().setHeight(210),
26+
width: ScreenUtil().setHeight(110),
27+
color: Colors.transparent,
28+
),
29+
Flexible(
30+
child: ContentPlaceholder(
31+
spacing: EdgeInsets.zero,
32+
child: Column(
33+
mainAxisAlignment: MainAxisAlignment.center,
34+
children: [
35+
ContentPlaceholder.block(
36+
topSpacing: ScreenUtil().setHeight(20),
37+
height: ScreenUtil().setHeight(40),
38+
width: ScreenUtil().setWidth(500),
39+
),
40+
ContentPlaceholder.block(
41+
height: ScreenUtil().setHeight(40),
42+
width: ScreenUtil().setWidth(500),
43+
),
44+
],
3645
),
37-
ContentPlaceholder.block(
38-
height: ScreenUtil().setHeight(40),
39-
width: ScreenUtil().setWidth(300),
40-
bottomSpacing: 0),
41-
],
46+
),
4247
),
43-
),
44-
RoundButton(
45-
icons: Icons.close,
46-
iconColor: Colors.white,
47-
backgroundColor: Theme.of(context).primaryColor,
48-
enableShadow: true,
49-
onTap: () => Navigator.pop(context))
50-
],
48+
RoundButton(
49+
icons: Icons.close,
50+
iconColor: Colors.white,
51+
backgroundColor: Theme.of(context).primaryColor,
52+
enableShadow: true,
53+
onTap: () => Navigator.pop(context))
54+
],
55+
),
5156
)),
5257
);
5358
}
5459

5560
Widget chapterBodyPlaceholder() {
56-
List count = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
61+
int count = 10;
5762

5863
return ListView.builder(
5964
shrinkWrap: true,
6065
padding: EdgeInsets.zero,
61-
itemCount: count.length,
66+
itemCount: count,
6267
itemBuilder: (context, index) {
6368
return Center(child: CustomCircularProgressIndicator());
6469
});

lib/screen/ui/chapter/chapter_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class _ChapterPageState extends State<ChapterPage> {
274274
),
275275
),
276276
Padding(
277-
padding: const EdgeInsets.all(8.0),
277+
padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
278278
child: Container(
279279
child: Row(
280280
mainAxisAlignment: MainAxisAlignment.spaceBetween,

lib/screen/ui/home/home_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class _HomePageState extends State<HomePage> {
8181
child: Column(
8282
crossAxisAlignment: CrossAxisAlignment.start,
8383
children: [
84-
Carousell(itemList: state.listBestSeries),
84+
//Carousell(itemList: state.listBestSeries),
8585
SizedBox(
8686
height: ScreenUtil().setHeight(30),
8787
),

lib/screen/ui/manga_detail/manga_detail_screen.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class _MangaDetailPageState extends State<MangaDetailPage> {
161161
? state.mangaDetail.chapterList.length
162162
: ITEM_COUNT;
163163
setState(() {
164+
data = [];
165+
originalData = [];
164166
isBookmarked = state.isBookmarked;
165167
currentIndex = length;
166168
data.addAll(state.mangaDetail.chapterList.getRange(0, length));
@@ -382,7 +384,7 @@ class _MangaDetailPageState extends State<MangaDetailPage> {
382384
fromHome: false));
383385
},
384386
child: ChapterItem(
385-
chapterListData: state.mangaDetail.chapterList[index],
387+
chapterListData: data[index],
386388
),
387389
),
388390
);

0 commit comments

Comments
 (0)