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)
|
||||
}
|
||||
}
|
||||
class AppMenuEdgeEffect(activity: MainActivity) : EdgeEffect(activity) {
|
||||
class AppMenuEdgeEffect(private val activity: MainActivity) : EdgeEffect(activity) {
|
||||
// Adjust the speed here
|
||||
private val animationSpeedFactor = 0.5f
|
||||
|
||||
|
|
@ -19,10 +19,7 @@ class AppMenuEdgeEffect(activity: MainActivity) : EdgeEffect(activity) {
|
|||
|
||||
override fun onPull(deltaDistance: Float, displacement: Float) {
|
||||
super.onPull(deltaDistance * animationSpeedFactor, displacement)
|
||||
}
|
||||
|
||||
override fun onRelease() {
|
||||
super.onRelease()
|
||||
activity.showHome()
|
||||
}
|
||||
|
||||
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 val sharedPreferenceManager = SharedPreferenceManager()
|
||||
private val appUtils = AppUtils()
|
||||
private val appMenuLinearLayoutManager = AppMenuLinearLayoutManager(this@MainActivity)
|
||||
private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -103,40 +102,42 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
adapter = AppMenuAdapter(this@MainActivity, newApps, this@MainActivity, this@MainActivity, this@MainActivity)
|
||||
withContext(Dispatchers.Main) {
|
||||
recyclerView = findViewById(R.id.recycler_view)
|
||||
recyclerView.layoutManager = appMenuLinearLayoutManager
|
||||
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
||||
recyclerView.adapter = adapter
|
||||
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() {
|
||||
for (i in findViewById<LinearLayout>(R.id.shortcuts).children) {
|
||||
|
||||
val textView = i as TextView
|
||||
|
||||
unselectedSetup(textView)
|
||||
|
||||
val savedView = sharedPreferenceManager.getShortcut(this, textView)
|
||||
|
||||
if (savedView?.get(1) != "e") {
|
||||
selectedSetup(textView, savedView)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun unselectedSetup(textView: TextView) {
|
||||
textView.setOnTouchListener() {_, event ->
|
||||
gestureDetector.onTouchEvent(event)
|
||||
super.onTouchEvent(event)
|
||||
}
|
||||
|
||||
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") {
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
@ -147,9 +148,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
selectedListeners(textView, savedView)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun unselectedListeners(textView: TextView) {
|
||||
textView.setOnClickListener {
|
||||
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
|
||||
showApps()
|
||||
|
||||
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
}
|
||||
|
|
@ -200,7 +197,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -210,6 +206,14 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
val updatedApps = appUtils.getInstalledApps(this@MainActivity)
|
||||
|
||||
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||
|
||||
applySearch(newFilteredApps)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -221,7 +225,9 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun applySearch(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
val changes = detectChanges(installedApps, newFilteredApps)
|
||||
installedApps = newFilteredApps
|
||||
withContext(Dispatchers.Main) {
|
||||
|
|
@ -229,8 +235,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun String.clean(): String {
|
||||
return this.replace("[^a-zA-Z0-9]".toRegex(), "")
|
||||
}
|
||||
|
|
@ -594,7 +598,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
|
||||
fun moveItem(position: Int, newPosition: Int) {
|
||||
Log.d("Movestatus","MOVED")
|
||||
adapter.moveApp(position, newPosition)
|
||||
adapter.notifyItemMoved(position, newPosition)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
android:padding="0dp"
|
||||
android:requiresFadingEdge="vertical"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:stackFromEnd="true">
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue