feature: submitting search opens first app matching the query

This commit is contained in:
Josia Pietsch 2024-08-28 09:43:05 +02:00
parent 62c6e1fc2f
commit f792271a5a
Signed by: jrpie
GPG key ID: E70B571D66986A2D
3 changed files with 35 additions and 23 deletions

View file

@ -40,9 +40,9 @@ import java.util.*
* @param forGesture - the action which an app is chosen for (when the intention is "pick")
*/
class AppsRecyclerAdapter(val activity: Activity,
val intention: ListActivity.ListActivityIntention
private val intention: ListActivity.ListActivityIntention
= ListActivity.ListActivityIntention.VIEW,
val forGesture: String? = ""):
private val forGesture: String? = ""):
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
private val appsListDisplayed: MutableList<AppInfo>
@ -53,24 +53,9 @@ class AppsRecyclerAdapter(val activity: Activity,
var img: ImageView = itemView.findViewById(R.id.list_apps_row_icon)
override fun onClick(v: View) {
val pos = adapterPosition
val appPackageName = appsListDisplayed[pos].packageName.toString()
val appUser = appsListDisplayed[pos].user
when (intention){
ListActivity.ListActivityIntention.VIEW -> {
val rect = Rect()
img.getGlobalVisibleRect(rect)
launchApp(appPackageName, appUser, activity, rect)
}
ListActivity.ListActivityIntention.PICK -> {
val returnIntent = Intent()
returnIntent.putExtra("value", appPackageName)
appUser?.let{ returnIntent.putExtra("user", it) }
returnIntent.putExtra("forGesture", forGesture)
activity.setResult(REQUEST_CHOOSE_APP, returnIntent)
activity.finish()
}
}
var rect = Rect()
img.getGlobalVisibleRect(rect)
selectItem(adapterPosition, rect)
}
init { itemView.setOnClickListener(this) }
@ -152,6 +137,27 @@ class AppsRecyclerAdapter(val activity: Activity,
appsListDisplayed.addAll(appsList)
}
fun selectItem(pos: Int, rect: Rect = Rect()) {
if(pos >= appsListDisplayed.size) {
return
}
val appPackageName = appsListDisplayed[pos].packageName.toString()
val appUser = appsListDisplayed[pos].user
when (intention){
ListActivity.ListActivityIntention.VIEW -> {
launchApp(appPackageName, appUser, activity, rect)
}
ListActivity.ListActivityIntention.PICK -> {
val returnIntent = Intent()
returnIntent.putExtra("value", appPackageName)
appUser?.let{ returnIntent.putExtra("user", it) }
returnIntent.putExtra("forGesture", forGesture)
activity.setResult(REQUEST_CHOOSE_APP, returnIntent)
activity.finish()
}
}
}
/**
* The function [filter] is used to search elements within this [RecyclerView].
*/

View file

@ -44,7 +44,7 @@ class ListFragmentApps : Fragment(), UIObject {
override fun adjustLayout() {
val appsRViewAdapter = AppsRecyclerAdapter(activity!!, intention, forGesture)
val appsRViewAdapter = AppsRecyclerAdapter(requireActivity(), intention, forGesture)
// set up the list / recycler
binding.listAppsRview.apply {
@ -59,7 +59,8 @@ class ListFragmentApps : Fragment(), UIObject {
override fun onQueryTextSubmit(query: String): Boolean {
appsRViewAdapter.filter(query)
return false
appsRViewAdapter.selectItem(0)
return true
}
override fun onQueryTextChange(newText: String): Boolean {

View file

@ -1,5 +1,10 @@
- Chinese translation (thank you, yzqzss!)
All Apps:
- Removed three dots in app list (use long click instead)
- Pressing enter opens the first app matching the query
- Fixed workaround for bug when opening keyboard in full screen mode
- Removed uninstall option for system apps
- Removed three dots in app list (use long click instead)
Settings:
- Fixed settings for small displays