From b7a76d679ed4838be611e3370f413f3a1339fe9b Mon Sep 17 00:00:00 2001 From: Raghav Date: Fri, 30 May 2025 23:02:29 +0530 Subject: [PATCH 1/2] Changed Delete button label to Uninstall --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 876d807f..e303cac2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -119,7 +119,7 @@ Disable Not working? Info - Delete + Uninstall Text size Enabled Disabled From eecffa74cb562674244c614804a830d00bd1562e Mon Sep 17 00:00:00 2001 From: Raghav Date: Sat, 7 Jun 2025 19:47:27 +0530 Subject: [PATCH 2/2] Fix: Hide previous app options mwnu when long-pressing another app in drawer --- .../java/app/olauncher/ui/AppDrawerAdapter.kt | 208 +++++++++--------- 1 file changed, 102 insertions(+), 106 deletions(-) diff --git a/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt b/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt index cc9dd2c9..aac607dd 100644 --- a/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt +++ b/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt @@ -1,5 +1,4 @@ package app.olauncher.ui - import android.content.Context import android.os.UserHandle import android.text.Editable @@ -22,7 +21,6 @@ import app.olauncher.helper.hideKeyboard import app.olauncher.helper.isSystemApp import app.olauncher.helper.showKeyboard import java.text.Normalizer - class AppDrawerAdapter( private var flag: Int, private val appLabelGravity: Int, @@ -32,7 +30,6 @@ class AppDrawerAdapter( private val appHideListener: (AppModel, Int) -> Unit, private val appRenameListener: (AppModel, String) -> Unit, ) : ListAdapter(DIFF_CALLBACK), Filterable { - companion object { val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: AppModel, newItem: AppModel): Boolean = @@ -47,6 +44,7 @@ class AppDrawerAdapter( private var isBangSearch = false private val appFilter = createAppFilter() private val myUserHandle = android.os.Process.myUserHandle() + private var previouslyOpenedHolder: ViewHolder? = null var appsList: MutableList = mutableListOf() var appFilteredList: MutableList = mutableListOf() @@ -56,7 +54,7 @@ class AppDrawerAdapter( override fun onBindViewHolder(holder: ViewHolder, position: Int) { try { - if (appFilteredList.size == 0 || position == RecyclerView.NO_POSITION) return + if (appFilteredList.isEmpty() || position == RecyclerView.NO_POSITION) return val appModel = appFilteredList[holder.bindingAdapterPosition] holder.bind( flag, @@ -67,7 +65,15 @@ class AppDrawerAdapter( appDeleteListener, appInfoListener, appHideListener, - appRenameListener + appRenameListener, + setOpenedHolder = { newHolder -> + previouslyOpenedHolder?.let { + it.binding.appHideLayout.visibility = View.GONE + it.binding.renameLayout.visibility = View.GONE + it.binding.appTitle.visibility = View.VISIBLE + } + previouslyOpenedHolder = newHolder + } ) } catch (e: Exception) { e.printStackTrace() @@ -82,12 +88,10 @@ class AppDrawerAdapter( isBangSearch = charSearch?.startsWith("!") ?: false autoLaunch = charSearch?.startsWith(" ")?.not() ?: true - val appFilteredList = (if (charSearch.isNullOrBlank()) appsList + val appFilteredList = if (charSearch.isNullOrBlank()) appsList else appsList.filter { app -> appLabelMatches(app.appLabel, charSearch) -// }.sortedByDescending { -// charSearch.contentEquals(it.appLabel, true) - } as MutableList) + } as MutableList val filterResults = FilterResults() filterResults.values = appFilteredList @@ -109,19 +113,16 @@ class AppDrawerAdapter( private fun autoLaunch() { try { - if (itemCount == 1 - && autoLaunch - && isBangSearch.not() - && flag == Constants.FLAG_LAUNCH_APP - && appFilteredList.size > 0 - ) appClickListener(appFilteredList[0]) + if (itemCount == 1 && autoLaunch && !isBangSearch && flag == Constants.FLAG_LAUNCH_APP && appFilteredList.isNotEmpty()) { + appClickListener(appFilteredList[0]) + } } catch (e: Exception) { e.printStackTrace() } } private fun appLabelMatches(appLabel: String, charSearch: CharSequence): Boolean { - return (appLabel.contains(charSearch.trim(), true) or + return (appLabel.contains(charSearch.trim(), true) || Normalizer.normalize(appLabel, Normalizer.Form.NFD) .replace(Regex("\\p{InCombiningDiacriticalMarks}+"), "") .replace(Regex("[-_+,. ]"), "") @@ -129,7 +130,6 @@ class AppDrawerAdapter( } fun setAppList(appsList: MutableList) { - // Add empty app for bottom padding in recyclerview appsList.add(AppModel("", null, "", "", false, android.os.Process.myUserHandle())) this.appsList = appsList this.appFilteredList = appsList @@ -137,11 +137,11 @@ class AppDrawerAdapter( } fun launchFirstInList() { - if (appFilteredList.size > 0) + if (appFilteredList.isNotEmpty()) appClickListener(appFilteredList[0]) } - class ViewHolder(private val binding: AdapterAppDrawerBinding) : RecyclerView.ViewHolder(binding.root) { + class ViewHolder(val binding: AdapterAppDrawerBinding) : RecyclerView.ViewHolder(binding.root) { fun bind( flag: Int, @@ -153,109 +153,104 @@ class AppDrawerAdapter( appInfoListener: (AppModel) -> Unit, appHideListener: (AppModel, Int) -> Unit, appRenameListener: (AppModel, String) -> Unit, - ) = - with(binding) { - appHideLayout.visibility = View.GONE - renameLayout.visibility = View.GONE - appTitle.visibility = View.VISIBLE - appTitle.text = appModel.appLabel + if (appModel.isNew == true) " ✦" else "" - appTitle.gravity = appLabelGravity - otherProfileIndicator.isVisible = appModel.user != myUserHandle + setOpenedHolder: (ViewHolder) -> Unit + ) = with(binding) { + appHideLayout.visibility = View.GONE + renameLayout.visibility = View.GONE + appTitle.visibility = View.VISIBLE + appTitle.text = appModel.appLabel + if (appModel.isNew == true) " \u2726" else "" + appTitle.gravity = appLabelGravity + otherProfileIndicator.isVisible = appModel.user != myUserHandle - appTitle.setOnClickListener { clickListener(appModel) } - appTitle.setOnLongClickListener { - if (appModel.appPackage.isNotEmpty()) { - appDelete.alpha = if (root.context.isSystemApp(appModel.appPackage)) 0.5f else 1.0f - appHide.text = if (flag == Constants.FLAG_HIDDEN_APPS) - root.context.getString(R.string.adapter_show) - else - root.context.getString(R.string.adapter_hide) - appTitle.visibility = View.INVISIBLE - appHideLayout.visibility = View.VISIBLE - appRename.isVisible = flag != Constants.FLAG_HIDDEN_APPS - } - true + appTitle.setOnClickListener { clickListener(appModel) } + + appTitle.setOnLongClickListener { + if (appModel.appPackage.isNotEmpty()) { + appDelete.alpha = if (root.context.isSystemApp(appModel.appPackage)) 0.5f else 1.0f + appHide.text = if (flag == Constants.FLAG_HIDDEN_APPS) + root.context.getString(R.string.adapter_show) + else + root.context.getString(R.string.adapter_hide) + + appTitle.visibility = View.INVISIBLE + appHideLayout.visibility = View.VISIBLE + appRename.isVisible = flag != Constants.FLAG_HIDDEN_APPS + + setOpenedHolder(this@ViewHolder) } - appRename.setOnClickListener { - if (appModel.appPackage.isNotEmpty()) { - etAppRename.hint = getAppName(etAppRename.context, appModel.appPackage) - etAppRename.setText(appModel.appLabel) - etAppRename.setSelectAllOnFocus(true) - renameLayout.visibility = View.VISIBLE - appHideLayout.visibility = View.GONE - etAppRename.showKeyboard() - etAppRename.imeOptions = EditorInfo.IME_ACTION_DONE; - } + true + } + + appRename.setOnClickListener { + if (appModel.appPackage.isNotEmpty()) { + etAppRename.hint = getAppName(etAppRename.context, appModel.appPackage) + etAppRename.setText(appModel.appLabel) + etAppRename.setSelectAllOnFocus(true) + renameLayout.visibility = View.VISIBLE + appHideLayout.visibility = View.GONE + etAppRename.showKeyboard() + etAppRename.imeOptions = EditorInfo.IME_ACTION_DONE } - etAppRename.onFocusChangeListener = View.OnFocusChangeListener { v, hasFocus -> - if (hasFocus) - appTitle.visibility = View.INVISIBLE - else - appTitle.visibility = View.VISIBLE + } + + etAppRename.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus -> + appTitle.visibility = if (hasFocus) View.INVISIBLE else View.VISIBLE + } + + etAppRename.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable?) { + etAppRename.hint = getAppName(etAppRename.context, appModel.appPackage) } - etAppRename.addTextChangedListener(object : TextWatcher { - override fun afterTextChanged(s: Editable?) { - etAppRename.hint = getAppName(etAppRename.context, appModel.appPackage) - } - override fun beforeTextChanged( - s: CharSequence?, - start: Int, - count: Int, - after: Int, - ) { - } + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} - override fun onTextChanged( - s: CharSequence?, - start: Int, - before: Int, - count: Int, - ) { - etAppRename.hint = "" - } - }) - etAppRename.setOnEditorActionListener { _, actionCode, _ -> - if (actionCode == EditorInfo.IME_ACTION_DONE) { - val renameLabel = etAppRename.text.toString().trim() - if (renameLabel.isNotBlank() && appModel.appPackage.isNotBlank()) { - appRenameListener(appModel, renameLabel) - renameLayout.visibility = View.GONE - } - true - } - false + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + etAppRename.hint = "" } - tvSaveRename.setOnClickListener { - etAppRename.hideKeyboard() + }) + + etAppRename.setOnEditorActionListener { _, actionCode, _ -> + if (actionCode == EditorInfo.IME_ACTION_DONE) { val renameLabel = etAppRename.text.toString().trim() if (renameLabel.isNotBlank() && appModel.appPackage.isNotBlank()) { appRenameListener(appModel, renameLabel) renameLayout.visibility = View.GONE - } else { - val packageManager = etAppRename.context.packageManager - appRenameListener( - appModel, - packageManager.getApplicationLabel( - packageManager.getApplicationInfo(appModel.appPackage, 0) - ).toString() - ) - renameLayout.visibility = View.GONE } - } - appInfo.setOnClickListener { appInfoListener(appModel) } - appDelete.setOnClickListener { appDeleteListener(appModel) } - appMenuClose.setOnClickListener { - appHideLayout.visibility = View.GONE - appTitle.visibility = View.VISIBLE - } - appRenameClose.setOnClickListener { + true + } else false + } + + tvSaveRename.setOnClickListener { + etAppRename.hideKeyboard() + val renameLabel = etAppRename.text.toString().trim() + if (renameLabel.isNotBlank() && appModel.appPackage.isNotBlank()) { + appRenameListener(appModel, renameLabel) + renameLayout.visibility = View.GONE + } else { + val packageManager = etAppRename.context.packageManager + appRenameListener( + appModel, + packageManager.getApplicationLabel( + packageManager.getApplicationInfo(appModel.appPackage, 0) + ).toString() + ) renameLayout.visibility = View.GONE - appTitle.visibility = View.VISIBLE } - appHide.setOnClickListener { appHideListener(appModel, bindingAdapterPosition) } } + appInfo.setOnClickListener { appInfoListener(appModel) } + appDelete.setOnClickListener { appDeleteListener(appModel) } + appMenuClose.setOnClickListener { + appHideLayout.visibility = View.GONE + appTitle.visibility = View.VISIBLE + } + appRenameClose.setOnClickListener { + renameLayout.visibility = View.GONE + appTitle.visibility = View.VISIBLE + } + appHide.setOnClickListener { appHideListener(appModel, bindingAdapterPosition) } + } + private fun getAppName(context: Context, appPackage: String): String { val packageManager = context.packageManager return packageManager.getApplicationLabel( @@ -263,4 +258,5 @@ class AppDrawerAdapter( ).toString() } } + }