mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Some (probably) optimizations and added swiping up from home screen to get to app menu.
This commit is contained in:
parent
02115b1ade
commit
eb61f8a9c8
4 changed files with 80 additions and 28 deletions
|
|
@ -17,6 +17,7 @@ import android.widget.LinearLayout
|
|||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.ottop.yamlauncher.databinding.ActivityAppMenuBinding
|
||||
|
|
@ -80,7 +81,6 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
actionMenuLayout: LinearLayout,
|
||||
editView: LinearLayout
|
||||
) {
|
||||
// Handle the long click action here, for example, show additional options or information about the app
|
||||
textView.visibility = View.INVISIBLE
|
||||
actionMenuLayout.visibility = View.VISIBLE
|
||||
val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull()
|
||||
|
|
@ -102,6 +102,7 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
filterItems(searchView.text.toString())
|
||||
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
|
|
@ -111,24 +112,29 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
}
|
||||
|
||||
private fun filterItems(query: String?) {
|
||||
val cleanQuery = query?.replace("[^a-zA-Z0-9]".toRegex(), "")
|
||||
filteredApps.clear()
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val cleanQuery = query?.clean()
|
||||
filteredApps.clear()
|
||||
|
||||
if (cleanQuery.isNullOrEmpty()) {
|
||||
filteredApps.addAll(installedApps)
|
||||
}
|
||||
|
||||
else {
|
||||
installedApps.forEach {
|
||||
val cleanItemText = it.first.applicationInfo.loadLabel(packageManager).replace("[^a-zA-Z0-9]".toRegex(), "")
|
||||
if (cleanItemText.contains(cleanQuery, ignoreCase=true)) {
|
||||
filteredApps.add(it)
|
||||
if (cleanQuery.isNullOrEmpty()) {
|
||||
filteredApps.addAll(installedApps)
|
||||
} else {
|
||||
installedApps.forEach {
|
||||
val cleanItemText = sharedPreferenceManager.getAppName(this@AppMenuActivity, it.first.applicationInfo.packageName, it.second.second, it.first.applicationInfo.loadLabel(packageManager)).toString().clean()
|
||||
if (cleanItemText.contains(cleanQuery, ignoreCase = true)) {
|
||||
filteredApps.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
adapter.updateApps(filteredApps)
|
||||
}
|
||||
}
|
||||
|
||||
adapter.updateApps(filteredApps)
|
||||
}
|
||||
|
||||
fun String.clean(): String {
|
||||
return this.replace("[^a-zA-Z0-9]".toRegex(), "")
|
||||
}
|
||||
|
||||
private fun getInstalledApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||
|
|
@ -160,10 +166,11 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
}
|
||||
|
||||
private fun startTask() {
|
||||
job = CoroutineScope(Dispatchers.IO).launch {
|
||||
job = CoroutineScope(Dispatchers.Default).launch {
|
||||
while (true) {
|
||||
if (!listsEqual(installedApps, getInstalledApps())) {
|
||||
installedApps = getInstalledApps()
|
||||
val updatedApps = getInstalledApps()
|
||||
if (!listsEqual(installedApps, updatedApps)) {
|
||||
installedApps = updatedApps
|
||||
withContext(Dispatchers.Main) {
|
||||
adapter.updateApps(installedApps)
|
||||
}
|
||||
|
|
@ -174,7 +181,7 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
}
|
||||
|
||||
fun manualRefreshApps() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
installedApps = getInstalledApps()
|
||||
withContext(Dispatchers.Main) {
|
||||
adapter.updateApps(installedApps)
|
||||
|
|
@ -197,4 +204,22 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AppMenuDiffCallback(
|
||||
private val oldList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
private val newList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
|
||||
) : DiffUtil.Callback() {
|
||||
|
||||
override fun getOldListSize(): Int = oldList.size
|
||||
override fun getNewListSize(): Int = newList.size
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return oldList[oldItemPosition].first.componentName == newList[newItemPosition].first.componentName
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
// If the items are the same, no need to update
|
||||
return oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
||||
}
|
||||
|
|
@ -12,9 +12,10 @@ import android.widget.FrameLayout
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class AppMenuAdapter(private val activity: AppMenuActivity, private var apps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, private val itemClickListener: OnItemClickListener, private val itemLongClickListener: OnItemLongClickListener) :
|
||||
class AppMenuAdapter(private val activity: AppMenuActivity, var apps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, private val itemClickListener: OnItemClickListener, private val itemLongClickListener: OnItemLongClickListener) :
|
||||
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
||||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package eu.ottop.yamlauncher
|
|||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.GestureDetector
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
||||
|
|
@ -9,6 +11,7 @@ import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
|||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var gestureDetector: GestureDetector
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -16,9 +19,40 @@ class MainActivity : AppCompatActivity() {
|
|||
setContentView(binding.root)
|
||||
setSupportActionBar(null)
|
||||
|
||||
gestureDetector = GestureDetector(this, GestureListener())
|
||||
|
||||
}
|
||||
|
||||
fun openAppMenuActivity(view: View) {
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
gestureDetector.onTouchEvent(event)
|
||||
return super.onTouchEvent(event)
|
||||
}
|
||||
|
||||
inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||
override fun onFling(
|
||||
e1: MotionEvent?,
|
||||
e2: MotionEvent,
|
||||
velocityX: Float,
|
||||
velocityY: Float
|
||||
): Boolean {
|
||||
// Detect swipe up gesture
|
||||
if (e1 != null) {
|
||||
val deltaY = e2.y - e1.y
|
||||
if (deltaY < -SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
openAppMenuActivity()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
companion object {
|
||||
private const val SWIPE_THRESHOLD = 100
|
||||
private const val SWIPE_VELOCITY_THRESHOLD = 100
|
||||
}
|
||||
|
||||
fun openAppMenuActivity() {
|
||||
startActivity(Intent(this, AppMenuActivity::class.java))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,5 @@
|
|||
android:fontFamily= "@null"
|
||||
android:textAppearance= "@android:style/TextAppearance.DeviceDefault" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:onClick="openAppMenuActivity"
|
||||
android:text="Button"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault" />
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue