mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Comments, refactoring and changed nested pairs to triples
This commit is contained in:
parent
e769baeed0
commit
382bc4a53d
10 changed files with 73 additions and 91 deletions
|
|
@ -72,7 +72,7 @@ class AppActionMenu {
|
|||
val editText = editLayout.findViewById<EditText>(R.id.appNameEdit)
|
||||
val resetButton = editLayout.findViewById<AppCompatButton>(R.id.reset)
|
||||
|
||||
val app = Pair(mainActivity!!, Pair(userHandle, workProfile))
|
||||
val app = Triple(mainActivity!!, userHandle, workProfile)
|
||||
|
||||
searchView.visibility = View.INVISIBLE
|
||||
editText.requestFocus()
|
||||
|
|
@ -127,7 +127,7 @@ class AppActionMenu {
|
|||
imm.hideSoftInputFromWindow(editLayout.windowToken, 0)
|
||||
sharedPreferenceManager.resetAppName(
|
||||
app.first.applicationInfo.packageName,
|
||||
app.second.second
|
||||
app.third
|
||||
)
|
||||
|
||||
activity.lifecycleScope.launch {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import com.google.android.material.textfield.TextInputEditText
|
|||
class AppMenuAdapter(
|
||||
|
||||
private val context: Context,
|
||||
private var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
private var apps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>,
|
||||
private val itemClickListener: OnItemClickListener,
|
||||
private val shortcutListener: OnShortcutListener,
|
||||
private val itemLongClickListener: OnItemLongClickListener,
|
||||
|
|
@ -74,10 +74,10 @@ 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.first, textView, apps[position].second.second, shortcutTextView!!)
|
||||
shortcutListener.onShortcut(app, apps[position].second, textView, apps[position].third, shortcutTextView!!)
|
||||
}
|
||||
else {
|
||||
itemClickListener.onItemClick(app, apps[position].second.first)
|
||||
itemClickListener.onItemClick(app, apps[position].second)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,14 +88,14 @@ 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.first, textView, apps[position].second.second, shortcutTextView!!)
|
||||
shortcutListener.onShortcut(app, apps[position].second, textView, apps[position].third, shortcutTextView!!)
|
||||
return@setOnLongClickListener true
|
||||
} else {
|
||||
|
||||
itemLongClickListener.onItemLongClick(
|
||||
app,
|
||||
apps[position].second.first,
|
||||
apps[position].second.second,
|
||||
apps[position].second,
|
||||
apps[position].third,
|
||||
textView,
|
||||
actionMenuLayout,
|
||||
editView,
|
||||
|
|
@ -117,7 +117,7 @@ class AppMenuAdapter(
|
|||
val app = apps[position]
|
||||
|
||||
// Set initial drawables
|
||||
if (app.second.second != 0) {
|
||||
if (app.third != 0) {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null, ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null)
|
||||
holder.textView.compoundDrawables[0].colorFilter =
|
||||
BlendModeColorFilter(sharedPreferenceManager.getTextColor(), BlendMode.SRC_ATOP)
|
||||
|
|
@ -133,7 +133,7 @@ class AppMenuAdapter(
|
|||
// Update the application information (allows updating apps to work)
|
||||
val appInfo = appUtils.getAppInfo(
|
||||
app.first.applicationInfo.packageName,
|
||||
app.second.second
|
||||
app.third
|
||||
)
|
||||
|
||||
holder.textView.setTextColor(sharedPreferenceManager.getTextColor())
|
||||
|
|
@ -144,7 +144,7 @@ class AppMenuAdapter(
|
|||
if (appInfo != null) {
|
||||
holder.textView.text = sharedPreferenceManager.getAppName(
|
||||
appInfo.packageName,
|
||||
app.second.second,
|
||||
app.third,
|
||||
appLabel
|
||||
)
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ class AppMenuAdapter(
|
|||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
fun updateApps(newApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
apps = newApps.toMutableList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||
|
||||
suspend fun getInstalledApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
var sortedApps = listOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
suspend fun getInstalledApps(): List<Triple<LauncherActivityInfo, UserHandle, Int>> {
|
||||
val allApps = mutableListOf<Triple<LauncherActivityInfo, UserHandle, Int>>()
|
||||
var sortedApps = listOf<Triple<LauncherActivityInfo, UserHandle, Int>>()
|
||||
withContext(Dispatchers.Default) {
|
||||
for (i in launcherApps.profiles.indices) { // Check apps on both, normal and work profiles
|
||||
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
|
||||
|
|
@ -24,7 +24,7 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
i
|
||||
) && app.applicationInfo.packageName != context.applicationInfo.packageName // Hide the launcher itself
|
||||
) {
|
||||
allApps.add(Pair(app, Pair(launcherApps.profiles[i], i)))
|
||||
allApps.add(Triple(app, launcherApps.profiles[i], i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
sortedApps = allApps.sortedBy {
|
||||
sharedPreferenceManager.getAppName(
|
||||
it.first.applicationInfo.packageName,
|
||||
it.second.second,
|
||||
it.third,
|
||||
it.first.applicationInfo.loadLabel(context.packageManager)
|
||||
).toString().lowercase()
|
||||
}
|
||||
|
|
@ -43,22 +43,23 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
}
|
||||
|
||||
// Get hidden apps for the hidden apps settings
|
||||
suspend fun getHiddenApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
var sortedApps = listOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
suspend fun getHiddenApps(): List<Triple<LauncherActivityInfo, UserHandle, Int>> {
|
||||
val allApps = mutableListOf<Triple<LauncherActivityInfo, UserHandle, Int>>()
|
||||
var sortedApps = listOf<Triple<LauncherActivityInfo, UserHandle, Int>>()
|
||||
withContext(Dispatchers.Default) {
|
||||
for (i in launcherApps.profiles.indices) {
|
||||
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
|
||||
if (sharedPreferenceManager.isAppHidden(app.applicationInfo.packageName, i)) {
|
||||
allApps.add(Pair(app, Pair(launcherApps.profiles[i], i)))
|
||||
allApps.add(Triple(app, launcherApps.profiles[i], i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Sort apps by name
|
||||
sortedApps = allApps.sortedBy {
|
||||
sharedPreferenceManager.getAppName(
|
||||
it.first.applicationInfo.packageName,
|
||||
it.second.second,
|
||||
it.third,
|
||||
context.packageManager.getApplicationLabel(it.first.applicationInfo)
|
||||
).toString().lowercase()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
|
||||
class GestureAppsAdapter(
|
||||
private val context: Context,
|
||||
var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
var apps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>,
|
||||
private val itemClickListener: OnItemClickListener
|
||||
) :
|
||||
RecyclerView.Adapter<GestureAppsAdapter.AppViewHolder>() {
|
||||
|
|
@ -34,7 +34,7 @@ class GestureAppsAdapter(
|
|||
textView.setOnClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
val app = apps[position].first
|
||||
itemClickListener.onItemClick(app, apps[position].second.second)
|
||||
itemClickListener.onItemClick(app, apps[position].third)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ class GestureAppsAdapter(
|
|||
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
||||
val app = apps[position]
|
||||
|
||||
if (app.second.second != 0) {
|
||||
if (app.third != 0) {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null,null,null)
|
||||
}
|
||||
else {
|
||||
|
|
@ -65,7 +65,7 @@ class GestureAppsAdapter(
|
|||
|
||||
holder.textView.text = sharedPreferenceManager.getAppName(
|
||||
app.first.applicationInfo.packageName,
|
||||
app.second.second,
|
||||
app.third,
|
||||
holder.itemView.context.packageManager.getApplicationLabel(appInfo)
|
||||
)
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ class GestureAppsAdapter(
|
|||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
fun updateApps(newApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
apps = newApps.toMutableList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
||||
class GestureAppsFragment(private val direction: String) : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
||||
|
||||
private var adapter: GestureAppsAdapter? = null
|
||||
private lateinit var sharedPreferenceManager: SharedPreferenceManager
|
||||
|
|
@ -44,7 +44,6 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
|||
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
||||
|
||||
lifecycleScope.launch {
|
||||
|
||||
adapter = GestureAppsAdapter(
|
||||
requireContext(),
|
||||
appUtils.getInstalledApps().toMutableList(),
|
||||
|
|
@ -100,7 +99,7 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
|||
private suspend fun filterItems(query: String?) {
|
||||
|
||||
val cleanQuery = stringUtils.cleanString(query)
|
||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
val newFilteredApps = mutableListOf<Triple<LauncherActivityInfo, UserHandle, Int>>()
|
||||
val updatedApps = appUtils.getInstalledApps()
|
||||
|
||||
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||
|
|
@ -109,14 +108,14 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
|||
|
||||
}
|
||||
|
||||
private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>, updatedApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
if (cleanQuery.isNullOrEmpty()) {
|
||||
newFilteredApps.addAll(updatedApps)
|
||||
} else {
|
||||
updatedApps.forEach {
|
||||
val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName(
|
||||
it.first.applicationInfo.packageName,
|
||||
it.second.second,
|
||||
it.third,
|
||||
requireActivity().packageManager.getApplicationLabel(it.first.applicationInfo)
|
||||
).toString())
|
||||
if (cleanItemText != null) {
|
||||
|
|
@ -128,7 +127,7 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun applySearch(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private fun applySearch(newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
adapter?.updateApps(newFilteredApps)
|
||||
}
|
||||
|
||||
|
|
@ -148,10 +147,9 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
|||
}
|
||||
|
||||
private fun performConfirmedAction(appInfo: LauncherActivityInfo, appName: String, profile: Int) {
|
||||
val result = Bundle().apply {
|
||||
putString("gesture_app", "$appName§splitter§${appInfo.applicationInfo.packageName}§splitter§$profile")
|
||||
}
|
||||
setFragmentResult("request_key", result)
|
||||
sharedPreferenceManager.setGestures(
|
||||
direction, "$appName§splitter§${appInfo.applicationInfo.packageName}§splitter§$profile"
|
||||
)
|
||||
requireActivity().supportFragmentManager.popBackStack()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ class GestureUtils(private val context: Context) {
|
|||
|
||||
if (app != null) {
|
||||
if (app.size >= 3)
|
||||
|
||||
return Pair(
|
||||
launcherApps.getActivityList(
|
||||
app[1], launcherApps.profiles[app[2]
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
|
||||
class HiddenAppsAdapter(
|
||||
private val context: Context,
|
||||
private var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
private var apps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>,
|
||||
private val itemClickListener: OnItemClickListener
|
||||
) :
|
||||
RecyclerView.Adapter<HiddenAppsAdapter.AppViewHolder>() {
|
||||
|
|
@ -35,7 +35,7 @@ class HiddenAppsAdapter(
|
|||
textView.setOnClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
val app = apps[position].first
|
||||
itemClickListener.onItemClick(app, apps[position].second.second)
|
||||
itemClickListener.onItemClick(app, apps[position].third)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ class HiddenAppsAdapter(
|
|||
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
||||
val app = apps[position]
|
||||
|
||||
if (app.second.second != 0) {
|
||||
if (app.third != 0) {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null,null,null)
|
||||
}
|
||||
else {
|
||||
|
|
@ -61,10 +61,11 @@ class HiddenAppsAdapter(
|
|||
|
||||
uiUtils.setAppSize(holder.textView)
|
||||
|
||||
// Separate activity from Main so does not need special update
|
||||
val appInfo = app.first.activityInfo.applicationInfo
|
||||
holder.textView.text = sharedPreferenceManager.getAppName(
|
||||
app.first.applicationInfo.packageName,
|
||||
app.second.second,
|
||||
app.third,
|
||||
holder.itemView.context.packageManager.getApplicationLabel(appInfo)
|
||||
)
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ class HiddenAppsAdapter(
|
|||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
fun updateApps(newApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
apps = newApps.toMutableList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
private suspend fun filterItems(query: String?) {
|
||||
|
||||
val cleanQuery = stringUtils.cleanString(query)
|
||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
val newFilteredApps = mutableListOf<Triple<LauncherActivityInfo, UserHandle, Int>>()
|
||||
val updatedApps = appUtils.getHiddenApps()
|
||||
|
||||
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||
|
|
@ -106,14 +106,14 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
|
||||
}
|
||||
|
||||
private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>, updatedApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
if (cleanQuery.isNullOrEmpty()) {
|
||||
newFilteredApps.addAll(updatedApps)
|
||||
} else {
|
||||
updatedApps.forEach {
|
||||
val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName(
|
||||
it.first.applicationInfo.packageName,
|
||||
it.second.second,
|
||||
it.third,
|
||||
requireActivity().packageManager.getApplicationLabel(it.first.applicationInfo)
|
||||
).toString())
|
||||
if (cleanItemText != null) {
|
||||
|
|
@ -125,7 +125,7 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun applySearch(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private fun applySearch(newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
adapter?.updateApps(newFilteredApps)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var launcherApps: LauncherApps
|
||||
private lateinit var installedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
|
||||
private lateinit var installedApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>
|
||||
|
||||
private lateinit var preferences: SharedPreferences
|
||||
|
||||
|
|
@ -420,11 +420,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
}
|
||||
|
||||
private fun listsEqual(list1: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, list2: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>): Boolean {
|
||||
private fun listsEqual(list1: List<Triple<LauncherActivityInfo, UserHandle, Int>>, list2: List<Triple<LauncherActivityInfo, UserHandle, Int>>): Boolean {
|
||||
if (list1.size != list2.size) return false
|
||||
|
||||
for (i in list1.indices) {
|
||||
if (list1[i].first.componentName != list2[i].first.componentName || list1[i].second.first != list2[i].second.first) {
|
||||
if (list1[i].first.componentName != list2[i].first.componentName || list1[i].second != list2[i].second) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -432,7 +432,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
return true
|
||||
}
|
||||
|
||||
private suspend fun updateMenu(updatedApps : List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private suspend fun updateMenu(updatedApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
withContext(Dispatchers.Main) {
|
||||
adapter?.updateApps(updatedApps)
|
||||
}
|
||||
|
|
@ -474,7 +474,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
}
|
||||
|
||||
private suspend fun setupRecyclerView(newApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private suspend fun setupRecyclerView(newApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
adapter = AppMenuAdapter(this@MainActivity, newApps, this@MainActivity, this@MainActivity, this@MainActivity, launcherApps)
|
||||
appMenuLinearLayoutManager.stackFromEnd = true
|
||||
recyclerView = findViewById(R.id.recyclerView)
|
||||
|
|
@ -531,13 +531,13 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
private suspend fun filterItems(query: String?) {
|
||||
|
||||
val cleanQuery = stringUtils.cleanString(query)
|
||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
val newFilteredApps = mutableListOf<Triple<LauncherActivityInfo, UserHandle, Int>>()
|
||||
val updatedApps = appUtils.getInstalledApps()
|
||||
|
||||
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||
}
|
||||
|
||||
private suspend fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private suspend fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>, updatedApps: List<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
if (cleanQuery.isNullOrEmpty()) {
|
||||
isJobActive = true
|
||||
updateMenu(updatedApps)
|
||||
|
|
@ -546,7 +546,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
updatedApps.forEach {
|
||||
val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName(
|
||||
it.first.applicationInfo.packageName,
|
||||
it.second.second,
|
||||
it.third,
|
||||
packageManager.getApplicationLabel(it.first.applicationInfo)
|
||||
).toString())
|
||||
if (cleanItemText != null) {
|
||||
|
|
@ -559,7 +559,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun applySearchFilter(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
private suspend fun applySearchFilter(newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) {
|
||||
if (!listsEqual(installedApps, newFilteredApps)) {
|
||||
updateMenu(newFilteredApps)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import androidx.preference.SwitchPreference
|
|||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
|
||||
private var manualLocationPref: Preference? = null
|
||||
private var leftSwipePref: Preference? = null
|
||||
private var rightSwipePref: Preference? = null
|
||||
private lateinit var sharedPreferenceManager: SharedPreferenceManager
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
|
|
@ -17,10 +19,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
|
||||
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
||||
|
||||
val gpsLocationPref: SwitchPreference? = findPreference("gpsLocation")
|
||||
val gpsLocationPref = findPreference<SwitchPreference?>("gpsLocation")
|
||||
manualLocationPref = findPreference("manualLocation")
|
||||
val leftSwipePref = findPreference<Preference?>("leftSwipeApp")
|
||||
val rightSwipePref = findPreference<Preference?>("rightSwipeApp")
|
||||
leftSwipePref = findPreference("leftSwipeApp")
|
||||
rightSwipePref = findPreference("rightSwipeApp")
|
||||
val aboutPref = findPreference<Preference?>("aboutPage")
|
||||
val hiddenPref = findPreference<Preference?>("hiddenApps")
|
||||
|
||||
|
|
@ -28,16 +30,15 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
leftSwipePref?.summary = sharedPreferenceManager.getGestureName("left")
|
||||
rightSwipePref?.summary = sharedPreferenceManager.getGestureName("right")
|
||||
|
||||
// Only enable manual location when gps location is disabled
|
||||
if (gpsLocationPref != null && manualLocationPref != null) {
|
||||
// Initial setup
|
||||
manualLocationPref?.isEnabled = !gpsLocationPref.isChecked
|
||||
|
||||
// Set up a listener to update the enabled state of manualLocationPref
|
||||
gpsLocationPref.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
val isGpsEnabled = newValue as Boolean
|
||||
manualLocationPref?.isEnabled = !isGpsEnabled
|
||||
true // Returning true means the change is persisted
|
||||
true
|
||||
}
|
||||
|
||||
manualLocationPref?.onPreferenceClickListener =
|
||||
|
|
@ -64,40 +65,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
Preference.OnPreferenceClickListener {
|
||||
requireActivity().supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.settingsLayout, GestureAppsFragment())
|
||||
.replace(R.id.settingsLayout, GestureAppsFragment("left"))
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
setFragmentResultListener("request_key") { _, bundle ->
|
||||
clearFragmentResultListener("request_key")
|
||||
val result = bundle.getString("gesture_app")
|
||||
|
||||
sharedPreferenceManager.setGestures(
|
||||
"left", result
|
||||
)
|
||||
|
||||
val appName = sharedPreferenceManager.getGestureName("left")
|
||||
leftSwipePref?.summary = appName
|
||||
}
|
||||
true }
|
||||
|
||||
rightSwipePref?.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
requireActivity().supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.settingsLayout, GestureAppsFragment())
|
||||
.replace(R.id.settingsLayout, GestureAppsFragment("right"))
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
setFragmentResultListener("request_key") { _, bundle ->
|
||||
clearFragmentResultListener("request_key")
|
||||
val result = bundle.getString("gesture_app")
|
||||
|
||||
sharedPreferenceManager.setGestures(
|
||||
"right", result
|
||||
)
|
||||
|
||||
val appName = sharedPreferenceManager.getGestureName("right")
|
||||
rightSwipePref?.summary = appName
|
||||
}
|
||||
true }
|
||||
|
||||
aboutPref?.onPreferenceClickListener =
|
||||
|
|
@ -113,5 +92,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
manualLocationPref?.summary = sharedPreferenceManager.getWeatherRegion()
|
||||
|
||||
leftSwipePref?.summary = sharedPreferenceManager.getGestureName("left")
|
||||
|
||||
rightSwipePref?.summary = sharedPreferenceManager.getGestureName("right")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue