remove unused imports/functions/variables, improve naming convention, remove unused widget context

This commit is contained in:
Luke Wass 2025-05-29 00:18:21 -05:00
parent 956ad9795c
commit ced2e30531
14 changed files with 17 additions and 37 deletions

View file

@ -28,7 +28,7 @@ import kotlinx.coroutines.launch
import kotlin.system.exitProcess import kotlin.system.exitProcess
const val APP_WIDGET_HOST_ID = 42; const val APP_WIDGET_HOST_ID = 42
class Application : android.app.Application() { class Application : android.app.Application() {

View file

@ -1,7 +1,6 @@
package de.jrpie.android.launcher.actions package de.jrpie.android.launcher.actions
import android.content.Context import android.content.Context
import android.hardware.camera2.CameraAccessException
import android.hardware.camera2.CameraCharacteristics import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CameraManager import android.hardware.camera2.CameraManager
import android.os.Build import android.os.Build

View file

@ -6,7 +6,6 @@ import android.widget.Button
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import de.jrpie.android.launcher.BuildConfig import de.jrpie.android.launcher.BuildConfig
import de.jrpie.android.launcher.R import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.actions.lock.LauncherAccessibilityService
import de.jrpie.android.launcher.preferences.LauncherPreferences import de.jrpie.android.launcher.preferences.LauncherPreferences

View file

@ -1,9 +1,7 @@
package de.jrpie.android.launcher.preferences.legacy package de.jrpie.android.launcher.preferences.legacy
import android.content.Context import android.content.Context
import de.jrpie.android.launcher.Application
import de.jrpie.android.launcher.preferences.LauncherPreferences import de.jrpie.android.launcher.preferences.LauncherPreferences
import de.jrpie.android.launcher.preferences.PREFERENCE_VERSION
import de.jrpie.android.launcher.widgets.ClockWidget import de.jrpie.android.launcher.widgets.ClockWidget
import de.jrpie.android.launcher.widgets.WidgetPanel import de.jrpie.android.launcher.widgets.WidgetPanel
import de.jrpie.android.launcher.widgets.WidgetPosition import de.jrpie.android.launcher.widgets.WidgetPosition

View file

@ -1,7 +1,6 @@
package de.jrpie.android.launcher.ui package de.jrpie.android.launcher.ui
import android.app.AlertDialog import android.app.AlertDialog
import android.app.Service
import android.content.Context import android.content.Context
import android.content.pm.LauncherApps import android.content.pm.LauncherApps
import android.content.pm.LauncherApps.PinItemRequest import android.content.pm.LauncherApps.PinItemRequest
@ -45,7 +44,7 @@ class PinShortcutActivity : AppCompatActivity(), UIObject {
binding = ActivityPinShortcutBinding.inflate(layoutInflater) binding = ActivityPinShortcutBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
val launcherApps = getSystemService(Service.LAUNCHER_APPS_SERVICE) as LauncherApps val launcherApps = getSystemService(LAUNCHER_APPS_SERVICE) as LauncherApps
val request = launcherApps.getPinItemRequest(intent) val request = launcherApps.getPinItemRequest(intent)
this.request = request this.request = request

View file

@ -237,9 +237,4 @@ class AppsRecyclerAdapter(
appFilter.favoritesVisibility = v appFilter.favoritesVisibility = v
updateAppsList() updateAppsList()
} }
fun setHiddenAppsVisibility(v: AppFilter.Companion.AppSetVisibility) {
appFilter.hiddenVisibility = v
updateAppsList()
}
} }

View file

