mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +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.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import eu.ottop.yamlauncher.databinding.ActivityAppMenuBinding
|
import eu.ottop.yamlauncher.databinding.ActivityAppMenuBinding
|
||||||
|
|
@ -80,7 +81,6 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
actionMenuLayout: LinearLayout,
|
actionMenuLayout: LinearLayout,
|
||||||
editView: LinearLayout
|
editView: LinearLayout
|
||||||
) {
|
) {
|
||||||
// Handle the long click action here, for example, show additional options or information about the app
|
|
||||||
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()
|
||||||
|
|
@ -102,6 +102,7 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
|
|
||||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||||
filterItems(searchView.text.toString())
|
filterItems(searchView.text.toString())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable?) {
|
override fun afterTextChanged(s: Editable?) {
|
||||||
|
|
@ -111,26 +112,31 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterItems(query: String?) {
|
private fun filterItems(query: String?) {
|
||||||
val cleanQuery = query?.replace("[^a-zA-Z0-9]".toRegex(), "")
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
val cleanQuery = query?.clean()
|
||||||
filteredApps.clear()
|
filteredApps.clear()
|
||||||
|
|
||||||
if (cleanQuery.isNullOrEmpty()) {
|
if (cleanQuery.isNullOrEmpty()) {
|
||||||
filteredApps.addAll(installedApps)
|
filteredApps.addAll(installedApps)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
installedApps.forEach {
|
installedApps.forEach {
|
||||||
val cleanItemText = it.first.applicationInfo.loadLabel(packageManager).replace("[^a-zA-Z0-9]".toRegex(), "")
|
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)) {
|
if (cleanItemText.contains(cleanQuery, ignoreCase = true)) {
|
||||||
filteredApps.add(it)
|
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>>> {
|
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
|
||||||
|
|
@ -160,10 +166,11 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startTask() {
|
private fun startTask() {
|
||||||
job = CoroutineScope(Dispatchers.IO).launch {
|
job = CoroutineScope(Dispatchers.Default).launch {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!listsEqual(installedApps, getInstalledApps())) {
|
val updatedApps = getInstalledApps()
|
||||||
installedApps = getInstalledApps()
|
if (!listsEqual(installedApps, updatedApps)) {
|
||||||
|
installedApps = updatedApps
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
adapter.updateApps(installedApps)
|
adapter.updateApps(installedApps)
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +181,7 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
fun manualRefreshApps() {
|
fun manualRefreshApps() {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
installedApps = getInstalledApps()
|
installedApps = getInstalledApps()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
adapter.updateApps(installedApps)
|
adapter.updateApps(installedApps)
|
||||||
|
|
@ -198,3 +205,21 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.widget.AppCompatButton
|
import androidx.appcompat.widget.AppCompatButton
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
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>() {
|
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package eu.ottop.yamlauncher
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.GestureDetector
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
||||||
|
|
@ -9,6 +11,7 @@ import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityMainBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
private lateinit var gestureDetector: GestureDetector
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -16,9 +19,40 @@ class MainActivity : AppCompatActivity() {
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
setSupportActionBar(null)
|
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))
|
startActivity(Intent(this, AppMenuActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,5 @@
|
||||||
android:fontFamily= "@null"
|
android:fontFamily= "@null"
|
||||||
android:textAppearance= "@android:style/TextAppearance.DeviceDefault" />
|
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>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue