diff --git a/app/src/main/java/io/github/zyrouge/symphony/services/radio/RadioQueue.kt b/app/src/main/java/io/github/zyrouge/symphony/services/radio/RadioQueue.kt index 3b08e47e..eb79bdd9 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/services/radio/RadioQueue.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/services/radio/RadioQueue.kt @@ -1,7 +1,7 @@ package io.github.zyrouge.symphony.services.radio import io.github.zyrouge.symphony.Symphony -import io.github.zyrouge.symphony.utils.ConcurrentList +import io.github.zyrouge.symphony.utils.concurrentListOf class RadioQueue(private val symphony: Symphony) { enum class LoopMode { @@ -14,10 +14,8 @@ class RadioQueue(private val symphony: Symphony) { } } - val originalQueue = ConcurrentList() - private set - val currentQueue = ConcurrentList() - private set + val originalQueue = concurrentListOf() + val currentQueue = concurrentListOf() var currentSongIndex = -1 private set(value) { diff --git a/app/src/main/java/io/github/zyrouge/symphony/utils/List.kt b/app/src/main/java/io/github/zyrouge/symphony/utils/List.kt index f085df39..c4c5b6a2 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/utils/List.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/utils/List.kt @@ -1,8 +1,6 @@ package io.github.zyrouge.symphony.utils -import java.util.concurrent.locks.ReentrantReadWriteLock -import kotlin.concurrent.read -import kotlin.concurrent.write +import java.util.concurrent.CopyOnWriteArrayList import kotlin.math.max import kotlin.math.min import kotlin.random.Random @@ -27,38 +25,4 @@ fun List.mutate(fn: MutableList.() -> Unit): List { return out } -class ConcurrentList : MutableList { - private val list = mutableListOf() - private val lock = ReentrantReadWriteLock() - - override val size: Int get() = lock.read { list.size } - - override operator fun set(index: Int, element: T) = lock.write { list.set(index, element) } - override operator fun get(index: Int) = lock.read { list[index] } - - override fun contains(element: T) = lock.read { list.contains(element) } - override fun containsAll(elements: Collection) = lock.read { list.containsAll(elements) } - override fun indexOf(element: T) = lock.read { list.indexOf(element) } - override fun lastIndexOf(element: T) = lock.read { list.lastIndexOf(element) } - override fun isEmpty() = lock.read { list.isEmpty() } - override fun subList(fromIndex: Int, toIndex: Int) = - lock.read { list.subList(fromIndex, toIndex) } - - override fun add(element: T) = lock.write { list.add(element) } - override fun add(index: Int, element: T) = lock.write { list.add(index, element) } - override fun addAll(elements: Collection) = lock.write { list.addAll(elements) } - override fun addAll(index: Int, elements: Collection) = - lock.write { list.addAll(index, elements) } - - override fun clear() = lock.write { list.clear() } - override fun remove(element: T) = lock.write { list.remove(element) } - override fun removeAll(elements: Collection) = lock.write { list.removeAll(elements) } - override fun removeAt(index: Int) = lock.write { list.removeAt(index) } - override fun retainAll(elements: Collection) = lock.write { list.retainAll(elements) } - - // NOTE: `write` lock since it returns `MutableIterator`s - override fun iterator() = lock.write { list.iterator() } - override fun listIterator() = lock.write { list.listIterator() } - override fun listIterator(index: Int) = lock.write { list.listIterator(index) } -} - +fun concurrentListOf(): MutableList = CopyOnWriteArrayList(mutableListOf())