Fix: Fixed the home screen gestures not working in blank spaces.
This commit is contained in:
@@ -4,19 +4,15 @@ import com.github.droidworksstudio.launcher.data.entities.AppInfo
|
||||
|
||||
class OnItemClickedListener {
|
||||
|
||||
interface OnAppsClickedListener{
|
||||
interface OnAppsClickedListener {
|
||||
fun onAppClicked(appInfo: AppInfo) {}
|
||||
}
|
||||
|
||||
interface OnAppLongClickedListener{
|
||||
interface OnAppLongClickedListener {
|
||||
fun onAppLongClicked(appInfo: AppInfo) {}
|
||||
}
|
||||
|
||||
interface BottomSheetDismissListener {
|
||||
fun onBottomSheetDismissed() {}
|
||||
}
|
||||
|
||||
interface OnAppStateClickListener{
|
||||
interface OnAppStateClickListener {
|
||||
fun onAppStateClicked(appInfo: AppInfo) {}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ internal open class OnSwipeTouchListener(c: Context?) : OnTouchListener {
|
||||
if (diffY < 0) onSwipeUp() else onSwipeDown()
|
||||
}
|
||||
}
|
||||
} catch (exception: NullPointerException) {
|
||||
} catch (_: NullPointerException) {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.github.droidworksstudio.launcher.listener
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.View.OnTouchListener
|
||||
import kotlin.math.abs
|
||||
|
||||
internal open class ViewSwipeTouchListener(c: Context?, v: View) : OnTouchListener {
|
||||
private val gestureDetector: GestureDetector = GestureDetector(c, GestureListener(v))
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
||||
when (motionEvent.action) {
|
||||
MotionEvent.ACTION_DOWN -> view.isPressed = true
|
||||
MotionEvent.ACTION_UP -> view.isPressed = false
|
||||
}
|
||||
return gestureDetector.onTouchEvent(motionEvent)
|
||||
}
|
||||
|
||||
private inner class GestureListener(private val view: View) : SimpleOnGestureListener() {
|
||||
private val swipeThreshold: Int = 100
|
||||
private val swipeVelocityThreshold: Int = 100
|
||||
|
||||
override fun onDown(e: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
onClick(view)
|
||||
return super.onSingleTapUp(e)
|
||||
}
|
||||
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
onDoubleClick()
|
||||
return super.onDoubleTap(e)
|
||||
}
|
||||
|
||||
override fun onLongPress(e: MotionEvent) {
|
||||
onLongClick(view)
|
||||
super.onLongPress(e)
|
||||
}
|
||||
|
||||
override fun onFling(
|
||||
event1: MotionEvent?,
|
||||
event2: MotionEvent,
|
||||
velocityX: Float,
|
||||
velocityY: Float
|
||||
): Boolean {
|
||||
try {
|
||||
val diffY = event2.y - event1!!.y
|
||||
val diffX = event2.x - event1.x
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold) {
|
||||
if (diffX > 0) onSwipeRight() else onSwipeLeft()
|
||||
}
|
||||
} else {
|
||||
if (abs(diffY) > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
||||
if (diffY < 0) onSwipeUp() else onSwipeDown()
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
open fun onSwipeRight() {}
|
||||
open fun onSwipeLeft() {}
|
||||
open fun onSwipeUp() {}
|
||||
open fun onSwipeDown() {}
|
||||
open fun onLongClick(view: View) {}
|
||||
open fun onDoubleClick() {}
|
||||
open fun onClick(view: View) {}
|
||||
}
|
||||
@@ -47,16 +47,11 @@ class AppInfoBottomSheetFragment(private val appInfo: AppInfo) : BottomSheetDial
|
||||
|
||||
private var appStateClickListener: OnItemClickedListener.OnAppStateClickListener? = null
|
||||
|
||||
private var dismissListener: OnItemClickedListener.BottomSheetDismissListener? = null
|
||||
|
||||
fun setOnAppStateClickListener(listener: OnItemClickedListener.OnAppStateClickListener) {
|
||||
appStateClickListener = listener
|
||||
}
|
||||
|
||||
fun setOnBottomSheetDismissedListener(listener: OnItemClickedListener.BottomSheetDismissListener) {
|
||||
dismissListener = listener
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
|
||||
@@ -50,7 +50,6 @@ import javax.inject.Inject
|
||||
class DrawFragment : Fragment(),
|
||||
OnItemClickedListener.OnAppsClickedListener,
|
||||
OnItemClickedListener.OnAppLongClickedListener,
|
||||
OnItemClickedListener.BottomSheetDismissListener,
|
||||
OnItemClickedListener.OnAppStateClickListener,
|
||||
BiometricHelper.Callback, ScrollEventListener {
|
||||
private var _binding: FragmentDrawBinding? = null
|
||||
@@ -307,7 +306,6 @@ class DrawFragment : Fragment(),
|
||||
binding.searchViewText.setQuery("", false)
|
||||
|
||||
val bottomSheetFragment = AppInfoBottomSheetFragment(appInfo)
|
||||
bottomSheetFragment.setOnBottomSheetDismissedListener(this)
|
||||
bottomSheetFragment.setOnAppStateClickListener(this)
|
||||
bottomSheetFragment.show(parentFragmentManager, "BottomSheetDialog")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import javax.inject.Inject
|
||||
@AndroidEntryPoint
|
||||
class FavoriteFragment : Fragment(),
|
||||
OnItemClickedListener.OnAppsClickedListener,
|
||||
OnItemClickedListener.BottomSheetDismissListener,
|
||||
OnItemClickedListener.OnAppStateClickListener,
|
||||
OnItemMoveListener.OnItemActionListener,
|
||||
BiometricHelper.Callback {
|
||||
|
||||
@@ -33,7 +33,6 @@ import javax.inject.Inject
|
||||
class HiddenFragment : Fragment(),
|
||||
OnItemClickedListener.OnAppsClickedListener,
|
||||
OnItemClickedListener.OnAppLongClickedListener,
|
||||
OnItemClickedListener.BottomSheetDismissListener,
|
||||
OnItemClickedListener.OnAppStateClickListener,
|
||||
BiometricHelper.Callback {
|
||||
private var _binding: FragmentHiddenBinding? = null
|
||||
@@ -140,7 +139,6 @@ class HiddenFragment : Fragment(),
|
||||
|
||||
private fun showSelectedApp(appInfo: AppInfo) {
|
||||
val bottomSheetFragment = AppInfoBottomSheetFragment(appInfo)
|
||||
bottomSheetFragment.setOnBottomSheetDismissedListener(this)
|
||||
bottomSheetFragment.setOnAppStateClickListener(this)
|
||||
bottomSheetFragment.show(parentFragmentManager, "BottomSheetDialog")
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.appcompat.widget.LinearLayoutCompat
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
@@ -46,6 +48,7 @@ import com.github.droidworksstudio.launcher.helper.PreferenceHelper
|
||||
import com.github.droidworksstudio.launcher.listener.OnItemClickedListener
|
||||
import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener
|
||||
import com.github.droidworksstudio.launcher.listener.ScrollEventListener
|
||||
import com.github.droidworksstudio.launcher.listener.ViewSwipeTouchListener
|
||||
import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.AppInfoBottomSheetFragment
|
||||
import com.github.droidworksstudio.launcher.utils.Constants
|
||||
import com.github.droidworksstudio.launcher.viewmodel.AppViewModel
|
||||
@@ -64,7 +67,6 @@ import javax.inject.Inject
|
||||
class HomeFragment : Fragment(),
|
||||
OnItemClickedListener.OnAppsClickedListener,
|
||||
OnItemClickedListener.OnAppLongClickedListener,
|
||||
OnItemClickedListener.BottomSheetDismissListener,
|
||||
OnItemClickedListener.OnAppStateClickListener,
|
||||
BiometricHelper.Callback, ScrollEventListener {
|
||||
|
||||
@@ -224,16 +226,25 @@ class HomeFragment : Fragment(),
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@SuppressLint("ClickableViewAccessibility", "InflateParams")
|
||||
private fun observeSwipeTouchListener() {
|
||||
binding.apply {
|
||||
touchArea.setOnTouchListener(getSwipeGestureListener(context))
|
||||
nestScrollView.setOnTouchListener(getSwipeGestureListener(context))
|
||||
appListTouchArea.setOnTouchListener(getSwipeGestureListener(context))
|
||||
|
||||
clock.setOnClickListener { context.launchClock() }
|
||||
date.setOnClickListener { context.launchCalendar() }
|
||||
battery.setOnClickListener { context.openBatteryManager() }
|
||||
|
||||
val appListViews =
|
||||
layoutInflater.inflate(R.layout.item_home, null) as ConstraintLayout
|
||||
appListViews.apply {
|
||||
// Find the TextView by its ID
|
||||
val appLayout = findViewById<LinearLayoutCompat>(R.id.linear_layout)
|
||||
|
||||
// Set the OnTouchListener on the TextView
|
||||
appLayout.setOnTouchListener(getHomeAppsGestureListener(context, this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +334,6 @@ class HomeFragment : Fragment(),
|
||||
|
||||
private fun showSelectedApp(appInfo: AppInfo) {
|
||||
val bottomSheetFragment = AppInfoBottomSheetFragment(appInfo)
|
||||
bottomSheetFragment.setOnBottomSheetDismissedListener(this)
|
||||
bottomSheetFragment.setOnAppStateClickListener(this)
|
||||
bottomSheetFragment.show(parentFragmentManager, "BottomSheetDialog")
|
||||
|
||||
@@ -369,6 +379,46 @@ class HomeFragment : Fragment(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun getHomeAppsGestureListener(context: Context, view: View): View.OnTouchListener {
|
||||
return object : ViewSwipeTouchListener(context, view) {
|
||||
override fun onLongClick(view: View) {
|
||||
super.onLongClick(view)
|
||||
trySettings()
|
||||
return
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onDoubleClick() {
|
||||
super.onDoubleClick()
|
||||
handleOtherAction(preferenceHelper.doubleTapAction, Constants.Swipe.DoubleTap)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeUp() {
|
||||
super.onSwipeUp()
|
||||
handleOtherAction(preferenceHelper.swipeUpAction, Constants.Swipe.Up)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeDown() {
|
||||
super.onSwipeDown()
|
||||
handleOtherAction(preferenceHelper.swipeDownAction, Constants.Swipe.Down)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeLeft() {
|
||||
super.onSwipeLeft()
|
||||
handleOtherAction(preferenceHelper.swipeLeftAction, Constants.Swipe.Left)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeRight() {
|
||||
super.onSwipeRight()
|
||||
handleOtherAction(preferenceHelper.swipeRightAction, Constants.Swipe.Right)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openApp(packageName: String) {
|
||||
val context = binding.root.context
|
||||
val pm: PackageManager = context.packageManager
|
||||
|
||||
Reference in New Issue
Block a user