Skip to content

Commit

Permalink
Add AndroidTarget and Parcel Support (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV-GH authored Jun 28, 2024
1 parent a33ec67 commit 1c4fa27
Show file tree
Hide file tree
Showing 229 changed files with 716 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ bin/
.DS_Store

temp
/local.properties
local.properties

# TODO temp
**/Secrets.kt
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/it.vercruysse.lemmyapi/lemmy-api?server=https%3A%2F%2Fs01.oss.sonatype.org)
![badge][badge-js]
![badge][badge-jvm]
![badge][badge-android]
![badge][badge-linux]
![badge][badge-windows]
![badge][badge-mac]
Expand Down Expand Up @@ -38,11 +39,16 @@ api.getSupportedEntries<SortType>()
```

## Installation
```
implementation("it.vercruysse.lemmyapi:lemmy-api:VERSION")

```kts
implementation("it.vercruysse.lemmyapi:lemmy-api:VERSION")
```
It is currently in beta, so only snapshots are available.

Add the following repository
```kts
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") }
```

## Goals

Expand Down Expand Up @@ -95,7 +101,10 @@ Now to prevent having to manually write the definition file, we can generate it
And these are generated by comparing the datatypes from the given source package version and the given target package version.
Datatypes, which exist in both, will have a mapping generated.

## Extra features

- JVM datatypes implement `Serializable`
- Android datatypes implement `Parcelable` and `Serializable`


[badge-android]: http://img.shields.io/badge/-android-6EDB8D.svg?style=flat
Expand Down
24 changes: 22 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ plugins {
id("com.google.devtools.ksp") version ("2.0.0-1.0.22")
id("com.vanniktech.maven.publish") version "0.29.0"
id("com.github.ben-manes.versions") version "0.51.0"
id("com.android.library")
id("kotlin-parcelize")
}

repositories {
mavenCentral()
gradlePluginPortal()
google()
}

android {
namespace = "it.vercruysse.lemmyapi"
compileSdk = 34
defaultConfig {
minSdk = 21
}
}

kotlin {
Expand All @@ -28,6 +39,12 @@ kotlin {
}
}

androidTarget {
compilerOptions {
freeCompilerArgs.addAll("-P", "plugin:org.jetbrains.kotlin.parcelize:additionalAnnotation=it.vercruysse.lemmyapi.CommonParcelize")
}
}

linuxX64()
linuxArm64()
mingwX64()
Expand All @@ -53,7 +70,7 @@ kotlin {

commonMain.dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")

implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
Expand Down Expand Up @@ -97,9 +114,12 @@ kotlin {
api("io.ktor:ktor-client-cio:$ktorVersion")
}

androidMain.dependencies {
api("io.ktor:ktor-client-okhttp:$ktorVersion")
}
}

val publicationsFromMainHost = listOf(jvm(), js()).map { it.name } + "kotlinMultiplatform"
val publicationsFromMainHost = listOf(jvm(), js(), androidTarget()).map { it.name } + "kotlinMultiplatform"

publishing {
publications {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package it.vercruysse.lemmyapi

actual interface DatatypeRoot :
android.os.Parcelable,
java.io.Serializable
9 changes: 9 additions & 0 deletions app/src/androidMain/kotlin/it/vercruysse/lemmyapi/LemmyApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.vercruysse.lemmyapi

import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.okhttp.OkHttpConfig

fun LemmyApi.setDefaultClientConfig(block: HttpClientConfig<OkHttpConfig>.() -> Unit) {
@Suppress("UNCHECKED_CAST")
defaultClient = defaultClient.config(block as HttpClientConfig<*>.() -> Unit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package it.vercruysse.lemmyapi

annotation class CommonParcelize
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.vercruysse.lemmyapi

// The sole purpose is to be defined by another platform
// Enables platform-specific implementation of all the datatypes
expect interface DatatypeRoot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package it.vercruysse.lemmyapi.datatypes

import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable
import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AddAdmin(
val person_id: PersonId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AddAdminResponse(
val admins: List<PersonView>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AddModToCommunity(
val community_id: CommunityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AddModToCommunityResponse(
val moderators: List<CommunityModeratorView>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgeComment(
val id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgeCommentView(
val admin_purge_comment: AdminPurgeComment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import it.vercruysse.lemmyapi.DatatypeRoot
import it.vercruysse.lemmyapi.Identity
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgeCommunity(
override val id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import it.vercruysse.lemmyapi.DatatypeRoot
import it.vercruysse.lemmyapi.Identity
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgeCommunityView(
val admin_purge_community: AdminPurgeCommunity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import it.vercruysse.lemmyapi.DatatypeRoot
import it.vercruysse.lemmyapi.Identity
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgePerson(
override val id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import it.vercruysse.lemmyapi.DatatypeRoot
import it.vercruysse.lemmyapi.Identity
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgePersonView(
val admin_purge_person: AdminPurgePerson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import it.vercruysse.lemmyapi.DatatypeRoot
import it.vercruysse.lemmyapi.Identity
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgePost(
override val id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import it.vercruysse.lemmyapi.DatatypeRoot
import it.vercruysse.lemmyapi.Identity
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class AdminPurgePostView(
val admin_purge_post: AdminPurgePost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class ApproveRegistrationApplication(
val id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BanFromCommunity(
val community_id: CommunityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BanFromCommunityResponse(
val person_view: PersonView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BanPerson(
val person_id: PersonId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BanPersonResponse(
val person_view: PersonView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BannedPersonsResponse(
val banned: List<PersonView>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BlockCommunity(
val community_id: CommunityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BlockCommunityResponse(
val community_view: CommunityView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BlockInstance(
val instance_id: InstanceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BlockInstanceResponse(
val blocked: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BlockPerson(
val person_id: PersonId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class BlockPersonResponse(
val person_view: PersonView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class CaptchaResponse(
val png: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package it.vercruysse.lemmyapi.datatypes
import it.vercruysse.lemmyapi.DatatypeRoot
import kotlinx.serialization.Serializable

import it.vercruysse.lemmyapi.CommonParcelize

@CommonParcelize
@Serializable
data class ChangePassword(
val new_password: String,
Expand Down
Loading

0 comments on commit 1c4fa27

Please sign in to comment.