mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Changed menu updates back to less efficient entire refresh due to bugs. Fixed a bug with menu position after back from search.
This commit is contained in:
parent
703eab30ed
commit
8a10313b9a
4 changed files with 44 additions and 145 deletions
|
|
@ -108,14 +108,7 @@ class AppActionMenu {
|
||||||
editText.text.toString()
|
editText.text.toString()
|
||||||
)
|
)
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
val newPosition = appUtils.getInstalledApps(activity)
|
activity.refreshAppMenu()
|
||||||
.indexOfFirst { it.first.applicationInfo.packageName == appInfo.packageName && it.second.second == workProfile }
|
|
||||||
activity.appUpdate = false
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
activity.updateItem(position, app)
|
|
||||||
activity.moveItem(position, newPosition)
|
|
||||||
}
|
|
||||||
activity.updateInstalledApps()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -135,14 +128,9 @@ class AppActionMenu {
|
||||||
)
|
)
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
val newPosition = appUtils.getInstalledApps(activity)
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
.indexOfFirst { it.first.applicationInfo.packageName == appInfo.packageName && it.second.second == workProfile }
|
activity.refreshAppMenu()
|
||||||
activity.appUpdate = false
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
activity.updateItem(position, app)
|
|
||||||
activity.moveItem(position, newPosition)
|
|
||||||
}
|
}
|
||||||
activity.updateInstalledApps()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,25 +123,8 @@ class AppMenuAdapter(
|
||||||
return apps.size
|
return apps.size
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addApp(position: Int, app: Pair<LauncherActivityInfo, Pair<UserHandle, Int>>) {
|
|
||||||
apps.add(position, app)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeApp(position: Int) {
|
|
||||||
apps.removeAt(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateApp(position: Int, app: Pair<LauncherActivityInfo, Pair<UserHandle, Int>>) {
|
|
||||||
apps[position] = app
|
|
||||||
}
|
|
||||||
|
|
||||||
fun moveApp(position: Int, newPosition: Int) {
|
|
||||||
val app = apps.removeAt(position)
|
|
||||||
apps.add(newPosition, app)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
apps = newApps.toMutableList()
|
apps = newApps.toMutableList()
|
||||||
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ class AppMenuLinearLayoutManager(private val activity: MainActivity) : LinearLay
|
||||||
val scrollRange = super.scrollVerticallyBy(dy, recycler, state)
|
val scrollRange = super.scrollVerticallyBy(dy, recycler, state)
|
||||||
val overscroll: Int = dy - scrollRange
|
val overscroll: Int = dy - scrollRange
|
||||||
|
|
||||||
if (overscroll < 0 && firstVisibleItemPosition == 0 && scrollStarted && activity.appUpdate) {
|
if (overscroll < 0 && firstVisibleItemPosition == 0 && scrollStarted && activity.isJobActive()) {
|
||||||
activity.backToHome()
|
activity.backToHome()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
private val swipeThreshold = 100
|
private val swipeThreshold = 100
|
||||||
private val swipeVelocityThreshold = 100
|
private val swipeVelocityThreshold = 100
|
||||||
|
|
||||||
var appUpdate = true
|
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -144,17 +142,14 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
// Detect swipe up
|
// Detect swipe up
|
||||||
if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
||||||
openAppMenuActivity()
|
openAppMenuActivity()
|
||||||
weatherSystem.getTemp(this@MainActivity)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect swipe down
|
// Detect swipe down
|
||||||
else if (deltaY > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
else if (deltaY > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
||||||
|
|
||||||
val statusBarService = getSystemService(Context.STATUS_BAR_SERVICE)
|
val statusBarService = getSystemService(Context.STATUS_BAR_SERVICE)
|
||||||
val statusBarManager: Class<*> = Class.forName("android.app.StatusBarManager")
|
val statusBarManager: Class<*> = Class.forName("android.app.StatusBarManager")
|
||||||
val expandMethod: Method = statusBarManager.getMethod("expandNotificationsPanel")
|
val expandMethod: Method = statusBarManager.getMethod("expandNotificationsPanel")
|
||||||
expandMethod.invoke(statusBarService)
|
expandMethod.invoke(statusBarService)
|
||||||
weatherSystem.getWeatherForCurrentLocation(this@MainActivity)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect swipe left
|
// Detect swipe left
|
||||||
|
|
@ -296,12 +291,10 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
|
|
||||||
if (searchView.text.isNullOrEmpty()) {
|
if (searchView.text.isNullOrEmpty()) {
|
||||||
startTask()
|
startTask()
|
||||||
appUpdate = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (bottom - top < oldBottom - oldTop) {
|
else if (bottom - top < oldBottom - oldTop) {
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
appUpdate = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,12 +304,13 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
|
||||||
filterItems(searchView.text.toString())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable?) {
|
override fun afterTextChanged(s: Editable?) {
|
||||||
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
filterItems(searchView.text.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -348,10 +342,11 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun applySearch(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
private suspend fun applySearch(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
val changes = detectChanges(installedApps, newFilteredApps)
|
if (!listsEqual(installedApps, newFilteredApps)) {
|
||||||
installedApps = newFilteredApps
|
withContext(Dispatchers.Main) {
|
||||||
withContext(Dispatchers.Main) {
|
updateMenu(newFilteredApps)
|
||||||
applyChanges(changes, installedApps)
|
}
|
||||||
|
installedApps = newFilteredApps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -390,16 +385,19 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
}
|
}
|
||||||
}, 100)
|
}, 100)
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
refreshAppMenu()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
recyclerView.scrollToPosition(0)
|
withContext(Dispatchers.Main) {
|
||||||
|
recyclerView.scrollToPosition(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (_: UninitializedPropertyAccessException) {
|
catch (_: UninitializedPropertyAccessException) {
|
||||||
|
|
||||||
}
|
}
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
}}, 150)
|
||||||
refreshAppMenu()
|
|
||||||
}
|
|
||||||
}, 150)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toAppMenu() {
|
private fun toAppMenu() {
|
||||||
|
|
@ -476,10 +474,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
suspend fun refreshAppMenu() {
|
suspend fun refreshAppMenu() {
|
||||||
try {
|
try {
|
||||||
val updatedApps = appUtils.getInstalledApps(this@MainActivity)
|
val updatedApps = appUtils.getInstalledApps(this@MainActivity)
|
||||||
val changes = detectChanges(installedApps, updatedApps)
|
println("update running")
|
||||||
installedApps = updatedApps
|
if (!listsEqual(installedApps, updatedApps)) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
applyChanges(changes, installedApps)
|
updateMenu(updatedApps)
|
||||||
|
}
|
||||||
|
installedApps = updatedApps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (_: UninitializedPropertyAccessException) {
|
catch (_: UninitializedPropertyAccessException) {
|
||||||
|
|
@ -493,103 +493,31 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
imm.hideSoftInputFromWindow(binding.root.windowToken, 0)
|
imm.hideSoftInputFromWindow(binding.root.windowToken, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun detectChanges(oldList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, newList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>): List<Change> {
|
|
||||||
val changes = mutableListOf<Change>()
|
|
||||||
val removalChanges = mutableListOf<Change>()
|
|
||||||
val oldSet = oldList.map { Pair(it.first.applicationInfo.packageName, it.second.second) }.toSet()
|
|
||||||
val newSet = newList.map { Pair(it.first.applicationInfo.packageName, it.second.second) }.toSet()
|
|
||||||
|
|
||||||
// Detect removals
|
|
||||||
oldList.forEachIndexed { index, oldItem ->
|
|
||||||
if (!newSet.contains(Pair(oldItem.first.applicationInfo.packageName, oldItem.second.second))) {
|
|
||||||
removalChanges.add(Change(ChangeType.REMOVE, index))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect insertions
|
|
||||||
newList.forEachIndexed { index, newItem ->
|
|
||||||
if (!oldSet.contains(Pair(newItem.first.applicationInfo.packageName, newItem.second.second))) {
|
|
||||||
changes.add(Change(ChangeType.INSERT, index))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
oldList.forEachIndexed { index, oldItem ->
|
|
||||||
if (newSet.contains(Pair(oldItem.first.applicationInfo.packageName, oldItem.second.second))) {
|
|
||||||
val newIndex = newList.indexOfFirst { it.first.applicationInfo.packageName == oldItem.first.applicationInfo.packageName && it.second.second == oldItem.second.second }
|
|
||||||
if (oldItem.first.componentName != newList[newIndex].first.componentName) {
|
|
||||||
changes.add(Change(ChangeType.UPDATE, index))
|
|
||||||
}
|
|
||||||
if (index != newIndex) {
|
|
||||||
if (appUpdate) {
|
|
||||||
changes.add(Change(ChangeType.MOVE, index))
|
|
||||||
appUpdate = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
changes.addAll(removalChanges.reversed())
|
|
||||||
|
|
||||||
return changes
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun applyChanges(changes: List<Change>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
private fun updateMenu(updatedApps : List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
changes.forEach { change ->
|
adapter.updateApps(updatedApps)
|
||||||
when (change.type) {
|
println("moved")
|
||||||
ChangeType.INSERT -> {
|
}
|
||||||
insertItem(change.position, updatedApps[change.position])
|
|
||||||
}
|
|
||||||
ChangeType.REMOVE -> {
|
|
||||||
try {
|
|
||||||
removeItem(change.position)
|
|
||||||
}
|
|
||||||
catch (_: IndexOutOfBoundsException) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ChangeType.UPDATE -> {
|
|
||||||
updateItem(change.position, updatedApps[change.position])
|
|
||||||
}
|
|
||||||
|
|
||||||
ChangeType.MOVE -> {
|
private fun listsEqual(list1: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, list2: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>): Boolean {
|
||||||
adapter.updateApps(updatedApps)
|
if (list1.size != list2.size) return false
|
||||||
adapter.notifyDataSetChanged()
|
|
||||||
println("moved")
|
|
||||||
appUpdate = true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (i in list1.indices) {
|
||||||
|
if (list1[i].first.componentName != list2[i].first.componentName || list1[i].second.first != list2[i].second.first) {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun insertItem(position: Int, app: Pair<LauncherActivityInfo, Pair<UserHandle, Int>>) {
|
fun isJobActive(): Boolean {
|
||||||
adapter.addApp(position, app)
|
return if (job != null) {
|
||||||
adapter.notifyItemInserted(position)
|
job!!.isActive
|
||||||
}
|
} else {
|
||||||
private fun removeItem(position: Int) {
|
false
|
||||||
adapter.removeApp(position)
|
}
|
||||||
adapter.notifyItemRemoved(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateItem(position: Int, app: Pair<LauncherActivityInfo, Pair<UserHandle, Int>>) {
|
|
||||||
adapter.updateApp(position, app)
|
|
||||||
adapter.notifyItemChanged(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun moveItem(position: Int, newPosition: Int) {
|
|
||||||
adapter.moveApp(position, newPosition)
|
|
||||||
adapter.notifyItemMoved(position, newPosition)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateInstalledApps() {
|
|
||||||
installedApps = appUtils.getInstalledApps(this@MainActivity)
|
|
||||||
appUpdate = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Change(val type: ChangeType, val position: Int, val newPosition: Int = 0)
|
|
||||||
|
|
||||||
enum class ChangeType {
|
|
||||||
INSERT, REMOVE, UPDATE, MOVE
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue