From ec512b25e66a7e3a183760802637059f9ba718df Mon Sep 17 00:00:00 2001 From: ottoptj Date: Wed, 20 Nov 2024 01:12:47 +0200 Subject: [PATCH] Changed how the shortcut information is stored in the sharedpreferences. --- .../eu/ottop/yamlauncher/AppMenuAdapter.kt | 7 ++-- .../eu/ottop/yamlauncher/ContactsAdapter.kt | 5 +-- .../java/eu/ottop/yamlauncher/MainActivity.kt | 33 +++++++++++-------- .../settings/SharedPreferenceManager.kt | 9 +++-- app/src/main/res/values-de/strings.xml | 3 +- app/src/main/res/values-fi/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index 562e359..222d8b3 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -35,6 +35,7 @@ class AppMenuAdapter( RecyclerView.Adapter() { // If the menu is opened to select shortcuts, the below variable is set + var shortcutIndex: Int = 0 var shortcutTextView: TextView? = null private val sharedPreferenceManager = SharedPreferenceManager(activity) @@ -47,7 +48,7 @@ class AppMenuAdapter( } interface OnShortcutListener { - fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView, userProfile: Int, shortcutView: TextView) + fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView, userProfile: Int, shortcutView: TextView, shortcutIndex: Int) } interface OnItemLongClickListener { @@ -71,7 +72,7 @@ class AppMenuAdapter( // If opened to select a shortcut, set the shortcut instead of launching the app if (shortcutTextView != null) { - shortcutListener.onShortcut(app, apps[position].second, textView, apps[position].third, shortcutTextView!!) + shortcutListener.onShortcut(app, apps[position].second, textView, apps[position].third, shortcutTextView!!, shortcutIndex) } else { itemClickListener.onItemClick(app, apps[position].second) @@ -85,7 +86,7 @@ class AppMenuAdapter( // If opened to select a shortcut, set the shortcut instead of opening the action menu if (shortcutTextView != null) { - shortcutListener.onShortcut(app, apps[position].second, textView, apps[position].third, shortcutTextView!!) + shortcutListener.onShortcut(app, apps[position].second, textView, apps[position].third, shortcutTextView!!, shortcutIndex) return@setOnLongClickListener true } else { diff --git a/app/src/main/java/eu/ottop/yamlauncher/ContactsAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/ContactsAdapter.kt index e94b9f2..421ae75 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/ContactsAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/ContactsAdapter.kt @@ -20,6 +20,7 @@ class ContactsAdapter( ) : RecyclerView.Adapter() { + var shortcutIndex: Int = 0 var shortcutTextView: TextView? = null private val uiUtils = UIUtils(activity) @@ -30,7 +31,7 @@ class ContactsAdapter( } interface OnContactShortcutListener { - fun onContactShortcut(contactId: Int, contactName: String, shortcutView: TextView) + fun onContactShortcut(contactId: Int, contactName: String, shortcutView: TextView, shortcutIndex: Int) } inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { @@ -42,7 +43,7 @@ class ContactsAdapter( if (shortcutTextView != null) { val position = bindingAdapterPosition val contact = contacts[position] - contactShortcutListener.onContactShortcut(contact.second, contact.first, shortcutTextView!!) + contactShortcutListener.onContactShortcut(contact.second, contact.first, shortcutTextView!!, shortcutIndex) } else { val position = bindingAdapterPosition val contact = contacts[position] diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index b93763a..5a3bb96 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -211,12 +211,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh else { textView.visibility = View.VISIBLE - val savedView = sharedPreferenceManager.getShortcut(textView) + val savedView = sharedPreferenceManager.getShortcut(i) // Set the non-work profile drawable by default textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null) - shortcutListeners(textView, savedView) + shortcutListeners(i, textView, savedView) if (savedView?.get(1) != "e") { setShortcutSetup(textView, savedView) @@ -231,7 +231,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } @SuppressLint("ClickableViewAccessibility") - private fun shortcutListeners(textView: TextView, savedView: List?) { + private fun shortcutListeners(index: Int, textView: TextView, savedView: List?) { // Don't go to settings on long click, but keep other gestures functional textView.setOnTouchListener {_, event -> shortcutGestureDetector.onTouchEvent(event) @@ -245,7 +245,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh menuTitle.setText(textView.text) menuTitle.visibility = View.VISIBLE if (savedView != null) { - setRenameShortcutListener(textView) + setRenameShortcutListener(index, textView) } appAdapter?.shortcutTextView = textView @@ -271,9 +271,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh menuTitle.setText(textView.text) menuTitle.visibility = View.VISIBLE if (savedView != null) { - setRenameShortcutListener(textView) + setRenameShortcutListener(index, textView) } + appAdapter?.shortcutIndex = index appAdapter?.shortcutTextView = textView + contactAdapter?.shortcutIndex = index contactAdapter?.shortcutTextView = textView toAppMenu() @@ -281,7 +283,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } } - private fun setRenameShortcutListener(textView: TextView) { + private fun setRenameShortcutListener(index: Int, textView: TextView) { menuTitle.setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_DONE) { @@ -292,18 +294,20 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm.hideSoftInputFromWindow(menuTitle.windowToken, 0) - val savedView = sharedPreferenceManager.getShortcut(textView)!! + val savedView = sharedPreferenceManager.getShortcut(index)!! textView.text = menuTitle.text try { sharedPreferenceManager.setShortcut( - textView, + index, + textView.text, savedView[0], savedView[1].toInt(), savedView.getOrNull(3)?.toBoolean() ?: false ) } catch (_: NumberFormatException) { sharedPreferenceManager.setShortcut( - textView, + index, + textView.text, savedView[0], 0, savedView.getOrNull(3)?.toBoolean() ?: false @@ -1052,7 +1056,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh userHandle: UserHandle, textView: TextView, userProfile: Int, - shortcutView: TextView + shortcutView: TextView, + shortcutIndex: Int ) { if (userProfile != 0) { shortcutView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null) @@ -1070,7 +1075,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle) } sharedPreferenceManager.setShortcut( - shortcutView, + shortcutIndex, + shortcutView.text, appInfo.applicationInfo.packageName, userProfile ) @@ -1183,13 +1189,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh returnAllowed = false } - override fun onContactShortcut(contactId: Int, contactName: String, shortcutView: TextView) { + override fun onContactShortcut(contactId: Int, contactName: String, shortcutView: TextView, shortcutIndex: Int) { shortcutView.text = contactName shortcutView.setOnClickListener { onContactClick(contactId) } sharedPreferenceManager.setShortcut( - shortcutView, + shortcutIndex, + shortcutView.text, contactName, contactId, true 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 401d95a..fabd8ec 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -4,7 +4,6 @@ import android.app.AlertDialog import android.content.Context import android.graphics.Color import android.util.TypedValue -import android.widget.TextView import androidx.preference.PreferenceManager import eu.ottop.yamlauncher.R @@ -89,14 +88,14 @@ class SharedPreferenceManager (private val context: Context) { return preferences.getString("dateSize", "medium") } - fun setShortcut(textView: TextView, packageName: String, profile: Int, isContact: Boolean = false) { + fun setShortcut(index: Int, text: CharSequence, packageName: String, profile: Int, isContact: Boolean = false) { val editor = preferences.edit() - editor.putString("shortcut${textView.id}", "$packageName§splitter§$profile§splitter§${textView.text}§splitter§${isContact}") + editor.putString("shortcut${index}", "$packageName§splitter§$profile§splitter§${text}§splitter§${isContact}") editor.apply() } - fun getShortcut(textView: TextView): List? { - val value = preferences.getString("shortcut${textView.id}", "e§splitter§e§splitter§e§splitter§e") + fun getShortcut(index: Int): List? { + val value = preferences.getString("shortcut${index}", "e§splitter§e§splitter§e§splitter§e") return value?.split("§splitter§") } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 35671f0..f5dfeee 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -126,6 +126,7 @@ Suche aktivieren Ausrichtung der Suche Größe der Suche + Fuzzy Search Tastatur automatisch öffnen Automatisches öffnen der Apps App automatisch öffnen, wenn sie das letzte Suchergebnis ist @@ -155,7 +156,7 @@ Stripe
(one-time)]]>
Open-Meteo.com
(CC BY 4.0)]]>
- Zurücksetzen + Reset YAM Launcher neu starten Alle Einstellungen zurücksetzen Du wirst ALLE Änderungen verlieren, die du an den Launcher-Einstellungen, Verknüpfungen, versteckten Apps usw. vorgenommen hast.\n\nBist du sicher? diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index f7afb31..72d0327 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -124,7 +124,7 @@ Näytä Hakupalkki Hakupalkin Sijainti Hakupalkin Koko - Ota sumea haku käyttöön + Sumea haku Avaa Näppäimistö Automaattisesti Avaa Hakutulos Automaattisesti Avaa sovellus automaattisesti kun se on viimeinen hakutulos diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8c71ae3..fa4ae56 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,7 +126,7 @@ Enable Search Search Alignment Search Size - Enable Fuzzy Search + Fuzzy Search Automatically Open Keyboard Automatic App Opening Automatically launch an app when it\'s the last search result