Refactor: Added widget page to the gestures.

Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
HeCodes2Much
2024-06-02 19:48:54 +01:00
parent 453477cf00
commit 94fe747ffd
12 changed files with 136 additions and 54 deletions

View File

@@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.github.droidworksstudio.common.hideKeyboard
@@ -297,37 +298,37 @@ class HomeFragment : Fragment(),
@RequiresApi(Build.VERSION_CODES.P)
override fun onDoubleClick() {
super.onDoubleClick()
handleOtherAction(preferenceHelper.doubleTapAction)
handleOtherAction(preferenceHelper.doubleTapAction, Constants.Swipe.DoubleTap)
}
@RequiresApi(Build.VERSION_CODES.P)
override fun onSwipeUp() {
super.onSwipeUp()
handleOtherAction(preferenceHelper.swipeUpAction)
handleOtherAction(preferenceHelper.swipeUpAction, Constants.Swipe.Up)
}
@RequiresApi(Build.VERSION_CODES.P)
override fun onSwipeDown() {
super.onSwipeDown()
handleOtherAction(preferenceHelper.swipeDownAction)
handleOtherAction(preferenceHelper.swipeDownAction, Constants.Swipe.Down)
}
@RequiresApi(Build.VERSION_CODES.P)
override fun onSwipeLeft() {
super.onSwipeLeft()
handleOtherAction(preferenceHelper.swipeLeftAction)
handleOtherAction(preferenceHelper.swipeLeftAction, Constants.Swipe.Left)
}
@RequiresApi(Build.VERSION_CODES.P)
override fun onSwipeRight() {
super.onSwipeRight()
handleOtherAction(preferenceHelper.swipeRightAction)
handleOtherAction(preferenceHelper.swipeRightAction, Constants.Swipe.Right)
}
}
}
@RequiresApi(Build.VERSION_CODES.P)
private fun handleOtherAction(action: Constants.Action) {
private fun handleOtherAction(action: Constants.Action, actionType: Constants.Swipe) {
when (action) {
// Constants.Action.OpenApp -> {}
@@ -341,14 +342,25 @@ class HomeFragment : Fragment(),
}
Constants.Action.ShowAppList -> {
val actionTypeNavOptions: NavOptions = getActionType(actionType)
Handler(Looper.getMainLooper()).post {
findNavController().navigate(R.id.action_HomeFragment_to_DrawFragment)
findNavController().navigate(
R.id.action_HomeFragment_to_DrawFragment,
null,
actionTypeNavOptions
)
}
}
Constants.Action.ShowFavoriteList -> {
val actionTypeNavOptions: NavOptions = getActionType(actionType)
Handler(Looper.getMainLooper()).post {
findNavController().navigate(R.id.action_HomeFragment_to_FavoriteFragment)
findNavController().navigate(
R.id.action_HomeFragment_to_FavoriteFragment,
null,
actionTypeNavOptions
)
}
}
@@ -361,6 +373,17 @@ class HomeFragment : Fragment(),
ActionService.instance()?.showRecents()
}
Constants.Action.ShowWidgets -> {
val actionTypeNavOptions: NavOptions = getActionType(actionType)
Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_HomeFragment_to_WidgetsFragment,
null,
actionTypeNavOptions
)
}
}
Constants.Action.OpenPowerDialog -> {
ActionService.runAccessibilityMode(context)
ActionService.instance()?.openPowerDialog()
@@ -375,6 +398,55 @@ class HomeFragment : Fragment(),
}
}
private fun getActionType(actionType: Constants.Swipe): NavOptions {
return when (actionType) {
Constants.Swipe.DoubleTap -> {
NavOptions.Builder()
.setEnterAnim(R.anim.zoom_in)
.setExitAnim(R.anim.zoom_out)
.setPopEnterAnim(R.anim.zoom_in)
.setPopExitAnim(R.anim.zoom_out)
.build()
}
Constants.Swipe.Up -> {
NavOptions.Builder()
.setEnterAnim(R.anim.slide_in_top)
.setExitAnim(R.anim.slide_out_top)
.setPopEnterAnim(R.anim.slide_in_bottom)
.setPopExitAnim(R.anim.slide_out_bottom)
.build()
}
Constants.Swipe.Down -> {
NavOptions.Builder()
.setEnterAnim(R.anim.slide_in_bottom)
.setExitAnim(R.anim.slide_out_bottom)
.setPopEnterAnim(R.anim.slide_in_top)
.setPopExitAnim(R.anim.slide_out_top)
.build()
}
Constants.Swipe.Left -> {
NavOptions.Builder()
.setEnterAnim(R.anim.slide_in_right)
.setExitAnim(R.anim.slide_out_right)
.setPopEnterAnim(R.anim.slide_in_left)
.setPopExitAnim(R.anim.slide_out_left)
.build()
}
Constants.Swipe.Right -> {
NavOptions.Builder()
.setEnterAnim(R.anim.slide_in_left)
.setExitAnim(R.anim.slide_out_left)
.setPopEnterAnim(R.anim.slide_in_right)
.setPopExitAnim(R.anim.slide_out_right)
.build()
}
}
}
private fun trySettings() {
lifecycleScope.launch(Dispatchers.Main) {
biometricPrompt = BiometricPrompt(this@HomeFragment,

View File

@@ -1,5 +1,6 @@
package com.github.droidworksstudio.launcher.ui.widgetmanager
import android.annotation.SuppressLint
import android.app.Activity
import android.appwidget.AppWidgetHost
import android.appwidget.AppWidgetManager
@@ -13,10 +14,12 @@ import android.view.ViewGroup
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.droidworksstudio.launcher.utils.Constants
import com.github.droidworksstudio.launcher.databinding.FragmentWidgetManagerBinding
import com.github.droidworksstudio.launcher.helper.AppHelper
import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@@ -54,6 +57,7 @@ class WidgetManagerFragment : Fragment(),
}
@SuppressLint("ClickableViewAccessibility")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
appHelper.dayNightMod(requireContext(), binding.drawBackground)
super.onViewCreated(view, savedInstanceState)
@@ -125,10 +129,25 @@ class WidgetManagerFragment : Fragment(),
}
}
// Set long-click listener on the root view
binding.widgetParent.setOnLongClickListener {
binding.widgetParent.setOnTouchListener(getSwipeGestureListener(context))
}
private fun getSwipeGestureListener(context: Context): View.OnTouchListener {
return object : OnSwipeTouchListener(context) {
override fun onLongClick() {
super.onLongClick()
selectWidget()
true // Indicate that the long-click event has been handled
}
override fun onSwipeLeft() {
super.onSwipeLeft()
findNavController().popBackStack()
}
override fun onSwipeRight() {
super.onSwipeRight()
findNavController().popBackStack()
}
}
}

