Skip to content

Commit 4304106

Browse files
committed
mq: Use epoch millis instead of LocalDateTime
1 parent 16ddc71 commit 4304106

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ android {
9898
// bottom sheet padding, ExoPlayer requiring multidex, vector drawables and poor SD support
9999
// That said, supporting Android 5.0 costs tolerable amounts of tech debt, and we plan to
100100
// keep support for it for a while.
101-
minSdk = 26 // TODO: revert later
101+
minSdk = 21
102102
targetSdk = 35
103103
versionCode = 20
104104
versionName = "1.0.17"

app/src/main/java/org/akanework/gramophone/logic/QueueBoard.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
package org.akanework.gramophone.logic
22

3-
import android.os.Build
43
import android.os.Bundle
54
import android.os.Parcelable
65
import android.util.Log
7-
import androidx.annotation.RequiresApi
86
import androidx.compose.ui.util.fastFirstOrNull
97
import androidx.compose.ui.util.fastSumBy
108
import androidx.media3.common.C
119
import androidx.media3.common.MediaItem
1210
import androidx.media3.common.Player.REPEAT_MODE_OFF
1311
import org.akanework.gramophone.logic.utils.CircularShuffleOrder
14-
import java.time.LocalDateTime
1512
import kotlin.random.Random
1613

14+
private const val QUEUE_EXPIRY_MS = 10 * 36000000 // 10 hrs
1715

1816
/**
1917
* Multiple queues manager.
2018
*
2119
* Queues are ordered most recent modification,
2220
*/
23-
//@RequiresApi(Build.VERSION_CODES.O) // TODO: LocalDateTime methods requires API level 26... but I don't think so...?
2421
class QueueBoard(
2522
private val player: GramophonePlaybackService,
2623
val masterQueues: MutableList<MultiQueueObject> = mutableListOf(),
@@ -99,7 +96,19 @@ class QueueBoard(
9996
}
10097

10198
fun unpinQueue(index: Int) {
102-
masterQueues[index].expiry = LocalDateTime.now()
99+
masterQueues[index].expiry = System.currentTimeMillis() + QUEUE_EXPIRY_MS
100+
}
101+
102+
/**
103+
* Remove expired queues from the QueueBoard
104+
*/
105+
fun trimQB() {
106+
val currentTimeMillis = System.currentTimeMillis()
107+
val newQueueList = masterQueues.filter {
108+
it.expiry == null || it.expiry!! > currentTimeMillis
109+
}
110+
masterQueues.clear()
111+
masterQueues.addAll(newQueueList)
103112
}
104113

105114

@@ -199,7 +208,7 @@ class QueueBoard(
199208
id = Random.nextLong(),
200209
index = -1,
201210
title = title,
202-
expiry = LocalDateTime.now().plusHours(10L),
211+
expiry = System.currentTimeMillis() + QUEUE_EXPIRY_MS,
203212
queue = ArrayList(mediaList),
204213
startIndex = mediaItemIndex,
205214
startPositionMs = C.TIME_UNSET,
@@ -467,7 +476,7 @@ data class MultiQueueObject(
467476
val id: Long, // queue uid
468477
var index: Int, // order of queue
469478
var title: String,
470-
var expiry: LocalDateTime?,
479+
var expiry: Long?,
471480
/**
472481
* The order of songs are dynamic. This should not be accessed from outside QueueBoard.
473482
*/
@@ -557,7 +566,7 @@ data class MultiQueueObject(
557566
id = bundle.getLong("id"),
558567
index = bundle.getInt("index"),
559568
title = bundle.getString("title") ?: "",
560-
expiry = bundle.getString("expiry")?.let { LocalDateTime.parse(it) },
569+
expiry = bundle.getString("expiry")?.toLongOrNull(),
561570
// queue = queue,
562571
queue = (bundle.getParcelableArrayList<Bundle>("queue")
563572
?: emptyList()).map { MediaItem.fromBundle(it) }.toMutableList(),

0 commit comments

Comments
 (0)