라이브 월페이퍼 명언 Realm 반복 조회 캐싱 및 충전 상태 전달 보완
- nextMediaCallback: 매 미디어 전환 시마다 QuoteItem 전체 조회 및 shuffled()를 수행하던 부분을 cachedQuotes 메모리 캐시로 대체 - drawBitmapFromText() 호출 시 isCharging 플래그 누락 보완
This commit is contained in:
+6
-4
@@ -753,15 +753,17 @@ class MyWallpaperService : WallpaperService() {
|
||||
val mediaDir = File(File(this@MyWallpaperService.getExternalFilesDir(null), "completed_torrents"), "Images")
|
||||
val supportedExtensions = listOf("mp4", "mkv", "avi", "mov","webm", "jpg", "jpeg", "png", "bmp", "webp", "gif")
|
||||
var randomQuote : QuoteItem? = null
|
||||
private var cachedQuotes: List<QuoteItem>? = null
|
||||
private val nextMediaCallback = object : NativeRenderer.NextMediaCallback {
|
||||
override fun onNextMediaRequested() {
|
||||
loadFiles()
|
||||
if (mediaFiles.isEmpty()) return
|
||||
val nextFile = mediaFiles.random()
|
||||
Log.d(TAG, "Callback: Preloading next random media: ${nextFile.absolutePath}")
|
||||
// ⑥ 명언 (DB 랜덤 추출)
|
||||
val realm = WorkersDb.getRealm()
|
||||
val quotes = realm.query<QuoteItem>(QuoteItem::class).find().shuffled()
|
||||
// ⑥ 명언 (DB 랜덤 추출 - 메모리 캐시 활용)
|
||||
val quotes = cachedQuotes ?: WorkersDb.getRealm().query<QuoteItem>(QuoteItem::class).find().also {
|
||||
cachedQuotes = it
|
||||
}
|
||||
randomQuote = if (quotes.isNotEmpty()) quotes.random() else null
|
||||
monoBold = randomFontOrDefault()
|
||||
quote = randomFontOrDefault()
|
||||
@@ -777,7 +779,7 @@ class MyWallpaperService : WallpaperService() {
|
||||
val (batteryLevel, isCharging) = getBatteryStatus()
|
||||
|
||||
if (batteryLevel >= 70 || isCharging) {
|
||||
val bitmap = drawBitmapFromText(weatherSummaryProvider())
|
||||
val bitmap = drawBitmapFromText(weatherSummaryProvider(), isCharging)
|
||||
bitmap?.let { nativeRenderer?.setWeatherBitmap(it) }
|
||||
nativeRenderer?.setImageRenderFrame(80)
|
||||
Log.d(TAG, "Battery Low: Weather updated only on media change.")
|
||||
|
||||
Reference in New Issue
Block a user