Added Manga/Manwha only option to filters

Fixes to the download listener
This commit is contained in:
Jay 2020-02-06 16:54:37 -08:00
parent 733dc3765e
commit 562de30173
10 changed files with 142 additions and 46 deletions

View File

@ -1,9 +1,27 @@
package eu.kanade.tachiyomi.data.database.models package eu.kanade.tachiyomi.data.database.models
import eu.kanade.tachiyomi.source.SourceManager
import uy.kohesive.injekt.injectLazy
import java.util.Locale
class LibraryManga : MangaImpl() { class LibraryManga : MangaImpl() {
var unread: Int = 0 var unread: Int = 0
var category: Int = 0 var category: Int = 0
fun mangaType(): Int {
val sourceManager:SourceManager by injectLazy()
return if (currentGenres()?.split(",")?.any
{ tag -> tag.trim().toLowerCase(Locale.getDefault()) == "long strip" } == true ||
sourceManager.getOrStub(source).name.contains("webtoon", true))
MANWHA
else MANGA
}
companion object {
const val MANGA = 1
const val MANWHA = 2
}
} }

View File

@ -77,7 +77,6 @@ class DownloadService : Service() {
* @param context the application context. * @param context the application context.
*/ */
fun stop(context: Context) { fun stop(context: Context) {
callListeners()
context.stopService(Intent(context, DownloadService::class.java)) context.stopService(Intent(context, DownloadService::class.java))
} }
@ -134,6 +133,7 @@ class DownloadService : Service() {
runningRelay.call(false) runningRelay.call(false)
subscriptions.unsubscribe() subscriptions.unsubscribe()
downloadManager.stopDownloads() downloadManager.stopDownloads()
callListeners()
wakeLock.releaseIfNeeded() wakeLock.releaseIfNeeded()
super.onDestroy() super.onDestroy()
} }

View File

