From 64843c6c07a32187542ee80b5c47ea532921e9e3 Mon Sep 17 00:00:00 2001 From: jeelpatel231 Date: Thu, 15 Aug 2024 15:54:51 +0530 Subject: [PATCH] port android lib to jvm --- build.gradle.kts | 3 +- common/build.gradle.kts | 59 ++++++------------- common/proguard-rules.pro | 3 - common/src/main/AndroidManifest.xml | 3 - .../echo/common/models/Album.kt | 8 +-- .../echo/common/models/Artist.kt | 16 ++--- .../echo/common/models/Bitmap.kt | 7 +++ .../echo/common/models/EchoMediaItem.kt | 55 +++++++++-------- .../echo/common/models/ImageHolder.kt | 18 +++--- .../echo/common/models/Playlist.kt | 8 +-- .../echo/common/models/Request.kt | 8 +-- .../echo/common/models/Streamable.kt | 8 +-- .../echo/common/models/StreamableAudio.kt | 12 ++-- .../echo/common/models/Track.kt | 15 +++-- .../brahmkshatriya/echo/common/models/User.kt | 10 ++-- .../echo/common/providers/ContextProvider.kt | 12 ++-- gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew | 0 settings.gradle.kts | 2 +- 19 files changed, 112 insertions(+), 139 deletions(-) delete mode 100644 common/proguard-rules.pro delete mode 100644 common/src/main/AndroidManifest.xml create mode 100644 common/src/main/java/dev/brahmkshatriya/echo/common/models/Bitmap.kt mode change 100644 => 100755 gradlew diff --git a/build.gradle.kts b/build.gradle.kts index 51284e0f..3ecd408c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("com.android.application") version "8.2.2" apply false id("org.jetbrains.kotlin.android") version "1.9.21" apply false - id("com.google.devtools.ksp") version "1.9.21-1.0.15" apply false + id("com.google.devtools.ksp") version "2.0.0-1.0.23" apply false id("com.google.dagger.hilt.android") version "2.48.1" apply false + id("org.jetbrains.kotlin.jvm") version "2.0.0" apply false } \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 459dab53..cfec1e85 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,52 +1,27 @@ plugins { - id("com.android.library") - id("org.jetbrains.kotlin.android") - id("kotlin-parcelize") + id("java-library") + id("org.jetbrains.kotlin.jvm") + kotlin("plugin.serialization") version "2.0.10" id("maven-publish") } -android { - namespace = "dev.brahmkshatriya.echo.common" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - consumerProguardFiles("consumer-rules.pro") - } - - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = "1.8" - } +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} - android { - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } - } +dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1") } -afterEvaluate { - publishing { - publications { - register("release") { - from(components["release"]) - } +publishing { + publications { + create("mavenJava") { + groupId = "dev.brahmkshatriya.echo" + artifactId = "common" + version = "1.0" + + from(components["java"]) } } } diff --git a/common/proguard-rules.pro b/common/proguard-rules.pro deleted file mode 100644 index 9f928da9..00000000 --- a/common/proguard-rules.pro +++ /dev/null @@ -1,3 +0,0 @@ -#-keepnames class dev.brahmkshatriya.echo.common.models.Album$Small -#-keepnames class dev.brahmkshatriya.echo.common.models.Album$WithCover --keepnames class dev.brahmkshatriya.echo.common.models.* \ No newline at end of file diff --git a/common/src/main/AndroidManifest.xml b/common/src/main/AndroidManifest.xml deleted file mode 100644 index 69fc4129..00000000 --- a/common/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Album.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Album.kt index 1132cdff..cdb643d6 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Album.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Album.kt @@ -1,9 +1,9 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize +@Serializable data class Album( val id: String, val title: String, @@ -16,4 +16,4 @@ data class Album( val description: String? = null, val subtitle: String? = null, val extras: Map = mapOf() -) : Parcelable \ No newline at end of file +) : JSerializable \ No newline at end of file diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Artist.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Artist.kt index 0d96112a..4b5c4683 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Artist.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Artist.kt @@ -1,16 +1,16 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize +@Serializable data class Artist( - override val id: String, - override val name: String, - override val cover: ImageHolder? = null, - override val extras: Map = mapOf(), + val id: String, + val name: String, + val cover: ImageHolder? = null, + val extras: Map = mapOf(), val subtitle: String? = null, val description: String? = null, val followers: Int? = null, val isFollowing : Boolean = false, -) : User(id, name, cover), Parcelable \ No newline at end of file +) : JSerializable diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Bitmap.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Bitmap.kt new file mode 100644 index 00000000..78d56b68 --- /dev/null +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Bitmap.kt @@ -0,0 +1,7 @@ +package dev.brahmkshatriya.echo.common.models + +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable + +@Serializable +class Bitmap: JSerializable diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/EchoMediaItem.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/EchoMediaItem.kt index 82b53add..e792a7b2 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/EchoMediaItem.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/EchoMediaItem.kt @@ -1,22 +1,21 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcel -import android.os.Parcelable -import kotlinx.parcelize.Parcelize -import kotlinx.parcelize.parcelableCreator +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -sealed class EchoMediaItem : Parcelable { - @Parcelize +sealed class EchoMediaItem : JSerializable { + + @Serializable data class TrackItem(val track: Track) : EchoMediaItem() - @Parcelize + @Serializable sealed class Profile : EchoMediaItem() { data class ArtistItem(val artist: Artist) : Profile() data class UserItem(val user: User) : Profile() } - @Parcelize + @Serializable sealed class Lists : EchoMediaItem() { data class AlbumItem(val album: Album) : Lists() data class PlaylistItem(val playlist: Playlist) : Lists() @@ -35,26 +34,26 @@ sealed class EchoMediaItem : Parcelable { fun User.toMediaItem() = Profile.UserItem(this) fun Playlist.toMediaItem() = Lists.PlaylistItem(this) - val creator = object : Parcelable.Creator { - - inline fun create(source: Parcel?) = runCatching { - parcelableCreator().createFromParcel(source)!! - }.getOrNull() - - override fun createFromParcel(source: Parcel?): EchoMediaItem { - return create(source) - ?: create(source) - ?: create(source) - ?: create(source) - ?: create(source) - ?: throw IllegalArgumentException("Unknown parcelable type") - } - - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } - - } +// val creator = object : Parcelable.Creator { +// +// inline fun create(source: Parcel?) = runCatching { +// parcelableCreator().createFromParcel(source)!! +// }.getOrNull() +// +// override fun createFromParcel(source: Parcel?): EchoMediaItem { +// return create(source) +// ?: create(source) +// ?: create(source) +// ?: create(source) +// ?: create(source) +// ?: throw IllegalArgumentException("Unknown parcelable type") +// } +// +// override fun newArray(size: Int): Array { +// return arrayOfNulls(size) +// } +// +// } } fun toMediaItemsContainer() = MediaItemsContainer.Item( diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/ImageHolder.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/ImageHolder.kt index bb4bd1e5..5f6b2275 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/ImageHolder.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/ImageHolder.kt @@ -1,25 +1,23 @@ package dev.brahmkshatriya.echo.common.models -import android.graphics.Bitmap -import android.net.Uri -import android.os.Parcelable import dev.brahmkshatriya.echo.common.models.Request.Companion.toRequest -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize -sealed class ImageHolder : Parcelable { +@Serializable +sealed class ImageHolder : JSerializable { abstract val crop: Boolean data class UrlRequestImageHolder(val request: Request, override val crop: Boolean) : ImageHolder() - data class UriImageHolder(val uri: Uri, override val crop: Boolean) : ImageHolder() + data class UriImageHolder(val uri: String, override val crop: Boolean) : ImageHolder() data class BitmapImageHolder(val bitmap: Bitmap, override val crop: Boolean) : ImageHolder() companion object { - fun Uri.toImageHolder(crop: Boolean = false): UriImageHolder { - return UriImageHolder(this, crop) - } +// fun Uri.toImageHolder(crop: Boolean = false): UriImageHolder { +// return UriImageHolder(this, crop) +// } fun String.toImageHolder( headers: Map = mapOf(), diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Playlist.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Playlist.kt index 7dd57305..2ad38337 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Playlist.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Playlist.kt @@ -1,9 +1,9 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize +@Serializable data class Playlist( val id: String, val title: String, @@ -16,4 +16,4 @@ data class Playlist( val description: String? = null, val subtitle: String? = null, val extras: Map = mapOf() -) : Parcelable \ No newline at end of file +) : JSerializable \ No newline at end of file diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Request.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Request.kt index 6d2712bc..cae6aad2 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Request.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Request.kt @@ -1,13 +1,13 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize +@Serializable data class Request( val url: String, val headers: Map = emptyMap() -) : Parcelable { +) : JSerializable { companion object { fun String.toRequest(headers: Map = emptyMap()): Request { return Request(this, headers) diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Streamable.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Streamable.kt index 07a311f5..b33b13a9 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Streamable.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Streamable.kt @@ -1,11 +1,11 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize +@Serializable data class Streamable( val id: String, val quality: Int, val extra: Map = mapOf() -) : Parcelable \ No newline at end of file +) : JSerializable \ No newline at end of file diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/StreamableAudio.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/StreamableAudio.kt index 88f4c1a5..0c812490 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/StreamableAudio.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/StreamableAudio.kt @@ -1,15 +1,15 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable import dev.brahmkshatriya.echo.common.models.Request.Companion.toRequest -import kotlinx.parcelize.Parcelize -import kotlinx.parcelize.RawValue import java.io.InputStream -@Parcelize -sealed class StreamableAudio : Parcelable { +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable + +@Serializable +sealed class StreamableAudio : JSerializable { data class StreamableRequest(val request: Request) : StreamableAudio() - data class ByteStreamAudio(val stream: @RawValue InputStream, val totalBytes: Long) : + data class ByteStreamAudio(val stream: InputStream, val totalBytes: Long) : StreamableAudio() companion object { diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Track.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Track.kt index 2202a7d8..ebc25797 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/Track.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/Track.kt @@ -1,10 +1,9 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable -import kotlinx.parcelize.Parcelize -import kotlinx.parcelize.parcelableCreator +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize +@Serializable data class Track( val id: String, val title: String, @@ -19,9 +18,9 @@ data class Track( val videoStreamable: List = listOf(), val audioStreamables: List = listOf(), val expiresAt: Long = 0, -) : Parcelable { +) : JSerializable { - companion object { - val creator = parcelableCreator() - } +// companion object { +// val creator = parcelableCreator() +// } } \ No newline at end of file diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/models/User.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/models/User.kt index 4506dab4..b187cc40 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/models/User.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/models/User.kt @@ -1,12 +1,12 @@ package dev.brahmkshatriya.echo.common.models -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable +import java.io.Serializable as JSerializable -@Parcelize +@Serializable open class User( open val id: String, open val name: String, open val cover: ImageHolder? = null, - open val extras: Map = mapOf() -) : Parcelable \ No newline at end of file + open val extras: Map = emptyMap(), +) : JSerializable \ No newline at end of file diff --git a/common/src/main/java/dev/brahmkshatriya/echo/common/providers/ContextProvider.kt b/common/src/main/java/dev/brahmkshatriya/echo/common/providers/ContextProvider.kt index 474973c8..6c1b9c1f 100644 --- a/common/src/main/java/dev/brahmkshatriya/echo/common/providers/ContextProvider.kt +++ b/common/src/main/java/dev/brahmkshatriya/echo/common/providers/ContextProvider.kt @@ -1,7 +1,7 @@ package dev.brahmkshatriya.echo.common.providers - -import android.content.Context - -interface ContextProvider { - fun setContext(context: Context) -} \ No newline at end of file +// +//import android.content.Context +// +//interface ContextProvider { +// fun setContext(context: Context) +//} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 29107a84..f49a40f0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Dec 23 17:02:09 IST 2023 +#Thu Aug 15 09:24:18 GMT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/settings.gradle.kts b/settings.gradle.kts index a24b0bc0..21266360 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,4 +17,4 @@ dependencyResolutionManagement { rootProject.name = "Echo" include(":app") -include(":common") \ No newline at end of file +include(":common")