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