v1.3: smooth 30fps rotation (6° steps), guaranteed minimum one full spin per tap
This commit is contained in:
@@ -11,8 +11,8 @@ android {
|
|||||||
applicationId = "me.khodak.claudeusage"
|
applicationId = "me.khodak.claudeusage"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 3
|
versionCode = 4
|
||||||
versionName = "1.2"
|
versionName = "1.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import androidx.work.*
|
import androidx.work.*
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import me.khodak.claudeusage.data.PreferencesManager
|
import me.khodak.claudeusage.data.PreferencesManager
|
||||||
|
|
||||||
class UsageUpdateWorker(
|
class UsageUpdateWorker(
|
||||||
@@ -31,6 +33,7 @@ class UsageUpdateWorker(
|
|||||||
prefs.saveUsageData(data)
|
prefs.saveUsageData(data)
|
||||||
} catch (_: Exception) {}
|
} catch (_: Exception) {}
|
||||||
animJob.cancel()
|
animJob.cancel()
|
||||||
|
animJob.join() // wait for the minimum-rotation finally block to finish
|
||||||
}
|
}
|
||||||
|
|
||||||
pushWidgetUpdate()
|
pushWidgetUpdate()
|
||||||
@@ -40,10 +43,25 @@ class UsageUpdateWorker(
|
|||||||
private suspend fun rotateRefreshIcon() {
|
private suspend fun rotateRefreshIcon() {
|
||||||
val manager = AppWidgetManager.getInstance(context)
|
val manager = AppWidgetManager.getInstance(context)
|
||||||
val ids = manager.getAppWidgetIds(ComponentName(context, ClaudeUsageWidget::class.java))
|
val ids = manager.getAppWidgetIds(ComponentName(context, ClaudeUsageWidget::class.java))
|
||||||
while (true) {
|
var totalDegrees = 0f
|
||||||
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 30f) % 360f
|
|
||||||
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
try {
|
||||||
delay(83) // ~12 fps — one full rotation per second
|
while (true) {
|
||||||
|
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 6f) % 360f
|
||||||
|
totalDegrees += 6f
|
||||||
|
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
||||||
|
delay(33) // 30 fps, one full rotation per second
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// Even if the fetch finishes early, complete at least one full 360°
|
||||||
|
withContext(NonCancellable) {
|
||||||
|
while (totalDegrees < 360f) {
|
||||||
|
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 6f) % 360f
|
||||||
|
totalDegrees += 6f
|
||||||
|
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
||||||
|
delay(33)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user