@ -96,7 +96,6 @@ class ListFragmentApps : Fragment(), UIObject {
if (LauncherPreferences.functionality().searchAutoCloseKeyboard()) { if (LauncherPreferences.functionality().searchAutoCloseKeyboard()) {
addOnScrollListener(object : RecyclerView.OnScrollListener() { addOnScrollListener(object : RecyclerView.OnScrollListener() {
var totalDy: Int = 0 var totalDy: Int = 0
var threshold = (resources.displayMetrics.density * 100).toInt()
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
totalDy += dy totalDy += dy

View file

@ -5,7 +5,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import de.jrpie.android.launcher.BuildConfig.VERSION_CODE
import de.jrpie.android.launcher.databinding.Tutorial5FinishBinding import de.jrpie.android.launcher.databinding.Tutorial5FinishBinding
import de.jrpie.android.launcher.preferences.LauncherPreferences import de.jrpie.android.launcher.preferences.LauncherPreferences
import de.jrpie.android.launcher.requestNotificationPermission import de.jrpie.android.launcher.requestNotificationPermission

View file

@ -61,7 +61,7 @@ open class WidgetContainerView(
it.value.y + it.value.height it.value.y + it.value.height
).contains(position) == true ).contains(position) == true
}.any { }.any {
Widget.byId(context, it.key)?.allowInteraction == false Widget.byId(it.key)?.allowInteraction == false
} }
} }
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {

View file

@ -9,7 +9,6 @@ import android.widget.EditText
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import de.jrpie.android.launcher.Application
import de.jrpie.android.launcher.R import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.databinding.ActivityManageWidgetPanelsBinding import de.jrpie.android.launcher.databinding.ActivityManageWidgetPanelsBinding
import de.jrpie.android.launcher.preferences.LauncherPreferences import de.jrpie.android.launcher.preferences.LauncherPreferences

View file

@ -5,7 +5,6 @@ import android.appwidget.AppWidgetManager
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Rect
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.ViewGroup import android.view.ViewGroup
@ -21,7 +20,6 @@ import de.jrpie.android.launcher.widgets.GRID_SIZE
import de.jrpie.android.launcher.widgets.WidgetPanel import de.jrpie.android.launcher.widgets.WidgetPanel
import de.jrpie.android.launcher.widgets.WidgetPosition import de.jrpie.android.launcher.widgets.WidgetPosition
import kotlin.math.max import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -132,7 +130,6 @@ class ManageWidgetsActivity : UIObject, Activity() {
private fun selectWidget() { private fun selectWidget() {
val appWidgetHost = (application as Application).appWidgetHost
startActivityForResult( startActivityForResult(
Intent(this, SelectWidgetActivity::class.java).also { Intent(this, SelectWidgetActivity::class.java).also {
it.putExtra( it.putExtra(

View file

@ -31,19 +31,19 @@ class WidgetManagerView(widgetPanelId: Int, context: Context, attrs: AttributeSe
WidgetContainerView(widgetPanelId, context, attrs) { WidgetContainerView(widgetPanelId, context, attrs) {
constructor(context: Context, attrs: AttributeSet?) : this(WidgetPanel.HOME.id, context, attrs) constructor(context: Context, attrs: AttributeSet?) : this(WidgetPanel.HOME.id, context, attrs)
val TOUCH_SLOP: Int val touchSlop: Int
val TOUCH_SLOP_SQUARE: Int val touchSlopSquare: Int
val LONG_PRESS_TIMEOUT: Long val longPressTimeout: Long
private var overlayViewById = HashMap<Int, WidgetOverlayView>() private var overlayViewById = HashMap<Int, WidgetOverlayView>()
init { init {
val configuration = ViewConfiguration.get(context) val configuration = ViewConfiguration.get(context)
TOUCH_SLOP = configuration.scaledTouchSlop touchSlop = configuration.scaledTouchSlop
TOUCH_SLOP_SQUARE = TOUCH_SLOP * TOUCH_SLOP touchSlopSquare = touchSlop * touchSlop
LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout().toLong() longPressTimeout = ViewConfiguration.getLongPressTimeout().toLong()
} }
@ -127,14 +127,14 @@ class WidgetManagerView(widgetPanelId: Int, context: Context, attrs: AttributeSe
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
endInteraction() endInteraction()
} }
}, LONG_PRESS_TIMEOUT) }, longPressTimeout)
} }
if (event.actionMasked == MotionEvent.ACTION_MOVE || if (event.actionMasked == MotionEvent.ACTION_MOVE ||
event.actionMasked == MotionEvent.ACTION_UP event.actionMasked == MotionEvent.ACTION_UP
) { ) {
val distanceX = event.x - (currentGestureStart?.x ?: return true) val distanceX = event.x - (currentGestureStart?.x ?: return true)
val distanceY = event.y - (currentGestureStart?.y ?: return true) val distanceY = event.y - (currentGestureStart?.y ?: return true)
if (distanceX * distanceX + distanceY * distanceY > TOUCH_SLOP_SQUARE) { if (distanceX * distanceX + distanceY * distanceY > touchSlopSquare) {
longPressHandler.removeCallbacksAndMessages(null) longPressHandler.removeCallbacksAndMessages(null)
} }
val view = selectedWidgetOverlayView ?: return true val view = selectedWidgetOverlayView ?: return true
@ -162,7 +162,7 @@ class WidgetManagerView(widgetPanelId: Int, context: Context, attrs: AttributeSe
if (event.actionMasked == MotionEvent.ACTION_UP) { if (event.actionMasked == MotionEvent.ACTION_UP) {
longPressHandler.removeCallbacksAndMessages(null) longPressHandler.removeCallbacksAndMessages(null)
val id = selectedWidgetOverlayView?.widgetId ?: return true val id = selectedWidgetOverlayView?.widgetId ?: return true
val widget = Widget.byId(context, id) ?: return true val widget = Widget.byId(id) ?: return true
widget.position = newPosition widget.position = newPosition
endInteraction() endInteraction()
updateWidget(widget) updateWidget(widget)

View file

@ -54,7 +54,7 @@ class WidgetOverlayView : ViewGroup {
var widgetId: Int = -1 var widgetId: Int = -1
set(newId) { set(newId) {
field = newId field = newId
preview = Widget.byId(context, widgetId)?.getPreview(context) preview = Widget.byId(widgetId)?.getPreview(context)
} }
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@ -93,13 +93,13 @@ class WidgetOverlayView : ViewGroup {
} }
fun showPopupMenu() { fun showPopupMenu() {
val widget = Widget.byId(context, widgetId)?: return val widget = Widget.byId(widgetId)?: return
val menu = PopupMenu(context, popupAnchor) val menu = PopupMenu(context, popupAnchor)
menu.menu.let { menu.menu.let {
it.add( it.add(
context.getString(R.string.widget_menu_remove) context.getString(R.string.widget_menu_remove)
).setOnMenuItemClickListener { _ -> ).setOnMenuItemClickListener { _ ->
Widget.byId(context, widgetId)?.delete(context) Widget.byId(widgetId)?.delete(context)
return@setOnMenuItemClickListener true return@setOnMenuItemClickListener true
} }
it.add( it.add(

View file

@ -38,10 +38,6 @@ sealed class Widget {
) )
} }
fun getPanel(): WidgetPanel? {
return WidgetPanel.byId(panelId)
}
override fun hashCode(): Int { override fun hashCode(): Int {
return id return id
} }
@ -57,9 +53,9 @@ sealed class Widget {
fun deserialize(serialized: String): Widget { fun deserialize(serialized: String): Widget {
return Json.decodeFromString(serialized) return Json.decodeFromString(serialized)
} }
fun byId(context: Context, id: Int): Widget? { fun byId(id: Int): Widget? {
// TODO: do some caching // TODO: do some caching
return LauncherPreferences.widgets().widgets().firstOrNull() { return LauncherPreferences.widgets().widgets().firstOrNull {
it.id == id it.id == id
} }
} }