Skip to content

Commit

Permalink
fix bugs & change history logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chocodon committed Oct 25, 2020
1 parent 4c419ad commit b8610a2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 73 deletions.
51 changes: 13 additions & 38 deletions lib/core/bloc/history_bloc/history_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,36 @@ class HistoryBloc extends Bloc<HistoryEvent, HistoryState> {
) async* {
if (event is AddHistory)
yield* insertHistoryToState(event);
else if (event is UpdateHistory)
yield* updateHistoryToState(event);
else if (event is DeleteHistory) yield* deleteHistoryToState(event);
}

Stream<HistoryState> insertHistoryToState(AddHistory event) async* {
try {
final data = event.historyModel;

final result = await _moorDBRepository.getHistory(
event.historyModel.title, event.historyModel.mangaEndpoint);

if (result == null) {
_moorDBRepository.insertHistory(History(
title: data.title,
mangaEndpoint: data.mangaEndpoint,
image: data.image,
author: data.author,
type: data.type,
rating: data.rating,
selectedIndex: data.selectedIndex,
chapterReached: data.chapterReached,
totalChapter: data.totalChapter,
chapterReachedName: data.chapterReachedName));

yield HistorySuccess();
} else {
yield* updateHistoryToState(UpdateHistory(historyModel: data));
}
} catch (e) {
yield HistoryError(error: e.toString());
}
}

Stream<HistoryState> updateHistoryToState(UpdateHistory event) async* {
try {
final data = event.historyModel;
final result =
await _moorDBRepository.getHistory(data.title, data.mangaEndpoint);

_moorDBRepository.updateHistory(History(
final historyModel = History(
title: data.title,
mangaEndpoint: data.mangaEndpoint,
image: data.image,
author: data.author,
type: data.type,
rating: data.rating,
selectedIndex: data.totalChapter > result.totalChapter
? data.selectedIndex + 1
: data.selectedIndex,
selectedIndex: data.selectedIndex,
chapterReached: data.chapterReached,
totalChapter: data.totalChapter,
chapterReachedName: data.chapterReachedName));
chapterReachedName: data.chapterReachedName);

yield HistorySuccess();
if (result == null) {
_moorDBRepository.insertHistory(historyModel);

yield HistorySuccess();
} else {
_moorDBRepository.deleteHistory(data.title, data.mangaEndpoint);

_moorDBRepository.insertHistory(historyModel);
yield HistorySuccess();
}
} catch (e) {
yield HistoryError(error: e.toString());
}
Expand Down
69 changes: 37 additions & 32 deletions lib/screen/ui/chapter/chapter_placholder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,54 @@ Widget chapterAppbarPlaceholder(BuildContext context) {
offset: Offset(0, 2),
color: Colors.grey)
]),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: ScreenUtil().setHeight(110),
width: ScreenUtil().setHeight(110),
color: Colors.transparent,
),
ContentPlaceholder(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ContentPlaceholder.block(
topSpacing: ScreenUtil().setHeight(40),
height: ScreenUtil().setHeight(40),
width: ScreenUtil().setWidth(500),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(30)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: ScreenUtil().setHeight(210),
width: ScreenUtil().setHeight(110),
color: Colors.transparent,
),
Flexible(
child: ContentPlaceholder(
spacing: EdgeInsets.zero,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ContentPlaceholder.block(
topSpacing: ScreenUtil().setHeight(20),
height: ScreenUtil().setHeight(40),
width: ScreenUtil().setWidth(500),
),
ContentPlaceholder.block(
height: ScreenUtil().setHeight(40),
width: ScreenUtil().setWidth(500),
),
],
),
ContentPlaceholder.block(
height: ScreenUtil().setHeight(40),
width: ScreenUtil().setWidth(300),
bottomSpacing: 0),
],
),
),
),
RoundButton(
icons: Icons.close,
iconColor: Colors.white,
backgroundColor: Theme.of(context).primaryColor,
enableShadow: true,
onTap: () => Navigator.pop(context))
],
RoundButton(
icons: Icons.close,
iconColor: Colors.white,
backgroundColor: Theme.of(context).primaryColor,
enableShadow: true,
onTap: () => Navigator.pop(context))
],
),
)),
);
}

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

return ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.zero,
itemCount: count.length,
itemCount: count,
itemBuilder: (context, index) {
return Center(child: CustomCircularProgressIndicator());
});
Expand Down
2 changes: 1 addition & 1 deletion lib/screen/ui/chapter/chapter_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class _ChapterPageState extends State<ChapterPage> {
),
),
Padding(
padding: const EdgeInsets.all(8.0),
padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down
2 changes: 1 addition & 1 deletion lib/screen/ui/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _HomePageState extends State<HomePage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Carousell(itemList: state.listBestSeries),
//Carousell(itemList: state.listBestSeries),
SizedBox(
height: ScreenUtil().setHeight(30),
),
Expand Down
4 changes: 3 additions & 1 deletion lib/screen/ui/manga_detail/manga_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class _MangaDetailPageState extends State<MangaDetailPage> {
? state.mangaDetail.chapterList.length
: ITEM_COUNT;
setState(() {
data = [];
originalData = [];
isBookmarked = state.isBookmarked;
currentIndex = length;
data.addAll(state.mangaDetail.chapterList.getRange(0, length));
Expand Down Expand Up @@ -382,7 +384,7 @@ class _MangaDetailPageState extends State<MangaDetailPage> {
fromHome: false));
},
child: ChapterItem(
chapterListData: state.mangaDetail.chapterList[index],
chapterListData: data[index],
),
),
);
Expand Down

0 comments on commit b8610a2

Please sign in to comment.