diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt index 00dccc4c69..61b5e9e3e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt @@ -20,6 +20,10 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut } else { toolbar_title.text = context.getString(resId) + post { + toolbar_title.text = context.getString(resId) + requestLayout() + } super.setTitle(null) } } @@ -31,6 +35,10 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut } else { toolbar_title.text = title + post { + toolbar_title.text = title + requestLayout() + } super.setTitle(null) } } 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 7feac35703..7773a0cd46 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 @@ -40,8 +40,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction -import eu.kanade.tachiyomi.ui.download.DownloadController -import eu.kanade.tachiyomi.ui.library.filter.SortFilterBottomSheet +import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.RootSearchInterface import eu.kanade.tachiyomi.ui.manga.MangaDetailsController @@ -51,7 +50,6 @@ import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.getResourceColor -import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener @@ -193,22 +191,22 @@ open class LibraryController( bottom_sheet.onGroupClicked = { when (it) { - SortFilterBottomSheet.ACTION_REFRESH -> onRefresh() - SortFilterBottomSheet.ACTION_FILTER -> onFilterChanged() - SortFilterBottomSheet.ACTION_HIDE_FILTER_TIP -> activity?.toast(R.string.hide_filters_tip) + FilterBottomSheet.ACTION_REFRESH -> onRefresh() + FilterBottomSheet.ACTION_FILTER -> onFilterChanged() + FilterBottomSheet.ACTION_HIDE_FILTER_TIP -> activity?.toast(R.string.hide_filters_tip) } } - fab.setOnClickListener { + /* fab.setOnClickListener { router.pushController(DownloadController().withFadeTransaction()) - } + }*/ - if (presenter.isDownloading()) { + /* if (presenter.isDownloading()) { fab.scaleY = 1f fab.scaleX = 1f fab.isClickable = true fab.isFocusable = true - } + }*/ val config = resources?.configuration phoneLandscape = (config?.orientation == Configuration.ORIENTATION_LANDSCAPE && @@ -287,14 +285,14 @@ open class LibraryController( } override fun downloadStatusChanged(downloading: Boolean) { - launchUI { + /* launchUI { val scale = if (downloading) 1f else 0f val fab = fab ?: return@launchUI fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start() fab.isClickable = downloading fab.isFocusable = downloading bottom_sheet?.adjustFiltersMargin(downloading) - } + }*/ } override fun onUpdateManga(manga: LibraryManga) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt index 0552a0d73a..7207b00abd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt @@ -16,7 +16,6 @@ import android.view.ViewGroup import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.PopupMenu import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.core.math.MathUtils.clamp import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -384,11 +383,11 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), val isCurrentController = router?.backstack?.lastOrNull()?.controller() == this - customTitleSpinner.category_title.text = + /*customTitleSpinner.category_title.text = presenter.categories[clamp(activeCategory, 0, presenter.categories.size - 1)].name - if (isCurrentController) setTitle() + if (isCurrentController) setTitle()*/ updateScroll = false if (!freshStart) { justStarted = false 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 185b72b0b6..212d248e18 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 @@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource +import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet import eu.kanade.tachiyomi.ui.migration.MigrationFlags import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.lang.removeArticles @@ -158,6 +159,8 @@ class LibraryPresenter( val filterMangaType by lazy { preferences.filterMangaType().getOrDefault() } + val filterTrackers = FilterBottomSheet.FILTER_TRACKER + val filterFn: (LibraryItem) -> Boolean = f@ { item -> // Filter when there isn't unread chapters. if (filterUnread == STATE_INCLUDE && @@ -184,11 +187,18 @@ class LibraryPresenter( if (filterTracked != STATE_IGNORE) { val tracks = db.getTracks(item.manga).executeAsBlocking() - val trackCount = loggedServices.count { service -> + val trackCount = loggedServices.any { service -> tracks.any { it.sync_id == service.id } } - if (filterTracked == STATE_INCLUDE && trackCount == 0) return@f false - if (filterTracked == STATE_EXCLUDE && trackCount > 0) return@f false + if (filterTracked == STATE_INCLUDE && !trackCount) return@f false + if (filterTracked == STATE_EXCLUDE && trackCount) return@f false + + if (filterTrackers.isNotEmpty()) { + val service = loggedServices.find { it.name == filterTrackers } + if (service != null) { + if (tracks.none { it.sync_id == service.id }) return@f false + } + } } // Filter when there are no downloads. if (filterDownloaded != STATE_IGNORE) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt similarity index 86% rename from app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index be34970acc..52ae793f51 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -33,7 +33,7 @@ import kotlin.math.max import kotlin.math.min import kotlin.math.roundToInt -class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) +class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs), FilterTagGroupListener { @@ -50,7 +50,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A private lateinit var tracked: FilterTagGroup - // private lateinit var categories: FilterTagGroup + private var trackers: FilterTagGroup? = null private var mangaType: FilterTagGroup? = null @@ -223,17 +223,19 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A launchUI { val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup mangaType.setup( - this@SortFilterBottomSheet, + this@FilterBottomSheet, types.first(), types.getOrNull(1), types.getOrNull(2) ) - this@SortFilterBottomSheet.mangaType = mangaType + this@FilterBottomSheet.mangaType = mangaType filter_layout.addView(mangaType) + filterItems.remove(tracked) filterItems.add(mangaType) + filterItems.add(tracked) } } - launchUI { + withContext(Dispatchers.Main) { hide_categories.visibleIf(showCategoriesCheckBox) // categories.setState(preferences.hideCategories().getOrDefault()) downloaded.setState(preferences.filterDownloaded()) @@ -244,11 +246,34 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A reSortViews() } + if (filterItems.contains(tracked)) { + val loggedServices = Injekt.get().services.filter { it.isLogged } + if (loggedServices.size > 1) { + val serviceNames = loggedServices.map { it.name } + withContext(Dispatchers.Main) { + trackers = inflate(R.layout.filter_buttons) as FilterTagGroup + trackers?.setup( + this@FilterBottomSheet, + serviceNames.first(), + serviceNames.getOrNull(1), + serviceNames.getOrNull(2) + ) + if (tracked.isActivated) { + filter_layout.addView(trackers) + filterItems.add(trackers!!) + } + } + } + } + } } override fun onFilterClicked(view: FilterTagGroup, index: Int, updatePreference:Boolean) { if (updatePreference) { + if (view == trackers) { + FILTER_TRACKER = view.nameOf(index) ?: "" + } else { when (view) { downloaded -> preferences.filterDownloaded() unread -> preferences.filterUnread() @@ -257,7 +282,18 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A mangaType -> preferences.filterMangaType() else -> null }?.set(index + 1) - onGroupClicked(ACTION_FILTER) + } + onGroupClicked(ACTION_FILTER) + } + if (preferences.filterTracked().getOrDefault() == 1 && + trackers != null && trackers?.parent == null) { + filter_layout.addView(trackers) + filterItems.add(trackers!!) + } + else if (preferences.filterTracked().getOrDefault() != 1 && + trackers?.parent != null) { + filter_layout.removeView(trackers) + filterItems.remove(trackers!!) } val hasFilters = hasActiveFilters() if (hasFilters && clearButton.parent == null) @@ -276,6 +312,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A preferences.filterCompleted().set(0) preferences.filterTracked().set(0) preferences.filterMangaType().set(0) + FILTER_TRACKER = "" val transition = androidx.transition.AutoTransition() transition.duration = 150 @@ -308,5 +345,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A const val ACTION_REFRESH = 0 const val ACTION_FILTER = 1 const val ACTION_HIDE_FILTER_TIP = 2 + var FILTER_TRACKER = "" + private set } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt index 49393c5656..720e613614 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt @@ -30,6 +30,8 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute return buttons.any { it.isActivated } } + fun nameOf(index: Int):String? = buttons.getOrNull(index)?.text as? String + fun setup(root: ViewGroup, firstText: Int, secondText: Int? = null, thirdText: Int? = null) { val text1 = context.getString(firstText) val text2 = if (secondText != null) context.getString(secondText) else null 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 066d8706fb..612d628007 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 @@ -659,7 +659,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { } override fun downloadStatusChanged(downloading: Boolean) { - val downloadManager = Injekt.get() + /*val downloadManager = Injekt.get() val hasQueue = downloading || downloadManager.hasQueue() launchUI { if (hasQueue) { @@ -669,7 +669,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { } else { navigationView?.removeBadge(R.id.nav_library) } - } + }*/ } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index a1d7e0eac6..60a0f4377e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt @@ -11,7 +11,6 @@ import androidx.core.content.ContextCompat import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItemsSingleChoice -import com.bluelinelabs.conductor.RouterTransaction import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -34,6 +33,13 @@ class SettingsDownloadController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.pref_category_downloads + preference { + titleRes = R.string.label_download_queue + onClick { + router.pushController(DownloadController().withFadeTransaction()) + } + } + preference { key = Keys.downloadsDirectory titleRes = R.string.pref_download_directory diff --git a/app/src/main/res/layout/filter_bottom_sheet.xml b/app/src/main/res/layout/filter_bottom_sheet.xml index 214d34ed4f..5df715915c 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/library_controller.xml b/app/src/main/res/layout/library_controller.xml index 25c689ea29..9bbef84f52 100644 --- a/app/src/main/res/layout/library_controller.xml +++ b/app/src/main/res/layout/library_controller.xml @@ -50,6 +50,7 @@ android:focusable="false" android:scaleX="0" android:scaleY="0" + android:visibility="gone" app:layout_anchor="@id/bottom_sheet" app:layout_anchorGravity="end|top" app:srcCompat="@drawable/ic_file_download_white_24dp" /> diff --git a/app/src/main/res/layout/library_list_controller.xml b/app/src/main/res/layout/library_list_controller.xml index ea36431bfa..cb7016ad26 100644 --- a/app/src/main/res/layout/library_list_controller.xml +++ b/app/src/main/res/layout/library_list_controller.xml @@ -51,6 +51,7 @@ android:scaleX="0" android:scaleY="0" app:layout_anchor="@id/bottom_sheet" + android:visibility="gone" app:layout_anchorGravity="end|top" app:srcCompat="@drawable/ic_file_download_white_24dp" />