Skip to content

Commit 674bc17

Browse files
committed
rename ConcurrentHashMap#toList to asList, update playhistory obj
1 parent 26835cc commit 674bc17

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import com.adamratzman.spotify.models.SpotifyAuthenticationException
2626
import com.adamratzman.spotify.models.Token
2727
import com.adamratzman.spotify.models.TokenValidityResponse
2828
import com.adamratzman.spotify.models.serialization.toObject
29+
import com.adamratzman.spotify.utils.asList
2930
import com.adamratzman.spotify.utils.runBlocking
30-
import com.adamratzman.spotify.utils.toList
31+
import kotlinx.coroutines.Dispatchers
3132
import kotlin.coroutines.CoroutineContext
3233
import kotlin.jvm.JvmOverloads
33-
import kotlinx.coroutines.Dispatchers
3434

3535
internal const val base = "https://api.spotify.com/v1"
3636

@@ -98,7 +98,7 @@ sealed class SpotifyApi<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>(
9898
/**
9999
* Obtain a map of all currently-cached requests
100100
*/
101-
fun getCache() = endpoints.map { it.cache.cachedRequests.toList() }.flatten().toMap()
101+
fun getCache() = endpoints.map { it.cache.cachedRequests.asList() }.flatten().toMap()
102102

103103
/**
104104
* If the method used to create the [token] supports token refresh and

src/commonMain/kotlin/com.adamratzman.spotify/models/PagingObjects.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.adamratzman.spotify.http.SpotifyEndpoint
66
import com.adamratzman.spotify.models.serialization.toCursorBasedPagingObject
77
import com.adamratzman.spotify.models.serialization.toPagingObject
88
import com.adamratzman.spotify.utils.runBlocking
9-
import kotlin.reflect.KClass
109
import kotlinx.coroutines.Dispatchers
1110
import kotlinx.coroutines.ExperimentalCoroutinesApi
1211
import kotlinx.coroutines.flow.Flow
@@ -18,6 +17,7 @@ import kotlinx.coroutines.flow.toList
1817
import kotlinx.serialization.SerialName
1918
import kotlinx.serialization.Serializable
2019
import kotlinx.serialization.Transient
20+
import kotlin.reflect.KClass
2121

2222
/*
2323
Types used in PagingObjects and CursorBasedPagingObjects:
@@ -137,7 +137,7 @@ class CursorBasedPagingObject<T : Any>(
137137
override val limit: Int,
138138
override val next: String?,
139139
@SerialName("cursors") val cursor: Cursor,
140-
override val total: Int
140+
override val total: Int = items.size
141141
) : AbstractPagingObject<T>(href, items, limit, next, 0, null, total) {
142142
/**
143143
* Get all CursorBasedPagingObjects associated with the request

src/commonMain/kotlin/com.adamratzman.spotify/models/Player.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ data class PlayHistoryContext(
1919
@SerialName("uri") private val uriString: String,
2020

2121
val type: String
22-
) : CoreObject(href, href, TrackUri(uriString), externalUrlsString) {
22+
) : CoreObject(
23+
href, href, when (type) {
24+
"artist" -> ArtistUri(uriString)
25+
"playlist" -> PlaylistUri(uriString)
26+
else -> AlbumUri(uriString)
27+
}, externalUrlsString
28+
) {
2329
override val uri: TrackUri get() = super.uri as TrackUri
2430
}
2531

@@ -34,7 +40,7 @@ data class PlayHistoryContext(
3440
data class PlayHistory(
3541
val track: SimpleTrack,
3642
@SerialName("played_at") val playedAt: String,
37-
val context: PlayHistoryContext
43+
val context: PlayHistoryContext?
3844
)
3945

4046
/**

src/commonMain/kotlin/com.adamratzman.spotify/utils/Types.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ expect class ConcurrentHashMap<K, V>() {
1111
val entries: MutableSet<MutableMap.MutableEntry<K, V>>
1212
}
1313

14-
expect fun <K, V> ConcurrentHashMap<K, V>.toList(): List<Pair<K, V>>
14+
expect fun <K, V> ConcurrentHashMap<K, V>.asList(): List<Pair<K, V>>
1515

1616
expect class BufferedImage
1717

src/jsMain/kotlin/com/adamratzman/spotify/utils/Types.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ actual typealias BufferedImage = File
77

88
actual typealias ConcurrentHashMap<K, V> = HashMap<K, V>
99

10-
actual fun <K, V> ConcurrentHashMap<K, V>.toList(): List<Pair<K, V>> = entries.map { (key, value) -> key to value }
10+
actual fun <K, V> ConcurrentHashMap<K, V>.asList(): List<Pair<K, V>> = toList()

src/jvmMain/kotlin/com/adamratzman/spotify/utils/Types.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ actual typealias BufferedImage = java.awt.image.BufferedImage
77

88
actual typealias File = java.io.File
99

10-
actual fun <K, V> ConcurrentHashMap<K, V>.toList(): List<Pair<K, V>> = entries.map { (key, value) -> key to value }
10+
actual fun <K, V> ConcurrentHashMap<K, V>.asList(): List<Pair<K, V>> = toList()

0 commit comments

Comments
 (0)