Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix widget bitmap leak and sleep timer cleanup

Barnabasd9a13682e13e
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt
index 05c863ee..6d49a397 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt
@@ -156,7 +156,10 @@ class NowPlayingWidget : AppWidgetProvider() {
val options = BitmapFactory.Options().apply { inSampleSize = 2 }
val bitmap = BitmapFactory.decodeFile(file.absolutePath, options)
if (bitmap != null) {
- views.setImageViewBitmap(R.id.widget_cover, roundBitmap(bitmap, 18f, context))
+ val rounded = roundBitmap(bitmap, 18f, context)
+ views.setImageViewBitmap(R.id.widget_cover, rounded)
+ bitmap.recycle()
+ rounded.recycle()
} else {
views.setImageViewResource(R.id.widget_cover, R.mipmap.ic_launcher)
}
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt
index 4db8bf0f..0c9a7c1f 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt
@@ -142,7 +142,10 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {
val options = BitmapFactory.Options().apply { inSampleSize = 2 }
val bitmap = BitmapFactory.decodeFile(file.absolutePath, options)
if (bitmap != null) {
- views.setImageViewBitmap(R.id.widget_cover, roundBitmap(bitmap, 24f, context))
+ val rounded = roundBitmap(bitmap, 24f, context)
+ views.setImageViewBitmap(R.id.widget_cover, rounded)
+ bitmap.recycle()
+ rounded.recycle()
} else {
views.setImageViewResource(R.id.widget_cover, R.mipmap.ic_launcher)
}
diff --git a/lib/services/sleep_timer_service.dart b/lib/services/sleep_timer_service.dart
index 4d28e097..83a68f58 100644
--- a/lib/services/sleep_timer_service.dart
+++ b/lib/services/sleep_timer_service.dart
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:math';
import 'package:flutter/foundation.dart';
-import 'package:flutter/services.dart';
import 'package:just_audio/just_audio.dart' as ja;
import 'package:sensors_plus/sensors_plus.dart';
import 'package:vibration/vibration.dart';
@@ -216,10 +215,6 @@ class SleepTimerService extends ChangeNotifier {
// Only count down when playing
if (isPlaying) {
_timeRemaining -= Duration(seconds: _tickIntervalSeconds);
- if (_timeRemaining.inSeconds % 30 == 0) {
-
- }
-
// Switch to fast ticks when approaching fade threshold
if (_tickIntervalSeconds > 1 &&
_timeRemaining <= _fadeThreshold + const Duration(seconds: 5)) {
@@ -378,7 +373,7 @@ class SleepTimerService extends ChangeNotifier {
_timer = null;
_positionSub?.cancel();
_positionSub = null;
- if (_accelSub != null) debugPrint('[Battery] Accelerometer stream STOPPED');
+ if (_accelSub != null) debugPrint('[SleepTimer] Accelerometer stream stopped');
_accelSub?.cancel();
_accelSub = null;
_mode = SleepTimerMode.off;