v1.2: fix rotation — use full updateWidget calls with currentRotation state instead of unreliable partiallyUpdateAppWidget
This commit is contained in:
@@ -6,16 +6,12 @@ import android.appwidget.AppWidgetManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import android.util.SizeF
|
||||
import android.widget.RemoteViews
|
||||
import androidx.work.*
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import me.khodak.claudeusage.data.PreferencesManager
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class UsageUpdateWorker(
|
||||
private val context: Context,
|
||||
@@ -44,30 +40,16 @@ class UsageUpdateWorker(
|
||||
private suspend fun rotateRefreshIcon() {
|
||||
val manager = AppWidgetManager.getInstance(context)
|
||||
val ids = manager.getAppWidgetIds(ComponentName(context, ClaudeUsageWidget::class.java))
|
||||
var angle = 0f
|
||||
while (true) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val small = RemoteViews(context.packageName, R.layout.widget_layout_small)
|
||||
small.setFloat(R.id.btn_refresh, "setRotation", angle)
|
||||
val large = RemoteViews(context.packageName, R.layout.widget_layout)
|
||||
large.setFloat(R.id.btn_refresh, "setRotation", angle)
|
||||
val rv = RemoteViews(mapOf(
|
||||
SizeF(50f, 50f) to small,
|
||||
SizeF(50f, 120f) to large
|
||||
))
|
||||
ids.forEach { id -> manager.partiallyUpdateAppWidget(id, rv) }
|
||||
} else {
|
||||
val rv = RemoteViews(context.packageName, R.layout.widget_layout)
|
||||
rv.setFloat(R.id.btn_refresh, "setRotation", angle)
|
||||
ids.forEach { id -> manager.partiallyUpdateAppWidget(id, rv) }
|
||||
}
|
||||
angle = (angle + 30f) % 360f
|
||||
delay(83) // ~12 fps, one full rotation per second
|
||||
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 30f) % 360f
|
||||
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
||||
delay(83) // ~12 fps — one full rotation per second
|
||||
}
|
||||
}
|
||||
|
||||
private fun pushWidgetUpdate() {
|
||||
ClaudeUsageWidget.isRefreshing = false
|
||||
ClaudeUsageWidget.currentRotation = 0f
|
||||
val manager = AppWidgetManager.getInstance(context)
|
||||
val ids = manager.getAppWidgetIds(ComponentName(context, ClaudeUsageWidget::class.java))
|
||||
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
||||
@@ -88,7 +70,8 @@ class UsageUpdateWorker(
|
||||
}
|
||||
|
||||
fun cancelPeriodicRefresh(context: Context) =
|
||||
(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) .cancel(alarmIntent(context))
|
||||
(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager)
|
||||
.cancel(alarmIntent(context))
|
||||
|
||||
fun triggerImmediateRefresh(context: Context) {
|
||||
WorkManager.getInstance(context).enqueueUniqueWork(
|
||||
|
||||
Reference in New Issue
Block a user