View File

@@ -101,6 +101,7 @@ object Constants {
ShowFavoriteList,
OpenQuickSettings,
ShowRecents,
ShowWidgets,
OpenPowerDialog,
TakeScreenShot,
Disabled;
@@ -114,6 +115,7 @@ object Constants {
ShowFavoriteList -> context.getString(R.string.settings_actions_show_favorite_list)
OpenQuickSettings -> context.getString(R.string.settings_actions_open_quick_settings)
ShowRecents -> context.getString(R.string.settings_actions_show_recents)
ShowWidgets -> context.getString(R.string.settings_actions_show_widgets)
OpenPowerDialog -> context.getString(R.string.settings_actions_open_power_dialog)
TakeScreenShot -> context.getString(R.string.settings_actions_take_a_screenshot)
Disabled -> context.getString(R.string.settings_actions_disabled)

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="600"
android:duration="800"
android:fromXDelta="-100%"
android:toXDelta="0%" />
</set>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="600"
android:duration="800"
android:fromXDelta="100%"
android:toXDelta="0%" />
</set>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="600"
android:duration="800"
android:fromXDelta="0%"
android:toXDelta="-100%" />
</set>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="600"
android:duration="800"
android:fromXDelta="0%"
android:toXDelta="100%" />
</set>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:toXScale="1.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true" />

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true" />

View File

@@ -6,13 +6,6 @@
android:id="@+id/draw_background"
tools:context=".ui.widgetmanager.WidgetManagerFragment">
<FrameLayout
android:id="@+id/touchArea"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/widget_parent"
android:layout_width="match_parent"

View File

@@ -12,33 +12,16 @@
<action
android:id="@+id/action_HomeFragment_to_DrawFragment"
app:destination="@id/DrawFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
app:destination="@id/DrawFragment" />
<action
android:id="@+id/action_HomeFragment_to_SettingsFragment"
app:destination="@id/SettingsFragment"
app:enterAnim="@anim/slide_in_top"
app:exitAnim="@anim/slide_out_top"
app:popEnterAnim="@anim/slide_in_bottom"
app:popExitAnim="@anim/slide_out_bottom" />
app:destination="@id/SettingsFragment" />
<action
android:id="@+id/action_HomeFragment_to_FavoriteFragment"
app:destination="@id/FavoriteFragment"
app:enterAnim="@anim/slide_in_left"
app:exitAnim="@anim/slide_out_right"
app:popEnterAnim="@anim/slide_in_right"
app:popExitAnim="@anim/slide_out_left" />
app:destination="@id/FavoriteFragment" />
<action
android:id="@+id/action_HomeFragment_to_WidgetsFragment"
app:destination="@id/WidgetsFragment"
app:enterAnim="@anim/slide_in_left"
app:exitAnim="@anim/slide_out_right"
app:popEnterAnim="@anim/slide_in_right"
app:popExitAnim="@anim/slide_out_left" />
app:destination="@id/WidgetsFragment" />
</fragment>
<fragment
@@ -48,18 +31,10 @@
tools:layout="@layout/fragment_settings">
<action
android:id="@+id/action_SettingsFragment_to_FavoriteFragment"
app:destination="@id/FavoriteFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
app:destination="@id/FavoriteFragment" />
<action
android:id="@+id/action_SettingsFragment_to_HiddenFragment"
app:destination="@id/HiddenFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
app:destination="@id/HiddenFragment" />
</fragment>
<fragment

View File

@@ -102,6 +102,7 @@
<string name="settings_actions_show_favorite_list">Show Favorites List</string>
<string name="settings_actions_open_quick_settings">Open Quick Settings</string>
<string name="settings_actions_show_recents">Show Recents</string>
<string name="settings_actions_show_widgets">Show Widgets</string>
<string name="settings_actions_open_power_dialog">Open Power Dialog</string>
<string name="settings_actions_take_a_screenshot">Take a ScreenShot</string>
<string name="settings_actions_disabled">Disabled</string>