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 000000000..1975952fb Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_favorite_border.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_favorite_border.png b/app/src/main/res/drawable-mdpi/ic_action_favorite_border.png new file mode 100644 index 000000000..1868fedfa Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_favorite_border.png differ 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 000000000..de48005bf Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_favorite_border.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_favorite_border.png b/app/src/main/res/drawable-xxhdpi/ic_action_favorite_border.png new file mode 100644 index 000000000..0917a4173 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_favorite_border.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_favorite_border.png b/app/src/main/res/drawable-xxxhdpi/ic_action_favorite_border.png new file mode 100644 index 000000000..c2532731a Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_favorite_border.png differ diff --git a/app/src/main/res/menu/manga.xml b/app/src/main/res/menu/manga_info.xml similarity index 50% rename from app/src/main/res/menu/manga.xml rename to app/src/main/res/menu/manga_info.xml index d3cc6ac6a..a19a08d15 100644 --- a/app/src/main/res/menu/manga.xml +++ b/app/src/main/res/menu/manga_info.xml @@ -5,7 +5,14 @@ android:id="@+id/action_favorite" android:title="@string/action_favorite" android:icon="@drawable/ic_action_favorite" - app:showAsAction="always" - android:visible="false"/> + android:visible="false" + app:showAsAction="ifRoom" /> + + \ 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