mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 00:55:08 +01:00
Minor changes
This commit is contained in:
parent
384bc3c690
commit
ef444b0b63
@ -1,8 +1,11 @@
|
||||
package eu.kanade.mangafeed.event;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import eu.kanade.mangafeed.data.database.models.Category;
|
||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||
|
||||
public class LibraryMangasEvent {
|
||||
@ -16,4 +19,9 @@ public class LibraryMangasEvent {
|
||||
public Map<Integer, List<Manga>> getMangas() {
|
||||
return mangas;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<Manga> getMangasForCategory(Category category) {
|
||||
return mangas.get(category.id);
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,4 @@ public class LibraryAdapter extends SmartFragmentStatePagerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasDefaultCategory() {
|
||||
return categories.get(0).id == 0;
|
||||
}
|
||||
|
||||
}
|
@ -108,7 +108,7 @@ public class LibraryCategoryFragment extends BaseFragment
|
||||
return;
|
||||
|
||||
Category category = categories.get(position);
|
||||
List<Manga> mangas = event.getMangas().get(category.id);
|
||||
List<Manga> mangas = event.getMangasForCategory(category);
|
||||
if (mangas == null) {
|
||||
mangas = new ArrayList<>();
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -119,26 +118,20 @@ public class LibraryFragment extends BaseRxFragment<LibraryPresenter>
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void onNextLibraryUpdate(Pair<List<Category>, Map<Integer, List<Manga>>> pair) {
|
||||
boolean mangasInDefaultCategory = pair.second.get(0) != null;
|
||||
boolean initialized = adapter.categories != null;
|
||||
public void onNextLibraryUpdate(List<Category> categories, Map<Integer, List<Manga>> mangas) {
|
||||
boolean hasMangasInDefaultCategory = mangas.get(0) != null;
|
||||
int activeCat = adapter.categories != null ? viewPager.getCurrentItem() : activeCategory;
|
||||
|
||||
// If there are mangas in the default category and the adapter doesn't have it,
|
||||
// create the default category
|
||||
if (mangasInDefaultCategory && (!initialized || !adapter.hasDefaultCategory())) {
|
||||
setCategoriesWithDefault(pair.first);
|
||||
}
|
||||
// If there aren't mangas in the default category and the adapter have it,
|
||||
// remove the default category
|
||||
else if (!mangasInDefaultCategory && (!initialized || adapter.hasDefaultCategory())) {
|
||||
setCategories(pair.first);
|
||||
if (hasMangasInDefaultCategory) {
|
||||
setCategoriesWithDefault(categories);
|
||||
} else {
|
||||
setCategories(categories);
|
||||
}
|
||||
// Restore active category
|
||||
if (!initialized) {
|
||||
viewPager.setCurrentItem(activeCategory, false);
|
||||
}
|
||||
viewPager.setCurrentItem(activeCat, false);
|
||||
|
||||
// Send the mangas to child fragments after the adapter is updated
|
||||
EventBus.getDefault().postSticky(new LibraryMangasEvent(pair.second));
|
||||
EventBus.getDefault().postSticky(new LibraryMangasEvent(mangas));
|
||||
}
|
||||
|
||||
private void setCategoriesWithDefault(List<Category> categories) {
|
||||
|
@ -42,7 +42,7 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
||||
|
||||
restartableLatestCache(GET_LIBRARY,
|
||||
this::getLibraryObservable,
|
||||
LibraryFragment::onNextLibraryUpdate);
|
||||
(view, pair) -> view.onNextLibraryUpdate(pair.first, pair.second));
|
||||
|
||||
start(GET_LIBRARY);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user