mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 12:01:52 +01:00
Hold the same manga instance (allowing to refresh manga state from the catalogue). Other minor changes.
This commit is contained in:
parent
e1aa460106
commit
07ed2e2ebb
12
app/src/main/java/eu/kanade/tachiyomi/event/MangaEvent.java
Normal file
12
app/src/main/java/eu/kanade/tachiyomi/event/MangaEvent.java
Normal file
@ -0,0 +1,12 @@
|
||||
package eu.kanade.tachiyomi.event;
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
|
||||
public class MangaEvent {
|
||||
|
||||
public final Manga manga;
|
||||
|
||||
public MangaEvent(Manga manga) {
|
||||
this.manga = manga;
|
||||
}
|
||||
}
|
@ -107,14 +107,14 @@ public class RxPresenter<View> extends Presenter<View> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a restartable is subscribed.
|
||||
* Checks if a restartable is unsubscribed.
|
||||
*
|
||||
* @param restartableId id of a restartable.
|
||||
* @return True if the restartable is subscribed, false otherwise.
|
||||
* @param restartableId id of the restartable.
|
||||
* @return true if the subscription is null or unsubscribed, false otherwise.
|
||||
*/
|
||||
public boolean isSubscribed(int restartableId) {
|
||||
Subscription s = restartableSubscriptions.get(restartableId);
|
||||
return s != null && !s.isUnsubscribed();
|
||||
public boolean isUnsubscribed(int restartableId) {
|
||||
Subscription subscription = restartableSubscriptions.get(restartableId);
|
||||
return subscription == null || subscription.isUnsubscribed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -243,7 +243,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
||||
|
||||
private void restartRequest(String newQuery) {
|
||||
// If text didn't change, do nothing
|
||||
if (query.equals(newQuery)) return;
|
||||
if (query.equals(newQuery) || getPresenter().getSource() == null)
|
||||
return;
|
||||
|
||||
query = newQuery;
|
||||
showProgressBar();
|
||||
@ -325,9 +326,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
||||
@Override
|
||||
public void onListItemLongClick(int position) {
|
||||
final Manga selectedManga = adapter.getItem(position);
|
||||
final Manga dbManga = getPresenter().getDbManga(selectedManga.id);
|
||||
|
||||
int textRes = dbManga.favorite ? R.string.remove_from_library : R.string.add_to_library;
|
||||
int textRes = selectedManga.favorite ? R.string.remove_from_library : R.string.add_to_library;
|
||||
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.items(getString(textRes))
|
||||
@ -335,6 +335,7 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
||||
switch (which) {
|
||||
case 0:
|
||||
getPresenter().changeMangaFavorite(selectedManga);
|
||||
adapter.notifyItemChanged(position);
|
||||
break;
|
||||
}
|
||||
})
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.catalogue;
|
||||
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -12,13 +13,20 @@ public class CatalogueListHolder extends CatalogueHolder {
|
||||
|
||||
@Bind(R.id.title) TextView title;
|
||||
|
||||
private final int favoriteColor;
|
||||
private final int unfavoriteColor;
|
||||
|
||||
public CatalogueListHolder(View view, CatalogueAdapter adapter, OnListItemClickListener listener) {
|
||||
super(view, adapter, listener);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
favoriteColor = ContextCompat.getColor(view.getContext(), R.color.hint_text);
|
||||
unfavoriteColor = ContextCompat.getColor(view.getContext(), R.color.primary_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetValues(Manga manga, CataloguePresenter presenter) {
|
||||
title.setText(manga.title);
|
||||
title.setTextColor(manga.favorite ? favoriteColor : unfavoriteColor);
|
||||
}
|
||||
}
|
||||
|
@ -167,10 +167,6 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
||||
.onErrorResumeNext(error -> Observable.just(manga));
|
||||
}
|
||||
|
||||
public Manga getDbManga(long id) {
|
||||
return db.getManga(id).executeAsBlocking();
|
||||
}
|
||||
|
||||
public Source getSource() {
|
||||
return source;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
||||
@Override
|
||||
protected void onTakeView(LibraryFragment libraryFragment) {
|
||||
super.onTakeView(libraryFragment);
|
||||
if (!isSubscribed(GET_LIBRARY)) {
|
||||
if (isUnsubscribed(GET_LIBRARY)) {
|
||||
start(GET_LIBRARY);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import javax.inject.Inject;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import eu.kanade.tachiyomi.App;
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
@ -30,21 +31,21 @@ public class MangaActivity extends BaseRxActivity<MangaPresenter> {
|
||||
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
@Bind(R.id.tabs) TabLayout tabs;
|
||||
@Bind(R.id.view_pager) ViewPager view_pager;
|
||||
@Bind(R.id.view_pager) ViewPager viewPager;
|
||||
|
||||
@Inject PreferencesHelper preferences;
|
||||
@Inject MangaSyncManager mangaSyncManager;
|
||||
|
||||
private MangaDetailAdapter adapter;
|
||||
private long manga_id;
|
||||
private boolean is_online;
|
||||
private boolean isOnline;
|
||||
|
||||
public final static String MANGA_ID = "manga_id";
|
||||
public final static String MANGA_ONLINE = "manga_online";
|
||||
|
||||
public static Intent newIntent(Context context, Manga manga) {
|
||||
Intent intent = new Intent(context, MangaActivity.class);
|
||||
intent.putExtra(MANGA_ID, manga.id);
|
||||
if (manga != null) {
|
||||
EventBus.getDefault().postSticky(manga);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -59,23 +60,19 @@ public class MangaActivity extends BaseRxActivity<MangaPresenter> {
|
||||
|
||||
Intent intent = getIntent();
|
||||
|
||||
manga_id = intent.getLongExtra(MANGA_ID, -1);
|
||||
is_online = intent.getBooleanExtra(MANGA_ONLINE, false);
|
||||
isOnline = intent.getBooleanExtra(MANGA_ONLINE, false);
|
||||
|
||||
setupViewPager();
|
||||
|
||||
if (savedState == null)
|
||||
getPresenter().queryManga(manga_id);
|
||||
}
|
||||
|
||||
private void setupViewPager() {
|
||||
adapter = new MangaDetailAdapter(getSupportFragmentManager(), this);
|
||||
|
||||
view_pager.setAdapter(adapter);
|
||||
tabs.setupWithViewPager(view_pager);
|
||||
viewPager.setAdapter(adapter);
|
||||
tabs.setupWithViewPager(viewPager);
|
||||
|
||||
if (!is_online)
|
||||
view_pager.setCurrentItem(MangaDetailAdapter.CHAPTERS_FRAGMENT);
|
||||
if (!isOnline)
|
||||
viewPager.setCurrentItem(MangaDetailAdapter.CHAPTERS_FRAGMENT);
|
||||
}
|
||||
|
||||
public void setManga(Manga manga) {
|
||||
@ -83,7 +80,7 @@ public class MangaActivity extends BaseRxActivity<MangaPresenter> {
|
||||
}
|
||||
|
||||
public boolean isCatalogueManga() {
|
||||
return is_online;
|
||||
return isOnline;
|
||||
}
|
||||
|
||||
class MangaDetailAdapter extends FragmentPagerAdapter {
|
||||
@ -104,7 +101,7 @@ public class MangaActivity extends BaseRxActivity<MangaPresenter> {
|
||||
};
|
||||
|
||||
pageCount = 2;
|
||||
if (!is_online && mangaSyncManager.getMyAnimeList().isLogged())
|
||||
if (!isOnline && mangaSyncManager.getMyAnimeList().isLogged())
|
||||
pageCount++;
|
||||
}
|
||||
|
||||
|
@ -7,17 +7,17 @@ import javax.inject.Inject;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper;
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
import eu.kanade.tachiyomi.event.MangaEvent;
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
|
||||
import eu.kanade.tachiyomi.util.EventBusHook;
|
||||
import icepick.State;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class MangaPresenter extends BasePresenter<MangaActivity> {
|
||||
|
||||
@Inject DatabaseHelper db;
|
||||
|
||||
@State long mangaId;
|
||||
@State Manga manga;
|
||||
|
||||
private static final int DB_MANGA = 1;
|
||||
|
||||
@ -26,24 +26,28 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
|
||||
super.onCreate(savedState);
|
||||
|
||||
restartableLatestCache(DB_MANGA, this::getDbMangaObservable, MangaActivity::setManga);
|
||||
|
||||
if (savedState == null)
|
||||
registerForStickyEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// Avoid new instances receiving wrong manga
|
||||
EventBus.getDefault().removeStickyEvent(Manga.class);
|
||||
EventBus.getDefault().removeStickyEvent(MangaEvent.class);
|
||||
}
|
||||
|
||||
private Observable<Manga> getDbMangaObservable() {
|
||||
return db.getManga(mangaId).asRxObservable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext(manga -> EventBus.getDefault().postSticky(manga));
|
||||
return Observable.just(manga)
|
||||
.doOnNext(manga -> EventBus.getDefault().postSticky(new MangaEvent(manga)));
|
||||
}
|
||||
|
||||
public void queryManga(long mangaId) {
|
||||
this.mangaId = mangaId;
|
||||
@EventBusHook
|
||||
public void onEventMainThread(Manga manga) {
|
||||
EventBus.getDefault().removeStickyEvent(manga);
|
||||
unregisterForEvents();
|
||||
this.manga = manga;
|
||||
start(DB_MANGA);
|
||||
}
|
||||
|
||||
|
@ -31,23 +31,24 @@ public class ChaptersHolder extends FlexibleViewHolder {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
|
||||
private final int readColor;
|
||||
private final int unreadColor;
|
||||
|
||||
public ChaptersHolder(View view, ChaptersAdapter adapter, OnListItemClickListener listener) {
|
||||
super(view, adapter, listener);
|
||||
this.adapter = adapter;
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
readColor = ContextCompat.getColor(view.getContext(), R.color.hint_text);
|
||||
unreadColor = ContextCompat.getColor(view.getContext(), R.color.primary_text);
|
||||
|
||||
chapterMenu.setOnClickListener(v -> v.post(() -> showPopupMenu(v)));
|
||||
}
|
||||
|
||||
public void onSetValues(Context context, Chapter chapter) {
|
||||
this.item = chapter;
|
||||
title.setText(chapter.name);
|
||||
|
||||
if (chapter.read) {
|
||||
title.setTextColor(ContextCompat.getColor(context, R.color.hint_text));
|
||||
} else {
|
||||
title.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
|
||||
}
|
||||
title.setTextColor(chapter.read ? readColor : unreadColor);
|
||||
|
||||
if (!chapter.read && chapter.last_page_read > 0) {
|
||||
pages.setText(context.getString(R.string.chapter_progress, chapter.last_page_read + 1));
|
||||
|
@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.data.source.SourceManager;
|
||||
import eu.kanade.tachiyomi.data.source.base.Source;
|
||||
import eu.kanade.tachiyomi.event.ChapterCountEvent;
|
||||
import eu.kanade.tachiyomi.event.DownloadChaptersEvent;
|
||||
import eu.kanade.tachiyomi.event.MangaEvent;
|
||||
import eu.kanade.tachiyomi.event.ReaderEvent;
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
|
||||
import eu.kanade.tachiyomi.util.EventBusHook;
|
||||
@ -90,10 +91,10 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||
}
|
||||
|
||||
@EventBusHook
|
||||
public void onEventMainThread(Manga manga) {
|
||||
this.manga = manga;
|
||||
public void onEventMainThread(MangaEvent event) {
|
||||
this.manga = event.manga;
|
||||
|
||||
if (!isSubscribed(DB_CHAPTERS)) {
|
||||
if (isUnsubscribed(DB_CHAPTERS)) {
|
||||
source = sourceManager.get(manga.source);
|
||||
start(DB_CHAPTERS);
|
||||
|
||||
|
@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
import eu.kanade.tachiyomi.data.source.SourceManager;
|
||||
import eu.kanade.tachiyomi.data.source.base.Source;
|
||||
import eu.kanade.tachiyomi.event.ChapterCountEvent;
|
||||
import eu.kanade.tachiyomi.event.MangaEvent;
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
|
||||
import eu.kanade.tachiyomi.util.EventBusHook;
|
||||
import rx.Observable;
|
||||
@ -26,8 +27,6 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||
protected Source source;
|
||||
private int count = -1;
|
||||
|
||||
private boolean isFetching;
|
||||
|
||||
private static final int GET_MANGA = 1;
|
||||
private static final int GET_CHAPTER_COUNT = 2;
|
||||
private static final int FETCH_MANGA_INFO = 3;
|
||||
@ -69,10 +68,10 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||
}
|
||||
|
||||
@EventBusHook
|
||||
public void onEventMainThread(Manga manga) {
|
||||
this.manga = manga;
|
||||
public void onEventMainThread(MangaEvent event) {
|
||||
this.manga = event.manga;
|
||||
source = sourceManager.get(manga.source);
|
||||
start(GET_MANGA);
|
||||
refreshManga();
|
||||
}
|
||||
|
||||
@EventBusHook
|
||||
@ -84,8 +83,7 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||
}
|
||||
|
||||
public void fetchMangaFromSource() {
|
||||
if (!isFetching) {
|
||||
isFetching = true;
|
||||
if (isUnsubscribed(FETCH_MANGA_INFO)) {
|
||||
start(FETCH_MANGA_INFO);
|
||||
}
|
||||
}
|
||||
@ -97,15 +95,16 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||
db.insertManga(manga).executeAsBlocking();
|
||||
return Observable.just(manga);
|
||||
})
|
||||
.finallyDo(() -> isFetching = false)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnCompleted(this::refreshManga);
|
||||
}
|
||||
|
||||
public void toggleFavorite() {
|
||||
manga.favorite = !manga.favorite;
|
||||
onMangaFavoriteChange(manga.favorite);
|
||||
db.insertManga(manga).executeAsBlocking();
|
||||
refreshManga();
|
||||
}
|
||||
|
||||
private void onMangaFavoriteChange(boolean isFavorite) {
|
||||
@ -116,4 +115,9 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||
}
|
||||
}
|
||||
|
||||
// Used to refresh the view
|
||||
private void refreshManga() {
|
||||
start(GET_MANGA);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaSync;
|
||||
import eu.kanade.tachiyomi.data.mangasync.MangaSyncManager;
|
||||
import eu.kanade.tachiyomi.data.mangasync.services.MyAnimeList;
|
||||
import eu.kanade.tachiyomi.event.MangaEvent;
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
|
||||
import eu.kanade.tachiyomi.util.EventBusHook;
|
||||
import eu.kanade.tachiyomi.util.ToastUtil;
|
||||
@ -102,8 +103,8 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
|
||||
}
|
||||
|
||||
@EventBusHook
|
||||
public void onEventMainThread(Manga manga) {
|
||||
this.manga = manga;
|
||||
public void onEventMainThread(MangaEvent event) {
|
||||
this.manga = event.manga;
|
||||
start(GET_MANGA_SYNC);
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
}
|
||||
|
||||
private void stopPreloadingNextChapter() {
|
||||
if (isSubscribed(PRELOAD_NEXT_CHAPTER)) {
|
||||
if (!isUnsubscribed(PRELOAD_NEXT_CHAPTER)) {
|
||||
stop(PRELOAD_NEXT_CHAPTER);
|
||||
if (nextChapterPageList != null)
|
||||
source.savePageList(nextChapter.url, nextChapterPageList);
|
||||
|
@ -23,6 +23,7 @@
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_action_add_18dp"
|
||||
app:backgroundTint="@color/colorPrimary"
|
||||
app:layout_anchor="@id/categories_list"
|
||||
app:layout_anchorGravity="bottom|right|end"
|
||||
app:layout_behavior="eu.kanade.tachiyomi.ui.base.fab.ScrollAwareFABBehavior"/>
|
||||
|
Loading…
Reference in New Issue
Block a user