Skip to content

Commit 94fe747

Browse files
Refactor: Added widget page to the gestures.
Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
1 parent 453477c commit 94fe747

File tree

12 files changed

+136
-54
lines changed

12 files changed

+136
-54
lines changed

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

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat
2020
import androidx.fragment.app.Fragment
2121
import androidx.fragment.app.viewModels
2222
import androidx.lifecycle.lifecycleScope
23+
import androidx.navigation.NavOptions
2324
import androidx.navigation.fragment.findNavController
2425
import androidx.recyclerview.widget.StaggeredGridLayoutManager
2526
import com.github.droidworksstudio.common.hideKeyboard
@@ -297,37 +298,37 @@ class HomeFragment : Fragment(),
297298
@RequiresApi(Build.VERSION_CODES.P)
298299
override fun onDoubleClick() {
299300
super.onDoubleClick()
300-
handleOtherAction(preferenceHelper.doubleTapAction)
301+
handleOtherAction(preferenceHelper.doubleTapAction, Constants.Swipe.DoubleTap)
301302
}
302303

303304
@RequiresApi(Build.VERSION_CODES.P)
304305
override fun onSwipeUp() {
305306
super.onSwipeUp()
306-
handleOtherAction(preferenceHelper.swipeUpAction)
307+
handleOtherAction(preferenceHelper.swipeUpAction, Constants.Swipe.Up)
307308
}
308309

309310
@RequiresApi(Build.VERSION_CODES.P)
310311
override fun onSwipeDown() {
311312
super.onSwipeDown()
312-
handleOtherAction(preferenceHelper.swipeDownAction)
313+
handleOtherAction(preferenceHelper.swipeDownAction, Constants.Swipe.Down)
313314
}
314315

315316
@RequiresApi(Build.VERSION_CODES.P)
316317
override fun onSwipeLeft() {
317318
super.onSwipeLeft()
318-
handleOtherAction(preferenceHelper.swipeLeftAction)
319+
handleOtherAction(preferenceHelper.swipeLeftAction, Constants.Swipe.Left)
319320
}
320321

321322
@RequiresApi(Build.VERSION_CODES.P)
322323
override fun onSwipeRight() {
323324
super.onSwipeRight()
324-
handleOtherAction(preferenceHelper.swipeRightAction)
325+
handleOtherAction(preferenceHelper.swipeRightAction, Constants.Swipe.Right)
325326
}
326327
}
327328
}
328329

329330
@RequiresApi(Build.VERSION_CODES.P)
330-
private fun handleOtherAction(action: Constants.Action) {
331+
private fun handleOtherAction(action: Constants.Action, actionType: Constants.Swipe) {
331332
when (action) {
332333
// Constants.Action.OpenApp -> {}
333334

@@ -341,14 +342,25 @@ class HomeFragment : Fragment(),
341342
}
342343

343344
Constants.Action.ShowAppList -> {
345+
val actionTypeNavOptions: NavOptions = getActionType(actionType)
344346
Handler(Looper.getMainLooper()).post {
345-
findNavController().navigate(R.id.action_HomeFragment_to_DrawFragment)
347+
findNavController().navigate(
348+
R.id.action_HomeFragment_to_DrawFragment,
349+
null,
350+
actionTypeNavOptions
351+
)
346352
}
347353
}
348354

355+
349356
Constants.Action.ShowFavoriteList -> {
357+
val actionTypeNavOptions: NavOptions = getActionType(actionType)
350358
Handler(Looper.getMainLooper()).post {
351-
findNavController().navigate(R.id.action_HomeFragment_to_FavoriteFragment)
359+
findNavController().navigate(
360+
R.id.action_HomeFragment_to_FavoriteFragment,
361+
null,
362+
actionTypeNavOptions
363+
)
352364
}
353365
}
354366

@@ -361,6 +373,17 @@ class HomeFragment : Fragment(),
361373
ActionService.instance()?.showRecents()
362374
}
363375

376+
Constants.Action.ShowWidgets -> {
377+
val actionTypeNavOptions: NavOptions = getActionType(actionType)
378+
Handler(Looper.getMainLooper()).post {
379+
findNavController().navigate(
380+
R.id.action_HomeFragment_to_WidgetsFragment,
381+
null,
382+
actionTypeNavOptions
383+
)
384+
}
385+
}
386+
364387
Constants.Action.OpenPowerDialog -> {
365388
ActionService.runAccessibilityMode(context)
366389
ActionService.instance()?.openPowerDialog()
@@ -375,6 +398,55 @@ class HomeFragment : Fragment(),
375398
}
376399
}
377400

