|
@@ -4,7 +4,10 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
+import android.support.v4.content.ContextCompat;
|
|
|
import android.support.v7.widget.GridLayoutManager;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
import android.support.v7.widget.SearchView;
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
import android.text.TextUtils;
|
|
@@ -14,9 +17,12 @@ import android.view.MenuInflater;
|
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.view.animation.Animation;
|
|
|
+import android.view.animation.AnimationUtils;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.ProgressBar;
|
|
|
import android.widget.Spinner;
|
|
|
+import android.widget.ViewSwitcher;
|
|
|
|
|
|
import com.afollestad.materialdialogs.MaterialDialog;
|
|
|
|
|
@@ -30,11 +36,13 @@ import eu.kanade.tachiyomi.data.database.models.Manga;
|
|
|
import eu.kanade.tachiyomi.data.source.base.Source;
|
|
|
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder;
|
|
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment;
|
|
|
+import eu.kanade.tachiyomi.ui.decoration.DividerItemDecoration;
|
|
|
import eu.kanade.tachiyomi.ui.main.MainActivity;
|
|
|
import eu.kanade.tachiyomi.ui.manga.MangaActivity;
|
|
|
import eu.kanade.tachiyomi.util.ToastUtil;
|
|
|
import eu.kanade.tachiyomi.widget.AutofitRecyclerView;
|
|
|
-import eu.kanade.tachiyomi.widget.EndlessRecyclerScrollListener;
|
|
|
+import eu.kanade.tachiyomi.widget.EndlessGridScrollListener;
|
|
|
+import eu.kanade.tachiyomi.widget.EndlessListScrollListener;
|
|
|
import icepick.State;
|
|
|
import nucleus.factory.RequiresPresenter;
|
|
|
import rx.Subscription;
|
|
@@ -45,14 +53,17 @@ import rx.subjects.PublishSubject;
|
|
|
public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
implements FlexibleViewHolder.OnListItemClickListener {
|
|
|
|
|
|
- @Bind(R.id.recycler) AutofitRecyclerView recycler;
|
|
|
+ @Bind(R.id.switcher) ViewSwitcher switcher;
|
|
|
+ @Bind(R.id.catalogue_grid) AutofitRecyclerView catalogueGrid;
|
|
|
+ @Bind(R.id.catalogue_list) RecyclerView catalogueList;
|
|
|
@Bind(R.id.progress) ProgressBar progress;
|
|
|
@Bind(R.id.progress_grid) ProgressBar progressGrid;
|
|
|
|
|
|
private Toolbar toolbar;
|
|
|
private Spinner spinner;
|
|
|
private CatalogueAdapter adapter;
|
|
|
- private EndlessRecyclerScrollListener scrollListener;
|
|
|
+ private EndlessGridScrollListener gridScrollListener;
|
|
|
+ private EndlessListScrollListener listScrollListener;
|
|
|
|
|
|
@State String query = "";
|
|
|
@State int selectedIndex = -1;
|
|
@@ -61,6 +72,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
private PublishSubject<String> queryDebouncerSubject;
|
|
|
private Subscription queryDebouncerSubscription;
|
|
|
|
|
|
+ private MenuItem displayMode;
|
|
|
+
|
|
|
public static CatalogueFragment newInstance() {
|
|
|
return new CatalogueFragment();
|
|
|
}
|
|
@@ -77,13 +90,32 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
View view = inflater.inflate(R.layout.fragment_catalogue, container, false);
|
|
|
ButterKnife.bind(this, view);
|
|
|
|
|
|
- // Initialize adapter and scroll listener
|
|
|
- GridLayoutManager layoutManager = (GridLayoutManager) recycler.getLayoutManager();
|
|
|
+ // Initialize adapter, scroll listener and recycler views
|
|
|
adapter = new CatalogueAdapter(this);
|
|
|
- scrollListener = new EndlessRecyclerScrollListener(layoutManager, this::requestNextPage);
|
|
|
- recycler.setHasFixedSize(true);
|
|
|
- recycler.setAdapter(adapter);
|
|
|
- recycler.addOnScrollListener(scrollListener);
|
|
|
+
|
|
|
+ GridLayoutManager glm = (GridLayoutManager) catalogueGrid.getLayoutManager();
|
|
|
+ gridScrollListener = new EndlessGridScrollListener(glm, this::requestNextPage);
|
|
|
+ catalogueGrid.setHasFixedSize(true);
|
|
|
+ catalogueGrid.setAdapter(adapter);
|
|
|
+ catalogueGrid.addOnScrollListener(gridScrollListener);
|
|
|
+
|
|
|
+ LinearLayoutManager llm = new LinearLayoutManager(getActivity());
|
|
|
+ listScrollListener = new EndlessListScrollListener(llm, this::requestNextPage);
|
|
|
+ catalogueList.setHasFixedSize(true);
|
|
|
+ catalogueList.setAdapter(adapter);
|
|
|
+ catalogueList.setLayoutManager(llm);
|
|
|
+ catalogueList.addOnScrollListener(listScrollListener);
|
|
|
+ catalogueList.addItemDecoration(new DividerItemDecoration(
|
|
|
+ ContextCompat.getDrawable(getContext(), R.drawable.line_divider)));
|
|
|
+
|
|
|
+ if (getPresenter().isListMode()) {
|
|
|
+ switcher.showNext();
|
|
|
+ }
|
|
|
+
|
|
|
+ Animation inAnim = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in);
|
|
|
+ Animation outAnim = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out);
|
|
|
+ switcher.setInAnimation(inAnim);
|
|
|
+ switcher.setOutAnimation(outAnim);
|
|
|
|
|
|
// Create toolbar spinner
|
|
|
Context themedContext = getBaseActivity().getSupportActionBar() != null ?
|
|
@@ -109,7 +141,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
} else {
|
|
|
selectedIndex = position;
|
|
|
showProgressBar();
|
|
|
- recycler.setAdapter(adapter);
|
|
|
+ glm.scrollToPositionWithOffset(0, 0);
|
|
|
+ llm.scrollToPositionWithOffset(0, 0);
|
|
|
getPresenter().startRequesting(source);
|
|
|
}
|
|
|
}
|
|
@@ -152,6 +185,22 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ // Show next display mode
|
|
|
+ displayMode = menu.findItem(R.id.action_display_mode);
|
|
|
+ int icon = getPresenter().isListMode() ?
|
|
|
+ R.drawable.ic_view_module_white_24dp : R.drawable.ic_view_list_white_24dp;
|
|
|
+ displayMode.setIcon(icon);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ switch (item.getItemId()) {
|
|
|
+ case R.id.action_display_mode:
|
|
|
+ swapDisplayMode();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -198,7 +247,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
|
|
|
query = newQuery;
|
|
|
showProgressBar();
|
|
|
- recycler.getLayoutManager().scrollToPosition(0);
|
|
|
+ catalogueGrid.getLayoutManager().scrollToPosition(0);
|
|
|
+ catalogueList.getLayoutManager().scrollToPosition(0);
|
|
|
|
|
|
getPresenter().restartRequest(query);
|
|
|
}
|
|
@@ -214,7 +264,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
hideProgressBar();
|
|
|
if (page == 0) {
|
|
|
adapter.clear();
|
|
|
- scrollListener.resetScroll();
|
|
|
+ gridScrollListener.resetScroll();
|
|
|
+ listScrollListener.resetScroll();
|
|
|
}
|
|
|
adapter.addItems(mangas);
|
|
|
}
|
|
@@ -224,15 +275,28 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
|
|
|
}
|
|
|
|
|
|
public void updateImage(Manga manga) {
|
|
|
- CatalogueHolder holder = getHolder(manga);
|
|
|
+ CatalogueGridHolder holder = getHolder(manga);
|
|
|
if (holder != null) {
|
|
|
holder.setImage(manga, getPresenter());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void swapDisplayMode() {
|
|
|
+ getPresenter().swapDisplayMode();
|
|
|
+ boolean isListMode = getPresenter().isListMode();
|
|
|
+ int icon = isListMode ?
|
|
|
+ R.drawable.ic_view_module_white_24dp : R.drawable.ic_view_list_white_24dp;
|
|
|
+ displayMode.setIcon(icon);
|
|
|
+ switcher.showNext();
|
|
|
+ if (!isListMode) {
|
|
|
+ // Initialize mangas if going to grid view
|
|
|
+ getPresenter().initializeMangas(adapter.getItems());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Nullable
|
|
|
- private CatalogueHolder getHolder(Manga manga) {
|
|
|
- return (CatalogueHolder) recycler.findViewHolderForItemId(manga.id);
|
|
|
+ private CatalogueGridHolder getHolder(Manga manga) {
|
|
|
+ return (CatalogueGridHolder) catalogueGrid.findViewHolderForItemId(manga.id);
|
|
|
}
|
|
|
|
|
|
private void showProgressBar() {
|