Skip to content

Commit ef93418

Browse files
committed
implement images on android
Signed-off-by: Adam Ratzman <[email protected]>
1 parent 7250297 commit ef93418

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ repositories {
3939
jcenter()
4040
}
4141
42-
compile group: 'com.adamratzman', name: 'spotify-api-kotlin-core', version: '3.2.10'
42+
compile group: 'com.adamratzman', name: 'spotify-api-kotlin-core', version: '3.2.11'
4343
```
4444

45+
Note that images and profiles are not supported on the Kotlin/JS target.
46+
4547
### Android
4648
**If you declare any release types not named debug or release, you may see "Could not resolve com.adamratzman:spotify-api-kotlin-android:VERSION". You need to do the following for each release type not named debug or release:**
4749
```

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ buildscript {
3131
}
3232

3333
group = "com.adamratzman"
34-
version = "3.2.10"
34+
version = "3.2.11"
3535

3636
tasks.withType<Test> {
3737
this.testLogging {
@@ -209,6 +209,7 @@ kotlin {
209209
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
210210
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializationVersion")
211211
api("io.ktor:ktor-client-cio:$ktorVersion")
212+
api("io.coil-kt:coil:0.11.0")
212213
implementation(kotlin("stdlib-jdk8"))
213214
}
214215
}
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.utils
33

4+
import android.graphics.Bitmap
5+
import android.graphics.BitmapFactory
6+
import android.util.Base64
7+
import java.io.ByteArrayOutputStream
8+
import java.net.URL
9+
10+
411
internal actual fun encodeBufferedImageToBase64String(image: BufferedImage): String {
5-
/*val bos = ByteArrayOutputStream()
6-
ImageIO.write(image, "jpg", bos)
7-
bos.close()
8-
return Base64.getEncoder().encodeToString(bos.toByteArray())*/
9-
throw NotImplementedError()
12+
val byteArrayOutputStream = ByteArrayOutputStream()
13+
image.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
14+
val byteArray: ByteArray = byteArrayOutputStream.toByteArray()
15+
return Base64.encodeToString(byteArray, Base64.DEFAULT)
1016
}
1117

12-
internal actual fun convertFileToBufferedImage(file: File): BufferedImage = throw NotImplementedError()
18+
internal actual fun convertFileToBufferedImage(file: File): BufferedImage = BitmapFactory.decodeFile(file.absolutePath)
1319

14-
internal actual fun convertLocalImagePathToBufferedImage(path: String): BufferedImage = throw NotImplementedError()
20+
internal actual fun convertLocalImagePathToBufferedImage(path: String): BufferedImage = BitmapFactory.decodeFile(path)
1521

16-
internal actual fun convertUrlPathToBufferedImage(url: String): BufferedImage = throw NotImplementedError()
22+
internal actual fun convertUrlPathToBufferedImage(url: String): BufferedImage {
23+
return URL(url).openConnection().getInputStream().use { inputStream ->
24+
BitmapFactory.decodeStream(inputStream)
25+
}
26+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.utils
33

4+
import android.graphics.Bitmap
5+
46
actual typealias ConcurrentHashMap<K, V> = java.util.concurrent.ConcurrentHashMap<K, V>
57

6-
actual typealias BufferedImage = String // TODO
8+
actual typealias BufferedImage = Bitmap // TODO
79

810
actual typealias File = java.io.File
911

0 commit comments

Comments
 (0)