From 21953424c0d5621d8a3d4a5474774a4b414a3f98 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 6 Apr 2020 15:06:17 -0400 Subject: [PATCH] Added theme style to swipe refresh Also fixed #161 --- .../ui/catalogue/CatalogueController.kt | 1 + .../tachiyomi/ui/library/LibraryController.kt | 7 ++++- .../ui/manga/MangaDetailsController.kt | 2 ++ .../RecentChaptersController.kt | 3 ++- .../tachiyomi/ui/recents/RecentsController.kt | 26 ++++++++++--------- .../tachiyomi/ui/recents/RecentsPresenter.kt | 3 ++- .../tachiyomi/ui/webview/WebViewActivity.kt | 4 +++ .../tachiyomi/util/view/ViewExtensions.kt | 7 ++++- .../main/res/layout/recents_controller.xml | 2 +- 9 files changed, 38 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt index 168d5befbf..842d191b23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt @@ -209,6 +209,7 @@ class CatalogueController : NucleusController(), override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (!type.isPush && handler is SettingsSourcesFadeChangeHandler) { + view?.applyWindowInsetsForRootController(activity!!.bottom_nav) ext_bottom_sheet.updateExtTitle() ext_bottom_sheet.presenter.refreshExtensions() } 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 a5005f0faf..9bf4345532 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 @@ -61,13 +61,17 @@ import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener +import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative import kotlinx.android.synthetic.main.filter_bottom_sheet.* import kotlinx.android.synthetic.main.library_grid_recycler.* +import kotlinx.android.synthetic.main.library_grid_recycler.recycler import kotlinx.android.synthetic.main.library_list_controller.* +import kotlinx.android.synthetic.main.library_list_controller.swipe_refresh import kotlinx.android.synthetic.main.main_activity.* +import kotlinx.android.synthetic.main.recents_controller.* import kotlinx.coroutines.delay import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -262,7 +266,7 @@ class LibraryController( val tv = TypedValue() activity!!.theme.resolveAttribute(R.attr.actionBarTintColor, tv, true) - + swipe_refresh.setStyle() scrollViewWith(recycler, swipeRefreshLayout = swipe_refresh) { insets -> fast_scroller.updateLayoutParams { topMargin = insets.systemWindowInsetTop @@ -392,6 +396,7 @@ class LibraryController( override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { + view?.applyWindowInsetsForRootController(activity!!.bottom_nav) presenter.getLibrary() DownloadService.callListeners() LibraryUpdateService.setListener(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index a132fa3fe0..4c3fc1f368 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -98,6 +98,7 @@ import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.getText import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener +import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative @@ -218,6 +219,7 @@ class MangaDetailsController : BaseController, array.recycle() val offset = 10.dpToPx var statusBarHeight = -1 + swipe_refresh.setStyle() swipe_refresh.setDistanceToTriggerSync(70.dpToPx) recycler.doOnApplyWindowInsets { v, insets, _ -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index 2ed2f4c4ad..584d15d556 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterAdapter import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.view.scrollViewWith +import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.snack import kotlinx.android.synthetic.main.download_bottom_sheet.* import kotlinx.android.synthetic.main.recent_chapters_controller.* @@ -81,7 +82,7 @@ class RecentChaptersController(bundle: Bundle? = null) : BaseController(bundle), ItemTouchHelper.LEFT ) if (presenter.chapters.isNotEmpty()) adapter?.updateDataSet(presenter.chapters.toList()) - + swipe_refresh.setStyle() swipe_refresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt()) swipe_refresh.setOnRefreshListener { if (!LibraryUpdateService.isRunning()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index a170eb9a99..f9bc614860 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -36,6 +36,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener +import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative @@ -59,6 +60,7 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), init { setHasOptionsMenu(true) + retainViewMode = RetainViewMode.RETAIN_DETACH } /** @@ -105,6 +107,7 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), val array = view.context.obtainStyledAttributes(attrsArray) val appBarHeight = array.getDimensionPixelSize(0, 0) array.recycle() + swipe_refresh.setStyle() scrollViewWith(recycler, skipFirstSnap = true, swipeRefreshLayout = swipe_refresh) { headerHeight = it.systemWindowInsetTop + appBarHeight } @@ -150,20 +153,15 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), shadow.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.5f else 0f } - retainViewMode = - if (state == BottomSheetBehavior.STATE_EXPANDED) RetainViewMode.RETAIN_DETACH else RetainViewMode.RELEASE_DETACH sheet_layout?.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED sheet_layout?.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED setPadding(dl_bottom_sheet.sheetBehavior?.isHideable == true) } }) - + swipe_refresh.isRefreshing = LibraryUpdateService.isRunning() swipe_refresh.setOnRefreshListener { if (!LibraryUpdateService.isRunning()) { LibraryUpdateService.start(view.context) - snack = view.snack(R.string.updating_library) { - anchorView = (activity as? MainActivity)?.bottom_nav - } } } @@ -173,15 +171,16 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), setPadding(dl_bottom_sheet.sheetBehavior?.isHideable == true) } - override fun onItemMove(fromPosition: Int, toPosition: Int) { + fun reEnableSwipe() { + swipe_refresh.isRefreshing = false } + override fun onItemMove(fromPosition: Int, toPosition: Int) { } - override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean { - return true - } + override fun shouldMoveItem(fromPosition: Int, toPosition: Int) = true override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { - swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_SWIPE + swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_SWIPE || + swipe_refresh.isRefreshing } override fun handleSheetBack(): Boolean { @@ -217,6 +216,7 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), fun refresh() = presenter.getRecents() fun showLists(recents: List) { + swipe_refresh.isRefreshing = LibraryUpdateService.isRunning() recentItems = recents adapter.updateDataSet(recents) if (lastChapterId != null) { @@ -347,9 +347,11 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { - if (type == ControllerChangeType.POP_EXIT) presenter.onCreate() + view?.applyWindowInsetsForRootController(activity!!.bottom_nav) + if (type == ControllerChangeType.POP_ENTER) presenter.onCreate() setHasOptionsMenu(true) } else { + if (type == ControllerChangeType.POP_EXIT) presenter.onDestroy() snack?.dismiss() setHasOptionsMenu(false) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt index 84f324df6c..8fa90be2b1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt @@ -173,7 +173,8 @@ class RecentsPresenter( } override fun onUpdateManga(manga: LibraryManga) { - getRecents() + if (manga.id == null) scope.launch(Dispatchers.Main) { controller.reEnableSwipe() } + else getRecents() } /** 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 16d9b4869a..4c570bb291 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 @@ -27,10 +27,13 @@ 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.marginBottom +import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePadding import eu.kanade.tachiyomi.util.view.visible +import kotlinx.android.synthetic.main.library_list_controller.* import kotlinx.android.synthetic.main.webview_activity.* +import kotlinx.android.synthetic.main.webview_activity.swipe_refresh import uy.kohesive.injekt.injectLazy class WebViewActivity : BaseActivity() { @@ -91,6 +94,7 @@ class WebViewActivity : BaseActivity() { 0, insets.systemWindowInsetBottom ) } + swipe_refresh.setStyle() swipe_refresh.setOnRefreshListener { refreshPage() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index a1176a99d5..a4e435d137 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -348,7 +348,7 @@ fun Controller.scrollViewWith( bottom = if (padBottom) insets.systemWindowInsetBottom else view.paddingBottom ) swipeRefreshLayout?.setProgressViewOffset( - false, headerHeight + (-60).dpToPx, headerHeight + true, headerHeight + (-60).dpToPx, headerHeight + 10.dpToPx ) statusBarHeight = insets.systemWindowInsetTop afterInsets?.invoke(insets) @@ -453,6 +453,11 @@ fun setBottomEdge(view: View, activity: Activity) { } } +fun SwipeRefreshLayout.setStyle() { + setColorSchemeColors(context.getResourceColor(R.attr.actionBarTintColor)) + setProgressBackgroundColorSchemeColor(context.getResourceColor(R.attr.colorPrimaryVariant)) +} + fun MaterialButton.resetStrokeColor() { strokeColor = ColorStateList.valueOf( ColorUtils.setAlphaComponent( diff --git a/app/src/main/res/layout/recents_controller.xml b/app/src/main/res/layout/recents_controller.xml index b3a53c31e1..89433a55d1 100644 --- a/app/src/main/res/layout/recents_controller.xml +++ b/app/src/main/res/layout/recents_controller.xml @@ -22,7 +22,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" - tools:listitem="@layout/catalogue_main_controller_card" /> + tools:listitem="@layout/recent_manga_item" />