mirror of
https://github.com/jrpie/Launcher.git
synced 2025-05-10 12:34:17 +02:00
This commit is contained in:
parent
08ec3988fd
commit
24e90deb62
5 changed files with 25 additions and 21 deletions
|
@ -22,8 +22,6 @@ import de.jrpie.android.launcher.apps.isPrivateSpaceLocked
|
|||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||
import de.jrpie.android.launcher.preferences.migratePreferencesToNewVersion
|
||||
import de.jrpie.android.launcher.preferences.resetPreferences
|
||||
import de.jrpie.android.launcher.widgets.LauncherWidgetProvider
|
||||
import de.jrpie.android.launcher.widgets.Widget
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -34,7 +32,6 @@ const val APP_WIDGET_HOST_ID = 42;
|
|||
|
||||
class Application : android.app.Application() {
|
||||
val apps = MutableLiveData<List<AbstractDetailedAppInfo>>()
|
||||
val widgets = MutableLiveData<Set<Widget>>()
|
||||
val privateSpaceLocked = MutableLiveData<Boolean>()
|
||||
lateinit var appWidgetHost: AppWidgetHost
|
||||
lateinit var appWidgetManager: AppWidgetManager
|
||||
|
@ -101,8 +98,6 @@ class Application : android.app.Application() {
|
|||
customAppNames = LauncherPreferences.apps().customNames()
|
||||
} else if (pref == LauncherPreferences.apps().keys().pinnedShortcuts()) {
|
||||
loadApps()
|
||||
} else if (pref == LauncherPreferences.widgets().keys().widgets()) {
|
||||
widgets.postValue(LauncherPreferences.widgets().widgets() ?: setOf())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ class ManageWidgetPanelsActivity : AppCompatActivity(), UIObject {
|
|||
})
|
||||
}
|
||||
binding.manageWidgetPanelsRecycler.apply {
|
||||
// improve performance (since content changes don't change the layout size)
|
||||
setHasFixedSize(true)
|
||||
layoutManager = viewManager
|
||||
adapter = viewAdapter
|
||||
|
|
|
@ -34,10 +34,11 @@ class ManageWidgetsActivity : Activity(), UIObject {
|
|||
|
||||
var panelId: Int = WidgetPanel.HOME.id
|
||||
|
||||
|
||||
// We can't observe the livedata because this is not an AppCompatActivity
|
||||
private var sharedPreferencesListener =
|
||||
SharedPreferences.OnSharedPreferenceChangeListener { _, prefKey ->
|
||||
if (prefKey == LauncherPreferences.widgets().keys().widgets()) {
|
||||
// We can't observe the livedata because this is not an AppCompatActivity
|
||||
findViewById<WidgetContainerView>(R.id.manage_widgets_container).updateWidgets(this,
|
||||
LauncherPreferences.widgets().widgets()
|
||||
)
|
||||
|
@ -63,7 +64,7 @@ class ManageWidgetsActivity : Activity(), UIObject {
|
|||
|
||||
findViewById<WidgetContainerView>(R.id.manage_widgets_container).let {
|
||||
it.widgetPanelId = panelId
|
||||
it.updateWidgets(this, (application as Application).widgets.value)
|
||||
it.updateWidgets(this, LauncherPreferences.widgets().widgets())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import androidx.core.graphics.minus
|
|||
import androidx.core.graphics.toRect
|
||||
import androidx.core.view.children
|
||||
import de.jrpie.android.launcher.ui.widgets.WidgetContainerView
|
||||
import de.jrpie.android.launcher.widgets.GRID_SIZE
|
||||
import de.jrpie.android.launcher.widgets.Widget
|
||||
import de.jrpie.android.launcher.widgets.WidgetPanel
|
||||
import de.jrpie.android.launcher.widgets.WidgetPosition
|
||||
|
@ -47,21 +48,27 @@ class WidgetManagerView(widgetPanelId: Int, context: Context, attrs: AttributeSe
|
|||
|
||||
|
||||
|
||||
enum class EditMode(val resize: (dx: Int, dy: Int, rect: Rect) -> Rect) {
|
||||
MOVE({ dx, dy, rect ->
|
||||
Rect(rect.left + dx, rect.top + dy, rect.right + dx, rect.bottom + dy)
|
||||
enum class EditMode(val resize: (dx: Int, dy: Int, screenWidth: Int, screenHeight: Int, rect: Rect) -> Rect) {
|
||||
MOVE({ dx, dy, sw, sh, rect ->
|
||||
val cdx = dx.coerceIn(-rect.left, sw - rect.right)
|
||||
val cdy = dy.coerceIn(-rect.top, sh - rect.bottom)
|
||||
Rect(rect.left + cdx, rect.top + cdy, rect.right + cdx, rect.bottom + cdy)
|
||||
}),
|
||||
TOP({ dx, dy, rect ->
|
||||
Rect(rect.left, min(rect.top + dy, rect.bottom - 200), rect.right, rect.bottom)
|
||||
TOP({ dx, dy, sw, sh, rect ->
|
||||
val cdy = dy.coerceIn(-rect.top, rect.bottom - rect.top - (2 * sh / GRID_SIZE) + 5)
|
||||
Rect(rect.left, rect.top + cdy, rect.right, rect.bottom)
|
||||
}),
|
||||
BOTTOM({ dx, dy, rect ->
|
||||
Rect(rect.left, rect.top, rect.right, max(rect.top + 200, rect.bottom + dy))
|
||||
BOTTOM({ dx, dy, sw, sh, rect ->
|
||||
val cdy = dy.coerceIn((2 * sh / GRID_SIZE) + 5 + rect.top - rect.bottom, sh - rect.bottom)
|
||||
Rect(rect.left, rect.top, rect.right, rect.bottom + cdy)
|
||||
}),
|
||||
LEFT({ dx, dy, rect ->
|
||||
Rect(min(rect.left + dx, rect.right - 200), rect.top, rect.right, rect.bottom)
|
||||
LEFT({ dx, dy, sw, sh, rect ->
|
||||
val cdx = dx.coerceIn(-rect.left, rect.right - rect.left - (2 * sw / GRID_SIZE) + 5)
|
||||
Rect(rect.left + cdx, rect.top, rect.right, rect.bottom)
|
||||
}),
|
||||
RIGHT({ dx, dy, rect ->
|
||||
Rect(rect.left, rect.top, max(rect.left + 200, rect.right + dx), rect.bottom)
|
||||
RIGHT({ dx, dy, sw, sh, rect ->
|
||||
val cdx = dx.coerceIn((2 * sw / GRID_SIZE) + 5 + rect.left - rect.right, sw - rect.right)
|
||||
Rect(rect.left, rect.top, rect.right + cdx, rect.bottom)
|
||||
}),
|
||||
}
|
||||
|
||||
|
@ -120,6 +127,7 @@ class WidgetManagerView(widgetPanelId: Int, context: Context, attrs: AttributeSe
|
|||
val absoluteNewPosition = view.mode?.resize(
|
||||
distanceX.toInt(),
|
||||
distanceY.toInt(),
|
||||
width, height,
|
||||
start
|
||||
) ?: return true
|
||||
val newPosition = WidgetPosition.fromAbsoluteRect(
|
||||
|
@ -162,7 +170,7 @@ class WidgetManagerView(widgetPanelId: Int, context: Context, attrs: AttributeSe
|
|||
if (widgets == null) {
|
||||
return
|
||||
}
|
||||
children.mapNotNull { it as? WidgetOverlayView }.forEach { removeView(it) }
|
||||
children.filter { it is WidgetOverlayView }.forEach { removeView(it) }
|
||||
|
||||
widgets.filter { it.panelId == widgetPanelId }.forEach { widget ->
|
||||
WidgetOverlayView(activity).let {
|
||||
|
|
|
@ -57,7 +57,8 @@ sealed class Widget {
|
|||
return Json.decodeFromString(serialized)
|
||||
}
|
||||
fun byId(context: Context, id: Int): Widget? {
|
||||
return (context.applicationContext as Application).widgets.value?.firstOrNull {
|
||||
// TODO: do some caching
|
||||
return LauncherPreferences.widgets().widgets().firstOrNull() {
|
||||
it.id == id
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue