mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-13 00:05:08 +01:00
Added Manga/Manwha only option to filters
Fixes to the download listener
This commit is contained in:
parent
733dc3765e
commit
562de30173
@ -1,9 +1,27 @@
|
||||
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() {
|
||||
|
||||
var unread: 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
|
||||
}
|
||||
|
||||
}
|
@ -77,7 +77,6 @@ class DownloadService : Service() {
|
||||
* @param context the application context.
|
||||
*/
|
||||
fun stop(context: Context) {
|
||||
callListeners()
|
||||
context.stopService(Intent(context, DownloadService::class.java))
|
||||
}
|
||||
|
||||
@ -134,6 +133,7 @@ class DownloadService : Service() {
|
||||
runningRelay.call(false)
|
||||
subscriptions.unsubscribe()
|
||||
downloadManager.stopDownloads()
|
||||
callListeners()
|
||||
wakeLock.releaseIfNeeded()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
@ -97,7 +97,9 @@ object PreferenceKeys {
|
||||
|
||||
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"
|
||||
|
||||
|
@ -183,7 +183,9 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
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)
|
||||
|
||||
|
@ -7,15 +7,23 @@ import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
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.getOrDefault
|
||||
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 kotlinx.android.synthetic.main.filter_bottom_sheet.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.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
@ -40,15 +48,17 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
||||
|
||||
private lateinit var categories:FilterTagGroup
|
||||
|
||||
private var mangaType:FilterTagGroup? = null
|
||||
|
||||
var lastCategory:Category? = null
|
||||
|
||||
val filterItems:List<FilterTagGroup> by lazy {
|
||||
val list = mutableListOf<FilterTagGroup>()
|
||||
if (Injekt.get<DatabaseHelper>().getCategories().executeAsBlocking().isNotEmpty())
|
||||
list.add(categories)
|
||||
list.add(downloaded)
|
||||
list.add(unread)
|
||||
list.add(completed)
|
||||
if (Injekt.get<DatabaseHelper>().getCategories().executeAsBlocking().isNotEmpty())
|
||||
list.add(categories)
|
||||
if (Injekt.get<TrackManager>().hasLoggedServices())
|
||||
list.add(tracked)
|
||||
list
|
||||
@ -58,10 +68,6 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
||||
val recycler = androidx.recyclerview.widget.RecyclerView(context)
|
||||
var pager:View? = null
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
fun onCreate(pagerView:View) {
|
||||
val sheetBehavior = BottomSheetBehavior.from(this)
|
||||
topbar.setOnClickListener {
|
||||
@ -83,10 +89,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
||||
updateTitle()
|
||||
sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
||||
override fun onSlide(bottomSheet: View, progress: Float) {
|
||||
updateRootPadding()
|
||||
updateRootPadding(progress)
|
||||
sortText.alpha = 1 - progress
|
||||
title.alpha = progress
|
||||
//line.alpha = 1 - progress
|
||||
}
|
||||
|
||||
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 minHeight = sheetBehavior.peekHeight
|
||||
val maxHeight = height
|
||||
val percent = ((if (sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) 1f else 0f)
|
||||
* 100).roundToInt()
|
||||
val trueProgress = progress ?: if (sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) 1f else 0f
|
||||
val percent = (trueProgress * 100).roundToInt()
|
||||
val value = (percent * (maxHeight - minHeight) / 100) + minHeight
|
||||
pager?.setPadding(0, 0, 0, value)
|
||||
}
|
||||
|
||||
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) {
|
||||
'a', 'b' -> LibrarySort.ALPHA
|
||||
'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>()
|
||||
var categoriesOn = preferences.showCategories().getOrDefault()
|
||||
if (!categoriesOn) {
|
||||
filters.add(R.string.hiding_categories)
|
||||
}
|
||||
var filter = preferences.filterDownloaded().getOrDefault()
|
||||
if (filter > 0) {
|
||||
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
|
||||
.ongoing)
|
||||
}
|
||||
val categoriesOn = preferences.showCategories().getOrDefault()
|
||||
if (!categoriesOn) {
|
||||
filters.add(R.string.hiding_categories)
|
||||
}
|
||||
filter = preferences.filterTracked().getOrDefault()
|
||||
if (filter > 0) {
|
||||
filters.add(if (filter == 1) R.string.action_filter_tracked else R.string
|
||||
.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
|
||||
}
|
||||
|
||||
|
||||
fun createTags() {
|
||||
categories = inflate(R.layout.filter_buttons) as FilterTagGroup
|
||||
categories.setup(this, R.string.categories)
|
||||
categories.firstButton.isActivated = preferences.showCategories().getOrDefault()
|
||||
categories.setup(this, R.string.hide_categories)
|
||||
categories.firstButton.isActivated = !preferences.showCategories().getOrDefault()
|
||||
categories.onItemClicked = { view, index -> onFilterClicked(view, index) }
|
||||
|
||||
downloaded = inflate(R.layout.filter_buttons) as FilterTagGroup
|
||||
@ -222,6 +239,29 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
||||
filterItems.forEach {
|
||||
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) {
|
||||
@ -239,7 +279,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
||||
}*/
|
||||
when (view) {
|
||||
categories -> {
|
||||
preferences.showCategories().set(index == 0)
|
||||
preferences.showCategories().set(index != 0)
|
||||
onGroupClicked(ACTION_REFRESH)
|
||||
}
|
||||
downloaded -> {
|
||||
@ -258,6 +298,10 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
|
||||
preferences.filterTracked().set(index + 1)
|
||||
onGroupClicked(ACTION_FILTER)
|
||||
}
|
||||
mangaType -> {
|
||||
preferences.filterMangaType().set(index + 1)
|
||||
onGroupClicked(ACTION_FILTER)
|
||||
}
|
||||
}
|
||||
updateTitle()
|
||||
}
|
||||
|
@ -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.MigrationProcedureConfig
|
||||
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.marginBottom
|
||||
import eu.kanade.tachiyomi.util.view.marginTop
|
||||
@ -214,23 +216,32 @@ class LibraryController(
|
||||
createActionModeIfNeeded()
|
||||
}
|
||||
|
||||
bottom_sheet.onCreate(library_pager)
|
||||
if (MainActivity.bottomNav) {
|
||||
bottom_sheet.onCreate(library_pager)
|
||||
|
||||
bottom_sheet?.onGroupClicked = {
|
||||
when (it) {
|
||||
FilterBottomSheet.ACTION_REFRESH -> onRefresh()
|
||||
FilterBottomSheet.ACTION_FILTER -> onFilterChanged()
|
||||
FilterBottomSheet.ACTION_SORT -> onSortChanged()
|
||||
FilterBottomSheet.ACTION_DISPLAY -> reattachAdapter()
|
||||
FilterBottomSheet.ACTION_BADGE -> onDownloadBadgeChanged()
|
||||
bottom_sheet?.onGroupClicked = {
|
||||
when (it) {
|
||||
FilterBottomSheet.ACTION_REFRESH -> onRefresh()
|
||||
FilterBottomSheet.ACTION_FILTER -> onFilterChanged()
|
||||
FilterBottomSheet.ACTION_SORT -> onSortChanged()
|
||||
FilterBottomSheet.ACTION_DISPLAY -> reattachAdapter()
|
||||
FilterBottomSheet.ACTION_BADGE -> onDownloadBadgeChanged()
|
||||
}
|
||||
}
|
||||
|
||||
fab.setOnClickListener {
|
||||
router.pushController(DownloadController().withFadeTransaction())
|
||||
}
|
||||
}
|
||||
|
||||
fab.setOnClickListener {
|
||||
router.pushController(DownloadController().withFadeTransaction())
|
||||
else {
|
||||
bottom_sheet.gone()
|
||||
shadow.gone()
|
||||
shadow2.gone()
|
||||
}
|
||||
fab.scaleX = 0f
|
||||
fab.scaleY = 0f
|
||||
fab.isClickable = false
|
||||
fab.isFocusable = false
|
||||
}
|
||||
|
||||
fun enableReorderItems(category: Category) {
|
||||
@ -279,10 +290,12 @@ class LibraryController(
|
||||
}
|
||||
|
||||
override fun downloadStatusChanged(downloading: Boolean) {
|
||||
val scale = if (downloading) 1f else 0f
|
||||
fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start()
|
||||
fab.isClickable = downloading
|
||||
fab.isFocusable = downloading
|
||||
launchUI {
|
||||
val scale = if (downloading) 1f else 0f
|
||||
fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start()
|
||||
fab.isClickable = downloading
|
||||
fab.isFocusable = downloading
|
||||
}
|
||||
}
|
||||
override fun onDetach(view: View) {
|
||||
destroyActionModeIfNeeded()
|
||||
|
@ -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.UPDATED_ASC
|
||||
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.MangaCategory
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
@ -139,6 +140,8 @@ class LibraryPresenter(
|
||||
|
||||
val filterTracked = preferences.filterTracked().getOrDefault()
|
||||
|
||||
val filterMangaType by lazy { preferences.filterMangaType().getOrDefault() }
|
||||
|
||||
val filterFn: (LibraryItem) -> Boolean = f@ { item ->
|
||||
// Filter when there isn't unread chapters.
|
||||
if (MainActivity.bottomNav) {
|
||||
@ -155,6 +158,14 @@ class LibraryPresenter(
|
||||
.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)
|
||||
return@f false
|
||||
|
@ -642,14 +642,14 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
||||
if (!bottomNav) return
|
||||
val downloadManager = Injekt.get<DownloadManager>()
|
||||
val hasQueue = downloading || downloadManager.hasQueue()
|
||||
if (hasQueue) {
|
||||
val badge = navigationView?.getOrCreateBadge(R.id.nav_drawer_library)
|
||||
?: return
|
||||
badge.clearNumber()
|
||||
badge.backgroundColor = getResourceColor(R.attr.badgeColor)
|
||||
}
|
||||
else {
|
||||
navigationView?.removeBadge(R.id.nav_drawer_library)
|
||||
launchUI {
|
||||
if (hasQueue) {
|
||||
val badge = navigationView?.getOrCreateBadge(R.id.nav_drawer_library) ?: return@launchUI
|
||||
badge.clearNumber()
|
||||
badge.backgroundColor = getResourceColor(R.attr.badgeColor)
|
||||
} else {
|
||||
navigationView?.removeBadge(R.id.nav_drawer_library)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
<eu.kanade.tachiyomi.ui.library.FilterTagGroup xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal" android:layout_width="wrap_content"
|
||||
android:background="@drawable/round_textview_border"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_height="32dp">
|
||||
<TextView
|
||||
android:id="@+id/firstButton"
|
||||
|
@ -6,6 +6,7 @@
|
||||
<string name="name">Name</string>
|
||||
<string name="categories">Categories</string>
|
||||
<string name="manga">Manga</string>
|
||||
<string name="manwha">Manwha</string>
|
||||
<string name="chapters">Chapters</string>
|
||||
<string name="track">Tracking</string>
|
||||
<string name="history">History</string>
|
||||
@ -43,7 +44,10 @@
|
||||
<string name="action_filter_read">Read</string>
|
||||
<string name="action_filter_tracked">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="manga_only">Manga only</string>
|
||||
<string name="manwha_only">Manwha only</string>
|
||||
|
||||
<string name="sorting_by_">Sorting by %1$s</string>
|
||||
<string name="action_filter_empty">Remove filter</string>
|
||||
|
Loading…
Reference in New Issue
Block a user