Skip to content

Commit

Permalink
refactor(openfeedback): migrate to KMP.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Nov 24, 2023
1 parent 6449dc0 commit 3187fc3
Show file tree
Hide file tree
Showing 35 changed files with 180 additions and 138 deletions.
8 changes: 8 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ gradlePlugin {
id = "io.openfeedback.plugins.lib"
implementationClass = "io.openfeedback.plugins.LibraryPlugin"
}
register("io.openfeedback.plugins.lib.multiplatform") {
id = "io.openfeedback.plugins.lib.multiplatform"
implementationClass = "io.openfeedback.plugins.MultiplatformPlugin"
}
register("io.openfeedback.plugins.compose.lib") {
id = "io.openfeedback.plugins.compose.lib"
implementationClass = "io.openfeedback.plugins.ComposeLibraryPlugin"
}
register("io.openfeedback.plugins.publishing") {
id = "io.openfeedback.plugins.publishing"
implementationClass = "io.openfeedback.plugins.PublishingPlugin"
}
register("io.openfeedback.plugins.app") {
id = "io.openfeedback.plugins.app"
implementationClass = "io.openfeedback.plugins.AppPlugin"
Expand Down
4 changes: 0 additions & 4 deletions build-logic/src/main/kotlin/io/openfeedback/OpenFeedback.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package io.openfeedback

import com.android.build.gradle.internal.tasks.factory.dependsOn
import io.openfeedback.extensions.*
import io.openfeedback.extensions.configurePublishingInternal
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.PathSensitivity

open class OpenFeedback(val project: Project) {
fun Project.configurePublishing(artifactName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions

internal fun CommonExtension<*, *, *, *, *>.configureKotlinAndroid() {
compileSdk = 34
Expand All @@ -22,10 +20,6 @@ internal fun CommonExtension<*, *, *, *, *>.configureKotlinAndroid() {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

internal fun CommonExtension<*, *, *, *, *>.configureAndroidCompose(project: Project) {
Expand All @@ -44,7 +38,3 @@ internal fun CommonExtension<*, *, *, *, *>.configureAndroidCompose(project: Pro
add("debugImplementation", "androidx.savedstate:savedstate-ktx:1.2.0")
}
}

private fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.openfeedback.plugins

import com.android.build.gradle.LibraryExtension
import io.openfeedback.OpenFeedback
import io.openfeedback.extensions.configureAndroidCompose
import io.openfeedback.extensions.configureKotlinAndroid
import io.openfeedback.extensions.configureKotlinCompiler
Expand All @@ -14,11 +13,8 @@ class ComposeLibraryPlugin : Plugin<Project> {
with(target.pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
apply("maven-publish")
apply("signing")
}

target.extensions.create("openfeedback", OpenFeedback::class.java, target)
target.extensions.configure<LibraryExtension> {
configureKotlinAndroid()
configureAndroidCompose(target)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.openfeedback.plugins

import com.android.build.gradle.LibraryExtension
import io.openfeedback.OpenFeedback
import io.openfeedback.extensions.configureKotlinAndroid
import io.openfeedback.extensions.configureKotlinCompiler
import org.gradle.api.Plugin
Expand All @@ -14,11 +13,8 @@ class LibraryPlugin : Plugin<Project> {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
apply("org.jetbrains.kotlin.plugin.serialization")
apply("maven-publish")
apply("signing")
}

target.extensions.create("openfeedback", OpenFeedback::class.java, target)
target.extensions.configure<LibraryExtension> {
configureKotlinAndroid()
defaultConfig.targetSdk = 34
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.openfeedback.plugins

import com.android.build.gradle.LibraryExtension
import io.openfeedback.extensions.configureKotlinAndroid
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class MultiplatformPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target.pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.multiplatform")
apply("org.jetbrains.kotlin.plugin.serialization")
}

target.extensions.configure<LibraryExtension> {
configureKotlinAndroid()
defaultConfig.targetSdk = 34
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.openfeedback.plugins

import io.openfeedback.OpenFeedback
import org.gradle.api.Plugin
import org.gradle.api.Project

class PublishingPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target.pluginManager) {
apply("maven-publish")
apply("signing")
}
target.extensions.create("openfeedback", OpenFeedback::class.java, target)
}
}
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import io.openfeedback.extensions.configureRoot

plugins {
id("io.openfeedback.plugins.compose.lib") apply false
alias(libs.plugins.moko.resources.generator) apply false
}

version = "0.1.2"
subprojects {
allprojects {
repositories {
google()
mavenCentral()
Expand Down
17 changes: 15 additions & 2 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
[versions]
kotlin_lang = "1.9.10"
kotlin_coroutines = "1.7.3"
kotlinx_datetime = "0.4.1"
kotlinx_serialization = "1.6.0"
androidx_core = "1.12.0"
androidx_compose_bom = "2023.10.01"
androidx_compose_compiler = "1.5.3"
androidx_lifecycle = "2.6.2"
firebase_common = "20.4.2"
firebase_firestore = "24.9.1"
firebase_auth = "22.3.0"
gitlive_firebase = "1.10.4"
moko_resources = "0.23.0"

[libraries]
android-gradle-plugin = "com.android.tools.build:gradle:8.1.2"
Expand All @@ -15,11 +20,14 @@ vespene = "net.mbonnin.vespene:vespene-lib:0.5"
kotlin_gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin_lang" }
kotlin_serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin_lang" }
kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin_coroutines" }
kotlin-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlin_coroutines" }
kotlin-coroutines-play-services = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-play-services", version.ref = "kotlin_coroutines" }

kotlinx_datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx_datetime" }
kotlinx_serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx_serialization" }

firebase_common = { module = "com.google.firebase:firebase-common", version.ref = "firebase_common" }
firebase_firestore = { module = "com.google.firebase:firebase-firestore-ktx", version.ref = "firebase_firestore" }
firebase_auth = { module = "com.google.firebase:firebase-auth", version.ref = "firebase_auth" }
gitlive_app = { module = "dev.gitlive:firebase-app", version.ref = "gitlive_firebase" }
gitlive_firestore = { module = "dev.gitlive:firebase-firestore", version.ref = "gitlive_firebase" }
gitlive_auth = { module = "dev.gitlive:firebase-auth", version.ref = "gitlive_firebase" }
gitlive_common = { module = "dev.gitlive:firebase-common", version.ref = "gitlive_firebase" }
Expand All @@ -32,3 +40,8 @@ androidx_compose_ui = { module = "androidx.compose.ui:ui" }
androidx_compose_runtime = { module = "androidx.compose.runtime:runtime" }
androidx_compose_uitooling = { module = "androidx.compose.ui:ui-tooling" }
androidx_lifecycle_viewmodel_compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx_lifecycle" }

moko_resources = { module = "dev.icerock.moko:resources", version.ref = "moko_resources"}

[plugins]
moko_resources_generator = { id = "dev.icerock.mobile.multiplatform-resources", version.ref = "moko_resources" }
1 change: 1 addition & 0 deletions openfeedback-m2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

plugins {
id("io.openfeedback.plugins.compose.lib")
id("io.openfeedback.plugins.publishing")
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.openfeedback.android.R as ROF
import io.openfeedback.R as ROF

@Composable
fun PoweredBy(
Expand Down
2 changes: 2 additions & 0 deletions openfeedback-m3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

plugins {
id("io.openfeedback.plugins.compose.lib")
id("io.openfeedback.plugins.publishing")
}

android {
Expand All @@ -14,6 +15,7 @@ openfeedback {
dependencies {
api(projects.openfeedback)
api(projects.openfeedbackViewmodel)

implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.material3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.openfeedback.android.R
import io.openfeedback.R
import io.openfeedback.android.viewmodels.models.UIComment
import io.openfeedback.android.viewmodels.models.UIDot

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.tooling.preview.Preview
import io.openfeedback.android.R
import io.openfeedback.R

@Composable
fun CommentInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.openfeedback.android.R
import io.openfeedback.android.viewmodels.models.UIComment
import io.openfeedback.android.viewmodels.models.UIDot
import io.openfeedback.R

@Composable
internal fun CommentItems(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import io.openfeedback.android.R as ROF
import io.openfeedback.R as ROF

@Composable
internal fun PoweredBy(
Expand Down
1 change: 1 addition & 0 deletions openfeedback-viewmodel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

plugins {
id("io.openfeedback.plugins.compose.lib")
id("io.openfeedback.plugins.publishing")
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import dev.gitlive.firebase.FirebaseApp
import io.openfeedback.android.OpenFeedbackRepository
import io.openfeedback.android.caches.OptimisticVoteCaching
import io.openfeedback.android.model.VoteStatus
import io.openfeedback.android.sources.OpenFeedbackAuth
import io.openfeedback.android.sources.OpenFeedbackFirestore
import io.openfeedback.OpenFeedbackRepository
import io.openfeedback.caches.OptimisticVoteCaching
import io.openfeedback.model.VoteStatus
import io.openfeedback.sources.OpenFeedbackAuth
import io.openfeedback.sources.OpenFeedbackFirestore
import io.openfeedback.android.viewmodels.mappers.convertToUiSessionFeedback
import io.openfeedback.android.viewmodels.models.UIComment
import io.openfeedback.android.viewmodels.models.UISessionFeedback
Expand All @@ -32,8 +32,8 @@ class OpenFeedbackViewModel(
private val locale: Locale
) : ViewModel() {
private val repository = OpenFeedbackRepository(
auth = OpenFeedbackAuth.Factory.create(firebaseApp),
firestore = OpenFeedbackFirestore.Factory.create(firebaseApp),
auth = OpenFeedbackAuth.create(firebaseApp),
firestore = OpenFeedbackFirestore.create(firebaseApp),
optimisticVoteCaching = OptimisticVoteCaching()
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package io.openfeedback.android.viewmodels.mappers

import io.openfeedback.android.model.Project
import io.openfeedback.android.model.SessionVotes
import io.openfeedback.android.model.UserVote
import io.openfeedback.android.viewmodels.models.UIComment
import io.openfeedback.android.viewmodels.models.UIDot
import io.openfeedback.android.viewmodels.models.UISessionFeedback
import io.openfeedback.android.viewmodels.models.UISessionFeedbackWithColors
import io.openfeedback.android.viewmodels.models.UIVoteItem
import io.openfeedback.model.Project
import io.openfeedback.model.SessionVotes
import io.openfeedback.model.UserVote
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import kotlin.math.absoluteValue
import kotlin.random.Random
Expand All @@ -19,18 +22,26 @@ fun convertToUiSessionFeedback(
totalVotes: SessionVotes,
locale: Locale
): UISessionFeedback {
val formatter = SimpleDateFormat("dd MMMM yyyy, hh:mm", locale)
val formatter = SimpleDateFormat("dd MMM, hh:mm", locale)
val userUpVoteIds = userVotes.filter { it.voteId != null }.map { it.voteId!! }
val userVoteIds = userVotes.map { it.voteItemId }
return UISessionFeedback(
commentValue = "",
commentVoteItemId = project.voteItems.find { it.type == "text" }?.id,
comments = totalVotes.comments.map { commentItem ->
val localDateTime = commentItem.value.createdAt.toLocalDateTime(TimeZone.currentSystemDefault())
UIComment(
id = commentItem.value.id,
voteItemId = commentItem.value.voteItemId,
message = commentItem.value.text,
createdAt = formatter.format(commentItem.value.createdAt.toDate()),
createdAt = formatter.format(Date(
localDateTime.date.year,
localDateTime.date.monthNumber,
localDateTime.date.dayOfMonth,
localDateTime.time.hour,
localDateTime.time.minute,
localDateTime.time.second
)),
upVotes = commentItem.value.plus.toInt(),
dots = dots(commentItem.value.plus.toInt(), project.chipColors),
votedByUser = userUpVoteIds.contains(commentItem.value.id)
Expand Down
Loading

0 comments on commit 3187fc3

Please sign in to comment.