From 902700e1f41c72a5530342ff80921917bead52dd Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 25 Apr 2020 11:05:29 -0400 Subject: [PATCH] Minor edits --- .../tachiyomi/data/download/DownloadStore.kt | 3 -- .../ui/library/LibraryCategoryView.kt | 36 +++++++++++-------- .../ui/library/LibrarySettingsSheet.kt | 13 +++---- .../tachiyomi/ui/webview/WebViewActivity.kt | 16 +++++---- .../main/res/layout/source_filter_sheet.xml | 1 - 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt index cfa82a2753..f5a6712636 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt @@ -29,9 +29,6 @@ class DownloadStore( */ private val gson: Gson by injectLazy() - /** - * Database helper. - */ private val db: DatabaseHelper by injectLazy() /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 72efe2fe9d..172dea2657 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -19,6 +19,13 @@ import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.library_category.view.fast_scroller import kotlinx.android.synthetic.main.library_category.view.swipe_refresh +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import reactivecircus.flowbinding.recyclerview.scrollStateChanges +import reactivecircus.flowbinding.swiperefreshlayout.refreshes import rx.subscriptions.CompositeSubscription import uy.kohesive.injekt.injectLazy @@ -30,9 +37,8 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener { - /** - * Preferences. - */ + private val scope = CoroutineScope(Job() + Dispatchers.Main) + private val preferences: PreferencesHelper by injectLazy() /** @@ -83,25 +89,27 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att swipe_refresh.addView(recycler) adapter.fastScroller = fast_scroller - recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { - override fun onScrollStateChanged(recycler: RecyclerView, newState: Int) { + recycler.scrollStateChanges() + .onEach { // Disable swipe refresh when view is not at the top val firstPos = (recycler.layoutManager as LinearLayoutManager) - .findFirstCompletelyVisibleItemPosition() + .findFirstCompletelyVisibleItemPosition() swipe_refresh.isEnabled = firstPos <= 0 } - }) + .launchIn(scope) // Double the distance required to trigger sync swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt()) - swipe_refresh.setOnRefreshListener { - if (LibraryUpdateService.start(context, category)) { - context.toast(R.string.updating_category) - } + swipe_refresh.refreshes() + .onEach { + if (LibraryUpdateService.start(context, category)) { + context.toast(R.string.updating_category) + } - // It can be a very long operation, so we disable swipe refresh and show a toast. - swipe_refresh.isRefreshing = false - } + // It can be a very long operation, so we disable swipe refresh and show a toast. + swipe_refresh.isRefreshing = false + } + .launchIn(scope) } fun onBind(category: Category) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index a8778bfc02..a2ec5eb1e8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -62,7 +62,7 @@ class LibrarySettingsSheet( private val filterGroup = FilterGroup() init { - addGroups(listOf(filterGroup)) + setGroups(listOf(filterGroup)) } /** @@ -110,7 +110,7 @@ class LibrarySettingsSheet( Settings(context, attrs) { init { - addGroups(listOf(SortGroup())) + setGroups(listOf(SortGroup())) } inner class SortGroup : Group { @@ -185,7 +185,7 @@ class LibrarySettingsSheet( Settings(context, attrs) { init { - addGroups(listOf(DisplayGroup(), BadgeGroup())) + setGroups(listOf(DisplayGroup(), BadgeGroup())) } inner class DisplayGroup : Group { @@ -247,15 +247,12 @@ class LibrarySettingsSheet( */ var onGroupClicked: (Group) -> Unit = {} - init { - addView(recycler) - } - - fun addGroups(groups: List) { + fun setGroups(groups: List) { adapter = Adapter(groups.map { it.createItems() }.flatten()) recycler.adapter = adapter groups.forEach { it.initModels() } + addView(recycler) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index e8ec80ff71..ba1b54a29e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -21,6 +21,10 @@ import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.invisible import eu.kanade.tachiyomi.util.view.visible +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import reactivecircus.flowbinding.appcompat.navigationClicks +import reactivecircus.flowbinding.swiperefreshlayout.refreshes import uy.kohesive.injekt.injectLazy class WebViewActivity : BaseActivity() { @@ -38,14 +42,14 @@ class WebViewActivity : BaseActivity() { title = intent.extras?.getString(TITLE_KEY) setSupportActionBar(binding.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) - binding.toolbar.setNavigationOnClickListener { - super.onBackPressed() - } + binding.toolbar.navigationClicks() + .onEach { super.onBackPressed() } + .launchIn(scope) binding.swipeRefresh.isEnabled = false - binding.swipeRefresh.setOnRefreshListener { - refreshPage() - } + binding.swipeRefresh.refreshes() + .onEach { refreshPage() } + .launchIn(scope) if (bundle == null) { val url = intent.extras!!.getString(URL_KEY) ?: return diff --git a/app/src/main/res/layout/source_filter_sheet.xml b/app/src/main/res/layout/source_filter_sheet.xml index 693865483b..f7e1b2f7a8 100644 --- a/app/src/main/res/layout/source_filter_sheet.xml +++ b/app/src/main/res/layout/source_filter_sheet.xml @@ -54,7 +54,6 @@ android:layout_height="0dp" android:layout_gravity="top" android:layout_weight="1" - android:paddingTop="8dp" android:paddingBottom="8dp" />