diff --git a/app/build.gradle.kts b/app/build.gradle.kts index fd9e6a1..2c12556 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -52,4 +52,5 @@ dependencies { implementation("androidx.preference:preference-ktx:1.2.1") implementation("androidx.activity:activity-ktx:1.9.3") implementation("androidx.constraintlayout:constraintlayout:2.2.0") + implementation("androidx.preference:preference:1.2.1") } \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt index bf711c4..14756b7 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt @@ -38,76 +38,134 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act userHandle: UserHandle, workProfile: Int ){ - ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_info)) { _, _ -> - appInfo(appActivity, userHandle) - true - } + val pinButton = actionMenu.findViewById(R.id.pin) + val infoButton = actionMenu.findViewById(R.id.info) + val uninstallButton = actionMenu.findViewById(R.id.uninstall) + val renameButton = actionMenu.findViewById(R.id.rename) + val hideButton = actionMenu.findViewById(R.id.hide) + val closeButton = actionMenu.findViewById(R.id.close) + val enablePin = sharedPreferenceManager.isPinEnabled() + val enableInfo = sharedPreferenceManager.isInfoEnabled() + val enableUninstall = sharedPreferenceManager.isUninstallEnabled() + val enableRename = sharedPreferenceManager.isRenameEnabled() + val enableHide = sharedPreferenceManager.isHideEnabled() + val enableClose = sharedPreferenceManager.isCloseEnabled() + + if (enablePin) { + pinButton.visibility = View.VISIBLE + setPinState(pinButton, appActivity, workProfile) + + ViewCompat.addAccessibilityAction( + textView, + activity.getString(R.string.accessibility_pin) + ) { _, _ -> + pinApp(appActivity, workProfile) + true + } + + pinButton.setOnClickListener { + pinApp(appActivity, workProfile) + animations.fadeViewOut(actionMenu) + textView.visibility = View.VISIBLE + } + } else {pinButton.visibility = View.GONE} + + if (enableInfo) { + infoButton.visibility = View.VISIBLE + + ViewCompat.addAccessibilityAction( + textView, + activity.getString(R.string.accessibility_info) + ) { _, _ -> + appInfo(appActivity, userHandle) + true + } + + infoButton.setOnClickListener { + appInfo(appActivity, userHandle) + animations.fadeViewOut(actionMenu) + textView.visibility = View.VISIBLE + } + } else {infoButton.visibility = View.GONE} + + if (enableUninstall) { + if (appActivity.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM == 0) { + uninstallButton.visibility = View.VISIBLE + } + + ViewCompat.addAccessibilityAction( + textView, + activity.getString(R.string.accessibility_uninstall) + ) { _, _ -> + uninstallApp(appActivity.applicationInfo, userHandle) + true + } + + uninstallButton.setOnClickListener { + uninstallApp(appActivity.applicationInfo, userHandle) + animations.fadeViewOut(actionMenu) + textView.visibility = View.VISIBLE + } + } else {uninstallButton.visibility = View.GONE} + + if (enableRename) { + renameButton.visibility = View.VISIBLE + + ViewCompat.addAccessibilityAction( + textView, + activity.getString(R.string.accessibility_rename) + ) { _, _ -> + renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile) + true + } + + renameButton.setOnClickListener { + renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile) + } + } else {renameButton.visibility = View.GONE} + + if (enableHide) { + hideButton.visibility = View.VISIBLE + + ViewCompat.addAccessibilityAction( + textView, + activity.getString(R.string.accessibility_hide) + ) { _, _ -> + hideApp(editLayout, textView, actionMenu, appActivity, workProfile) + true + } + + hideButton.setOnClickListener { + hideApp(editLayout, textView, actionMenu, appActivity, workProfile) + } + } else {hideButton.visibility = View.GONE} + + if (enableClose) { + closeButton.visibility = View.VISIBLE + + closeButton.setOnClickListener { + animations.fadeViewOut(actionMenu) + textView.visibility = View.VISIBLE + } + } else {closeButton.visibility = View.GONE} + } + + private fun setPinState(button: TextView, appActivity: LauncherActivityInfo, workProfile: Int) { val isPinned = sharedPreferenceManager.isAppPinned(appActivity.componentName.flattenToString(), workProfile) val topDrawable = when (isPinned) { true -> getDrawable(activity, R.drawable.keep_off_24px) false -> getDrawable(activity,R.drawable.keep_24px) } - actionMenu.findViewById(R.id.pin).setCompoundDrawablesWithIntrinsicBounds(null, topDrawable, null, null) + button.setCompoundDrawablesWithIntrinsicBounds(null, topDrawable, null, null) val pinLabel = when (isPinned) { true -> "Unpin" false -> "Pin" } - actionMenu.findViewById(R.id.pin).text = pinLabel - - actionMenu.findViewById(R.id.pin).setOnClickListener { - pinApp(appActivity, workProfile) - animations.fadeViewOut(actionMenu) - textView.visibility = View.VISIBLE - } - - ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_info)) { _, _ -> - appInfo(appActivity, userHandle) - true - } - - actionMenu.findViewById(R.id.info).setOnClickListener { - appInfo(appActivity, userHandle) - animations.fadeViewOut(actionMenu) - textView.visibility = View.VISIBLE - } - - ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_uninstall)) { _, _ -> - uninstallApp(appActivity.applicationInfo, userHandle) - true - } - - actionMenu.findViewById(R.id.uninstall).setOnClickListener { - uninstallApp(appActivity.applicationInfo, userHandle) - animations.fadeViewOut(actionMenu) - textView.visibility = View.VISIBLE - } - - ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_rename)) { _, _ -> - renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile) - true - } - - actionMenu.findViewById(R.id.rename).setOnClickListener { - renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile) - } - - ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_hide)) { _, _ -> - hideApp(editLayout, textView, actionMenu, appActivity, workProfile) - true - } - - actionMenu.findViewById(R.id.hide).setOnClickListener { - hideApp(editLayout, textView, actionMenu, appActivity, workProfile) - } - - actionMenu.findViewById(R.id.close).setOnClickListener { - animations.fadeViewOut(actionMenu) - textView.visibility = View.VISIBLE - } + button.text = pinLabel } private fun pinApp(appActivity: LauncherActivityInfo, workProfile: Int) { diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/AppMenuSettingsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/AppMenuSettingsFragment.kt index 4bc2c48..160c887 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/AppMenuSettingsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/AppMenuSettingsFragment.kt @@ -7,6 +7,7 @@ import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference import eu.ottop.yamlauncher.R import eu.ottop.yamlauncher.utils.PermissionUtils +import eu.ottop.yamlauncher.utils.UIUtils class AppMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { private val permissionUtils = PermissionUtils() private var contactPref: SwitchPreference? = null @@ -15,6 +16,10 @@ class AppMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { priv override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.app_menu_preferences, rootKey) + + val uiUtils = UIUtils(requireContext()) + val contextMenuSettings = findPreference("contextMenuSettings") + contactPref = findPreference("contactsEnabled") webSearchPref = findPreference("webSearchEnabled") autoLaunchPref = findPreference("autoLaunch") @@ -41,6 +46,11 @@ class AppMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { priv return@OnPreferenceChangeListener true } } + + contextMenuSettings?.onPreferenceClickListener = + Preference.OnPreferenceClickListener { + uiUtils.switchFragment(requireActivity(), ContextMenuSettingsFragment()) + true } } override fun getTitle(): String { diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/ContextMenuSettingsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/ContextMenuSettingsFragment.kt new file mode 100644 index 0000000..b54f651 --- /dev/null +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/ContextMenuSettingsFragment.kt @@ -0,0 +1,16 @@ +package eu.ottop.yamlauncher.settings + +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat +import eu.ottop.yamlauncher.R + +class ContextMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.context_menu_preferences, rootKey) + } + + override fun getTitle(): String { + return getString(R.string.context_menu_settings_title) + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt index e3b14be..275d5ce 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -243,6 +243,30 @@ class SharedPreferenceManager (private val context: Context) { return preferences.getString("appMenuSize", "medium") } + fun isPinEnabled(): Boolean { + return preferences.getBoolean("pinEnabled", true) + } + + fun isInfoEnabled(): Boolean { + return preferences.getBoolean("infoEnabled", false) + } + + fun isUninstallEnabled(): Boolean { + return preferences.getBoolean("uninstallEnabled", true) + } + + fun isRenameEnabled(): Boolean { + return preferences.getBoolean("renameEnabled", true) + } + + fun isHideEnabled(): Boolean { + return preferences.getBoolean("hideEnabled", true) + } + + fun isCloseEnabled(): Boolean { + return preferences.getBoolean("closeEnabled", true) + } + fun isSearchEnabled(): Boolean { return preferences.getBoolean("searchEnabled", true) } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index ec08be2..c925f46 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -42,6 +42,7 @@ Umbenennen Verstecken Schließen + Pin app App-Info App deinstallieren App umbenennen @@ -125,6 +126,17 @@ Berechtigung verweigert Web Search Button + Context Menu Settings + Context Menu + Enable/disable context menu items + + Pin App + App Info + Uninstall App + Rename App + Hide App + Close Menu + Suche Suche aktivieren Ausrichtung der Suche diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index f449e00..55d5398 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -40,6 +40,7 @@ Nimeä Piilota Sulje + Pin app Sovellustiedot Poista sovellus Uudelleen-nimeä sovellus @@ -123,6 +124,17 @@ Tarvittavat Luvat Kielletty Verkkohaku Nappi + Context Menu Settings + Context Menu + Enable/disable context menu items + + Pin App + App Info + Uninstall App + Rename App + Hide App + Close Menu + Hakupalkki Näytä Hakupalkki Hakupalkin Sijainti diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index e8bfcc2..4c5c1f1 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -81,4 +81,14 @@ Extra Large Huge + + + Reply + Reply to all + + + + reply + reply_all + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df21a8d..6fc7897 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -42,6 +42,7 @@ Rename Hide Close + Pin app App info Uninstall app Rename app @@ -125,6 +126,17 @@ Permission Denied Web Search Button + Context Menu Settings + Context Menu + Enable/disable context menu items + + Pin App + App Info + Uninstall App + Rename App + Hide App + Close Menu + Search Enable Search Search Alignment @@ -183,5 +195,4 @@ To lock with double tap, enable YAM Launcher in accessibility settings. The permission is required for double tap to work for locking the screen.\n\nIt is only needed if you want to use the double tap to lock screen feature in YAM Launcher. - \ No newline at end of file diff --git a/app/src/main/res/xml/app_menu_preferences.xml b/app/src/main/res/xml/app_menu_preferences.xml index ded3cf4..8903b2a 100644 --- a/app/src/main/res/xml/app_menu_preferences.xml +++ b/app/src/main/res/xml/app_menu_preferences.xml @@ -46,6 +46,14 @@ app:dependency="searchEnabled" app:key="webSearchEnabled" /> + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 1707f35..3ec2fdb 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -13,7 +13,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" app:allowDividerAbove="false" - app:title="@string/customization" > + app:title="@string/customization">