|
@@ -74,6 +74,17 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
*/
|
|
|
private var selectedCoverManga: Manga? = null
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TODO
|
|
|
+ */
|
|
|
+ var isFilterDownloaded = false
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TODO
|
|
|
+ */
|
|
|
+ var isFilterUnread = false
|
|
|
+
|
|
|
companion object {
|
|
|
/**
|
|
|
* Key to change the cover of a manga in [onActivityResult].
|
|
@@ -104,6 +115,8 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setHasOptionsMenu(true)
|
|
|
+ isFilterDownloaded = presenter.preferences.filterDownloaded().get() as Boolean
|
|
|
+ isFilterUnread = presenter.preferences.filterUnread().get() as Boolean
|
|
|
}
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? {
|
|
@@ -116,6 +129,14 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
|
|
|
appBar = (activity as MainActivity).appBar
|
|
|
tabs = appBar.inflate(R.layout.library_tab_layout) as TabLayout
|
|
|
+
|
|
|
+ // Workaround to prevent: Tab belongs to a different TabLayout.
|
|
|
+ // Internal bug in Support library v23.2.0.
|
|
|
+ // See https://code.google.com/p/android/issues/detail?id=201827
|
|
|
+ for (j in 0..16) {
|
|
|
+ tabs.newTab()
|
|
|
+ }
|
|
|
+
|
|
|
appBar.addView(tabs)
|
|
|
|
|
|
adapter = LibraryAdapter(childFragmentManager)
|
|
@@ -144,6 +165,8 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
inflater.inflate(R.menu.library, menu)
|
|
|
|
|
|
// Initialize search menu
|
|
|
+ val filterDownloadedItem = menu.findItem(R.id.action_filter_downloaded)
|
|
|
+ val filterUnreadItem = menu.findItem(R.id.action_filter_unread)
|
|
|
val searchItem = menu.findItem(R.id.action_search)
|
|
|
val searchView = searchItem.actionView as SearchView
|
|
|
|
|
@@ -153,6 +176,9 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
searchView.clearFocus()
|
|
|
}
|
|
|
|
|
|
+ filterDownloadedItem.isChecked = isFilterDownloaded;
|
|
|
+ filterUnreadItem.isChecked = isFilterUnread;
|
|
|
+
|
|
|
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
|
|
override fun onQueryTextSubmit(query: String): Boolean {
|
|
|
onSearchTextChange(query)
|
|
@@ -168,6 +194,32 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
when (item.itemId) {
|
|
|
+ R.id.action_filter_unread -> {
|
|
|
+ // Change unread filter status.
|
|
|
+ isFilterUnread = !isFilterUnread
|
|
|
+ // Update settings.
|
|
|
+ presenter.preferences.filterUnread().set(isFilterUnread)
|
|
|
+ // Apply filter.
|
|
|
+ onFilterCheckboxChanged()
|
|
|
+ }
|
|
|
+ R.id.action_filter_downloaded -> {
|
|
|
+ // Change downloaded filter status.
|
|
|
+ isFilterDownloaded = !isFilterDownloaded
|
|
|
+ // Update settings.
|
|
|
+ presenter.preferences.filterDownloaded().set(isFilterDownloaded)
|
|
|
+ // Apply filter.
|
|
|
+ onFilterCheckboxChanged()
|
|
|
+ }
|
|
|
+ R.id.action_filter_empty -> {
|
|
|
+ // Remove filter status.
|
|
|
+ isFilterUnread = false
|
|
|
+ isFilterDownloaded = false
|
|
|
+ // Update settings.
|
|
|
+ presenter.preferences.filterUnread().set(isFilterUnread)
|
|
|
+ presenter.preferences.filterDownloaded().set(isFilterDownloaded)
|
|
|
+ // Apply filter
|
|
|
+ onFilterCheckboxChanged()
|
|
|
+ }
|
|
|
R.id.action_refresh -> LibraryUpdateService.start(activity)
|
|
|
R.id.action_edit_categories -> {
|
|
|
val intent = CategoryActivity.newIntent(activity)
|
|
@@ -179,6 +231,16 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Applies filter change
|
|
|
+ */
|
|
|
+ private fun onFilterCheckboxChanged() {
|
|
|
+ presenter.updateLibrary()
|
|
|
+ adapter.notifyDataSetChanged()
|
|
|
+ adapter.refreshRegisteredAdapters()
|
|
|
+ activity.supportInvalidateOptionsMenu();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Updates the query.
|
|
|
*
|
|
@@ -211,6 +273,10 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|
|
// Restore active category.
|
|
|
view_pager.setCurrentItem(activeCat, false)
|
|
|
if (tabs.tabCount > 0) {
|
|
|
+ // Prevent IndexOutOfBoundsException
|
|
|
+ if (tabs.tabCount <= view_pager.currentItem) {
|
|
|
+ view_pager.currentItem = (tabs.tabCount - 1)
|
|
|
+ }
|
|
|
tabs.getTabAt(view_pager.currentItem)?.select()
|
|
|
}
|
|
|
|