Skip to content

Commit

Permalink
port android lib to jvm
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelPatel231 committed Aug 15, 2024
1 parent 3a588a2 commit 64843c6
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 139 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
59 changes: 17 additions & 42 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<MavenPublication>("release") {
from(components["release"])
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = "dev.brahmkshatriya.echo"
artifactId = "common"
version = "1.0"

from(components["java"])
}
}
}
3 changes: 0 additions & 3 deletions common/proguard-rules.pro

This file was deleted.

3 changes: 0 additions & 3 deletions common/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,4 +16,4 @@ data class Album(
val description: String? = null,
val subtitle: String? = null,
val extras: Map<String, String> = mapOf()
) : Parcelable
) : JSerializable
Original file line number Diff line number Diff line change
@@ -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<String, String> = mapOf(),
val id: String,
val name: String,
val cover: ImageHolder? = null,
val extras: Map<String, String> = mapOf(),
val subtitle: String? = null,
val description: String? = null,
val followers: Int? = null,
val isFollowing : Boolean = false,
) : User(id, name, cover), Parcelable
) : JSerializable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.brahmkshatriya.echo.common.models

import kotlinx.serialization.Serializable
import java.io.Serializable as JSerializable

@Serializable
class Bitmap: JSerializable
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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<EchoMediaItem> {

inline fun <reified T : Parcelable> create(source: Parcel?) = runCatching {
parcelableCreator<T>().createFromParcel(source)!!
}.getOrNull()

override fun createFromParcel(source: Parcel?): EchoMediaItem {
return create<Lists.AlbumItem>(source)
?: create<Lists.PlaylistItem>(source)
?: create<TrackItem>(source)
?: create<Profile.ArtistItem>(source)
?: create<Profile.UserItem>(source)
?: throw IllegalArgumentException("Unknown parcelable type")
}

override fun newArray(size: Int): Array<EchoMediaItem?> {
return arrayOfNulls(size)
}

}
// val creator = object : Parcelable.Creator<EchoMediaItem> {
//
// inline fun <reified T : Parcelable> create(source: Parcel?) = runCatching {
// parcelableCreator<T>().createFromParcel(source)!!
// }.getOrNull()
//
// override fun createFromParcel(source: Parcel?): EchoMediaItem {
// return create<Lists.AlbumItem>(source)
// ?: create<Lists.PlaylistItem>(source)
// ?: create<TrackItem>(source)
// ?: create<Profile.ArtistItem>(source)
// ?: create<Profile.UserItem>(source)
// ?: throw IllegalArgumentException("Unknown parcelable type")
// }
//
// override fun newArray(size: Int): Array<EchoMediaItem?> {
// return arrayOfNulls(size)
// }
//
// }
}

fun toMediaItemsContainer() = MediaItemsContainer.Item(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> = mapOf(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,4 +16,4 @@ data class Playlist(
val description: String? = null,
val subtitle: String? = null,
val extras: Map<String, String> = mapOf()
) : Parcelable
) : JSerializable
Original file line number Diff line number Diff line change
@@ -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<String, String> = emptyMap()
) : Parcelable {
) : JSerializable {
companion object {
fun String.toRequest(headers: Map<String, String> = emptyMap()): Request {
return Request(this, headers)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> = mapOf()
) : Parcelable
) : JSerializable
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -19,9 +18,9 @@ data class Track(
val videoStreamable: List<Streamable> = listOf(),
val audioStreamables: List<Streamable> = listOf(),
val expiresAt: Long = 0,
) : Parcelable {
) : JSerializable {

companion object {
val creator = parcelableCreator<Track>()
}
// companion object {
// val creator = parcelableCreator<Track>()
// }
}
Original file line number Diff line number Diff line change
@@ -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<String, String> = mapOf()
) : Parcelable
open val extras: Map<String, String> = emptyMap(),
) : JSerializable
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.brahmkshatriya.echo.common.providers

import android.content.Context

interface ContextProvider {
fun setContext(context: Context)
}
//
//import android.content.Context
//
//interface ContextProvider {
// fun setContext(context: Context)
//}
Loading

0 comments on commit 64843c6

Please sign in to comment.