Skip to content

Commit 83841be

Browse files
Fix: Fixed the swiping gestures.
1 parent 4725128 commit 83841be

File tree

4 files changed

+32
-132
lines changed

4 files changed

+32
-132
lines changed

app/src/main/java/com/github/droidworksstudio/launcher/listener/OnSwipeTouchListener.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,37 @@ internal open class OnSwipeTouchListener(c: Context?) : OnTouchListener {
6767
super.onLongPress(e)
6868
}
6969

70+
// Detecting swipe or drag movement
71+
override fun onScroll(
72+
event1: MotionEvent?,
73+
event2: MotionEvent,
74+
distanceX: Float,
75+
distanceY: Float
76+
): Boolean {
77+
try {
78+
if (event1 == null) return false
79+
80+
val diffX = event2.x - event1.x
81+
val diffY = event2.y - event1.y
82+
83+
// Horizontal swipe
84+
if (abs(diffX) > abs(diffY)) {
85+
if (abs(diffX) > swipeThreshold && abs(distanceX) > swipeVelocityThreshold) {
86+
if (diffX > 0) onSwipeRight() else onSwipeLeft()
87+
}
88+
}
89+
// Vertical swipe
90+
else {
91+
if (abs(diffY) > swipeThreshold && abs(distanceY) > swipeVelocityThreshold) {
92+
if (diffY > 0) onSwipeDown() else onSwipeUp()
93+
}
94+
}
95+
} catch (_: NullPointerException) {
96+
return false
97+
}
98+
return false
99+
}
100+
70101
override fun onFling(
71102
event1: MotionEvent?,
72103
event2: MotionEvent,

app/src/main/java/com/github/droidworksstudio/launcher/listener/ViewSwipeTouchListener.kt

Lines changed: 0 additions & 79 deletions
This file was deleted.

app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeFragment.kt

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import android.view.ViewGroup
2020
import android.widget.LinearLayout
2121
import androidx.annotation.RequiresApi
2222
import androidx.appcompat.widget.AppCompatTextView
23-
import androidx.appcompat.widget.LinearLayoutCompat
2423
import androidx.biometric.BiometricPrompt
25-
import androidx.constraintlayout.widget.ConstraintLayout
2624
import androidx.core.content.ContextCompat
2725
import androidx.fragment.app.Fragment
2826
import androidx.fragment.app.viewModels
@@ -48,7 +46,6 @@ import com.github.droidworksstudio.launcher.helper.PreferenceHelper
4846
import com.github.droidworksstudio.launcher.listener.OnItemClickedListener
4947
import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener
5048
import com.github.droidworksstudio.launcher.listener.ScrollEventListener
51-
import com.github.droidworksstudio.launcher.listener.ViewSwipeTouchListener
5249
import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.AppInfoBottomSheetFragment
5350
import com.github.droidworksstudio.launcher.utils.Constants
5451
import com.github.droidworksstudio.launcher.viewmodel.AppViewModel
@@ -234,16 +231,6 @@ class HomeFragment : Fragment(),
234231
clock.setOnClickListener { context.launchClock() }
235232
date.setOnClickListener { context.launchCalendar() }
236233
battery.setOnClickListener { context.openBatteryManager() }
237-
238-
val appListViews =
239-
layoutInflater.inflate(R.layout.item_home, null) as ConstraintLayout
240-
appListViews.apply {
241-
// Find the TextView by its ID
242-
val appLayout = findViewById<LinearLayoutCompat>(R.id.linear_layout)
243-
244-
// Set the OnTouchListener on the TextView
245-
appLayout.setOnTouchListener(getHomeAppsGestureListener(context, this))
246-
}
247234
}
248235
}
249236

@@ -378,46 +365,6 @@ class HomeFragment : Fragment(),
378365
}
379366
}
380367

381-
private fun getHomeAppsGestureListener(context: Context, view: View): View.OnTouchListener {
382-
return object : ViewSwipeTouchListener(context, view) {
383-
override fun onLongClick(view: View) {
384-
super.onLongClick(view)
385-
trySettings()
386-
return
387-
}
388-
389-
@RequiresApi(Build.VERSION_CODES.P)
390-
override fun onDoubleClick() {
391-
super.onDoubleClick()
392-
handleOtherAction(preferenceHelper.doubleTapAction, Constants.Swipe.DoubleTap)
393-
}
394-
395-
@RequiresApi(Build.VERSION_CODES.P)
396-
override fun onSwipeUp() {
397-
super.onSwipeUp()
398-
handleOtherAction(preferenceHelper.swipeUpAction, Constants.Swipe.Up)
399-
}
400-
401-
@RequiresApi(Build.VERSION_CODES.P)
402-
override fun onSwipeDown() {
403-
super.onSwipeDown()
404-
handleOtherAction(preferenceHelper.swipeDownAction, Constants.Swipe.Down)
405-
}
406-
407-
@RequiresApi(Build.VERSION_CODES.P)
408-
override fun onSwipeLeft() {
409-
super.onSwipeLeft()
410-
handleOtherAction(preferenceHelper.swipeLeftAction, Constants.Swipe.Left)
411-
}
412-
413-
@RequiresApi(Build.VERSION_CODES.P)
414-
override fun onSwipeRight() {
415-
super.onSwipeRight()
416-
handleOtherAction(preferenceHelper.swipeRightAction, Constants.Swipe.Right)
417-
}
418-
}
419-
}
420-
421368
private fun openApp(packageName: String) {
422369
val context = binding.root.context
423370
val pm: PackageManager = context.packageManager

app/src/main/res/layout/fragment_home.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
android:orientation="vertical">
4040

4141
<androidx.appcompat.widget.LinearLayoutCompat
42+
android:id="@+id/blockView"
4243
android:layout_width="match_parent"
4344
android:layout_height="wrap_content"
4445
android:layout_marginTop="16dp"

0 commit comments

Comments
 (0)