mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-02 16:20:57 +02:00
fix(downloads): hide unknown byte totals in notifications
This commit is contained in:
@@ -89,10 +89,14 @@ class DownloadService : Service() {
|
||||
internal const val NATIVE_REPLAYGAIN_JOURNAL_FILE = "native_replaygain_journal.json"
|
||||
internal const val NATIVE_WORKER_CONTRACT_VERSION = NativeDownloadFinalizer.NATIVE_WORKER_CONTRACT_VERSION
|
||||
internal const val NOTIFICATION_PERCENT_TOTAL = 10_000L
|
||||
private const val LEGACY_NOTIFICATION_PERCENT_TOTAL = 100L
|
||||
internal val NATIVE_WORKER_STATE_FILE_LOCK = Any()
|
||||
internal val NATIVE_REPLAYGAIN_JOURNAL_FILE_LOCK = Any()
|
||||
|
||||
private var isRunning = false
|
||||
|
||||
internal fun isPercentOnlyNotificationTotal(total: Long): Boolean =
|
||||
total == NOTIFICATION_PERCENT_TOTAL || total == LEGACY_NOTIFICATION_PERCENT_TOTAL
|
||||
|
||||
fun isServiceRunning(): Boolean = isRunning
|
||||
|
||||
@@ -1818,7 +1822,7 @@ class DownloadService : Service() {
|
||||
|
||||
val visibleProgress = when {
|
||||
total <= 0L -> "indeterminate"
|
||||
total == NOTIFICATION_PERCENT_TOTAL ->
|
||||
isPercentOnlyNotificationTotal(total) ->
|
||||
"percent:${(progress * 100 / total).toInt()}"
|
||||
else -> {
|
||||
// buildNotification renders one decimal place for MB and an
|
||||
@@ -1909,7 +1913,7 @@ class DownloadService : Service() {
|
||||
"Preparing download..."
|
||||
} else if (currentArtistName.isNotEmpty() && queueCount <= 1) {
|
||||
currentArtistName
|
||||
} else if (total == NOTIFICATION_PERCENT_TOTAL) {
|
||||
} else if (isPercentOnlyNotificationTotal(total)) {
|
||||
val progressPercent = (progress * 100 / total).toInt()
|
||||
"$progressPercent%"
|
||||
} else if (total > 0) {
|
||||
|
||||
@@ -6,6 +6,14 @@ import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class NativeWorkerPolicyTest {
|
||||
@Test
|
||||
fun percentOnlyNotificationTotalsDoNotRenderAsBytes() {
|
||||
assertTrue(DownloadService.isPercentOnlyNotificationTotal(10_000L))
|
||||
assertTrue(DownloadService.isPercentOnlyNotificationTotal(100L))
|
||||
assertFalse(DownloadService.isPercentOnlyNotificationTotal(72L * 1024L * 1024L))
|
||||
assertFalse(DownloadService.isPercentOnlyNotificationTotal(0L))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rateLimitRetriesExactlyOnce() {
|
||||
assertTrue(
|
||||
|
||||
@@ -373,8 +373,11 @@ extension _DownloadQueueProgress on DownloadQueueNotifier {
|
||||
notifProgress = 0;
|
||||
notifTotal = 0;
|
||||
} else if (bytesTotal <= 0) {
|
||||
notifProgress = (progressPercent * 100).toInt();
|
||||
notifTotal = 100;
|
||||
notifTotal = PlatformBridge.notificationPercentTotal;
|
||||
notifProgress = (progressPercent * notifTotal)
|
||||
.round()
|
||||
.clamp(0, notifTotal)
|
||||
.toInt();
|
||||
}
|
||||
final serviceStatus = notifTotal <= 0 ? 'preparing' : 'downloading';
|
||||
|
||||
|
||||
@@ -145,6 +145,10 @@ class _BridgeInFlight<T> {
|
||||
}
|
||||
|
||||
class PlatformBridge {
|
||||
/// Sentinel shared with Android's foreground service for progress reports
|
||||
/// that contain a percentage but no byte counts.
|
||||
static const int notificationPercentTotal = 10000;
|
||||
|
||||
static const _channel = MethodChannel('com.zarz.spotiflac/backend');
|
||||
static const _jsonResultFileKey = '__json_file';
|
||||
static const _backgroundJsonDecodeThresholdBytes = 128 * 1024;
|
||||
|
||||
Reference in New Issue
Block a user