mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Now passively checks for moved apps (for app name changing between updates, etc)
This commit is contained in:
parent
d0112bbbe4
commit
de79b2752d
10 changed files with 64 additions and 25 deletions
|
|
@ -24,6 +24,7 @@
|
|||
tools:targetApi="34">
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:theme="@style/SettingsTheme"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
|
|
|
|||
|
|
@ -110,10 +110,12 @@ class AppActionMenu {
|
|||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val newPosition = appUtils.getInstalledApps(activity)
|
||||
.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,10 +137,12 @@ class AppActionMenu {
|
|||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val newPosition = appUtils.getInstalledApps(activity)
|
||||
.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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,4 +140,8 @@ class AppMenuAdapter(
|
|||
apps.add(newPosition, app)
|
||||
|
||||
}
|
||||
|
||||
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
apps = newApps.toMutableList()
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@ import android.text.TextWatcher
|
|||
import android.view.GestureDetector
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
|
|
@ -65,6 +64,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
private val swipeThreshold = 100
|
||||
private val swipeVelocityThreshold = 100
|
||||
|
||||
var appUpdate = true
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -120,9 +121,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
startTask()
|
||||
|
||||
// Keyboard is sometimes open when going back to the app, so close it.
|
||||
val imm =
|
||||
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(binding.root.windowToken, 0)
|
||||
closeKeyboard()
|
||||
}
|
||||
|
||||
open inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||
|
|
@ -187,10 +186,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
val newApps = installedApps.toMutableList()
|
||||
|
||||
setupRecyclerView(newApps)
|
||||
|
||||
searchView = findViewById(R.id.searchView)
|
||||
setupSearch()
|
||||
}
|
||||
|
||||
searchView = findViewById(R.id.searchView)
|
||||
setupSearch()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -284,19 +285,20 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
|
||||
private fun setupSearch() {
|
||||
binding.root.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||
|
||||
if (bottom - top > oldBottom - oldTop) {
|
||||
|
||||
searchView.clearFocus()
|
||||
|
||||
if (searchView.text.isNullOrEmpty()) {
|
||||
job?.cancel()
|
||||
startTask()
|
||||
appUpdate = true
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (bottom - top < oldBottom - oldTop) {
|
||||
job?.cancel()
|
||||
appUpdate = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,6 +357,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
|
||||
private fun startTask() {
|
||||
job?.cancel()
|
||||
job = CoroutineScope(Dispatchers.Default).launch {
|
||||
while (true) {
|
||||
refreshAppMenu()
|
||||
|
|
@ -371,6 +374,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
|
||||
fun backToHome() {
|
||||
closeKeyboard()
|
||||
searchView.setText("")
|
||||
animations.showHome(binding)
|
||||
animations.backgroundOut(this@MainActivity, binding)
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
|
|
@ -464,6 +469,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
|
||||
}
|
||||
|
||||
private fun closeKeyboard() {
|
||||
val imm =
|
||||
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
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>()
|
||||
|
|
@ -477,6 +488,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -500,6 +517,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
return changes
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun applyChanges(changes: List<Change>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
changes.forEach { change ->
|
||||
when (change.type) {
|
||||
|
|
@ -516,6 +534,14 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
ChangeType.UPDATE -> {
|
||||
updateItem(change.position, updatedApps[change.position])
|
||||
}
|
||||
|
||||
ChangeType.MOVE -> {
|
||||
adapter.updateApps(updatedApps)
|
||||
adapter.notifyDataSetChanged()
|
||||
println("moved")
|
||||
appUpdate = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -538,10 +564,15 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
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
|
||||
INSERT, REMOVE, UPDATE, MOVE
|
||||
}
|
||||
|
|
@ -12,6 +12,5 @@ class SettingsActivity : AppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
window.statusBarColor = getColor(R.color.settings_bg)
|
||||
}
|
||||
}
|
||||
4
app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt
Normal file
4
app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
class WeatherSystem {
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
android:id="@+id/linearLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/settings_bg"
|
||||
android:orientation="vertical"
|
||||
tools:context=".SettingsActivity">
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Base.Theme.YamLauncher" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
|
||||
<item name="android:windowShowWallpaper">true</item>
|
||||
</style>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
@ -1,10 +1,3 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<style name="Theme.YamLauncher" parent="Base.Theme.YamLauncher">
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -4,9 +4,18 @@
|
|||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
|
||||
<item name="android:windowShowWallpaper">true</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="SettingsTheme" parent="Base.Theme.YamLauncher">
|
||||
<item name="android:windowBackground">@color/settings_bg</item>
|
||||
</style>
|
||||
|
||||
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
|
||||
<item name="android:textSize">25sp</item>
|
||||
<item name="android:editTextColor">#f3f3f3</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue