mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Improvements to exiting the app menu
This commit is contained in:
parent
228dd2966b
commit
e3636bccc7
3 changed files with 48 additions and 13 deletions
|
|
@ -1,17 +1,29 @@
|
||||||
package eu.ottop.yamlauncher
|
package eu.ottop.yamlauncher
|
||||||
|
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.widget.EdgeEffect
|
import android.widget.EdgeEffect
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
class AppMenuEdgeFactory(private val activity: MainActivity) : RecyclerView.EdgeEffectFactory() {
|
class AppMenuEdgeFactory(private val activity: MainActivity) : RecyclerView.EdgeEffectFactory() {
|
||||||
|
|
||||||
|
private var isScrollingUp = false
|
||||||
|
private val scrollListener = object : RecyclerView.OnScrollListener() {
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
isScrollingUp = dy < 0
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect {
|
override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect {
|
||||||
|
view.addOnScrollListener(scrollListener)
|
||||||
return AppMenuEdgeEffect(activity)
|
return AppMenuEdgeEffect(activity)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
class AppMenuEdgeEffect(private val activity: MainActivity) : EdgeEffect(activity) {
|
inner class AppMenuEdgeEffect(private val activity: MainActivity) : EdgeEffect(activity) {
|
||||||
// Adjust the speed here
|
|
||||||
private val animationSpeedFactor = 0.5f
|
private val animationSpeedFactor = 0.5f
|
||||||
|
private val pullDistanceThreshold = 0.03f // Set a suitable threshold
|
||||||
|
private val debounceInterval = 100L // Milliseconds
|
||||||
|
private var lastActionTime = 0L
|
||||||
|
|
||||||
override fun onAbsorb(velocity: Int) {
|
override fun onAbsorb(velocity: Int) {
|
||||||
super.onAbsorb((velocity * animationSpeedFactor).toInt())
|
super.onAbsorb((velocity * animationSpeedFactor).toInt())
|
||||||
|
|
@ -19,10 +31,25 @@ class AppMenuEdgeEffect(private val activity: MainActivity) : EdgeEffect(activit
|
||||||
|
|
||||||
override fun onPull(deltaDistance: Float, displacement: Float) {
|
override fun onPull(deltaDistance: Float, displacement: Float) {
|
||||||
super.onPull(deltaDistance * animationSpeedFactor, displacement)
|
super.onPull(deltaDistance * animationSpeedFactor, displacement)
|
||||||
|
if (shouldTriggerAction(deltaDistance) && isScrollingUp) {
|
||||||
|
super.onPull(deltaDistance * animationSpeedFactor, displacement)
|
||||||
|
if (activity.recyclerAtTop()) {
|
||||||
activity.showHome()
|
activity.showHome()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
super.onPull(deltaDistance * animationSpeedFactor, displacement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPullDistance(deltaDistance: Float, displacement: Float): Float {
|
override fun onPullDistance(deltaDistance: Float, displacement: Float): Float {
|
||||||
return super.onPullDistance(deltaDistance * animationSpeedFactor, displacement)
|
return super.onPullDistance(deltaDistance * animationSpeedFactor, displacement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun shouldTriggerAction(deltaDistance: Float): Boolean {
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
return deltaDistance > pullDistanceThreshold && (currentTime - lastActionTime > debounceInterval).also {
|
||||||
|
if (it) lastActionTime = currentTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,6 +82,10 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun recyclerAtTop() : Boolean {
|
||||||
|
return recyclerView.scrollY == 0
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupApps() {
|
private fun setupApps() {
|
||||||
handleListItems()
|
handleListItems()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<ViewSwitcher
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/app_view"
|
android:id="@+id/app_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue