diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt index b9a7d94286..66eddd2b75 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt @@ -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 + } + } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt index 9d90657937..ce5da66453 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt @@ -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() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 40e1591bc9..ccc0306a0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -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" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 502e73c5b8..8bf8e6dbd1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt index cd07fcdfe6..072d5a55b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt @@ -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 by lazy { val list = mutableListOf() - if (Injekt.get().getCategories().executeAsBlocking().isNotEmpty()) - list.add(categories) list.add(downloaded) list.add(unread) list.add(completed) + if (Injekt.get().getCategories().executeAsBlocking().isNotEmpty()) + list.add(categories) if (Injekt.get().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 { + private fun getFilters(): List { val filters = mutableListOf() - 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() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 91c15a0a26..0851be8da2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index cc9bc9c424..28fdb4c6e4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 2d393de4cd..a2800bbb42 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -642,14 +642,14 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { if (!bottomNav) return val downloadManager = Injekt.get() 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) + } } } diff --git a/app/src/main/res/layout/filter_buttons.xml b/app/src/main/res/layout/filter_buttons.xml index 921688a333..ed97009edf 100644 --- a/app/src/main/res/layout/filter_buttons.xml +++ b/app/src/main/res/layout/filter_buttons.xml @@ -2,6 +2,8 @@ Name Categories Manga + Manwha Chapters Tracking History @@ -43,7 +44,10 @@ Read Tracked Not tracked + Hide categories Hiding categories + Manga only + Manwha only Sorting by %1$s Remove filter