Added theme style to swipe refresh

Also fixed #161
This commit is contained in:
Jay 2020-04-06 15:06:17 -04:00
parent e571fcb1be
commit 21953424c0
9 changed files with 38 additions and 17 deletions

View File

@ -209,6 +209,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
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()
}

View File

@ -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<ViewGroup.MarginLayoutParams> {
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)

View File

@ -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, _ ->

View File

@ -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()) {

View File

@ -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<RecentMangaItem>) {
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)
}

View File

@ -173,7 +173,8 @@ class RecentsPresenter(
}
override fun onUpdateManga(manga: LibraryManga) {
getRecents()
if (manga.id == null) scope.launch(Dispatchers.Main) { controller.reEnableSwipe() }
else getRecents()
}
/**

View File

@ -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()
}

View File

@ -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(

View File

@ -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" />
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>