Skip to content

Commit

Permalink
Feature: Added a toggle to disable animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeCodeCat committed Nov 29, 2024
1 parent 8f83174 commit 4138c02
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
get() = prefs.getBoolean(Constants.TOGGLE_SETTING_LOCK, false)
set(value) = prefs.edit().putBoolean(Constants.TOGGLE_SETTING_LOCK, value).apply()

var disableAnimations: Boolean
get() = prefs.getBoolean(Constants.DISABLE_ANIMATIONS, false)
set(value) = prefs.edit().putBoolean(Constants.DISABLE_ANIMATIONS, value).apply()

var searchEngines: Constants.SearchEngines
get() {
return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -14,6 +16,7 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
Expand Down Expand Up @@ -191,16 +194,38 @@ class DrawFragment : Fragment(),
RecyclerView.SCROLL_STATE_DRAGGING -> {
onTop = !recyclerView.canScrollVertically(-1)
if (onTop) binding.searchViewText.hideKeyboard()
if (onTop && !recyclerView.canScrollVertically(1))
findNavController().popBackStack()
if (onTop && !recyclerView.canScrollVertically(1)) {
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.Up)

Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_DrawFragment_to_HomeFragment,
null,
actionTypeNavOptions
)
}
}
}

RecyclerView.SCROLL_STATE_IDLE -> {
if (!recyclerView.canScrollVertically(1)) {
binding.searchViewText.hideKeyboard()
} else if (!recyclerView.canScrollVertically(-1)) {
if (onTop) findNavController().popBackStack()
else binding.searchViewText.showKeyboard()
if (onTop) {
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.Up)

Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_DrawFragment_to_HomeFragment,
null,
actionTypeNavOptions
)
}
} else binding.searchViewText.showKeyboard()
}
}
}
Expand All @@ -213,12 +238,32 @@ class DrawFragment : Fragment(),
return object : OnSwipeTouchListener(context) {
override fun onSwipeLeft() {
super.onSwipeLeft()
findNavController().navigateUp()
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.Left)

Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_DrawFragment_to_HomeFragment,
null,
actionTypeNavOptions
)
}
}

override fun onSwipeRight() {
super.onSwipeRight()
findNavController().navigateUp()
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.Right)

Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_DrawFragment_to_HomeFragment,
null,
actionTypeNavOptions
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ class HomeFragment : Fragment(),
}

Constants.Action.ShowAppList -> {
val actionTypeNavOptions: NavOptions = appHelper.getActionType(actionType)
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(actionType)
Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_HomeFragment_to_DrawFragment,
Expand All @@ -430,7 +432,9 @@ class HomeFragment : Fragment(),


Constants.Action.ShowFavoriteList -> {
val actionTypeNavOptions: NavOptions = appHelper.getActionType(actionType)
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(actionType)
Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_HomeFragment_to_FavoriteFragment,
Expand All @@ -441,7 +445,9 @@ class HomeFragment : Fragment(),
}

Constants.Action.ShowHiddenList -> {
val actionTypeNavOptions: NavOptions = appHelper.getActionType(actionType)
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(actionType)
Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_HomeFragment_to_HiddenFragment,
Expand All @@ -465,7 +471,9 @@ class HomeFragment : Fragment(),
}

Constants.Action.ShowWidgets -> {
val actionTypeNavOptions: NavOptions = appHelper.getActionType(actionType)
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(actionType)
Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_HomeFragment_to_WidgetsFragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class SettingsFeaturesFragment : Fragment(),
automaticOpenAppSwitchCompat.isChecked = preferenceHelper.automaticOpenApp
searchFromStartSwitchCompat.isChecked = preferenceHelper.searchFromStart
lockSettingsSwitchCompat.isChecked = preferenceHelper.settingsLock
disableAnimationsSwitchCompat.isChecked = preferenceHelper.disableAnimations
}
}

Expand Down Expand Up @@ -361,6 +362,12 @@ class SettingsFeaturesFragment : Fragment(),
val feedbackType = if (isChecked) "on" else "off"
appHelper.triggerHapticFeedback(context, feedbackType)
}

disableAnimationsSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
preferenceViewModel.setDisableAnimations(isChecked)
val feedbackType = if (isChecked) "on" else "off"
appHelper.triggerHapticFeedback(context, feedbackType)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,26 +389,47 @@ class WidgetFragment : Fragment(),
return object : OnSwipeTouchListener(context) {
override fun onLongClick() {
super.onLongClick()
val actionTypeNavOptions: NavOptions =
appHelper.getActionType(Constants.Swipe.DoubleTap)
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.DoubleTap)

Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_WidgetsFragment_to_WidgetsSettingsFragment,
null,
actionTypeNavOptions
)
}
return
}

override fun onSwipeLeft() {
super.onSwipeLeft()
findNavController().navigateUp()
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.Left)

Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_WidgetsFragment_to_HomeFragment,
null,
actionTypeNavOptions
)
}
}

override fun onSwipeRight() {
super.onSwipeRight()
findNavController().navigateUp()
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.Right)

Handler(Looper.getMainLooper()).post {
findNavController().navigate(
R.id.action_WidgetsFragment_to_HomeFragment,
null,
actionTypeNavOptions
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ object Constants {
const val SEARCH_FROM_START = "SEARCH_FROM_START"
const val FILTER_STRENGTH = "FILTER_STRENGTH"
const val TOGGLE_SETTING_LOCK = "TOGGLE_SETTING_LOCK"
const val DISABLE_ANIMATIONS = "DISABLE_ANIMATIONS"

const val HOME_DATE_ALIGNMENT = "HOME_DATE_ALIGNMENT"
const val HOME_TIME_ALIGNMENT = "HOME_TIME_ALIGNMENT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PreferenceViewModel @Inject constructor(
private val searchFromStartLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val autoKeyboardLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val lockSettingsLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val disableAnimationsLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val appGroupPaddingSizeLiveData: MutableLiveData<Float> = MutableLiveData()
private val appPaddingSizeLiveData: MutableLiveData<Float> = MutableLiveData()

Expand Down Expand Up @@ -278,6 +279,11 @@ class PreferenceViewModel @Inject constructor(
lockSettingsLiveData.postValue((preferenceHelper.settingsLock))
}

fun setDisableAnimations(disableAnimations: Boolean) {
preferenceHelper.disableAnimations = disableAnimations
disableAnimationsLiveData.postValue((preferenceHelper.disableAnimations))
}

fun setAppLanguage(appLanguage: Constants.Language) {
preferenceHelper.appLanguage = appLanguage
appLanguageLiveData.postValue((preferenceHelper.appLanguage))
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/res/layout/fragment_settings_features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,37 @@
tools:ignore="TouchTargetSizeCheck" />

</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:ignore="MissingConstraints">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/disableAnimations_text"
style="@style/TextDefaultStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center"
android:text="@string/settings_display_disable_animations"
android:textSize="@dimen/text_large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/disableAnimations_switchCompat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.7"
android:scaleY="0.8"
android:thumb="@drawable/shape_switch_thumb"
app:track="@drawable/selector_switch"
tools:ignore="TouchTargetSizeCheck" />

</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.LinearLayoutCompat
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
<action
android:id="@+id/action_WidgetsFragment_to_WidgetsSettingsFragment"
app:destination="@id/WidgetsSettingsFragment" />

<action
android:id="@+id/action_WidgetsFragment_to_HomeFragment"
app:destination="@id/HomeFragment" />
</fragment>

<fragment
Expand All @@ -82,7 +86,13 @@
android:id="@+id/DrawFragment"
android:name="com.github.droidworksstudio.launcher.ui.drawer.DrawFragment"
android:label="@string/draw_fragment_label"
tools:layout="@layout/fragment_draw" />
tools:layout="@layout/fragment_draw">

<action
android:id="@+id/action_DrawFragment_to_HomeFragment"
app:destination="@id/HomeFragment" />
</fragment>


<fragment
android:id="@+id/FavoriteFragment"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<string name="settings_display_auto_open_apps">Auto Open Last App</string>
<string name="settings_search_from_start">Search From Start</string>
<string name="settings_display_lock_settings">Lock Settings</string>
<string name="settings_display_disable_animations">Disable Animations</string>

<string name="settings_appearance_text_size_title">Size</string>
<string name="settings_appearance_color_title">Color</string>
Expand Down

0 comments on commit 4138c02

Please sign in to comment.