401+
private fun getActionType(actionType: Constants.Swipe): NavOptions {
402+
return when (actionType) {
403+
Constants.Swipe.DoubleTap -> {
404+
NavOptions.Builder()
405+
.setEnterAnim(R.anim.zoom_in)
406+
.setExitAnim(R.anim.zoom_out)
407+
.setPopEnterAnim(R.anim.zoom_in)
408+
.setPopExitAnim(R.anim.zoom_out)
409+
.build()
410+
}
411+
412+
Constants.Swipe.Up -> {
413+
NavOptions.Builder()
414+
.setEnterAnim(R.anim.slide_in_top)
415+
.setExitAnim(R.anim.slide_out_top)
416+
.setPopEnterAnim(R.anim.slide_in_bottom)
417+
.setPopExitAnim(R.anim.slide_out_bottom)
418+
.build()
419+
}
420+
421+
Constants.Swipe.Down -> {
422+
NavOptions.Builder()
423+
.setEnterAnim(R.anim.slide_in_bottom)
424+
.setExitAnim(R.anim.slide_out_bottom)
425+
.setPopEnterAnim(R.anim.slide_in_top)
426+
.setPopExitAnim(R.anim.slide_out_top)
427+
.build()
428+
}
429+
430+
Constants.Swipe.Left -> {
431+
NavOptions.Builder()
432+
.setEnterAnim(R.anim.slide_in_right)
433+
.setExitAnim(R.anim.slide_out_right)
434+
.setPopEnterAnim(R.anim.slide_in_left)
435+
.setPopExitAnim(R.anim.slide_out_left)
436+
.build()
437+
}
438+
439+
Constants.Swipe.Right -> {
440+
NavOptions.Builder()
441+
.setEnterAnim(R.anim.slide_in_left)
442+
.setExitAnim(R.anim.slide_out_left)
443+
.setPopEnterAnim(R.anim.slide_in_right)
444+
.setPopExitAnim(R.anim.slide_out_right)
445+
.build()
446+
}
447+
}
448+
}
449+
378450
private fun trySettings() {
379451
lifecycleScope.launch(Dispatchers.Main) {
380452
biometricPrompt = BiometricPrompt(this@HomeFragment,

app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetManagerFragment.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.droidworksstudio.launcher.ui.widgetmanager
22

3+
import android.annotation.SuppressLint
34
import android.app.Activity
45
import android.appwidget.AppWidgetHost
56
import android.appwidget.AppWidgetManager
@@ -13,10 +14,12 @@ import android.view.ViewGroup
1314
import androidx.activity.result.ActivityResultLauncher
1415
import androidx.activity.result.contract.ActivityResultContracts
1516
import androidx.fragment.app.Fragment
17+
import androidx.navigation.fragment.findNavController
1618
import androidx.recyclerview.widget.LinearLayoutManager
1719
import com.github.droidworksstudio.launcher.utils.Constants
1820
import com.github.droidworksstudio.launcher.databinding.FragmentWidgetManagerBinding
1921
import com.github.droidworksstudio.launcher.helper.AppHelper
22+
import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener
2023
import dagger.hilt.android.AndroidEntryPoint
2124
import javax.inject.Inject
2225

@@ -54,6 +57,7 @@ class WidgetManagerFragment : Fragment(),
5457

5558
}
5659

60+
@SuppressLint("ClickableViewAccessibility")
5761
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
5862
appHelper.dayNightMod(requireContext(), binding.drawBackground)
5963
super.onViewCreated(view, savedInstanceState)
@@ -125,10 +129,25 @@ class WidgetManagerFragment : Fragment(),
125129
}
126130
}
127131

