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