Skip to content

Commit

Permalink
Fix: Fixed the swiping gestures.
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeCodeCat committed Nov 28, 2024
1 parent 4725128 commit 83841be
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ internal open class OnSwipeTouchListener(c: Context?) : OnTouchListener {
super.onLongPress(e)
}

// Detecting swipe or drag movement
override fun onScroll(
event1: MotionEvent?,
event2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean {
try {
if (event1 == null) return false

val diffX = event2.x - event1.x
val diffY = event2.y - event1.y

// Horizontal swipe
if (abs(diffX) > abs(diffY)) {
if (abs(diffX) > swipeThreshold && abs(distanceX) > swipeVelocityThreshold) {
if (diffX > 0) onSwipeRight() else onSwipeLeft()
}
}
// Vertical swipe
else {
if (abs(diffY) > swipeThreshold && abs(distanceY) > swipeVelocityThreshold) {
if (diffY > 0) onSwipeDown() else onSwipeUp()
}
}
} catch (_: NullPointerException) {
return false
}
return false
}

override fun onFling(
event1: MotionEvent?,
event2: MotionEvent,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ 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
Expand All @@ -48,7 +46,6 @@ 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
Expand Down Expand Up @@ -234,16 +231,6 @@ class HomeFragment : Fragment(),
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))
}
}
}

Expand Down Expand Up @@ -378,46 +365,6 @@ 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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
android:orientation="vertical">

<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/blockView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand Down

0 comments on commit 83841be

Please sign in to comment.