Skip to content

Commit

Permalink
Copy-paste the Learn DSL code
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Dec 11, 2024
1 parent 5701598 commit 0d4a6a9
Show file tree
Hide file tree
Showing 8 changed files with 739 additions and 3 deletions.
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ kotest = "5.9.1"
[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.7.3" }

[bundles]
test = [
Expand All @@ -18,4 +19,5 @@ test = [
[plugins]
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
publish = { id = "com.vanniktech.maven.publish", version = "0.29.0" }
publish = { id = "com.vanniktech.maven.publish", version = "0.29.0" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
5 changes: 3 additions & 2 deletions learn-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.publish)
alias(libs.plugins.kotlinSerialization)
}

kotlin {
Expand All @@ -30,7 +31,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
//put your multiplatform dependencies here
implementation(libs.kotlin.serialization)
}
}
val commonTest by getting {
Expand All @@ -43,7 +44,7 @@ kotlin {
}

android {
namespace = "com.ivy_apps.learn.dsl"
namespace = "com.ivy_apps.learn"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
Expand Down
17 changes: 17 additions & 0 deletions learn-dsl/src/commonMain/kotlin/ivy/learn/CourseModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ivy.learn

import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline

@Serializable
data class Course(
override val id: CourseId,
val name: String,
val tagline: String,
val image: ImageUrl,
val lessons: List<LessonId>,
) : Identifiable<CourseId>

@Serializable
@JvmInline
value class CourseId(override val value: String) : Id
9 changes: 9 additions & 0 deletions learn-dsl/src/commonMain/kotlin/ivy/learn/Identifiable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ivy.learn

interface Identifiable<AId : Id> {
val id: AId
}

interface Id {
val value: String
}
172 changes: 172 additions & 0 deletions learn-dsl/src/commonMain/kotlin/ivy/learn/LessonModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package ivy.learn

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline

@Serializable
data class Lesson(
override val id: LessonId,
val name: String,
val tagline: String,
val image: ImageUrl,
val content: LessonContent,
val completed: Boolean,
) : Identifiable<LessonId>

@Serializable
data class LessonContent(
val rootItem: LessonItemId,
val items: Map<LessonItemId, LessonItem>,
)

@Serializable
@JvmInline
value class LessonId(override val value: String) : Id

@Serializable
sealed interface LessonItem {
val id: LessonItemId
}

@Serializable
@JvmInline
value class LessonItemId(val value: String)

/**
* Item that doesn't branch the tree.
*/
interface LinearItem {
val next: LessonItemId?
}

@Serializable
@SerialName("TextItem")
data class TextItem(
override val id: LessonItemId,
val text: String,
val style: TextStyle,
override val next: LessonItemId?,
) : LessonItem, LinearItem

@Serializable
enum class TextStyle {
Heading,
Body,
BodySpacingMedium,
BodySpacingLarge
}

@Serializable
@SerialName("QuestionItem")
data class QuestionItem(
override val id: LessonItemId,
val question: String,
val clarification: String?,
val answers: List<Answer>,
val correct: Set<AnswerId>,
override val next: LessonItemId?,
) : LessonItem, LinearItem

@Serializable
data class Answer(
val id: AnswerId,
val text: String,
val explanation: String?,
)

@Serializable
@JvmInline
value class AnswerId(val value: String)

@Serializable
@SerialName("OpenQuestionItem")
data class OpenQuestionItem(
override val id: LessonItemId,
val question: String,
val correctAnswer: String,
override val next: LessonItemId?,
) : LessonItem, LinearItem

@Serializable
@SerialName("LinkItem")
data class LinkItem(
override val id: LessonItemId,
val text: String,
val url: String,
override val next: LessonItemId?,
) : LessonItem, LinearItem

@Serializable
@SerialName("LessonNavigationItem")
data class LessonNavigationItem(
override val id: LessonItemId,
val text: String,
val onClick: LessonItemId,
override val next: LessonItemId?,
) : LessonItem, LinearItem

@Serializable
@SerialName("LottieAnimationItem")
data class LottieAnimationItem(
override val id: LessonItemId,
val lottie: LottieAnimation,
override val next: LessonItemId?,
) : LessonItem, LinearItem

@Serializable
@JvmInline
value class LottieAnimation(val url: String)

@Serializable
@SerialName("ImageItem")
data class ImageItem(
override val id: LessonItemId,
val image: ImageUrl,
override val next: LessonItemId?,
) : LessonItem, LinearItem

@Serializable
@JvmInline
value class ImageUrl(val url: String)

@Serializable
@SerialName("ChoiceItem")
data class ChoiceItem(
override val id: LessonItemId,
val question: String,
val options: List<ChoiceOption>,
) : LessonItem

@Serializable
data class ChoiceOption(
val id: ChoiceOptionId,
val text: String,
val next: LessonItemId,
)

@Serializable
@JvmInline
value class ChoiceOptionId(val value: String)

@Serializable
@SerialName("MysteryItem")
data class MysteryItem(
override val id: LessonItemId,
val text: String,
val hidden: LessonItemId,
override val next: LessonItemId?
) : LessonItem, LinearItem

@Serializable
@SerialName("SoundItem")
data class SoundItem(
override val id: LessonItemId,
val text: String,
val sound: SoundUrl,
override val next: LessonItemId?
) : LessonItem, LinearItem

@Serializable
@JvmInline
value class SoundUrl(val url: String)
15 changes: 15 additions & 0 deletions learn-dsl/src/commonMain/kotlin/ivy/learn/TopicModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ivy.learn

import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline

@Serializable
data class Topic(
override val id: TopicId,
val name: String,
val courses: List<CourseId>
) : Identifiable<TopicId>

@JvmInline
@Serializable
value class TopicId(override val value: String) : Id
Loading

0 comments on commit 0d4a6a9

Please sign in to comment.