Added Specific trackers to filters, moved download queue to settings

This commit is contained in:
Jay 2020-03-12 00:15:31 -07:00
parent b3cda93f3c
commit 1a9614b5de
11 changed files with 93 additions and 29 deletions

View File

@ -20,6 +20,10 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut
} }
else { else {
toolbar_title.text = context.getString(resId) toolbar_title.text = context.getString(resId)
post {
toolbar_title.text = context.getString(resId)
requestLayout()
}
super.setTitle(null) super.setTitle(null)
} }
} }
@ -31,6 +35,10 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut
} }
else { else {
toolbar_title.text = title toolbar_title.text = title
post {
toolbar_title.text = title
requestLayout()
}
super.setTitle(null) super.setTitle(null)
} }
} }

View File

@ -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.BaseController
import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.TabbedController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet
import eu.kanade.tachiyomi.ui.library.filter.SortFilterBottomSheet
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.main.RootSearchInterface import eu.kanade.tachiyomi.ui.main.RootSearchInterface
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController 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.migration.manga.process.MigrationProcedureConfig
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
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.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
@ -193,22 +191,22 @@ open class LibraryController(
bottom_sheet.onGroupClicked = { bottom_sheet.onGroupClicked = {
when (it) { when (it) {
SortFilterBottomSheet.ACTION_REFRESH -> onRefresh() FilterBottomSheet.ACTION_REFRESH -> onRefresh()
SortFilterBottomSheet.ACTION_FILTER -> onFilterChanged() FilterBottomSheet.ACTION_FILTER -> onFilterChanged()
SortFilterBottomSheet.ACTION_HIDE_FILTER_TIP -> activity?.toast(R.string.hide_filters_tip) FilterBottomSheet.ACTION_HIDE_FILTER_TIP -> activity?.toast(R.string.hide_filters_tip)
} }
} }
fab.setOnClickListener { /* fab.setOnClickListener {
router.pushController(DownloadController().withFadeTransaction()) router.pushController(DownloadController().withFadeTransaction())
} }*/
if (presenter.isDownloading()) { /* if (presenter.isDownloading()) {
fab.scaleY = 1f fab.scaleY = 1f
fab.scaleX = 1f fab.scaleX = 1f
fab.isClickable = true fab.isClickable = true
fab.isFocusable = true fab.isFocusable = true
} }*/
val config = resources?.configuration val config = resources?.configuration
phoneLandscape = (config?.orientation == Configuration.ORIENTATION_LANDSCAPE && phoneLandscape = (config?.orientation == Configuration.ORIENTATION_LANDSCAPE &&
@ -287,14 +285,14 @@ open class LibraryController(
} }
override fun downloadStatusChanged(downloading: Boolean) { override fun downloadStatusChanged(downloading: Boolean) {
launchUI { /* launchUI {
val scale = if (downloading) 1f else 0f val scale = if (downloading) 1f else 0f
val fab = fab ?: return@launchUI val fab = fab ?: return@launchUI
fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start() fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start()
fab.isClickable = downloading fab.isClickable = downloading
fab.isFocusable = downloading fab.isFocusable = downloading
bottom_sheet?.adjustFiltersMargin(downloading) bottom_sheet?.adjustFiltersMargin(downloading)
} }*/
} }
override fun onUpdateManga(manga: LibraryManga) { override fun onUpdateManga(manga: LibraryManga) {

View File

@ -16,7 +16,6 @@ import android.view.ViewGroup
import androidx.appcompat.view.ActionMode import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.math.MathUtils.clamp
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -384,11 +383,11 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
val isCurrentController = router?.backstack?.lastOrNull()?.controller() == val isCurrentController = router?.backstack?.lastOrNull()?.controller() ==
this this
customTitleSpinner.category_title.text = /*customTitleSpinner.category_title.text =
presenter.categories[clamp(activeCategory, presenter.categories[clamp(activeCategory,
0, 0,
presenter.categories.size - 1)].name presenter.categories.size - 1)].name
if (isCurrentController) setTitle() if (isCurrentController) setTitle()*/
updateScroll = false updateScroll = false
if (!freshStart) { if (!freshStart) {
justStarted = false justStarted = false

View File

@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource 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.ui.migration.MigrationFlags
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.lang.removeArticles import eu.kanade.tachiyomi.util.lang.removeArticles
@ -158,6 +159,8 @@ class LibraryPresenter(
val filterMangaType by lazy { preferences.filterMangaType().getOrDefault() } val filterMangaType by lazy { preferences.filterMangaType().getOrDefault() }
val filterTrackers = FilterBottomSheet.FILTER_TRACKER
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 (filterUnread == STATE_INCLUDE && if (filterUnread == STATE_INCLUDE &&
@ -184,11 +187,18 @@ class LibraryPresenter(
if (filterTracked != STATE_IGNORE) { if (filterTracked != STATE_IGNORE) {
val tracks = db.getTracks(item.manga).executeAsBlocking() val tracks = db.getTracks(item.manga).executeAsBlocking()
val trackCount = loggedServices.count { service -> val trackCount = loggedServices.any { service ->
tracks.any { it.sync_id == service.id } tracks.any { it.sync_id == service.id }
} }
if (filterTracked == STATE_INCLUDE && trackCount == 0) return@f false if (filterTracked == STATE_INCLUDE && !trackCount) return@f false
if (filterTracked == STATE_EXCLUDE && trackCount > 0) 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. // Filter when there are no downloads.
if (filterDownloaded != STATE_IGNORE) { if (filterDownloaded != STATE_IGNORE) {

View File

@ -33,7 +33,7 @@ import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.roundToInt 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), : LinearLayout(context, attrs),
FilterTagGroupListener { FilterTagGroupListener {
@ -50,7 +50,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A
private lateinit var tracked: FilterTagGroup private lateinit var tracked: FilterTagGroup
// private lateinit var categories: FilterTagGroup private var trackers: FilterTagGroup? = null
private var mangaType: FilterTagGroup? = null private var mangaType: FilterTagGroup? = null
@ -223,17 +223,19 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A
launchUI { launchUI {
val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup
mangaType.setup( mangaType.setup(
this@SortFilterBottomSheet, this@FilterBottomSheet,
types.first(), types.first(),
types.getOrNull(1), types.getOrNull(1),
types.getOrNull(2) types.getOrNull(2)
) )
this@SortFilterBottomSheet.mangaType = mangaType this@FilterBottomSheet.mangaType = mangaType
filter_layout.addView(mangaType) filter_layout.addView(mangaType)
filterItems.remove(tracked)
filterItems.add(mangaType) filterItems.add(mangaType)
filterItems.add(tracked)
} }
} }
launchUI { withContext(Dispatchers.Main) {
hide_categories.visibleIf(showCategoriesCheckBox) hide_categories.visibleIf(showCategoriesCheckBox)
// categories.setState(preferences.hideCategories().getOrDefault()) // categories.setState(preferences.hideCategories().getOrDefault())
downloaded.setState(preferences.filterDownloaded()) downloaded.setState(preferences.filterDownloaded())
@ -244,11 +246,34 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A
reSortViews() reSortViews()
} }
if (filterItems.contains(tracked)) {
val loggedServices = Injekt.get<TrackManager>().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) { override fun onFilterClicked(view: FilterTagGroup, index: Int, updatePreference:Boolean) {
if (updatePreference) { if (updatePreference) {
if (view == trackers) {
FILTER_TRACKER = view.nameOf(index) ?: ""
} else {
when (view) { when (view) {
downloaded -> preferences.filterDownloaded() downloaded -> preferences.filterDownloaded()
unread -> preferences.filterUnread() unread -> preferences.filterUnread()
@ -257,7 +282,18 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A
mangaType -> preferences.filterMangaType() mangaType -> preferences.filterMangaType()
else -> null else -> null
}?.set(index + 1) }?.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() val hasFilters = hasActiveFilters()
if (hasFilters && clearButton.parent == null) if (hasFilters && clearButton.parent == null)
@ -276,6 +312,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A
preferences.filterCompleted().set(0) preferences.filterCompleted().set(0)
preferences.filterTracked().set(0) preferences.filterTracked().set(0)
preferences.filterMangaType().set(0) preferences.filterMangaType().set(0)
FILTER_TRACKER = ""
val transition = androidx.transition.AutoTransition() val transition = androidx.transition.AutoTransition()
transition.duration = 150 transition.duration = 150
@ -308,5 +345,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A
const val ACTION_REFRESH = 0 const val ACTION_REFRESH = 0
const val ACTION_FILTER = 1 const val ACTION_FILTER = 1
const val ACTION_HIDE_FILTER_TIP = 2 const val ACTION_HIDE_FILTER_TIP = 2
var FILTER_TRACKER = ""
private set
} }
} }

View File

@ -30,6 +30,8 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
return buttons.any { it.isActivated } 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) { fun setup(root: ViewGroup, firstText: Int, secondText: Int? = null, thirdText: Int? = null) {
val text1 = context.getString(firstText) val text1 = context.getString(firstText)
val text2 = if (secondText != null) context.getString(secondText) else null val text2 = if (secondText != null) context.getString(secondText) else null

View File

@ -659,7 +659,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
override fun downloadStatusChanged(downloading: Boolean) { override fun downloadStatusChanged(downloading: Boolean) {
val downloadManager = Injekt.get<DownloadManager>() /*val downloadManager = Injekt.get<DownloadManager>()
val hasQueue = downloading || downloadManager.hasQueue() val hasQueue = downloading || downloadManager.hasQueue()
launchUI { launchUI {
if (hasQueue) { if (hasQueue) {
@ -669,7 +669,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} else { } else {
navigationView?.removeBadge(R.id.nav_library) navigationView?.removeBadge(R.id.nav_library)
} }
} }*/
} }

View File

@ -11,7 +11,6 @@ import androidx.core.content.ContextCompat
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.bluelinelabs.conductor.RouterTransaction
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
@ -34,6 +33,13 @@ class SettingsDownloadController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
titleRes = R.string.pref_category_downloads titleRes = R.string.pref_category_downloads
preference {
titleRes = R.string.label_download_queue
onClick {
router.pushController(DownloadController().withFadeTransaction())
}
}
preference { preference {
key = Keys.downloadsDirectory key = Keys.downloadsDirectory
titleRes = R.string.pref_download_directory titleRes = R.string.pref_download_directory

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<eu.kanade.tachiyomi.ui.library.filter.SortFilterBottomSheet xmlns:android="http://schemas.android.com/apk/res/android" <eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_sheet" android:id="@+id/bottom_sheet"
style="@style/BottomSheetDialogTheme" style="@style/BottomSheetDialogTheme"
@ -105,4 +105,4 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</eu.kanade.tachiyomi.ui.library.filter.SortFilterBottomSheet> </eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet>

View File

@ -50,6 +50,7 @@
android:focusable="false" android:focusable="false"
android:scaleX="0" android:scaleX="0"
android:scaleY="0" android:scaleY="0"
android:visibility="gone"
app:layout_anchor="@id/bottom_sheet" app:layout_anchor="@id/bottom_sheet"
app:layout_anchorGravity="end|top" app:layout_anchorGravity="end|top"
app:srcCompat="@drawable/ic_file_download_white_24dp" /> app:srcCompat="@drawable/ic_file_download_white_24dp" />

View File

@ -51,6 +51,7 @@
android:scaleX="0" android:scaleX="0"
android:scaleY="0" android:scaleY="0"
app:layout_anchor="@id/bottom_sheet" app:layout_anchor="@id/bottom_sheet"
android:visibility="gone"
app:layout_anchorGravity="end|top" app:layout_anchorGravity="end|top"
app:srcCompat="@drawable/ic_file_download_white_24dp" /> app:srcCompat="@drawable/ic_file_download_white_24dp" />