Skip to content

Commit

Permalink
increase swipe to refresh trigger distance
Browse files Browse the repository at this point in the history
  • Loading branch information
solrudev committed Apr 17, 2023
1 parent efc8fd1 commit 0b06824
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.github.solrudev.jetmvi.JetView
import ru.solrudev.okkeipatcher.ui.main.screen.home.HomeViewModel
import ru.solrudev.okkeipatcher.ui.main.screen.home.model.HomeUiState
import ru.solrudev.okkeipatcher.ui.main.screen.home.model.PatchEvent.PatchUpdatesRequested
import ru.solrudev.okkeipatcher.ui.main.util.applyDistanceToTrigger

class RefreshController(
private val swipeRefreshLayout: SwipeRefreshLayout,
Expand All @@ -40,7 +41,7 @@ class RefreshController(
}

private fun setupRefresh() = with(swipeRefreshLayout) {
setDistanceToTriggerSync((192 * context.resources.displayMetrics.density).toInt())
applyDistanceToTrigger()
setOnRefreshListener {
viewModel.dispatchEvent(PatchUpdatesRequested)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.github.solrudev.jetmvi.JetView
import ru.solrudev.okkeipatcher.ui.main.screen.update.UpdateViewModel
import ru.solrudev.okkeipatcher.ui.main.screen.update.model.UpdateEvent.UpdateDataRequested
import ru.solrudev.okkeipatcher.ui.main.screen.update.model.UpdateUiState
import ru.solrudev.okkeipatcher.ui.main.util.applyDistanceToTrigger

class RefreshController(
private val swipeRefreshLayout: SwipeRefreshLayout,
Expand All @@ -40,7 +41,7 @@ class RefreshController(
}

private fun setupRefresh() = with(swipeRefreshLayout) {
setDistanceToTriggerSync((192 * context.resources.displayMetrics.density).toInt())
applyDistanceToTrigger()
setOnRefreshListener {
viewModel.dispatchEvent(UpdateDataRequested(refresh = true))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Okkei Patcher
* Copyright (C) 2023 Ilya Fomichev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package ru.solrudev.okkeipatcher.ui.main.util

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout

private const val SWIPE_REFRESH_DISTANCE_TO_TRIGGER = 256

fun SwipeRefreshLayout.applyDistanceToTrigger() =
setDistanceToTriggerSync((SWIPE_REFRESH_DISTANCE_TO_TRIGGER * context.resources.displayMetrics.density).toInt())

0 comments on commit 0b06824

Please sign in to comment.