128-
// Set long-click listener on the root view
129-
binding.widgetParent.setOnLongClickListener {
130-
selectWidget()
131-
true // Indicate that the long-click event has been handled
132+
binding.widgetParent.setOnTouchListener(getSwipeGestureListener(context))
133+
}
134+
135+
private fun getSwipeGestureListener(context: Context): View.OnTouchListener {
136+
return object : OnSwipeTouchListener(context) {
137+
override fun onLongClick() {
138+
super.onLongClick()
139+
selectWidget()
140+
}
141+
142+
override fun onSwipeLeft() {
143+
super.onSwipeLeft()
144+
findNavController().popBackStack()
145+
}
146+
147+
override fun onSwipeRight() {
148+
super.onSwipeRight()
149+
findNavController().popBackStack()
150+
}
132151
}
133152
}
134153

app/src/main/java/com/github/droidworksstudio/launcher/utils/Constants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ object Constants {
101101
ShowFavoriteList,
102102
OpenQuickSettings,
103103
ShowRecents,
104+
ShowWidgets,
104105
OpenPowerDialog,
105106
TakeScreenShot,
106107
Disabled;
@@ -114,6 +115,7 @@ object Constants {
114115
ShowFavoriteList -> context.getString(R.string.settings_actions_show_favorite_list)
115116
OpenQuickSettings -> context.getString(R.string.settings_actions_open_quick_settings)
116117
ShowRecents -> context.getString(R.string.settings_actions_show_recents)
118+
ShowWidgets -> context.getString(R.string.settings_actions_show_widgets)
117119
OpenPowerDialog -> context.getString(R.string.settings_actions_open_power_dialog)
118120
TakeScreenShot -> context.getString(R.string.settings_actions_take_a_screenshot)
119121
Disabled -> context.getString(R.string.settings_actions_disabled)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<set xmlns:android="http://schemas.android.com/apk/res/android">
33
<translate
4-
android:duration="600"
4+
android:duration="800"
55
android:fromXDelta="-100%"
66
android:toXDelta="0%" />
77
</set>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<set xmlns:android="http://schemas.android.com/apk/res/android">
33
<translate
4-
android:duration="600"
4+
android:duration="800"
55
android:fromXDelta="100%"
66
android:toXDelta="0%" />
77
</set>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<set xmlns:android="http://schemas.android.com/apk/res/android">
33
<translate
4-
android:duration="600"
4+
android:duration="800"
55
android:fromXDelta="0%"
66
android:toXDelta="-100%" />
77
</set>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<set xmlns:android="http://schemas.android.com/apk/res/android">
33
<translate
4-
android:duration="600"
4+
android:duration="800"
55
android:fromXDelta="0%"
66
android:toXDelta="100%" />
77
</set>

app/src/main/res/anim/zoom_in.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<scale xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="300"
4+
android:fromXScale="0.0"
5+
android:fromYScale="0.0"
6+
android:toXScale="1.0"
7+
android:toYScale="1.0"
8+
android:pivotX="50%"
9+
android:pivotY="50%"
10+
android:fillAfter="true" />

app/src/main/res/anim/zoom_out.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<scale xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="300"
4+
android:fromXScale="1.0"
5+
android:fromYScale="1.0"
6+
android:toXScale="0.0"
7+
android:toYScale="0.0"
8+
android:pivotX="50%"
9+
android:pivotY="50%"
10+
android:fillAfter="true" />

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
android:id="@+id/draw_background"
77
tools:context=".ui.widgetmanager.WidgetManagerFragment">
88

9-
<FrameLayout
10-
android:id="@+id/touchArea"
11-
android:layout_marginTop="20dp"
12-
android:layout_marginBottom="20dp"
13-
android:layout_width="match_parent"
14-
android:layout_height="match_parent" />
15-
169
<FrameLayout
1710
android:id="@+id/widget_parent"
1811
android:layout_width="match_parent"

0 commit comments

Comments
 (0)