diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt index 0473e9c..eddf989 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt @@ -72,7 +72,7 @@ class AppActionMenu { val editText = editLayout.findViewById(R.id.appNameEdit) val resetButton = editLayout.findViewById(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 { diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index 0cf3e87..07a8d99 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -22,7 +22,7 @@ import com.google.android.material.textfield.TextInputEditText class AppMenuAdapter( private val context: Context, - private var apps: MutableList>>, + private var apps: MutableList>, 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>>) { + fun updateApps(newApps: List>) { apps = newApps.toMutableList() notifyDataSetChanged() } diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt index e43a397..7feb568 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt @@ -13,9 +13,9 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA private val sharedPreferenceManager = SharedPreferenceManager(context) - suspend fun getInstalledApps(): List>> { - val allApps = mutableListOf>>() - var sortedApps = listOf>>() + suspend fun getInstalledApps(): List> { + val allApps = mutableListOf>() + var sortedApps = listOf>() 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,24 +43,25 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA } // Get hidden apps for the hidden apps settings - suspend fun getHiddenApps(): List>> { - val allApps = mutableListOf>>() - var sortedApps = listOf>>() + suspend fun getHiddenApps(): List> { + val allApps = mutableListOf>() + var sortedApps = listOf>() 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)) } } } - sortedApps = allApps.sortedBy { - sharedPreferenceManager.getAppName( - it.first.applicationInfo.packageName, - it.second.second, - context.packageManager.getApplicationLabel(it.first.applicationInfo) - ).toString().lowercase() + //Sort apps by name + sortedApps = allApps.sortedBy { + sharedPreferenceManager.getAppName( + it.first.applicationInfo.packageName, + it.third, + context.packageManager.getApplicationLabel(it.first.applicationInfo) + ).toString().lowercase() } } return sortedApps diff --git a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt index eb0dfef..f9a1736 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt @@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView class GestureAppsAdapter( private val context: Context, - var apps: MutableList>>, + var apps: MutableList>, private val itemClickListener: OnItemClickListener ) : RecyclerView.Adapter() { @@ -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>>) { + fun updateApps(newApps: List>) { apps = newApps.toMutableList() notifyDataSetChanged() } diff --git a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt index b447dfc..f1ce023 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt @@ -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>>() + val newFilteredApps = mutableListOf>() val updatedApps = appUtils.getInstalledApps() getFilteredApps(cleanQuery, newFilteredApps, updatedApps) @@ -109,14 +108,14 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener { } - private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList>>, updatedApps: List>>) { + private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList>, updatedApps: List>) { 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>>) { + private fun applySearch(newFilteredApps: MutableList>) { 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() } diff --git a/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt index a409766..38f25c2 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt @@ -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] diff --git a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt index 9273a26..da0207b 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt @@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView class HiddenAppsAdapter( private val context: Context, - private var apps: MutableList>>, + private var apps: MutableList>, private val itemClickListener: OnItemClickListener ) : RecyclerView.Adapter() { @@ -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>>) { + fun updateApps(newApps: List>) { apps = newApps.toMutableList() notifyDataSetChanged() } diff --git a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt index 6d0bc58..d382402 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt @@ -97,7 +97,7 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener { private suspend fun filterItems(query: String?) { val cleanQuery = stringUtils.cleanString(query) - val newFilteredApps = mutableListOf>>() + val newFilteredApps = mutableListOf>() val updatedApps = appUtils.getHiddenApps() getFilteredApps(cleanQuery, newFilteredApps, updatedApps) @@ -106,14 +106,14 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener { } - private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList>>, updatedApps: List>>) { + private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList>, updatedApps: List>) { 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>>) { + private fun applySearch(newFilteredApps: MutableList>) { adapter?.updateApps(newFilteredApps) } diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index b3c01f1..f0922f3 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -69,7 +69,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh private lateinit var binding: ActivityMainBinding private lateinit var launcherApps: LauncherApps - private lateinit var installedApps: List>> + private lateinit var installedApps: List> private lateinit var preferences: SharedPreferences @@ -420,11 +420,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } } - private fun listsEqual(list1: List>>, list2: List>>): Boolean { + private fun listsEqual(list1: List>, list2: List>): 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>>) { + private suspend fun updateMenu(updatedApps: List>) { withContext(Dispatchers.Main) { adapter?.updateApps(updatedApps) } @@ -474,7 +474,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } - private suspend fun setupRecyclerView(newApps: MutableList>>) { + private suspend fun setupRecyclerView(newApps: MutableList>) { 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>>() + val newFilteredApps = mutableListOf>() val updatedApps = appUtils.getInstalledApps() getFilteredApps(cleanQuery, newFilteredApps, updatedApps) } - private suspend fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList>>, updatedApps: List>>) { + private suspend fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList>, updatedApps: List>) { 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>>) { + private suspend fun applySearchFilter(newFilteredApps: MutableList>) { if (!listsEqual(installedApps, newFilteredApps)) { updateMenu(newFilteredApps) diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt index d73b1d6..71d9dde 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt @@ -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("gpsLocation") manualLocationPref = findPreference("manualLocation") - val leftSwipePref = findPreference("leftSwipeApp") - val rightSwipePref = findPreference("rightSwipeApp") + leftSwipePref = findPreference("leftSwipeApp") + rightSwipePref = findPreference("rightSwipeApp") val aboutPref = findPreference("aboutPage") val hiddenPref = findPreference("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") } } \ No newline at end of file