mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Changed how the shortcut information is stored in the sharedpreferences.
This commit is contained in:
parent
7083567e6a
commit
ec512b25e6
7 changed files with 35 additions and 26 deletions
|
|
@ -35,6 +35,7 @@ class AppMenuAdapter(
|
||||||
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
||||||
|
|
||||||
// If the menu is opened to select shortcuts, the below variable is set
|
// If the menu is opened to select shortcuts, the below variable is set
|
||||||
|
var shortcutIndex: Int = 0
|
||||||
var shortcutTextView: TextView? = null
|
var shortcutTextView: TextView? = null
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager(activity)
|
private val sharedPreferenceManager = SharedPreferenceManager(activity)
|
||||||
|
|
@ -47,7 +48,7 @@ class AppMenuAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OnShortcutListener {
|
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 {
|
interface OnItemLongClickListener {
|
||||||
|
|
@ -71,7 +72,7 @@ class AppMenuAdapter(
|
||||||
|
|
||||||
// If opened to select a shortcut, set the shortcut instead of launching the app
|
// If opened to select a shortcut, set the shortcut instead of launching the app
|
||||||
if (shortcutTextView != null) {
|
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 {
|
else {
|
||||||
itemClickListener.onItemClick(app, apps[position].second)
|
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 opened to select a shortcut, set the shortcut instead of opening the action menu
|
||||||
if (shortcutTextView != null) {
|
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
|
return@setOnLongClickListener true
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class ContactsAdapter(
|
||||||
) :
|
) :
|
||||||
RecyclerView.Adapter<ContactsAdapter.AppViewHolder>() {
|
RecyclerView.Adapter<ContactsAdapter.AppViewHolder>() {
|
||||||
|
|
||||||
|
var shortcutIndex: Int = 0
|
||||||
var shortcutTextView: TextView? = null
|
var shortcutTextView: TextView? = null
|
||||||
|
|
||||||
private val uiUtils = UIUtils(activity)
|
private val uiUtils = UIUtils(activity)
|
||||||
|
|
@ -30,7 +31,7 @@ class ContactsAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OnContactShortcutListener {
|
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) {
|
inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
|
|
@ -42,7 +43,7 @@ class ContactsAdapter(
|
||||||
if (shortcutTextView != null) {
|
if (shortcutTextView != null) {
|
||||||
val position = bindingAdapterPosition
|
val position = bindingAdapterPosition
|
||||||
val contact = contacts[position]
|
val contact = contacts[position]
|
||||||
contactShortcutListener.onContactShortcut(contact.second, contact.first, shortcutTextView!!)
|
contactShortcutListener.onContactShortcut(contact.second, contact.first, shortcutTextView!!, shortcutIndex)
|
||||||
} else {
|
} else {
|
||||||
val position = bindingAdapterPosition
|
val position = bindingAdapterPosition
|
||||||
val contact = contacts[position]
|
val contact = contacts[position]
|
||||||
|
|
|
||||||
|
|
@ -211,12 +211,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
else {
|
else {
|
||||||
textView.visibility = View.VISIBLE
|
textView.visibility = View.VISIBLE
|
||||||
|
|
||||||
val savedView = sharedPreferenceManager.getShortcut(textView)
|
val savedView = sharedPreferenceManager.getShortcut(i)
|
||||||
|
|
||||||
// Set the non-work profile drawable by default
|
// Set the non-work profile drawable by default
|
||||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
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") {
|
if (savedView?.get(1) != "e") {
|
||||||
setShortcutSetup(textView, savedView)
|
setShortcutSetup(textView, savedView)
|
||||||
|
|
@ -231,7 +231,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun shortcutListeners(textView: TextView, savedView: List<String>?) {
|
private fun shortcutListeners(index: Int, textView: TextView, savedView: List<String>?) {
|
||||||
// Don't go to settings on long click, but keep other gestures functional
|
// Don't go to settings on long click, but keep other gestures functional
|
||||||
textView.setOnTouchListener {_, event ->
|
textView.setOnTouchListener {_, event ->
|
||||||
shortcutGestureDetector.onTouchEvent(event)
|
shortcutGestureDetector.onTouchEvent(event)
|
||||||
|
|
@ -245,7 +245,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
menuTitle.setText(textView.text)
|
menuTitle.setText(textView.text)
|
||||||
menuTitle.visibility = View.VISIBLE
|
menuTitle.visibility = View.VISIBLE
|
||||||
if (savedView != null) {
|
if (savedView != null) {
|
||||||
setRenameShortcutListener(textView)
|
setRenameShortcutListener(index, textView)
|
||||||
}
|
}
|
||||||
|
|
||||||
appAdapter?.shortcutTextView = textView
|
appAdapter?.shortcutTextView = textView
|
||||||
|
|
@ -271,9 +271,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
menuTitle.setText(textView.text)
|
menuTitle.setText(textView.text)
|
||||||
menuTitle.visibility = View.VISIBLE
|
menuTitle.visibility = View.VISIBLE
|
||||||
if (savedView != null) {
|
if (savedView != null) {
|
||||||
setRenameShortcutListener(textView)
|
setRenameShortcutListener(index, textView)
|
||||||
}
|
}
|
||||||
|
appAdapter?.shortcutIndex = index
|
||||||
appAdapter?.shortcutTextView = textView
|
appAdapter?.shortcutTextView = textView
|
||||||
|
contactAdapter?.shortcutIndex = index
|
||||||
contactAdapter?.shortcutTextView = textView
|
contactAdapter?.shortcutTextView = textView
|
||||||
toAppMenu()
|
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, _ ->
|
menuTitle.setOnEditorActionListener { _, actionId, _ ->
|
||||||
|
|
||||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||||
|
|
@ -292,18 +294,20 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
val imm =
|
val imm =
|
||||||
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.hideSoftInputFromWindow(menuTitle.windowToken, 0)
|
imm.hideSoftInputFromWindow(menuTitle.windowToken, 0)
|
||||||
val savedView = sharedPreferenceManager.getShortcut(textView)!!
|
val savedView = sharedPreferenceManager.getShortcut(index)!!
|
||||||
textView.text = menuTitle.text
|
textView.text = menuTitle.text
|
||||||
try {
|
try {
|
||||||
sharedPreferenceManager.setShortcut(
|
sharedPreferenceManager.setShortcut(
|
||||||
textView,
|
index,
|
||||||
|
textView.text,
|
||||||
savedView[0],
|
savedView[0],
|
||||||
savedView[1].toInt(),
|
savedView[1].toInt(),
|
||||||
savedView.getOrNull(3)?.toBoolean() ?: false
|
savedView.getOrNull(3)?.toBoolean() ?: false
|
||||||
)
|
)
|
||||||
} catch (_: NumberFormatException) {
|
} catch (_: NumberFormatException) {
|
||||||
sharedPreferenceManager.setShortcut(
|
sharedPreferenceManager.setShortcut(
|
||||||
textView,
|
index,
|
||||||
|
textView.text,
|
||||||
savedView[0],
|
savedView[0],
|
||||||
0,
|
0,
|
||||||
savedView.getOrNull(3)?.toBoolean() ?: false
|
savedView.getOrNull(3)?.toBoolean() ?: false
|
||||||
|
|
@ -1052,7 +1056,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
userHandle: UserHandle,
|
userHandle: UserHandle,
|
||||||
textView: TextView,
|
textView: TextView,
|
||||||
userProfile: Int,
|
userProfile: Int,
|
||||||
shortcutView: TextView
|
shortcutView: TextView,
|
||||||
|
shortcutIndex: Int
|
||||||
) {
|
) {
|
||||||
if (userProfile != 0) {
|
if (userProfile != 0) {
|
||||||
shortcutView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null)
|
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)
|
appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle)
|
||||||
}
|
}
|
||||||
sharedPreferenceManager.setShortcut(
|
sharedPreferenceManager.setShortcut(
|
||||||
shortcutView,
|
shortcutIndex,
|
||||||
|
shortcutView.text,
|
||||||
appInfo.applicationInfo.packageName,
|
appInfo.applicationInfo.packageName,
|
||||||
userProfile
|
userProfile
|
||||||
)
|
)
|
||||||
|
|
@ -1183,13 +1189,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
returnAllowed = false
|
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.text = contactName
|
||||||
shortcutView.setOnClickListener {
|
shortcutView.setOnClickListener {
|
||||||
onContactClick(contactId)
|
onContactClick(contactId)
|
||||||
}
|
}
|
||||||
sharedPreferenceManager.setShortcut(
|
sharedPreferenceManager.setShortcut(
|
||||||
shortcutView,
|
shortcutIndex,
|
||||||
|
shortcutView.text,
|
||||||
contactName,
|
contactName,
|
||||||
contactId,
|
contactId,
|
||||||
true
|
true
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import eu.ottop.yamlauncher.R
|
import eu.ottop.yamlauncher.R
|
||||||
|
|
||||||
|
|
@ -89,14 +88,14 @@ class SharedPreferenceManager (private val context: Context) {
|
||||||
return preferences.getString("dateSize", "medium")
|
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()
|
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()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getShortcut(textView: TextView): List<String>? {
|
fun getShortcut(index: Int): List<String>? {
|
||||||
val value = preferences.getString("shortcut${textView.id}", "e§splitter§e§splitter§e§splitter§e")
|
val value = preferences.getString("shortcut${index}", "e§splitter§e§splitter§e§splitter§e")
|
||||||
return value?.split("§splitter§")
|
return value?.split("§splitter§")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@
|
||||||
<string name="enable_search">Suche aktivieren</string>
|
<string name="enable_search">Suche aktivieren</string>
|
||||||
<string name="search_alignment">Ausrichtung der Suche</string>
|
<string name="search_alignment">Ausrichtung der Suche</string>
|
||||||
<string name="search_size">Größe der Suche</string>
|
<string name="search_size">Größe der Suche</string>
|
||||||
|
<string name="enable_fuzzy_search">Fuzzy Search</string>
|
||||||
<string name="automatically_open_keyboard">Tastatur automatisch öffnen</string>
|
<string name="automatically_open_keyboard">Tastatur automatisch öffnen</string>
|
||||||
<string name="automatic_app_opening">Automatisches öffnen der Apps</string>
|
<string name="automatic_app_opening">Automatisches öffnen der Apps</string>
|
||||||
<string name="auto_launch_summary">App automatisch öffnen, wenn sie das letzte Suchergebnis ist</string>
|
<string name="auto_launch_summary">App automatisch öffnen, wenn sie das letzte Suchergebnis ist</string>
|
||||||
|
|
@ -155,7 +156,7 @@
|
||||||
<string name="stripe_link"><![CDATA[<a href="https://donate.stripe.com/14k6s2bMJdnDgtW288">Stripe</a><br>(one-time)]]></string>
|
<string name="stripe_link"><![CDATA[<a href="https://donate.stripe.com/14k6s2bMJdnDgtW288">Stripe</a><br>(one-time)]]></string>
|
||||||
<string name="weather_link"><![CDATA[Weather data by <a href="https://open-meteo.com/">Open-Meteo.com</a><br>(<a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>)]]></string>
|
<string name="weather_link"><![CDATA[Weather data by <a href="https://open-meteo.com/">Open-Meteo.com</a><br>(<a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>)]]></string>
|
||||||
|
|
||||||
<string name="reset">Zurücksetzen</string>
|
<string name="reset">Reset</string>
|
||||||
<string name="restart_text">YAM Launcher neu starten</string>
|
<string name="restart_text">YAM Launcher neu starten</string>
|
||||||
<string name="reset_text">Alle Einstellungen zurücksetzen</string>
|
<string name="reset_text">Alle Einstellungen zurücksetzen</string>
|
||||||
<string name="reset_confirm_text">Du wirst ALLE Änderungen verlieren, die du an den Launcher-Einstellungen, Verknüpfungen, versteckten Apps usw. vorgenommen hast.\n\nBist du sicher?</string>
|
<string name="reset_confirm_text">Du wirst ALLE Änderungen verlieren, die du an den Launcher-Einstellungen, Verknüpfungen, versteckten Apps usw. vorgenommen hast.\n\nBist du sicher?</string>
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@
|
||||||
<string name="enable_search">Näytä Hakupalkki</string>
|
<string name="enable_search">Näytä Hakupalkki</string>
|
||||||
<string name="search_alignment">Hakupalkin Sijainti</string>
|
<string name="search_alignment">Hakupalkin Sijainti</string>
|
||||||
<string name="search_size">Hakupalkin Koko</string>
|
<string name="search_size">Hakupalkin Koko</string>
|
||||||
<string name="enable_fuzzy_search">Ota sumea haku käyttöön</string>
|
<string name="enable_fuzzy_search">Sumea haku</string>
|
||||||
<string name="automatically_open_keyboard">Avaa Näppäimistö Automaattisesti</string>
|
<string name="automatically_open_keyboard">Avaa Näppäimistö Automaattisesti</string>
|
||||||
<string name="automatic_app_opening">Avaa Hakutulos Automaattisesti</string>
|
<string name="automatic_app_opening">Avaa Hakutulos Automaattisesti</string>
|
||||||
<string name="auto_launch_summary">Avaa sovellus automaattisesti kun se on viimeinen hakutulos</string>
|
<string name="auto_launch_summary">Avaa sovellus automaattisesti kun se on viimeinen hakutulos</string>
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@
|
||||||
<string name="enable_search">Enable Search</string>
|
<string name="enable_search">Enable Search</string>
|
||||||
<string name="search_alignment">Search Alignment</string>
|
<string name="search_alignment">Search Alignment</string>
|
||||||
<string name="search_size">Search Size</string>
|
<string name="search_size">Search Size</string>
|
||||||
<string name="enable_fuzzy_search">Enable Fuzzy Search</string>
|
<string name="enable_fuzzy_search">Fuzzy Search</string>
|
||||||
<string name="automatically_open_keyboard">Automatically Open Keyboard</string>
|
<string name="automatically_open_keyboard">Automatically Open Keyboard</string>
|
||||||
<string name="automatic_app_opening">Automatic App Opening</string>
|
<string name="automatic_app_opening">Automatic App Opening</string>
|
||||||
<string name="auto_launch_summary">Automatically launch an app when it\'s the last search result</string>
|
<string name="auto_launch_summary">Automatically launch an app when it\'s the last search result</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue