mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Search functions. Hiding broken.
This commit is contained in:
parent
8963b97149
commit
f5a75f4263
4 changed files with 157 additions and 118 deletions
|
|
@ -35,7 +35,7 @@ class AppActionMenu {
|
||||||
userHandle: UserHandle,
|
userHandle: UserHandle,
|
||||||
workProfile: Int,
|
workProfile: Int,
|
||||||
launcherApps: LauncherApps,
|
launcherApps: LauncherApps,
|
||||||
mainActivity: LauncherActivityInfo?
|
mainActivity: LauncherActivityInfo?,
|
||||||
){
|
){
|
||||||
|
|
||||||
actionMenu.findViewById<TextView>(R.id.info).setOnClickListener {
|
actionMenu.findViewById<TextView>(R.id.info).setOnClickListener {
|
||||||
|
|
@ -104,8 +104,7 @@ class AppActionMenu {
|
||||||
|
|
||||||
actionMenu.findViewById<TextView>(R.id.hide).setOnClickListener {
|
actionMenu.findViewById<TextView>(R.id.hide).setOnClickListener {
|
||||||
sharedPreferenceManager.setAppHidden(activity, appInfo.packageName, workProfile, true)
|
sharedPreferenceManager.setAppHidden(activity, appInfo.packageName, workProfile, true)
|
||||||
actionMenu.visibility = View.INVISIBLE
|
|
||||||
textView.visibility = View.INVISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actionMenu.findViewById<TextView>(R.id.close).setOnClickListener {
|
actionMenu.findViewById<TextView>(R.id.close).setOnClickListener {
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,10 @@ import eu.ottop.yamlauncher.databinding.ActivityAppMenuBinding
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -34,11 +36,14 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
private lateinit var recyclerView: RecyclerView
|
private lateinit var recyclerView: RecyclerView
|
||||||
private lateinit var searchView: EditText
|
private lateinit var searchView: EditText
|
||||||
private lateinit var adapter: AppMenuAdapter
|
private lateinit var adapter: AppMenuAdapter
|
||||||
private lateinit var shownApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
|
private lateinit var filteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
|
||||||
|
private lateinit var installedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
|
||||||
private lateinit var job: Job
|
private lateinit var job: Job
|
||||||
private var appActionMenu = AppActionMenu()
|
private var appActionMenu = AppActionMenu()
|
||||||
private lateinit var launcherApps: LauncherApps
|
private lateinit var launcherApps: LauncherApps
|
||||||
|
|
||||||
|
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityAppMenuBinding.inflate(layoutInflater)
|
binding = ActivityAppMenuBinding.inflate(layoutInflater)
|
||||||
|
|
@ -49,15 +54,12 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
|
|
||||||
recyclerView = findViewById(R.id.recycler_view)
|
recyclerView = findViewById(R.id.recycler_view)
|
||||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
shownApps = getInstalledApps()
|
installedApps = getInstalledApps()
|
||||||
adapter = AppMenuAdapter(shownApps, this, this)
|
filteredApps = mutableListOf()
|
||||||
|
adapter = AppMenuAdapter(installedApps, this, this)
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
|
|
||||||
binding.root.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
setupSearch()
|
||||||
if (bottom - top > oldBottom - oldTop) {
|
|
||||||
searchView.clearFocus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
||||||
|
|
@ -79,24 +81,6 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
editView: LinearLayout
|
editView: LinearLayout
|
||||||
) {
|
) {
|
||||||
// Handle the long click action here, for example, show additional options or information about the app
|
// Handle the long click action here, for example, show additional options or information about the app
|
||||||
editView.findViewById<EditText>(R.id.app_name_edit).addTextChangedListener(object :
|
|
||||||
TextWatcher {
|
|
||||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
|
||||||
// This method is called before the text is changed
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
|
||||||
// This method is called when the text is changed
|
|
||||||
// You can perform actions here based on the text changes
|
|
||||||
// For example, check if text is inserted or removed
|
|
||||||
filterItems(editView.findViewById<EditText>(R.id.app_name_edit).text.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable?) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
textView.visibility = View.INVISIBLE
|
textView.visibility = View.INVISIBLE
|
||||||
actionMenuLayout.visibility = View.VISIBLE
|
actionMenuLayout.visibility = View.VISIBLE
|
||||||
val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull()
|
val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull()
|
||||||
|
|
@ -104,38 +88,59 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupSearch() {
|
||||||
|
binding.root.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||||
|
if (bottom - top > oldBottom - oldTop) {
|
||||||
|
searchView.clearFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
searchView.addTextChangedListener(object :
|
||||||
|
TextWatcher {
|
||||||
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||||
|
filterItems(searchView.text.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun afterTextChanged(s: Editable?) {
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private fun filterItems(query: String?) {
|
private fun filterItems(query: String?) {
|
||||||
val cleanQuery = query?.replace("[^a-zA-Z0-9]".toRegex(), "")
|
val cleanQuery = query?.replace("[^a-zA-Z0-9]".toRegex(), "")
|
||||||
|
filteredApps.clear()
|
||||||
|
|
||||||
for (i in 0 until binding.recyclerView.childCount) {
|
if (cleanQuery.isNullOrEmpty()) {
|
||||||
val view = binding.recyclerView.getChildAt(i)
|
filteredApps.addAll(installedApps)
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
if (view is FrameLayout) {
|
installedApps.forEach {
|
||||||
for (i in 0 until view.childCount) {
|
val cleanItemText = it.first.applicationInfo.loadLabel(packageManager).replace("[^a-zA-Z0-9]".toRegex(), "")
|
||||||
val text = view.getChildAt(i)
|
if (cleanItemText.contains(cleanQuery, ignoreCase=true)) {
|
||||||
if (text is TextView) {
|
filteredApps.add(it)
|
||||||
val itemText = text.text.toString()
|
|
||||||
val cleanItemText = itemText.replace("[^a-zA-Z0-9]".toRegex(), "")
|
|
||||||
|
|
||||||
if (cleanItemText.contains(cleanQuery ?: "", ignoreCase = true)) {
|
|
||||||
view.visibility = View.VISIBLE
|
|
||||||
} else {
|
|
||||||
view.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adapter.updateApps(filteredApps)
|
||||||
|
|
||||||
}
|
}
|
||||||
}}
|
|
||||||
|
|
||||||
private fun getInstalledApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
private fun getInstalledApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||||
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
val launcherApps = getSystemService(LAUNCHER_APPS_SERVICE) as LauncherApps
|
val launcherApps = getSystemService(LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||||
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(this@AppMenuActivity, app.applicationInfo.packageName, i)) {
|
||||||
allApps.add(Pair(app, Pair(launcherApps.profiles[i], i)))
|
allApps.add(Pair(app, Pair(launcherApps.profiles[i], i)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return allApps.sortedBy {
|
return allApps.sortedBy {
|
||||||
it.first.applicationInfo.loadLabel(packageManager).toString().lowercase()
|
it.first.applicationInfo.loadLabel(packageManager).toString().lowercase()
|
||||||
}
|
}
|
||||||
|
|
@ -155,10 +160,10 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
private fun startTask() {
|
private fun startTask() {
|
||||||
job = CoroutineScope(Dispatchers.IO).launch {
|
job = CoroutineScope(Dispatchers.IO).launch {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!listsEqual(shownApps, getInstalledApps())) {
|
if (!listsEqual(installedApps, getInstalledApps())) {
|
||||||
shownApps = getInstalledApps()
|
installedApps = getInstalledApps()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
adapter.updateApps(shownApps)
|
adapter.updateApps(installedApps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(5000)
|
delay(5000)
|
||||||
|
|
@ -166,6 +171,15 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun manualRefreshApps() {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
installedApps = getInstalledApps()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
adapter.updateApps(installedApps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun listsEqual(
|
private fun listsEqual(
|
||||||
list1: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
list1: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||||
list2: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
|
list2: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
|
||||||
|
|
@ -183,75 +197,7 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppMenuAdapter(private var apps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, private val itemClickListener: OnItemClickListener, private val itemLongClickListener: OnItemLongClickListener) :
|
|
||||||
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
|
||||||
|
|
||||||
interface OnItemClickListener {
|
|
||||||
fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface OnItemLongClickListener {
|
|
||||||
fun onItemLongClick(
|
|
||||||
appInfo: LauncherActivityInfo,
|
|
||||||
userHandle: UserHandle,
|
|
||||||
userProfile: Int,
|
|
||||||
textView: TextView,
|
|
||||||
actionMenuLayout: LinearLayout,
|
|
||||||
editView: LinearLayout
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|
||||||
private val listItem: FrameLayout = itemView.findViewById(R.id.list_item)
|
|
||||||
val textView: TextView = listItem.findViewById(R.id.app_name)
|
|
||||||
val actionMenuLayout: LinearLayout = listItem.findViewById(R.id.action_menu)
|
|
||||||
val editView: LinearLayout = listItem.findViewById(R.id.rename_view)
|
|
||||||
|
|
||||||
init {
|
|
||||||
itemView.setOnClickListener {
|
|
||||||
val position = bindingAdapterPosition
|
|
||||||
if (position != RecyclerView.NO_POSITION) {
|
|
||||||
val app = apps[position].first
|
|
||||||
itemClickListener.onItemClick(app, apps[position].second.first)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
itemView.setOnLongClickListener {
|
|
||||||
val position = bindingAdapterPosition
|
|
||||||
if (position != RecyclerView.NO_POSITION) {
|
|
||||||
val app = apps[position].first
|
|
||||||
itemLongClickListener.onItemLongClick(app, apps[position].second.first, apps[position].second.second, textView, actionMenuLayout, editView)
|
|
||||||
return@setOnLongClickListener true
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
|
|
||||||
val view = LayoutInflater.from(parent.context)
|
|
||||||
.inflate(R.layout.app_item_layout, parent, false)
|
|
||||||
return AppViewHolder(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
|
||||||
val app = apps[position]
|
|
||||||
val appInfo = app.first.activityInfo.applicationInfo
|
|
||||||
holder.textView.text = appInfo.loadLabel(holder.itemView.context.packageManager)
|
|
||||||
holder.editView.findViewById<EditText>(R.id.app_name_edit).setText(holder.textView.text)
|
|
||||||
holder.actionMenuLayout.viewTreeObserver.addOnGlobalLayoutListener {
|
|
||||||
Log.d("Yooo", position.toString())
|
|
||||||
// Perform any action you want here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
|
||||||
return apps.size
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
|
||||||
apps = newApps
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
private lateinit var binding: ActivityAppMenuBinding
|
private lateinit var binding: ActivityAppMenuBinding
|
||||||
|
|
|
||||||
86
app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt
Normal file
86
app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
package eu.ottop.yamlauncher
|
||||||
|
|
||||||
|
import android.content.pm.LauncherActivityInfo
|
||||||
|
import android.os.UserHandle
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
class AppMenuAdapter(private var apps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, private val itemClickListener: OnItemClickListener, private val itemLongClickListener: OnItemLongClickListener) :
|
||||||
|
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
||||||
|
|
||||||
|
interface OnItemClickListener {
|
||||||
|
fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OnItemLongClickListener {
|
||||||
|
fun onItemLongClick(
|
||||||
|
appInfo: LauncherActivityInfo,
|
||||||
|
userHandle: UserHandle,
|
||||||
|
userProfile: Int,
|
||||||
|
textView: TextView,
|
||||||
|
actionMenuLayout: LinearLayout,
|
||||||
|
editView: LinearLayout
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
|
private val listItem: FrameLayout = itemView.findViewById(R.id.list_item)
|
||||||
|
val textView: TextView = listItem.findViewById(R.id.app_name)
|
||||||
|
val actionMenuLayout: LinearLayout = listItem.findViewById(R.id.action_menu)
|
||||||
|
val editView: LinearLayout = listItem.findViewById(R.id.rename_view)
|
||||||
|
|
||||||
|
init {
|
||||||
|
actionMenuLayout.visibility = View.GONE
|
||||||
|
editView.visibility = View.GONE
|
||||||
|
|
||||||
|
itemView.setOnClickListener {
|
||||||
|
val position = bindingAdapterPosition
|
||||||
|
if (position != RecyclerView.NO_POSITION) {
|
||||||
|
val app = apps[position].first
|
||||||
|
itemClickListener.onItemClick(app, apps[position].second.first)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemView.setOnLongClickListener {
|
||||||
|
val position = bindingAdapterPosition
|
||||||
|
if (position != RecyclerView.NO_POSITION) {
|
||||||
|
val app = apps[position].first
|
||||||
|
itemLongClickListener.onItemLongClick(app, apps[position].second.first, apps[position].second.second, textView, actionMenuLayout, editView)
|
||||||
|
return@setOnLongClickListener true
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
|
||||||
|
val view = LayoutInflater.from(parent.context)
|
||||||
|
.inflate(R.layout.app_item_layout, parent, false)
|
||||||
|
return AppViewHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
||||||
|
val app = apps[position]
|
||||||
|
val appInfo = app.first.activityInfo.applicationInfo
|
||||||
|
holder.textView.text = appInfo.loadLabel(holder.itemView.context.packageManager)
|
||||||
|
holder.editView.findViewById<EditText>(R.id.app_name_edit).setText(holder.textView.text)
|
||||||
|
holder.actionMenuLayout.viewTreeObserver.addOnGlobalLayoutListener {
|
||||||
|
Log.d("Yooo", position.toString())
|
||||||
|
// Perform any action you want here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return apps.size
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
|
apps = newApps
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
8
local.properties
Normal file
8
local.properties
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
## This file must *NOT* be checked into Version Control Systems,
|
||||||
|
# as it contains information specific to your local configuration.
|
||||||
|
#
|
||||||
|
# Location of the SDK. This is only used by Gradle.
|
||||||
|
# For customization when using a Version Control System, please read the
|
||||||
|
# header note.
|
||||||
|
#Sat May 11 12:03:38 EEST 2024
|
||||||
|
sdk.dir=/home/otto/Android/Sdk
|
||||||
Loading…
Add table
Add a link
Reference in a new issue