|
@@ -14,15 +14,11 @@ import com.f2prateek.rx.preferences.Preference;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-import javax.inject.Inject;
|
|
|
|
-
|
|
|
|
import butterknife.Bind;
|
|
import butterknife.Bind;
|
|
import butterknife.ButterKnife;
|
|
import butterknife.ButterKnife;
|
|
-import eu.kanade.mangafeed.App;
|
|
|
|
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.data.preference.PreferencesHelper;
|
|
|
|
import eu.kanade.mangafeed.event.LibraryMangasEvent;
|
|
import eu.kanade.mangafeed.event.LibraryMangasEvent;
|
|
import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
|
|
import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
|
|
import eu.kanade.mangafeed.ui.base.adapter.FlexibleViewHolder;
|
|
import eu.kanade.mangafeed.ui.base.adapter.FlexibleViewHolder;
|
|
@@ -37,8 +33,6 @@ import rx.Subscription;
|
|
public class LibraryCategoryFragment extends BaseFragment implements
|
|
public class LibraryCategoryFragment extends BaseFragment implements
|
|
ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener {
|
|
ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener {
|
|
|
|
|
|
- @Inject PreferencesHelper preferences;
|
|
|
|
-
|
|
|
|
@Bind(R.id.library_mangas) AutofitRecyclerView recycler;
|
|
@Bind(R.id.library_mangas) AutofitRecyclerView recycler;
|
|
|
|
|
|
@State Category category;
|
|
@State Category category;
|
|
@@ -47,20 +41,12 @@ public class LibraryCategoryFragment extends BaseFragment implements
|
|
|
|
|
|
private Subscription numColumnsSubscription;
|
|
private Subscription numColumnsSubscription;
|
|
|
|
|
|
- private static final int INVALID_POSITION = -1;
|
|
|
|
-
|
|
|
|
public static LibraryCategoryFragment newInstance(Category category) {
|
|
public static LibraryCategoryFragment newInstance(Category category) {
|
|
LibraryCategoryFragment fragment = new LibraryCategoryFragment();
|
|
LibraryCategoryFragment fragment = new LibraryCategoryFragment();
|
|
fragment.category = category;
|
|
fragment.category = category;
|
|
return fragment;
|
|
return fragment;
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public void onCreate(Bundle savedInstanceState) {
|
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
|
- App.get(getActivity()).getComponent().inject(this);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
|
// Inflate the layout for this fragment
|
|
// Inflate the layout for this fragment
|
|
@@ -75,8 +61,8 @@ public class LibraryCategoryFragment extends BaseFragment implements
|
|
|
|
|
|
Preference<Integer> columnsPref = getResources().getConfiguration()
|
|
Preference<Integer> columnsPref = getResources().getConfiguration()
|
|
.orientation == Configuration.ORIENTATION_PORTRAIT ?
|
|
.orientation == Configuration.ORIENTATION_PORTRAIT ?
|
|
- preferences.portraitColumns() :
|
|
|
|
- preferences.landscapeColumns();
|
|
|
|
|
|
+ getLibraryPresenter().preferences.portraitColumns() :
|
|
|
|
+ getLibraryPresenter().preferences.landscapeColumns();
|
|
|
|
|
|
numColumnsSubscription = columnsPref.asObservable()
|
|
numColumnsSubscription = columnsPref.asObservable()
|
|
.subscribe(recycler::setSpanCount);
|
|
.subscribe(recycler::setSpanCount);
|
|
@@ -110,6 +96,7 @@ public class LibraryCategoryFragment extends BaseFragment implements
|
|
|
|
|
|
@EventBusHook
|
|
@EventBusHook
|
|
public void onEventMainThread(LibraryMangasEvent event) {
|
|
public void onEventMainThread(LibraryMangasEvent event) {
|
|
|
|
+ destroyActionModeIfNeeded();
|
|
setMangas(event.getMangas().get(category.id));
|
|
setMangas(event.getMangas().get(category.id));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -128,7 +115,7 @@ public class LibraryCategoryFragment extends BaseFragment implements
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean onListItemClick(int position) {
|
|
public boolean onListItemClick(int position) {
|
|
- if (actionMode != null && position != INVALID_POSITION) {
|
|
|
|
|
|
+ if (actionMode != null && position != -1) {
|
|
toggleSelection(position);
|
|
toggleSelection(position);
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
@@ -145,6 +132,22 @@ public class LibraryCategoryFragment extends BaseFragment implements
|
|
toggleSelection(position);
|
|
toggleSelection(position);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void toggleSelection(int position) {
|
|
|
|
+ adapter.toggleSelection(position, false);
|
|
|
|
+
|
|
|
|
+ int count = adapter.getSelectedItemCount();
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ actionMode.finish();
|
|
|
|
+ } else {
|
|
|
|
+ setContextTitle(count);
|
|
|
|
+ actionMode.invalidate();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setContextTitle(int count) {
|
|
|
|
+ actionMode.setTitle(getString(R.string.label_selected, count));
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
mode.getMenuInflater().inflate(R.menu.library_selection, menu);
|
|
mode.getMenuInflater().inflate(R.menu.library_selection, menu);
|
|
@@ -169,19 +172,17 @@ public class LibraryCategoryFragment extends BaseFragment implements
|
|
actionMode = null;
|
|
actionMode = null;
|
|
}
|
|
}
|
|
|
|
|
|
- private void toggleSelection(int position) {
|
|
|
|
- adapter.toggleSelection(position, false);
|
|
|
|
-
|
|
|
|
- int count = adapter.getSelectedItemCount();
|
|
|
|
- if (count == 0) {
|
|
|
|
|
|
+ public void destroyActionModeIfNeeded() {
|
|
|
|
+ if (actionMode != null) {
|
|
actionMode.finish();
|
|
actionMode.finish();
|
|
- } else {
|
|
|
|
- setContextTitle(count);
|
|
|
|
- actionMode.invalidate();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void setContextTitle(int count) {
|
|
|
|
- actionMode.setTitle(getString(R.string.selected_chapters_title, count));
|
|
|
|
|
|
+ private LibraryFragment getLibraryFragment() {
|
|
|
|
+ return (LibraryFragment) getParentFragment();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private LibraryPresenter getLibraryPresenter() {
|
|
|
|
+ return getLibraryFragment().getPresenter();
|
|
}
|
|
}
|
|
}
|
|
}
|