mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-24 18:08:24 +01:00
Can now filter downloads only on library view. Fix #27
This commit is contained in:
parent
e4ee03cb61
commit
d9f5a97d56
@ -182,4 +182,8 @@ class PreferencesHelper(private val context: Context) {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_library_update_interval_key), 0)
|
||||
}
|
||||
|
||||
fun filterDownloaded(): Preference<Boolean> {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_filter_downloaded), false)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
isFilterDownloaded = presenter.preferences.filterDownloaded().get() as Boolean
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? {
|
||||
@ -116,6 +128,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 +164,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 +175,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 +193,25 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_filter_unread -> {
|
||||
isFilterUnread = !isFilterUnread
|
||||
activity.supportInvalidateOptionsMenu();
|
||||
ToastUtil.showShort(context, "Filter Unread Clicked")
|
||||
}
|
||||
R.id.action_filter_downloaded -> {
|
||||
isFilterDownloaded = !isFilterDownloaded
|
||||
presenter.preferences.filterDownloaded().set(isFilterDownloaded)
|
||||
presenter.updateLibrary()
|
||||
adapter.notifyDataSetChanged()
|
||||
activity.supportInvalidateOptionsMenu();
|
||||
ToastUtil.showShort(context, "Filter Download Clicked")
|
||||
}
|
||||
R.id.action_filter_empty -> {
|
||||
isFilterUnread = false
|
||||
isFilterDownloaded = false
|
||||
activity.supportInvalidateOptionsMenu();
|
||||
ToastUtil.showShort(context, "Filter Clear Clicked")
|
||||
}
|
||||
R.id.action_refresh -> LibraryUpdateService.start(activity)
|
||||
R.id.action_edit_categories -> {
|
||||
val intent = CategoryActivity.newIntent(activity)
|
||||
@ -211,6 +255,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()
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,10 @@ import android.util.Pair
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaCategory
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||
import eu.kanade.tachiyomi.event.LibraryMangasEvent
|
||||
@ -35,6 +37,8 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
*/
|
||||
lateinit var selectedMangas: MutableList<Manga>
|
||||
|
||||
lateinit var libraryFragment: LibraryFragment
|
||||
|
||||
/**
|
||||
* Search query of the library.
|
||||
*/
|
||||
@ -91,6 +95,7 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
|
||||
override fun onTakeView(libraryFragment: LibraryFragment) {
|
||||
super.onTakeView(libraryFragment)
|
||||
this.libraryFragment = libraryFragment
|
||||
if (isUnsubscribed(GET_LIBRARY)) {
|
||||
start(GET_LIBRARY)
|
||||
}
|
||||
@ -107,6 +112,10 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun updateLibrary() {
|
||||
start(GET_LIBRARY)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the categories from the database.
|
||||
*
|
||||
@ -126,12 +135,32 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
fun getLibraryMangasObservable(): Observable<Map<Int, List<Manga>>> {
|
||||
return db.libraryMangas.asRxObservable()
|
||||
.flatMap { mangas -> Observable.from(mangas)
|
||||
.filter {
|
||||
if (preferences.filterDownloaded().get() as Boolean) {
|
||||
val downloadManager = DownloadManager(context, sourceManager, preferences)
|
||||
|
||||
val chapters = getChapters(it)
|
||||
|
||||
var hasDownloaded = false
|
||||
chapters?.forEach { chapter ->
|
||||
if (downloadManager.isChapterDownloaded(sourceManager.get(it.source), it, chapter)) {
|
||||
hasDownloaded = true
|
||||
}
|
||||
}
|
||||
hasDownloaded
|
||||
} else
|
||||
true
|
||||
}
|
||||
.groupBy { it.category }
|
||||
.flatMap { group -> group.toList().map { Pair(group.key, it) } }
|
||||
.toMap({ it.first }, { it.second })
|
||||
}
|
||||
}
|
||||
|
||||
fun getChapters(manga: Manga): MutableList<Chapter>? {
|
||||
return db.getChapters(manga).executeAsBlocking()
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a manga is opened.
|
||||
*/
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_filter_list_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_filter_list_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 111 B |
BIN
app/src/main/res/drawable-mdpi/ic_filter_list_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_filter_list_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 B |
BIN
app/src/main/res/drawable-xhdpi/ic_filter_list_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_filter_list_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 103 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_filter_list_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_filter_list_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 107 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 B |
@ -2,6 +2,26 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_filter"
|
||||
android:title="@string/action_filter"
|
||||
android:icon="@drawable/ic_filter_list_white_24dp"
|
||||
app:showAsAction="ifRoom">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/action_filter_downloaded"
|
||||
android:checkable="true"
|
||||
android:title="@string/action_filter_downloaded"/>
|
||||
<item
|
||||
android:id="@+id/action_filter_unread"
|
||||
android:checkable="true"
|
||||
android:title="@string/action_filter_unread"/>
|
||||
<item
|
||||
android:id="@+id/action_filter_empty"
|
||||
android:title="@string/action_filter_empty"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_search"
|
||||
android:title="@string/action_search"
|
||||
|
@ -28,6 +28,7 @@
|
||||
<string name="pref_reader_theme_key">pref_reader_theme_key</string>
|
||||
<string name="pref_image_decoder_key">pref_image_decoder_key</string>
|
||||
<string name="pref_seamless_mode_key">pref_seamless_mode_key</string>
|
||||
<string name="pref_filter_downloaded">pref_filter_downloaded</string>
|
||||
|
||||
<string name="pref_download_directory_key">pref_download_directory_key</string>
|
||||
<string name="pref_download_slots_key">pref_download_slots_key</string>
|
||||
|
@ -14,6 +14,10 @@
|
||||
|
||||
<!-- Actions -->
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_filter">Filter</string>
|
||||
<string name="action_filter_downloaded">Downloaded</string>
|
||||
<string name="action_filter_unread">Unread</string>
|
||||
<string name="action_filter_empty">Remove filter</string>
|
||||
<string name="action_search">Search</string>
|
||||
<string name="action_refresh">Refresh</string>
|
||||
<string name="action_select_all">Select all</string>
|
||||
|
@ -15,7 +15,7 @@
|
||||
<item name="actionModeBackground">@color/colorPrimarySuperDark</item>
|
||||
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
|
||||
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
|
||||
<item name="colorAccent">@color/white</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.Overlay.Dark" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
|
Loading…
Reference in New Issue
Block a user