mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +01:00
Categories improvements
This commit is contained in:
parent
e3bc13630d
commit
4900284c48
@ -0,0 +1,19 @@
|
|||||||
|
package eu.kanade.mangafeed.event;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||||
|
|
||||||
|
public class LibraryMangasEvent {
|
||||||
|
|
||||||
|
private final Map<Integer, List<Manga>> mangas;
|
||||||
|
|
||||||
|
public LibraryMangasEvent(Map<Integer, List<Manga>> mangas) {
|
||||||
|
this.mangas = mangas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, List<Manga>> getMangas() {
|
||||||
|
return mangas;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.mangafeed.ui.base.activity;
|
package eu.kanade.mangafeed.ui.base.activity;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -36,11 +35,6 @@ public class BaseActivity extends AppCompatActivity {
|
|||||||
getSupportActionBar().setSubtitle(getString(titleResource));
|
getSupportActionBar().setSubtitle(getString(titleResource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setToolbarElevation(int elevation) {
|
|
||||||
if (getSupportActionBar() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
getSupportActionBar().setElevation(elevation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Context getActivity() {
|
public Context getActivity() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,75 +1,40 @@
|
|||||||
package eu.kanade.mangafeed.ui.library;
|
package eu.kanade.mangafeed.ui.library;
|
||||||
|
|
||||||
import android.view.View;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.ViewGroup;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.widget.Filter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.widget.Filterable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
import eu.kanade.mangafeed.data.database.models.Category;
|
||||||
import rx.Observable;
|
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
|
||||||
|
|
||||||
public class LibraryAdapter extends EasyAdapter<Manga> implements Filterable {
|
class LibraryAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
List<Manga> mangas;
|
private List<Category> categories;
|
||||||
Filter filter;
|
|
||||||
private LibraryPresenter presenter;
|
|
||||||
|
|
||||||
public LibraryAdapter(LibraryFragment fragment) {
|
public LibraryAdapter(FragmentManager fm) {
|
||||||
super(fragment.getActivity(), LibraryHolder.class);
|
super(fm);
|
||||||
filter = new LibraryFilter();
|
|
||||||
presenter = fragment.getPresenter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNewItems(List<Manga> list) {
|
|
||||||
super.setItems(list);
|
|
||||||
mangas = list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Filter getFilter() {
|
public Fragment getItem(int position) {
|
||||||
return filter;
|
Category category = categories.get(position);
|
||||||
}
|
return LibraryCategoryFragment.newInstance(category);
|
||||||
|
|
||||||
private class LibraryFilter extends Filter {
|
|
||||||
@Override
|
|
||||||
protected FilterResults performFiltering(CharSequence charSequence) {
|
|
||||||
FilterResults results = new FilterResults();
|
|
||||||
String query = charSequence.toString().toLowerCase();
|
|
||||||
|
|
||||||
if (query.length() == 0) {
|
|
||||||
results.values = mangas;
|
|
||||||
results.count = mangas.size();
|
|
||||||
} else {
|
|
||||||
List<Manga> filteredMangas = Observable.from(mangas)
|
|
||||||
.filter(x ->
|
|
||||||
(x.title != null && x.title.toLowerCase().contains(query)) ||
|
|
||||||
(x.author != null && x.author.toLowerCase().contains(query)) ||
|
|
||||||
(x.artist != null && x.artist.toLowerCase().contains(query)))
|
|
||||||
.toList()
|
|
||||||
.toBlocking()
|
|
||||||
.single();
|
|
||||||
results.values = filteredMangas;
|
|
||||||
results.count = filteredMangas.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void publishResults(CharSequence constraint, FilterResults results) {
|
|
||||||
setItems((List<Manga>) results.values);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public int getCount() {
|
||||||
View view = super.getView(position, convertView, parent);
|
return categories == null ? 0 : categories.size();
|
||||||
LibraryHolder holder = (LibraryHolder) view.getTag();
|
|
||||||
Manga manga = getItem(position);
|
|
||||||
holder.loadCover(manga, presenter.sourceManager.get(manga.source), presenter.coverCache);
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getPageTitle(int position) {
|
||||||
|
return categories.get(position).name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategories(List<Category> categories) {
|
||||||
|
this.categories = categories;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,69 +1,76 @@
|
|||||||
package eu.kanade.mangafeed.ui.library;
|
package eu.kanade.mangafeed.ui.library;
|
||||||
|
|
||||||
import android.support.annotation.Nullable;
|
import android.view.View;
|
||||||
import android.support.v4.app.Fragment;
|
import android.view.ViewGroup;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.widget.Filter;
|
||||||
|
import android.widget.Filterable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
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;
|
||||||
import eu.kanade.mangafeed.ui.reader.viewer.common.SmartFragmentStatePagerAdapter;
|
import eu.kanade.mangafeed.ui.main.MainActivity;
|
||||||
|
import rx.Observable;
|
||||||
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||||
|
|
||||||
class LibraryCategoryAdapter extends SmartFragmentStatePagerAdapter {
|
public class LibraryCategoryAdapter extends EasyAdapter<Manga> implements Filterable {
|
||||||
|
|
||||||
private LibraryFragment fragment;
|
List<Manga> mangas;
|
||||||
private List<Category> categories;
|
Filter filter;
|
||||||
private Map<Integer, List<Manga>> mangas;
|
private LibraryPresenter presenter;
|
||||||
|
|
||||||
public LibraryCategoryAdapter(LibraryFragment fragment, FragmentManager fm) {
|
public LibraryCategoryAdapter(MainActivity activity) {
|
||||||
super(fm);
|
super(activity, LibraryHolder.class);
|
||||||
this.fragment = fragment;
|
filter = new LibraryFilter();
|
||||||
|
presenter = ((LibraryFragment) activity.getActiveFragment()).getPresenter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewItems(List<Manga> list) {
|
||||||
|
super.setItems(list);
|
||||||
|
mangas = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Filter getFilter() {
|
||||||
Category category = categories.get(position);
|
return filter;
|
||||||
return LibraryCategoryFragment.newInstance(fragment, category,
|
|
||||||
mangas != null ? mangas.get(category.id) : null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class LibraryFilter extends Filter {
|
||||||
public int getCount() {
|
@Override
|
||||||
return categories == null ? 0 : categories.size();
|
protected FilterResults performFiltering(CharSequence charSequence) {
|
||||||
}
|
FilterResults results = new FilterResults();
|
||||||
|
String query = charSequence.toString().toLowerCase();
|
||||||
|
|
||||||
@Override
|
if (query.length() == 0) {
|
||||||
public CharSequence getPageTitle(int position) {
|
results.values = mangas;
|
||||||
return categories.get(position).name;
|
results.count = mangas.size();
|
||||||
}
|
} else {
|
||||||
|
List<Manga> filteredMangas = Observable.from(mangas)
|
||||||
public void setCategories(List<Category> categories) {
|
.filter(x ->
|
||||||
this.categories = categories;
|
(x.title != null && x.title.toLowerCase().contains(query)) ||
|
||||||
notifyDataSetChanged();
|
(x.author != null && x.author.toLowerCase().contains(query)) ||
|
||||||
}
|
(x.artist != null && x.artist.toLowerCase().contains(query)))
|
||||||
|
.toList()
|
||||||
public void setMangasOnCategories(Map<Integer, List<Manga>> mangas) {
|
.toBlocking()
|
||||||
this.mangas = mangas;
|
.single();
|
||||||
for (Map.Entry<Integer, List<Manga>> entry : mangas.entrySet()) {
|
results.values = filteredMangas;
|
||||||
LibraryCategoryFragment fragment = getFragment(entry.getKey());
|
results.count = filteredMangas.size();
|
||||||
if (fragment != null) {
|
|
||||||
fragment.setMangas(entry.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
|
setItems((List<Manga>) results.values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Override
|
||||||
public LibraryCategoryFragment getFragment(int categoryId) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
if (categories != null) {
|
View view = super.getView(position, convertView, parent);
|
||||||
for (int i = 0; i < categories.size(); i++) {
|
LibraryHolder holder = (LibraryHolder) view.getTag();
|
||||||
if (categories.get(i).id == categoryId) {
|
Manga manga = getItem(position);
|
||||||
return (LibraryCategoryFragment) getRegisteredFragment(i);
|
holder.loadCover(manga, presenter.sourceManager.get(manga.source), presenter.coverCache);
|
||||||
}
|
return view;
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -2,7 +2,6 @@ package eu.kanade.mangafeed.ui.library;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -16,60 +15,78 @@ import butterknife.OnItemClick;
|
|||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.data.database.models.Category;
|
import eu.kanade.mangafeed.data.database.models.Category;
|
||||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||||
|
import eu.kanade.mangafeed.event.LibraryMangasEvent;
|
||||||
import eu.kanade.mangafeed.ui.base.fragment.BaseFragment;
|
import eu.kanade.mangafeed.ui.base.fragment.BaseFragment;
|
||||||
|
import eu.kanade.mangafeed.ui.main.MainActivity;
|
||||||
import eu.kanade.mangafeed.ui.manga.MangaActivity;
|
import eu.kanade.mangafeed.ui.manga.MangaActivity;
|
||||||
|
import eu.kanade.mangafeed.util.EventBusHook;
|
||||||
|
import icepick.Icepick;
|
||||||
|
import icepick.State;
|
||||||
|
|
||||||
public class LibraryCategoryFragment extends BaseFragment {
|
public class LibraryCategoryFragment extends BaseFragment {
|
||||||
|
|
||||||
@Bind(R.id.gridView) GridView grid;
|
@Bind(R.id.gridView) GridView grid;
|
||||||
|
|
||||||
private LibraryFragment parent;
|
protected LibraryCategoryAdapter adapter;
|
||||||
private LibraryAdapter adapter;
|
@State Category category;
|
||||||
private Category category;
|
|
||||||
private List<Manga> mangas;
|
|
||||||
|
|
||||||
public static LibraryCategoryFragment newInstance(LibraryFragment parent, Category category,
|
public static LibraryCategoryFragment newInstance(Category category) {
|
||||||
List<Manga> mangas) {
|
|
||||||
LibraryCategoryFragment fragment = new LibraryCategoryFragment();
|
LibraryCategoryFragment fragment = new LibraryCategoryFragment();
|
||||||
fragment.initialize(parent, category, mangas);
|
fragment.category = category;
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize(LibraryFragment parent, Category category, List<Manga> mangas) {
|
|
||||||
this.parent = parent;
|
|
||||||
this.category = category;
|
|
||||||
this.mangas = mangas;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
||||||
Bundle savedInstanceState) {
|
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_library_category, container, false);
|
View view = inflater.inflate(R.layout.fragment_library_category, container, false);
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
Icepick.restoreInstanceState(this, savedState);
|
||||||
|
|
||||||
adapter = new LibraryAdapter(parent);
|
adapter = new LibraryCategoryAdapter((MainActivity) getActivity());
|
||||||
grid.setAdapter(adapter);
|
grid.setAdapter(adapter);
|
||||||
|
|
||||||
if (mangas != null) {
|
|
||||||
setMangas(mangas);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
registerForStickyEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
unregisterForEvents();
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
Icepick.saveInstanceState(this, outState);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventBusHook
|
||||||
|
public void onEventMainThread(LibraryMangasEvent event) {
|
||||||
|
setMangas(event.getMangas().get(category.id));
|
||||||
|
}
|
||||||
|
|
||||||
@OnItemClick(R.id.gridView)
|
@OnItemClick(R.id.gridView)
|
||||||
protected void onMangaClick(int position) {
|
protected void onMangaClick(int position) {
|
||||||
Intent intent = MangaActivity.newIntent(
|
Intent intent = MangaActivity.newIntent(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
adapter.getItem(position)
|
adapter.getItem(position)
|
||||||
);
|
);
|
||||||
parent.getPresenter().onOpenManga();
|
|
||||||
getActivity().startActivity(intent);
|
getActivity().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMangas(List<Manga> mangas) {
|
public void setMangas(List<Manga> mangas) {
|
||||||
adapter.setNewItems(mangas);
|
if (mangas != null) {
|
||||||
|
adapter.setNewItems(mangas);
|
||||||
|
} else {
|
||||||
|
adapter.getItems().clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package eu.kanade.mangafeed.ui.library;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
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.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -13,23 +14,24 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.data.database.models.Category;
|
import eu.kanade.mangafeed.data.database.models.Category;
|
||||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
|
||||||
import eu.kanade.mangafeed.data.sync.LibraryUpdateService;
|
import eu.kanade.mangafeed.data.sync.LibraryUpdateService;
|
||||||
import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment;
|
import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment;
|
||||||
|
import eu.kanade.mangafeed.ui.main.MainActivity;
|
||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
|
|
||||||
@RequiresPresenter(LibraryPresenter.class)
|
@RequiresPresenter(LibraryPresenter.class)
|
||||||
public class LibraryFragment extends BaseRxFragment<LibraryPresenter> {
|
public class LibraryFragment extends BaseRxFragment<LibraryPresenter> {
|
||||||
|
|
||||||
@Bind(R.id.tabs) TabLayout tabs;
|
TabLayout tabs;
|
||||||
|
AppBarLayout appBar;
|
||||||
|
|
||||||
@Bind(R.id.view_pager) ViewPager categoriesPager;
|
@Bind(R.id.view_pager) ViewPager categoriesPager;
|
||||||
private LibraryCategoryAdapter adapter;
|
protected LibraryAdapter adapter;
|
||||||
|
|
||||||
public static LibraryFragment newInstance() {
|
public static LibraryFragment newInstance() {
|
||||||
return new LibraryFragment();
|
return new LibraryFragment();
|
||||||
@ -49,12 +51,23 @@ public class LibraryFragment extends BaseRxFragment<LibraryPresenter> {
|
|||||||
setToolbarTitle(getString(R.string.label_library));
|
setToolbarTitle(getString(R.string.label_library));
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
adapter = new LibraryCategoryAdapter(this, getChildFragmentManager());
|
appBar = ((MainActivity) getActivity()).getAppBar();
|
||||||
|
tabs = (TabLayout) inflater.inflate(R.layout.tab_layout, appBar, false);
|
||||||
|
appBar.addView(tabs);
|
||||||
|
|
||||||
|
|
||||||
|
adapter = new LibraryAdapter(getChildFragmentManager());
|
||||||
categoriesPager.setAdapter(adapter);
|
categoriesPager.setAdapter(adapter);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
appBar.removeView(tabs);
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.library, menu);
|
inflater.inflate(R.menu.library, menu);
|
||||||
@ -75,14 +88,9 @@ public class LibraryFragment extends BaseRxFragment<LibraryPresenter> {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNextMangas(Map<Integer, List<Manga>> mangas) {
|
|
||||||
adapter.setMangasOnCategories(mangas);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNextCategories(List<Category> categories) {
|
public void onNextCategories(List<Category> categories) {
|
||||||
List<Category> actualCategories = new ArrayList<>();
|
List<Category> actualCategories = new ArrayList<>();
|
||||||
|
|
||||||
// TODO should we always add this?
|
|
||||||
Category defaultCat = Category.create("Default");
|
Category defaultCat = Category.create("Default");
|
||||||
defaultCat.id = 0;
|
defaultCat.id = 0;
|
||||||
actualCategories.add(defaultCat);
|
actualCategories.add(defaultCat);
|
||||||
@ -90,6 +98,8 @@ public class LibraryFragment extends BaseRxFragment<LibraryPresenter> {
|
|||||||
actualCategories.addAll(categories);
|
actualCategories.addAll(categories);
|
||||||
adapter.setCategories(actualCategories);
|
adapter.setCategories(actualCategories);
|
||||||
tabs.setupWithViewPager(categoriesPager);
|
tabs.setupWithViewPager(categoriesPager);
|
||||||
|
|
||||||
|
tabs.setVisibility(actualCategories.size() == 1 ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,15 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import de.greenrobot.event.EventBus;
|
||||||
import eu.kanade.mangafeed.data.cache.CoverCache;
|
import eu.kanade.mangafeed.data.cache.CoverCache;
|
||||||
import eu.kanade.mangafeed.data.database.DatabaseHelper;
|
import eu.kanade.mangafeed.data.database.DatabaseHelper;
|
||||||
import eu.kanade.mangafeed.data.database.models.Category;
|
|
||||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||||
import eu.kanade.mangafeed.data.preference.PreferencesHelper;
|
import eu.kanade.mangafeed.data.preference.PreferencesHelper;
|
||||||
import eu.kanade.mangafeed.data.source.SourceManager;
|
import eu.kanade.mangafeed.data.source.SourceManager;
|
||||||
|
import eu.kanade.mangafeed.event.LibraryMangasEvent;
|
||||||
import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
|
import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
|
||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
|
|
||||||
public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
||||||
@ -27,7 +27,6 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
|||||||
@Inject SourceManager sourceManager;
|
@Inject SourceManager sourceManager;
|
||||||
|
|
||||||
private static final int GET_CATEGORIES = 1;
|
private static final int GET_CATEGORIES = 1;
|
||||||
private static final int GET_MANGAS = 2;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedState) {
|
protected void onCreate(Bundle savedState) {
|
||||||
@ -37,20 +36,20 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
|||||||
() -> db.getCategories().createObservable(),
|
() -> db.getCategories().createObservable(),
|
||||||
LibraryFragment::onNextCategories);
|
LibraryFragment::onNextCategories);
|
||||||
|
|
||||||
restartableLatestCache(GET_MANGAS,
|
|
||||||
this::getLibraryMangasObservable,
|
|
||||||
LibraryFragment::onNextMangas);
|
|
||||||
|
|
||||||
start(GET_CATEGORIES);
|
start(GET_CATEGORIES);
|
||||||
|
|
||||||
|
add(getLibraryMangasObservable()
|
||||||
|
.subscribe(mangas ->
|
||||||
|
EventBus.getDefault().postSticky(new LibraryMangasEvent(mangas))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Observable<Map<Integer, List<Manga>>> getLibraryMangasObservable() {
|
||||||
protected void onTakeView(LibraryFragment view) {
|
return db.getLibraryMangas().createObservable()
|
||||||
super.onTakeView(view);
|
.flatMap(mangas -> Observable.from(mangas)
|
||||||
|
.groupBy(manga -> manga.category)
|
||||||
if (!isSubscribed(GET_MANGAS)) {
|
.flatMap(group -> group.toList()
|
||||||
start(GET_MANGAS);
|
.map(list -> Pair.create(group.getKey(), list)))
|
||||||
}
|
.toMap(pair -> pair.first, pair -> pair.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteMangas(Observable<Manga> selectedMangas) {
|
public void deleteMangas(Observable<Manga> selectedMangas) {
|
||||||
@ -62,17 +61,5 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
|||||||
.subscribe());
|
.subscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<Map<Integer, List<Manga>>> getLibraryMangasObservable() {
|
|
||||||
return db.getLibraryMangas().createObservable()
|
|
||||||
.flatMap(mangas -> Observable.from(mangas)
|
|
||||||
.groupBy(manga -> manga.category)
|
|
||||||
.flatMap(group -> group.toList()
|
|
||||||
.map(list -> Pair.create(group.getKey(), list)))
|
|
||||||
.toMap(pair -> pair.first, pair -> pair.second))
|
|
||||||
.observeOn(AndroidSchedulers.mainThread());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onOpenManga() {
|
|
||||||
stop(GET_MANGAS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package eu.kanade.mangafeed.ui.main;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.AppBarLayout;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@ -22,6 +23,7 @@ import nucleus.view.ViewWithPresenter;
|
|||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
|
@Bind(R.id.appbar) AppBarLayout appBar;
|
||||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||||
|
|
||||||
@Bind(R.id.drawer_container) FrameLayout container;
|
@Bind(R.id.drawer_container) FrameLayout container;
|
||||||
@ -111,8 +113,16 @@ public class MainActivity extends BaseActivity {
|
|||||||
fragmentStack.replace(fragment);
|
fragmentStack.replace(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Fragment getActiveFragment() {
|
||||||
|
return fragmentStack.peek();
|
||||||
|
}
|
||||||
|
|
||||||
public Toolbar getToolbar() {
|
public Toolbar getToolbar() {
|
||||||
return toolbar;
|
return toolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AppBarLayout getAppBar() {
|
||||||
|
return appBar;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,10 @@ public class MangaActivity extends BaseRxActivity<MangaPresenter> {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
App.get(this).getComponent().inject(this);
|
App.get(this).getComponent().inject(this);
|
||||||
setContentView(R.layout.activity_manga_detail);
|
setContentView(R.layout.activity_manga);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
setupToolbar(toolbar);
|
setupToolbar(toolbar);
|
||||||
setToolbarElevation(0);
|
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
|
|
||||||
|
@ -3,16 +3,22 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center">
|
android:gravity="center">
|
||||||
|
|
||||||
<include
|
<android.support.design.widget.AppBarLayout
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/appbar"
|
||||||
layout="@layout/toolbar" />
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:theme="@style/ThemeOverlay.AppTheme.Dark">
|
||||||
|
|
||||||
|
<include layout="@layout/toolbar" />
|
||||||
|
|
||||||
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
<!-- the layout which will contain (host) the drawerLayout -->
|
<!-- the layout which will contain (host) the drawerLayout -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/drawer_container"
|
android:id="@+id/drawer_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_below="@id/toolbar">
|
android:layout_below="@id/appbar">
|
||||||
|
|
||||||
<!-- the layout which will be the content of the activity (which will be hosted inside the drawer (NOT the list of the drawer)) -->
|
<!-- the layout which will be the content of the activity (which will be hosted inside the drawer (NOT the list of the drawer)) -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -14,14 +13,7 @@
|
|||||||
|
|
||||||
<include layout="@layout/toolbar" />
|
<include layout="@layout/toolbar" />
|
||||||
|
|
||||||
<android.support.design.widget.TabLayout
|
<include layout="@layout/tab_layout" />
|
||||||
android:id="@+id/tabs"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:theme="@style/ThemeOverlay.AppTheme.Dark"
|
|
||||||
app:tabGravity="fill"
|
|
||||||
android:background="@color/colorPrimary"
|
|
||||||
app:tabIndicatorColor="@color/white" />
|
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
@ -3,9 +3,7 @@
|
|||||||
android:orientation="vertical" android:layout_width="match_parent"
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<include
|
<include layout="@layout/toolbar"/>
|
||||||
android:id="@+id/toolbar"
|
|
||||||
layout="@layout/toolbar"/>
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/settings_content"
|
android:id="@+id/settings_content"
|
||||||
|
@ -1,27 +1,8 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<android.support.design.widget.AppBarLayout
|
|
||||||
android:id="@+id/appbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:theme="@style/ThemeOverlay.AppTheme.Dark">
|
|
||||||
|
|
||||||
<android.support.design.widget.TabLayout
|
|
||||||
android:id="@+id/tabs"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:theme="@style/ThemeOverlay.AppTheme.Dark"
|
|
||||||
app:tabGravity="fill"
|
|
||||||
android:background="@color/colorPrimary"
|
|
||||||
app:tabIndicatorColor="@color/white" />
|
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
|
||||||
|
|
||||||
<android.support.v4.view.ViewPager
|
<android.support.v4.view.ViewPager
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
12
app/src/main/res/layout/tab_layout.xml
Normal file
12
app/src/main/res/layout/tab_layout.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.design.widget.TabLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/tabs"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:theme="@style/ThemeOverlay.AppTheme.Dark"
|
||||||
|
app:tabGravity="fill"
|
||||||
|
android:background="@color/colorPrimary"
|
||||||
|
android:elevation="4dp"
|
||||||
|
app:tabIndicatorColor="@color/white"/>
|
Loading…
Reference in New Issue
Block a user