Allow to remove a favorite manga from info tab
This commit is contained in:
parent
04dfdba0b7
commit
b3f12ae333
@ -30,7 +30,6 @@ public class MangaDetailPresenter extends BasePresenter<MangaDetailActivity> {
|
||||
.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<MangaDetailActivity> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -60,4 +60,14 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||
}
|
||||
}
|
||||
|
||||
public void initFavoriteIcon() {
|
||||
if (getView() != null)
|
||||
getView().setFavoriteIcon(manga.favorite);
|
||||
}
|
||||
|
||||
public void toggleFavorite() {
|
||||
manga.favorite = !manga.favorite;
|
||||
db.insertMangaBlock(manga);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<MangaDetailPresenter> {
|
||||
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<MangaDetailPresenter> {
|
||||
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<MangaDetailPresenter> {
|
||||
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;
|
||||
|
@ -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<MangaInfoPresenter> {
|
||||
@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<MangaInfoPresenter> {
|
||||
@Override
|
||||
public void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,6 +55,26 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
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<MangaInfoPresenter> {
|
||||
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<MangaInfoPresenter> {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_action_favorite_border.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_favorite_border.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 584 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_favorite_border.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_favorite_border.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 378 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_favorite_border.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_favorite_border.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 732 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_favorite_border.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_favorite_border.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_favorite_border.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_favorite_border.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
@ -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" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_remove_favorite"
|
||||
android:title="@string/action_remove_favorite"
|
||||
android:icon="@drawable/ic_action_favorite_border"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
@ -70,8 +70,8 @@
|
||||
<string name="success">Success</string>
|
||||
<string name="invalid_login">Login error</string>
|
||||
<string name="loading">Loading…</string>
|
||||
<string name="toast_added_favorites">Added to favorites</string>
|
||||
<string name="action_favorite">Favorite</string>
|
||||
<string name="action_favorite">Add to favorites</string>
|
||||
<string name="action_remove_favorite">Remove from favorites</string>
|
||||
<string name="downloading">Downloading…</string>
|
||||
<string name="download_progress">Downloaded %1$d%%</string>
|
||||
<string name="chapter_progress">Page: %1$d</string>
|
||||
|
Loading…
Reference in New Issue
Block a user