@ -97,7 +97,9 @@ object PreferenceKeys {
const val filterCompleted = "pref_filter_completed_key" const val filterCompleted = "pref_filter_completed_key"
const val filterTrcaked = "pref_filter_tracked_key" const val filterTracked = "pref_filter_tracked_key"
const val filterMangaType = "pref_filter_manga_type_key"
const val librarySortingMode = "library_sorting_mode" const val librarySortingMode = "library_sorting_mode"

View File

@ -183,7 +183,9 @@ class PreferencesHelper(val context: Context) {
fun filterCompleted() = rxPrefs.getInteger(Keys.filterCompleted, 0) fun filterCompleted() = rxPrefs.getInteger(Keys.filterCompleted, 0)
fun filterTracked() = rxPrefs.getInteger(Keys.filterTrcaked, 0) fun filterTracked() = rxPrefs.getInteger(Keys.filterTracked, 0)
fun filterMangaType() = rxPrefs.getInteger(Keys.filterMangaType, 0)
fun hideCategories() = rxPrefs.getBoolean("hide_categories", false) fun hideCategories() = rxPrefs.getBoolean("hide_categories", false)

View File

@ -7,15 +7,23 @@ import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.util.view.inflate
import kotlinx.android.synthetic.main.filter_bottom_sheet.view.* import kotlinx.android.synthetic.main.filter_bottom_sheet.view.*
import kotlinx.android.synthetic.main.filter_buttons.view.* import kotlinx.android.synthetic.main.filter_buttons.view.*
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -40,15 +48,17 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
private lateinit var categories:FilterTagGroup private lateinit var categories:FilterTagGroup
private var mangaType:FilterTagGroup? = null
var lastCategory:Category? = null var lastCategory:Category? = null
val filterItems:List<FilterTagGroup> by lazy { val filterItems:List<FilterTagGroup> by lazy {
val list = mutableListOf<FilterTagGroup>() val list = mutableListOf<FilterTagGroup>()
if (Injekt.get<DatabaseHelper>().getCategories().executeAsBlocking().isNotEmpty())
list.add(categories)
list.add(downloaded) list.add(downloaded)
list.add(unread) list.add(unread)
list.add(completed) list.add(completed)
if (Injekt.get<DatabaseHelper>().getCategories().executeAsBlocking().isNotEmpty())
list.add(categories)
if (Injekt.get<TrackManager>().hasLoggedServices()) if (Injekt.get<TrackManager>().hasLoggedServices())
list.add(tracked) list.add(tracked)
list list
@ -58,10 +68,6 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
val recycler = androidx.recyclerview.widget.RecyclerView(context) val recycler = androidx.recyclerview.widget.RecyclerView(context)
var pager:View? = null var pager:View? = null
init {
}
fun onCreate(pagerView:View) { fun onCreate(pagerView:View) {
val sheetBehavior = BottomSheetBehavior.from(this) val sheetBehavior = BottomSheetBehavior.from(this)
topbar.setOnClickListener { topbar.setOnClickListener {
@ -83,10 +89,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
updateTitle() updateTitle()
sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) { override fun onSlide(bottomSheet: View, progress: Float) {
updateRootPadding() updateRootPadding(progress)
sortText.alpha = 1 - progress sortText.alpha = 1 - progress
title.alpha = progress title.alpha = progress
//line.alpha = 1 - progress
} }
override fun onStateChanged(p0: View, p1: Int) { override fun onStateChanged(p0: View, p1: Int) {
@ -134,18 +139,26 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
} }
} }
fun updateRootPadding() { fun moveTitleMargin(downloading: Boolean) {
(sortText.layoutParams as? MarginLayoutParams)?.rightMargin =
(if (downloading) 40 else 8).dpToPx
}
fun updateRootPadding(progress: Float? = null) {
val sheetBehavior = BottomSheetBehavior.from(this) val sheetBehavior = BottomSheetBehavior.from(this)
val minHeight = sheetBehavior.peekHeight val minHeight = sheetBehavior.peekHeight
val maxHeight = height val maxHeight = height
val percent = ((if (sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) 1f else 0f) val trueProgress = progress ?: if (sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) 1f else 0f
* 100).roundToInt() val percent = (trueProgress * 100).roundToInt()
val value = (percent * (maxHeight - minHeight) / 100) + minHeight val value = (percent * (maxHeight - minHeight) / 100) + minHeight
pager?.setPadding(0, 0, 0, value) pager?.setPadding(0, 0, 0, value)
} }
fun sorting(): Int { fun sorting(): Int {
return if (lastCategory != null && preferences.showCategories().getOrDefault()) { val sortingMode = preferences.librarySortingMode().getOrDefault()
return if (sortingMode == LibrarySort.DRAG_AND_DROP &&
lastCategory != null &&
preferences.showCategories().getOrDefault()) {
when (lastCategory?.mangaSort) { when (lastCategory?.mangaSort) {
'a', 'b' -> LibrarySort.ALPHA 'a', 'b' -> LibrarySort.ALPHA
'c', 'd' -> LibrarySort.LAST_UPDATED 'c', 'd' -> LibrarySort.LAST_UPDATED
@ -159,12 +172,8 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
} }
} }
fun getFilters(): List<Int> { private fun getFilters(): List<Int> {
val filters = mutableListOf<Int>() val filters = mutableListOf<Int>()
var categoriesOn = preferences.showCategories().getOrDefault()
if (!categoriesOn) {
filters.add(R.string.hiding_categories)
}
var filter = preferences.filterDownloaded().getOrDefault() var filter = preferences.filterDownloaded().getOrDefault()
if (filter > 0) { if (filter > 0) {
filters.add(if (filter == 1) R.string.action_filter_downloaded else R.string filters.add(if (filter == 1) R.string.action_filter_downloaded else R.string
@ -183,19 +192,27 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
filters.add(if (filter == 1) R.string.completed else R.string filters.add(if (filter == 1) R.string.completed else R.string
.ongoing) .ongoing)
} }
val categoriesOn = preferences.showCategories().getOrDefault()
if (!categoriesOn) {
filters.add(R.string.hiding_categories)
}
filter = preferences.filterTracked().getOrDefault() filter = preferences.filterTracked().getOrDefault()
if (filter > 0) { if (filter > 0) {
filters.add(if (filter == 1) R.string.action_filter_tracked else R.string filters.add(if (filter == 1) R.string.action_filter_tracked else R.string
.action_filter_not_tracked) .action_filter_not_tracked)
} }
filter = preferences.filterMangaType().getOrDefault()
if (filter > 0) {
filters.add(if (filter == 1) R.string.manga_only else R.string.manwha_only)
}
return filters return filters
} }
fun createTags() { fun createTags() {
categories = inflate(R.layout.filter_buttons) as FilterTagGroup categories = inflate(R.layout.filter_buttons) as FilterTagGroup
categories.setup(this, R.string.categories) categories.setup(this, R.string.hide_categories)
categories.firstButton.isActivated = preferences.showCategories().getOrDefault() categories.firstButton.isActivated = !preferences.showCategories().getOrDefault()
categories.onItemClicked = { view, index -> onFilterClicked(view, index) } categories.onItemClicked = { view, index -> onFilterClicked(view, index) }
downloaded = inflate(R.layout.filter_buttons) as FilterTagGroup downloaded = inflate(R.layout.filter_buttons) as FilterTagGroup
@ -222,6 +239,29 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
filterItems.forEach { filterItems.forEach {
filterLayout.addView(it) filterLayout.addView(it)
} }
checkForWebtoons()
}
private fun checkForWebtoons() {
GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) {
val db:DatabaseHelper by injectLazy()
val librryManga = db.getLibraryMangas().executeAsBlocking()
if (librryManga.any { it.mangaType() == LibraryManga.MANWHA }) {
launchUI {
val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup
mangaType.setup(
this@FilterBottomSheet,
R.string.manga,
R.string.manwha
)
mangaType.setState(preferences.filterMangaType())
mangaType.onItemClicked = { view, index -> onFilterClicked(view, index) }
this@FilterBottomSheet.mangaType = mangaType
filterLayout.addView(mangaType)
}
}
}
} }
private fun onFilterClicked(view: View, index: Int) { private fun onFilterClicked(view: View, index: Int) {
@ -239,7 +279,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
}*/ }*/
when (view) { when (view) {
categories -> { categories -> {
preferences.showCategories().set(index == 0) preferences.showCategories().set(index != 0)
onGroupClicked(ACTION_REFRESH) onGroupClicked(ACTION_REFRESH)
} }
downloaded -> { downloaded -> {
@ -258,6 +298,10 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
preferences.filterTracked().set(index + 1) preferences.filterTracked().set(index + 1)
onGroupClicked(ACTION_FILTER) onGroupClicked(ACTION_FILTER)
} }
mangaType -> {
preferences.filterMangaType().set(index + 1)
onGroupClicked(ACTION_FILTER)
}
} }
updateTitle() updateTitle()
} }

View File

@ -54,6 +54,8 @@ import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController
import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController
import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.util.view.inflate
import eu.kanade.tachiyomi.util.view.marginBottom import eu.kanade.tachiyomi.util.view.marginBottom
import eu.kanade.tachiyomi.util.view.marginTop import eu.kanade.tachiyomi.util.view.marginTop
@ -214,23 +216,32 @@ class LibraryController(
createActionModeIfNeeded() createActionModeIfNeeded()
} }
bottom_sheet.onCreate(library_pager) if (MainActivity.bottomNav) {
bottom_sheet.onCreate(library_pager)
bottom_sheet?.onGroupClicked = { bottom_sheet?.onGroupClicked = {
when (it) { when (it) {
FilterBottomSheet.ACTION_REFRESH -> onRefresh() FilterBottomSheet.ACTION_REFRESH -> onRefresh()
FilterBottomSheet.ACTION_FILTER -> onFilterChanged() FilterBottomSheet.ACTION_FILTER -> onFilterChanged()
FilterBottomSheet.ACTION_SORT -> onSortChanged() FilterBottomSheet.ACTION_SORT -> onSortChanged()
FilterBottomSheet.ACTION_DISPLAY -> reattachAdapter() FilterBottomSheet.ACTION_DISPLAY -> reattachAdapter()
FilterBottomSheet.ACTION_BADGE -> onDownloadBadgeChanged() FilterBottomSheet.ACTION_BADGE -> onDownloadBadgeChanged()
}
}
fab.setOnClickListener {
router.pushController(DownloadController().withFadeTransaction())
} }
} }
else {
fab.setOnClickListener { bottom_sheet.gone()
router.pushController(DownloadController().withFadeTransaction()) shadow.gone()
shadow2.gone()
} }
fab.scaleX = 0f fab.scaleX = 0f
fab.scaleY = 0f fab.scaleY = 0f
fab.isClickable = false
fab.isFocusable = false
} }
fun enableReorderItems(category: Category) { fun enableReorderItems(category: Category) {
@ -279,10 +290,12 @@ class LibraryController(
} }
override fun downloadStatusChanged(downloading: Boolean) { override fun downloadStatusChanged(downloading: Boolean) {
val scale = if (downloading) 1f else 0f launchUI {
fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start() val scale = if (downloading) 1f else 0f
fab.isClickable = downloading fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start()
fab.isFocusable = downloading fab.isClickable = downloading
fab.isFocusable = downloading
}
} }
override fun onDetach(view: View) { override fun onDetach(view: View) {
destroyActionModeIfNeeded() destroyActionModeIfNeeded()

View File

@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.database.models.Category.Companion.UNREAD_ASC
import eu.kanade.tachiyomi.data.database.models.Category.Companion.UNREAD_DSC import eu.kanade.tachiyomi.data.database.models.Category.Companion.UNREAD_DSC
import eu.kanade.tachiyomi.data.database.models.Category.Companion.UPDATED_ASC import eu.kanade.tachiyomi.data.database.models.Category.Companion.UPDATED_ASC
import eu.kanade.tachiyomi.data.database.models.Category.Companion.UPDATED_DSC import eu.kanade.tachiyomi.data.database.models.Category.Companion.UPDATED_DSC
import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.MangaCategory
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
@ -139,6 +140,8 @@ class LibraryPresenter(
val filterTracked = preferences.filterTracked().getOrDefault() val filterTracked = preferences.filterTracked().getOrDefault()
val filterMangaType by lazy { preferences.filterMangaType().getOrDefault() }
val filterFn: (LibraryItem) -> Boolean = f@ { item -> val filterFn: (LibraryItem) -> Boolean = f@ { item ->
// Filter when there isn't unread chapters. // Filter when there isn't unread chapters.
if (MainActivity.bottomNav) { if (MainActivity.bottomNav) {
@ -155,6 +158,14 @@ class LibraryPresenter(
.manga.unread > 0) return@f false .manga.unread > 0) return@f false
} }
if (MainActivity.bottomNav) {
if (filterMangaType == LibraryManga.MANGA &&
item.manga.mangaType() == LibraryManga.MANWHA)
return@f false
if ((filterMangaType == LibraryManga.MANWHA) &&
item.manga.mangaType() == LibraryManga.MANGA) return@f false
}
if (filterCompleted == STATE_INCLUDE && item.manga.status != SManga.COMPLETED) if (filterCompleted == STATE_INCLUDE && item.manga.status != SManga.COMPLETED)
return@f false return@f false

View File

@ -642,14 +642,14 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
if (!bottomNav) return if (!bottomNav) return
val downloadManager = Injekt.get<DownloadManager>() val downloadManager = Injekt.get<DownloadManager>()
val hasQueue = downloading || downloadManager.hasQueue() val hasQueue = downloading || downloadManager.hasQueue()
if (hasQueue) { launchUI {
val badge = navigationView?.getOrCreateBadge(R.id.nav_drawer_library) if (hasQueue) {
?: return val badge = navigationView?.getOrCreateBadge(R.id.nav_drawer_library) ?: return@launchUI
badge.clearNumber() badge.clearNumber()
badge.backgroundColor = getResourceColor(R.attr.badgeColor) badge.backgroundColor = getResourceColor(R.attr.badgeColor)
} } else {
else { navigationView?.removeBadge(R.id.nav_drawer_library)
navigationView?.removeBadge(R.id.nav_drawer_library) }
} }
} }

View File

@ -2,6 +2,8 @@
<eu.kanade.tachiyomi.ui.library.FilterTagGroup xmlns:android="http://schemas.android.com/apk/res/android" <eu.kanade.tachiyomi.ui.library.FilterTagGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="wrap_content" android:orientation="horizontal" android:layout_width="wrap_content"
android:background="@drawable/round_textview_border" android:background="@drawable/round_textview_border"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_height="32dp"> android:layout_height="32dp">
<TextView <TextView
android:id="@+id/firstButton" android:id="@+id/firstButton"

View File

@ -6,6 +6,7 @@
<string name="name">Name</string> <string name="name">Name</string>
<string name="categories">Categories</string> <string name="categories">Categories</string>
<string name="manga">Manga</string> <string name="manga">Manga</string>
<string name="manwha">Manwha</string>
<string name="chapters">Chapters</string> <string name="chapters">Chapters</string>
<string name="track">Tracking</string> <string name="track">Tracking</string>
<string name="history">History</string> <string name="history">History</string>
@ -43,7 +44,10 @@
<string name="action_filter_read">Read</string> <string name="action_filter_read">Read</string>
<string name="action_filter_tracked">Tracked</string> <string name="action_filter_tracked">Tracked</string>
<string name="action_filter_not_tracked">Not tracked</string> <string name="action_filter_not_tracked">Not tracked</string>
<string name="hide_categories">Hide categories</string>
<string name="hiding_categories">Hiding categories</string> <string name="hiding_categories">Hiding categories</string>
<string name="manga_only">Manga only</string>
<string name="manwha_only">Manwha only</string>
<string name="sorting_by_">Sorting by %1$s</string> <string name="sorting_by_">Sorting by %1$s</string>
<string name="action_filter_empty">Remove filter</string> <string name="action_filter_empty">Remove filter</string>