mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Contacts can now be set as shortcuts
This commit is contained in:
parent
5558c666c8
commit
53f4d792e9
3 changed files with 60 additions and 16 deletions
|
|
@ -15,10 +15,13 @@ import eu.ottop.yamlauncher.utils.UIUtils
|
|||
class ContactsAdapter(
|
||||
private val activity: MainActivity,
|
||||
private var contacts: MutableList<Pair<String, Int>>,
|
||||
private val contactClickListener: OnContactClickListener
|
||||
private val contactClickListener: OnContactClickListener,
|
||||
private val contactShortcutListener: OnContactShortcutListener,
|
||||
) :
|
||||
RecyclerView.Adapter<ContactsAdapter.AppViewHolder>() {
|
||||
|
||||
var shortcutTextView: TextView? = null
|
||||
|
||||
private val uiUtils = UIUtils(activity)
|
||||
private val sharedPreferenceManager = SharedPreferenceManager(activity)
|
||||
|
||||
|
|
@ -26,16 +29,25 @@ class ContactsAdapter(
|
|||
fun onContactClick(contactId: Int)
|
||||
}
|
||||
|
||||
interface OnContactShortcutListener {
|
||||
fun onContactShortcut(contactId: Int, contactName: String, shortcutView: TextView)
|
||||
}
|
||||
|
||||
inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val listItem: FrameLayout = itemView.findViewById(R.id.listItem)
|
||||
val textView: TextView = listItem.findViewById(R.id.appName)
|
||||
|
||||
init {
|
||||
textView.setOnClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
val contact = contacts[position]
|
||||
contactClickListener.onContactClick(contact.second)
|
||||
|
||||
if (shortcutTextView != null) {
|
||||
val position = bindingAdapterPosition
|
||||
val contact = contacts[position]
|
||||
contactShortcutListener.onContactShortcut(contact.second, contact.first, shortcutTextView!!)
|
||||
} else {
|
||||
val position = bindingAdapterPosition
|
||||
val contact = contacts[position]
|
||||
contactClickListener.onContactClick(contact.second)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ import java.lang.reflect.Method
|
|||
import kotlin.math.abs
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener, AppMenuAdapter.OnItemClickListener, AppMenuAdapter.OnShortcutListener, AppMenuAdapter.OnItemLongClickListener, ContactsAdapter.OnContactClickListener {
|
||||
class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener, AppMenuAdapter.OnItemClickListener, AppMenuAdapter.OnShortcutListener, AppMenuAdapter.OnItemLongClickListener, ContactsAdapter.OnContactClickListener, ContactsAdapter.OnContactShortcutListener {
|
||||
|
||||
private lateinit var weatherSystem: WeatherSystem
|
||||
private lateinit var appUtils: AppUtils
|
||||
|
|
@ -211,7 +211,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
else {
|
||||
textView.visibility = View.VISIBLE
|
||||
|
||||
val savedView = sharedPreferenceManager.getShortcut(textView)
|
||||
val savedView = sharedPreferenceManager.getShortcut(textView)?.toMutableList()
|
||||
|
||||
if (savedView != null && savedView.size < 4) {
|
||||
savedView.add(3, "false")
|
||||
}
|
||||
|
||||
// Set the non-work profile drawable by default
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
||||
|
|
@ -249,6 +253,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
|
||||
appAdapter?.shortcutTextView = textView
|
||||
contactAdapter?.shortcutTextView = textView
|
||||
toAppMenu()
|
||||
true
|
||||
}
|
||||
|
|
@ -273,8 +278,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
setRenameShortcutListener(textView, savedView)
|
||||
}
|
||||
appAdapter?.shortcutTextView = textView
|
||||
contactAdapter?.shortcutTextView = textView
|
||||
toAppMenu()
|
||||
searchSwitcher.visibility = View.GONE
|
||||
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
|
|
@ -296,13 +301,15 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
sharedPreferenceManager.setShortcut(
|
||||
textView,
|
||||
savedView[0],
|
||||
savedView[1].toInt()
|
||||
savedView[1].toInt(),
|
||||
savedView[3].toBoolean()
|
||||
)
|
||||
} catch (_: NumberFormatException) {
|
||||
sharedPreferenceManager.setShortcut(
|
||||
textView,
|
||||
savedView[0],
|
||||
0
|
||||
0,
|
||||
savedView[3].toBoolean()
|
||||
)
|
||||
}
|
||||
backToHome()
|
||||
|
|
@ -313,6 +320,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
|
||||
private fun toAppMenu() {
|
||||
uiUtils.setContactsVisibility(searchSwitcher, binding.searchLayout, binding.searchReplacement)
|
||||
try {
|
||||
// The menu opens from the top
|
||||
appRecycler.scrollToPosition(0)
|
||||
|
|
@ -349,11 +357,15 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
private fun setShortcutSetup(textView: TextView, savedView: List<String>?) {
|
||||
// Set the work profile drawable for work profile apps
|
||||
textView.text = savedView?.get(2)
|
||||
if (savedView != null && savedView[3].toBoolean()) {
|
||||
setShortcutContactListeners(textView, savedView[1].toInt())
|
||||
return
|
||||
}
|
||||
if (savedView?.get(1) != "0") {
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null)
|
||||
}
|
||||
|
||||
textView.text = savedView?.get(2)
|
||||
setShortcutListeners(textView, savedView)
|
||||
}
|
||||
|
||||
|
|
@ -365,6 +377,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
}
|
||||
|
||||
private fun setShortcutContactListeners(textView: TextView, contactId: Int) {
|
||||
textView.setOnClickListener {
|
||||
onContactClick(contactId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setPreferences() {
|
||||
uiUtils.setBackground(window)
|
||||
|
||||
|
|
@ -502,8 +520,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
private fun openAppMenu() {
|
||||
appAdapter?.shortcutTextView = null
|
||||
contactAdapter?.shortcutTextView = null
|
||||
menuTitle.visibility = View.GONE
|
||||
uiUtils.setContactsVisibility(searchSwitcher, binding.searchLayout, binding.searchReplacement)
|
||||
toAppMenu()
|
||||
}
|
||||
|
||||
|
|
@ -803,7 +821,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
private fun setupContactRecycler() {
|
||||
uiUtils.setImageColor(searchSwitcher)
|
||||
|
||||
contactAdapter = ContactsAdapter(this, mutableListOf(), this)
|
||||
contactAdapter = ContactsAdapter(this, mutableListOf(), this@MainActivity, this@MainActivity)
|
||||
contactMenuLinearLayoutManager.stackFromEnd = true
|
||||
contactRecycler = binding.contactRecycler
|
||||
contactRecycler.layoutManager = contactMenuLinearLayoutManager
|
||||
|
|
@ -1052,7 +1070,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
backToHome()
|
||||
}
|
||||
|
||||
|
||||
override fun onItemLongClick(
|
||||
textView: TextView,
|
||||
actionMenuLayout: LinearLayout,
|
||||
|
|
@ -1157,4 +1174,19 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
startActivity(intent)
|
||||
returnAllowed = false
|
||||
}
|
||||
|
||||
override fun onContactShortcut(contactId: Int, contactName: String, shortcutView: TextView) {
|
||||
shortcutView.text = contactName
|
||||
shortcutView.setOnClickListener {
|
||||
onContactClick(contactId)
|
||||
}
|
||||
sharedPreferenceManager.setShortcut(
|
||||
shortcutView,
|
||||
contactName,
|
||||
contactId,
|
||||
true
|
||||
)
|
||||
uiUtils.setDrawables(shortcutView, sharedPreferenceManager.getShortcutAlignment())
|
||||
backToHome()
|
||||
}
|
||||
}
|
||||
|
|
@ -89,9 +89,9 @@ class SharedPreferenceManager (private val context: Context) {
|
|||
return preferences.getString("dateSize", "medium")
|
||||
}
|
||||
|
||||
fun setShortcut(textView: TextView, packageName: String, profile: Int) {
|
||||
fun setShortcut(textView: TextView, packageName: String, profile: Int, isContact: Boolean = false) {
|
||||
val editor = preferences.edit()
|
||||
editor.putString("shortcut${textView.id}", "$packageName§splitter§$profile§splitter§${textView.text}")
|
||||
editor.putString("shortcut${textView.id}", "$packageName§splitter§$profile§splitter§${textView.text}§splitter§${isContact}")
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue