mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Some refactoring and improved returning to home screen from app menu.
This commit is contained in:
parent
b12d076208
commit
228dd2966b
4 changed files with 51 additions and 73 deletions
|
|
@ -9,7 +9,7 @@ class AppMenuEdgeFactory(private val activity: MainActivity) : RecyclerView.Edge
|
||||||
return AppMenuEdgeEffect(activity)
|
return AppMenuEdgeEffect(activity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class AppMenuEdgeEffect(activity: MainActivity) : EdgeEffect(activity) {
|
class AppMenuEdgeEffect(private val activity: MainActivity) : EdgeEffect(activity) {
|
||||||
// Adjust the speed here
|
// Adjust the speed here
|
||||||
private val animationSpeedFactor = 0.5f
|
private val animationSpeedFactor = 0.5f
|
||||||
|
|
||||||
|
|
@ -19,10 +19,7 @@ class AppMenuEdgeEffect(activity: MainActivity) : EdgeEffect(activity) {
|
||||||
|
|
||||||
override fun onPull(deltaDistance: Float, displacement: Float) {
|
override fun onPull(deltaDistance: Float, displacement: Float) {
|
||||||
super.onPull(deltaDistance * animationSpeedFactor, displacement)
|
super.onPull(deltaDistance * animationSpeedFactor, displacement)
|
||||||
}
|
activity.showHome()
|
||||||
|
|
||||||
override fun onRelease() {
|
|
||||||
super.onRelease()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPullDistance(deltaDistance: Float, displacement: Float): Float {
|
override fun onPullDistance(deltaDistance: Float, displacement: Float): Float {
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package eu.ottop.yamlauncher
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
|
|
||||||
class AppMenuLinearLayoutManager(private val activity: MainActivity) : LinearLayoutManager(activity) {
|
|
||||||
|
|
||||||
private var scrollState = RecyclerView.SCROLL_STATE_IDLE
|
|
||||||
fun setScrollState(state: Int) {
|
|
||||||
scrollState = state
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler?, state: RecyclerView.State?): Int {
|
|
||||||
val scrollRange = super.scrollVerticallyBy(dy, recycler, state)
|
|
||||||
val overscroll: Int = dy - scrollRange
|
|
||||||
if (overscroll < 0 && scrollState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
|
||||||
activity.showHome()
|
|
||||||
}
|
|
||||||
return scrollRange
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -59,7 +59,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
private var appActionMenu = AppActionMenu()
|
private var appActionMenu = AppActionMenu()
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||||
private val appUtils = AppUtils()
|
private val appUtils = AppUtils()
|
||||||
private val appMenuLinearLayoutManager = AppMenuLinearLayoutManager(this@MainActivity)
|
|
||||||
private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity)
|
private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
@ -103,53 +102,52 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
adapter = AppMenuAdapter(this@MainActivity, newApps, this@MainActivity, this@MainActivity, this@MainActivity)
|
adapter = AppMenuAdapter(this@MainActivity, newApps, this@MainActivity, this@MainActivity, this@MainActivity)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
recyclerView = findViewById(R.id.recycler_view)
|
recyclerView = findViewById(R.id.recycler_view)
|
||||||
recyclerView.layoutManager = appMenuLinearLayoutManager
|
|
||||||
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
recyclerView.scrollToPosition(0)
|
recyclerView.scrollToPosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerView.addOnScrollListener(object: OnScrollListener() {
|
|
||||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
|
||||||
super.onScrollStateChanged(recyclerView, newState)
|
|
||||||
appMenuLinearLayoutManager.setScrollState(newState)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
|
||||||
private fun handleListItems() {
|
private fun handleListItems() {
|
||||||
for (i in findViewById<LinearLayout>(R.id.shortcuts).children) {
|
for (i in findViewById<LinearLayout>(R.id.shortcuts).children) {
|
||||||
|
|
||||||
val textView = i as TextView
|
val textView = i as TextView
|
||||||
|
|
||||||
textView.setOnTouchListener() {_, event ->
|
unselectedSetup(textView)
|
||||||
gestureDetector.onTouchEvent(event)
|
|
||||||
super.onTouchEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
val savedView = sharedPreferenceManager.getShortcut(this, textView)
|
val savedView = sharedPreferenceManager.getShortcut(this, textView)
|
||||||
|
|
||||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
|
||||||
|
|
||||||
textView.compoundDrawablePadding = 0
|
|
||||||
unselectedListeners(textView)
|
|
||||||
|
|
||||||
if (savedView?.get(1) != "e") {
|
if (savedView?.get(1) != "e") {
|
||||||
|
selectedSetup(textView, savedView)
|
||||||
if (savedView?.get(1) != "0") {
|
|
||||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
|
||||||
}
|
|
||||||
textView.text = savedView?.get(2)
|
|
||||||
selectedListeners(textView, savedView)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
private fun unselectedSetup(textView: TextView) {
|
||||||
|
textView.setOnTouchListener() {_, event ->
|
||||||
|
gestureDetector.onTouchEvent(event)
|
||||||
|
super.onTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
||||||
|
|
||||||
|
textView.compoundDrawablePadding = 0
|
||||||
|
unselectedListeners(textView)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selectedSetup(textView: TextView, savedView: List<String>?) {
|
||||||
|
if (savedView?.get(1) != "0") {
|
||||||
|
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
||||||
|
}
|
||||||
|
textView.text = savedView?.get(2)
|
||||||
|
selectedListeners(textView, savedView)
|
||||||
|
}
|
||||||
|
|
||||||
private fun unselectedListeners(textView: TextView) {
|
private fun unselectedListeners(textView: TextView) {
|
||||||
textView.setOnClickListener {
|
textView.setOnClickListener {
|
||||||
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
|
||||||
|
|
@ -159,7 +157,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
adapter.shortcutTextView = textView
|
adapter.shortcutTextView = textView
|
||||||
showApps()
|
showApps()
|
||||||
|
|
||||||
|
|
||||||
return@setOnLongClickListener true
|
return@setOnLongClickListener true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -200,7 +197,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable?) {
|
override fun afterTextChanged(s: Editable?) {
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,27 +206,35 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
val updatedApps = appUtils.getInstalledApps(this@MainActivity)
|
val updatedApps = appUtils.getInstalledApps(this@MainActivity)
|
||||||
|
|
||||||
if (cleanQuery.isNullOrEmpty()) {
|
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||||
manualRefresh()
|
|
||||||
newFilteredApps.addAll(installedApps)
|
|
||||||
} else {
|
|
||||||
updatedApps.forEach {
|
|
||||||
val cleanItemText = sharedPreferenceManager.getAppName(this@MainActivity, it.first.applicationInfo.packageName, it.second.second, it.first.applicationInfo.loadLabel(packageManager)).toString().clean()
|
|
||||||
if (cleanItemText.contains(cleanQuery, ignoreCase = true)) {
|
|
||||||
newFilteredApps.add(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val changes = detectChanges(installedApps, newFilteredApps)
|
applySearch(newFilteredApps)
|
||||||
installedApps = newFilteredApps
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
applyChanges(changes, installedApps)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
|
if (cleanQuery.isNullOrEmpty()) {
|
||||||
|
manualRefresh()
|
||||||
|
newFilteredApps.addAll(installedApps)
|
||||||
|
} else {
|
||||||
|
updatedApps.forEach {
|
||||||
|
val cleanItemText = sharedPreferenceManager.getAppName(this@MainActivity, it.first.applicationInfo.packageName, it.second.second, it.first.applicationInfo.loadLabel(packageManager)).toString().clean()
|
||||||
|
if (cleanItemText.contains(cleanQuery, ignoreCase = true)) {
|
||||||
|
newFilteredApps.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun applySearch(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
|
val changes = detectChanges(installedApps, newFilteredApps)
|
||||||
|
installedApps = newFilteredApps
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
applyChanges(changes, installedApps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun String.clean(): String {
|
private fun String.clean(): String {
|
||||||
return this.replace("[^a-zA-Z0-9]".toRegex(), "")
|
return this.replace("[^a-zA-Z0-9]".toRegex(), "")
|
||||||
}
|
}
|
||||||
|
|
@ -594,7 +598,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
}
|
}
|
||||||
|
|
||||||
fun moveItem(position: Int, newPosition: Int) {
|
fun moveItem(position: Int, newPosition: Int) {
|
||||||
Log.d("Movestatus","MOVED")
|
|
||||||
adapter.moveApp(position, newPosition)
|
adapter.moveApp(position, newPosition)
|
||||||
adapter.notifyItemMoved(position, newPosition)
|
adapter.notifyItemMoved(position, newPosition)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@
|
||||||
android:padding="0dp"
|
android:padding="0dp"
|
||||||
android:requiresFadingEdge="vertical"
|
android:requiresFadingEdge="vertical"
|
||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
app:stackFromEnd="true">
|
app:stackFromEnd="true">
|
||||||
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue