From b3f12ae333ccc557b27a61cffb5163c00bfa5b49 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 2 Nov 2015 21:22:31 +0100 Subject: [PATCH] Allow to remove a favorite manga from info tab --- .../presenter/MangaDetailPresenter.java | 11 ------ .../presenter/MangaInfoPresenter.java | 10 +++++ .../ui/activity/MangaDetailActivity.java | 30 --------------- .../ui/fragment/MangaInfoFragment.java | 35 ++++++++++++++++++ .../ic_action_favorite_border.png | Bin 0 -> 584 bytes .../ic_action_favorite_border.png | Bin 0 -> 378 bytes .../ic_action_favorite_border.png | Bin 0 -> 732 bytes .../ic_action_favorite_border.png | Bin 0 -> 1070 bytes .../ic_action_favorite_border.png | Bin 0 -> 1426 bytes app/src/main/res/menu/manga.xml | 11 ------ app/src/main/res/menu/manga_info.xml | 18 +++++++++ app/src/main/res/values/strings.xml | 4 +- 12 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_action_favorite_border.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_favorite_border.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_favorite_border.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_favorite_border.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_action_favorite_border.png delete mode 100644 app/src/main/res/menu/manga.xml create mode 100644 app/src/main/res/menu/manga_info.xml diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java index cb96c2a31..2f200c8e4 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java @@ -30,7 +30,6 @@ public class MangaDetailPresenter extends BasePresenter { .doOnNext(manga -> this.manga = manga), (view, manga) -> { view.setManga(manga); - view.setFavoriteBtnVisible(!manga.favorite); EventBus.getDefault().postSticky(manga); }); } @@ -54,14 +53,4 @@ public class MangaDetailPresenter extends BasePresenter { start(DB_MANGA); } - public void setFavoriteVisibility() { - if (getView() != null) { - getView().setFavoriteBtnVisible(!manga.favorite); - } - } - - public boolean addToFavorites() { - manga.favorite = true; - return db.insertMangaBlock(manga).numberOfRowsUpdated() == 1; - } } diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaInfoPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaInfoPresenter.java index a4bbe7cc0..be913c7e1 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaInfoPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaInfoPresenter.java @@ -60,4 +60,14 @@ public class MangaInfoPresenter extends BasePresenter { } } + public void initFavoriteIcon() { + if (getView() != null) + getView().setFavoriteIcon(manga.favorite); + } + + public void toggleFavorite() { + manga.favorite = !manga.favorite; + db.insertMangaBlock(manga); + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java index e5ff188e0..6a755206b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java @@ -10,9 +10,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; -import android.view.Menu; import android.view.MenuItem; -import android.widget.Toast; import butterknife.Bind; import butterknife.ButterKnife; @@ -34,7 +32,6 @@ public class MangaDetailActivity extends BaseRxActivity { private MangaDetailAdapter adapter; private long manga_id; private boolean is_online; - private MenuItem favoriteBtn; public final static String MANGA_ID = "manga_id"; public final static String MANGA_ONLINE = "manga_online"; @@ -65,23 +62,12 @@ public class MangaDetailActivity extends BaseRxActivity { getPresenter().queryManga(manga_id); } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.manga, menu); - favoriteBtn = menu.findItem(R.id.action_favorite); - getPresenter().setFavoriteVisibility(); - return true; - } - @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; - case R.id.action_favorite: - onFavoriteClick(); - return true; } return super.onOptionsItemSelected(item); } @@ -104,30 +90,14 @@ public class MangaDetailActivity extends BaseRxActivity { view_pager.setCurrentItem(MangaDetailAdapter.CHAPTERS_FRAGMENT); } - public long getMangaId() { - return manga_id; - } - public void setManga(Manga manga) { setToolbarTitle(manga.title); } - public void setFavoriteBtnVisible(boolean visible) { - if (favoriteBtn != null) - favoriteBtn.setVisible(visible); - } - public boolean isOnlineManga() { return is_online; } - private void onFavoriteClick() { - if (getPresenter().addToFavorites()) { - Toast.makeText(this, getString(R.string.toast_added_favorites), Toast.LENGTH_SHORT) - .show(); - } - } - class MangaDetailAdapter extends FragmentPagerAdapter { final int PAGE_COUNT = 2; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java index dfa02f30c..096736ff4 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java @@ -2,6 +2,9 @@ package eu.kanade.mangafeed.ui.fragment; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -29,6 +32,9 @@ public class MangaInfoFragment extends BaseRxFragment { @Bind(R.id.manga_summary) TextView mDescription; @Bind(R.id.manga_cover) ImageView mCover; + private MenuItem favoriteBtn; + private MenuItem removeFavoriteBtn; + public static MangaInfoFragment newInstance() { return new MangaInfoFragment(); } @@ -36,6 +42,7 @@ public class MangaInfoFragment extends BaseRxFragment { @Override public void onCreate(Bundle savedState) { super.onCreate(savedState); + setHasOptionsMenu(true); } @Override @@ -48,6 +55,26 @@ public class MangaInfoFragment extends BaseRxFragment { return view; } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.manga_info, menu); + favoriteBtn = menu.findItem(R.id.action_favorite); + removeFavoriteBtn = menu.findItem(R.id.action_remove_favorite); + getPresenter().initFavoriteIcon(); + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_favorite: + case R.id.action_remove_favorite: + getPresenter().toggleFavorite(); + break; + } + return super.onOptionsItemSelected(item); + } + public void setMangaInfo(Manga manga) { mArtist.setText(manga.artist); mAuthor.setText(manga.author); @@ -55,6 +82,8 @@ public class MangaInfoFragment extends BaseRxFragment { mStatus.setText("Ongoing"); //TODO mDescription.setText(manga.description); + setFavoriteIcon(manga.favorite); + Glide.with(getActivity()) .load(manga.thumbnail_url) .diskCacheStrategy(DiskCacheStrategy.RESULT) @@ -65,4 +94,10 @@ public class MangaInfoFragment extends BaseRxFragment { public void setChapterCount(int count) { mChapters.setText(String.valueOf(count)); } + + public void setFavoriteIcon(boolean isFavorite) { + if (favoriteBtn != null) favoriteBtn.setVisible(!isFavorite); + if (removeFavoriteBtn != null) removeFavoriteBtn.setVisible(isFavorite); + } + } diff --git a/app/src/main/res/drawable-hdpi/ic_action_favorite_border.png b/app/src/main/res/drawable-hdpi/ic_action_favorite_border.png new file mode 100644 index 0000000000000000000000000000000000000000..1975952fbff6e45778056bda3422b1ca3d95c7db GIT binary patch literal 584 zcmV-O0=NB%P)PF~(6Tmxlz zh*1Rb6ipUI!z~P9T&NFFmf7SQmXN?XzG46xDfxJYP>S*gi>S1-=|B|e*hD#e*j6YJ z+*R2$;fMovv4AP8A;#km_{2|#Sj8k}@t((V+_c(w@tLIW=rXxtOyktdpTrAXF||&7 zBlaUavQZz=G1OWT44Ov$7RAqR{8*+ph@4O?`4uT^3MEL&x=em7sVk$a#?Hy4vBBN0jP4nSLndDmx#-GhndZ#P# zIN6c^S>x!D_+Gw95&MOwSIeJVnID!E#%)`w!WXWM z6QWKV*u(W)I-F0mfmFOhd9KZ}gm09N*XN}_7pp?imUOJxo?^#V8sP&Ss5vX-@lGR(rl zuTW-ueCPJ+-Z$PnthldU_k8c?+;i?d=Oz;WchEzDGF5Kbq1PyV>;}p<`FebYH|%(4 zj(IAM^2&60_Zq%M9*->R0rbHtU8JP=#wBMR3N_r>V9_`%IEo)4lqqhO+I3c6%29G6 zO4h8(^kT2X6Hy6A=!|v9iny`np3J3Khh-5(YmUmiC({t`;8DbgD;-EUjy?xXoM?4F zEVfaS=ttm5RUWQstzQ`ASqm#)@C~U?3`B*VH1%F1>C|IW$_rzS4mYI+Ky~+m+=~XE zh`YXVg@;3$Y2iq-2Zq0E^C9j8o^qytnf{-=jBc(>^IgVQ-*w4w!8z@}d4FlrfA#i1 Y0Y(WLaJ&uz`~Uy|07*qoM6N<$f^dedA^-pY literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_action_favorite_border.png b/app/src/main/res/drawable-xhdpi/ic_action_favorite_border.png new file mode 100644 index 0000000000000000000000000000000000000000..de48005bf71f5a55250cc67e4bb6d5a0b7372889 GIT binary patch literal 732 zcmV<20wev2P)Rh3vC}q*YSzFdj z;zH3v!j{>TGz-Pqnd9Rz&-?S9^S;md_d0jyclEx{_xpT*&-;C!=l48MNl7t^QIMdX zBSaY^&QHeGQ#*|gP7_Dz;e%qt74t4_EX+>4n)Ad+jcG1YC!7W@tCrOG!8zt+l5b@g zQ%taBhO?DPBj*jx>E%C@E)wi!55LlKCX6YRIsZogPWj$K6&0-H5U*@067u|lgM<|0 z52uZ{(*D|Dl=9w+2>v9*$FUU8<7xo2k~n@k1U>6MbF5z*aZSI?HumYif5XA)kl*c` zQEFmZ=J*X3o|XhB4Gh1S9Cm_H4YeDmz-+n|E6ObbM$Tcaa@z@wX{g215^dHhqfRKU zp(;-a{90wo2~BAz;3+|+R*5;GaSeq$C0M0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xxhdpi/ic_action_favorite_border.png new file mode 100644 index 0000000000000000000000000000000000000000..c2532731aef684fdd80446d5b7b9f37180a5071d GIT binary patch literal 1426 zcmV;D1#S9?P)4cuq7XH*AjBvjS{JMmi)?$GEse4>-|U?`_c7h%p8d1g?KyM4?wxPu z`(`XFM2HX}LWBqrB7`C^2IXi%8xA0bf6#{>_O1gBsK6LUI(b-#Mr^@BrqIWfVu+%Z zeKH>x`ei)}_o5wf$PmXiEX4?0ooqaSt`s_FSRi*J;;s1z9>O{oZ}2?km2sR-vC|w zgd6|UDZvqKops34x8Djk_zPtNI&*Q#l}?LR2<+k60JrGHOqAiYYn^vA9we-kh@D0= zs@X%4&wil@3UD));{&P5KiNwb-1~z%5vG*S-YsLF$aJ1@o_XS=ojT-67N(Vo3G!^R zt)Ukz7DzpN^r-1P%~{^35@!brQ?hdL2KsHy_v1B;PN{PVwi3KO4%P*>Y>8-6c@8lT zCsW%09kUcvGVvl)Gc(F0+x^gEO4lDsjz;usBM_}{8Oi~inIv!H)*K6AmpN4ds4ZO z_wzJ{F6LDFaHWPy0jm^}ahE-*iK8@YZbX*isdHXSG*$RtvcaCx#!;$`R)9}9o&~H# zOh$>(07^MG`|T+)j*@RQfU%sLZhHzpZL*98FpN(r_LM%3GQwy8+58^Xp2F`1FE$!L zA?N0}J>@V*nPxPA63$K3p0b^zR2dDRnsd``PkEE0ylpgq^_-hVd&+|xCFXIL%vlcN ztBXo|(iOrsY>u%2?i9R?SD{5YQme55IyfhL)o3pZRqWM9>=z6F|9UmzWP!NZNC3^k zmi#hRYL^hgt%2LWT`X+fOrE{L?ul6b`9|?Y14ecf1Ko={K$JCLa>H;HI<|AA|Lvp*F*!gxKH;6}2NY|$3^Vt)dT5u+`3EBh89 z`mIj4&bABpJu%W+FV@753E|I?q&MWd4Sj9?pI*;KO}Fy zEbt@EEho=iwqcaE;%GLLC_L=fLQ_i)w=4CrsZ=c&pOShjEdPKP$ss>;c3*2iDIZ^u zTF?2t*=it%-G_@Dsf@>Wq|TZkw!4kw&W(>afObvk0C6Q+_4g}Ii8o?+bXxr0<$Go`d49U)uMkXzmx - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/manga_info.xml b/app/src/main/res/menu/manga_info.xml new file mode 100644 index 000000000..a19a08d15 --- /dev/null +++ b/app/src/main/res/menu/manga_info.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 747235e06..e8ab12505 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -70,8 +70,8 @@ Success Login error Loading… - Added to favorites - Favorite + Add to favorites + Remove from favorites Downloading… Downloaded %1$d%% Page: %1$d