Skip to content

Commit

Permalink
Update dependencies, Add sort and error handling
Browse files Browse the repository at this point in the history
- Update SqlDelight version
- Update dependencies
- Add sort and error handling
  • Loading branch information
KaushalVasava committed Jan 8, 2024
1 parent 8fea9df commit b3bd320
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 100 deletions.
18 changes: 9 additions & 9 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ plugins {

android {
namespace = "com.kaushalvasava.apps.taskapp.android"
compileSdk = 33
compileSdk = 34
defaultConfig {
applicationId = "com.kaushalvasava.apps.taskapp.android"
minSdk = 23
targetSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.7"
kotlinCompilerExtensionVersion = "1.5.6"
}
packaging {
resources {
Expand All @@ -40,10 +40,10 @@ android {

dependencies {
implementation(project(":shared"))
implementation("androidx.compose.ui:ui:1.4.3")
implementation("androidx.compose.ui:ui-tooling:1.4.3")
implementation("androidx.compose.ui:ui-tooling-preview:1.4.3")
implementation("androidx.compose.foundation:foundation:1.4.3")
implementation("androidx.compose.material:material:1.4.3")
implementation("androidx.activity:activity-compose:1.7.1")
implementation("androidx.compose.ui:ui:1.5.4")
implementation("androidx.compose.ui:ui-tooling:1.5.4")
implementation("androidx.compose.ui:ui-tooling-preview:1.5.4")
implementation("androidx.compose.foundation:foundation:1.5.4")
implementation("androidx.compose.material:material:1.5.4")
implementation("androidx.activity:activity-compose:1.8.2")
}
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins {
//trick: for the same plugin versions in all sub-modules
id("com.android.application").version("8.1.0").apply(false)
id("com.android.library").version("8.1.0").apply(false)
kotlin("android").version("1.8.21").apply(false)
kotlin("multiplatform").version("1.8.21").apply(false)
id("com.squareup.sqldelight").version("1.5.5").apply(false)
kotlin("android").version("1.9.10").apply(false)
kotlin("multiplatform").version("1.9.20").apply(false)
id("app.cash.sqldelight").version("2.0.1").apply(false)
}

tasks.register("clean", Delete::class) {
Expand Down
Binary file added desktopApp/TaskDatabase.db
Binary file not shown.
Binary file added desktopApp/TaskDatabase2.db
Binary file not shown.
Binary file modified desktopApp/task_database.db
Binary file not shown.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ kotlin.mpp.androidSourceSetLayoutVersion=2

#Compose
org.jetbrains.compose.experimental.uikit.enabled=true
kotlin.native.cacheKind=none
#kotlin.native.cacheKind=none

#Android
android.useAndroidX=true
android.compileSdk=33
android.targetSdk=33
android.compileSdk=34
android.targetSdk=34
android.minSdk=23

#Versions
kotlin.version=1.8.21
kotlin.version=1.9.20
agp.version=8.1.0
compose.version=1.4.3
sqlDelight.version=1.5.5
compose.version=1.5.11
sqlDelight.version=2.0.1
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 08 16:38:57 IST 2023
#Mon Jan 08 16:38:01 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {
id("com.android.application").version(agpVersion)
id("com.android.library").version(agpVersion)
id("org.jetbrains.compose").version(composeVersion)
id("com.squareup.sqldelight").version(extra["sqlDelight.version"] as String)
id("app.cash.sqldelight").version(extra["sqlDelight.version"] as String)
}
}

Expand Down
31 changes: 17 additions & 14 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ plugins {
kotlin("multiplatform")
id("com.android.library")
id("org.jetbrains.compose")
id("com.squareup.sqldelight")
id("app.cash.sqldelight")
// version("2.0.1")
}

kotlin {
Expand Down Expand Up @@ -32,20 +33,20 @@ kotlin {
implementation(compose.material)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
api("dev.icerock.moko:mvvm-core:0.16.1") // only ViewModel, EventsDispatcher, Dispatchers.UI
api("dev.icerock.moko:mvvm-compose:0.16.1") // api mvvm-core, getViewModel for Compose Multiplatfrom

api("dev.icerock.moko:mvvm-compose:0.16.1") // api mvvm-core, getViewModel for Compose Multi platfrom
implementation("app.cash.sqldelight:coroutines-extensions:2.0.1")
}
}
val androidMain by getting {
dependencies {
api("androidx.activity:activity-compose:1.7.2")
api("androidx.activity:activity-compose:1.8.2")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.10.1")
api("androidx.core:core-ktx:1.12.0")

implementation("com.squareup.sqldelight:android-driver:1.5.5")
implementation("app.cash.sqldelight:android-driver:2.0.1")
}
}
val iosX64Main by getting
Expand All @@ -57,7 +58,7 @@ kotlin {
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies {
implementation("com.squareup.sqldelight:native-driver:1.5.5")
implementation("app.cash.sqldelight:native-driver:2.0.1")
}
}
val commonTest by getting {
Expand All @@ -69,23 +70,25 @@ kotlin {
dependencies {
implementation(compose.desktop.common)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.7.3")
implementation("com.squareup.sqldelight:sqlite-driver:1.5.5")
implementation("app.cash.sqldelight:sqlite-driver:2.0.1")
}
}
}
}


sqldelight {
database("TaskDatabase") {
packageName = "task_database.db"
sourceFolders = listOf("kotlin")
databases {
create("TaskDatabase") {
packageName.set("com.kaushalvasava.apps.taskapp")
}
}
}



android {
namespace = "com.kaushalvasava.apps.taskapp"
compileSdk = 33
compileSdk = 34

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.kaushalvasava.apps.taskapp.datasource

import android.content.Context
import com.squareup.sqldelight.android.AndroidSqliteDriver
import com.squareup.sqldelight.db.SqlDriver
import task_database.db.TaskDatabase

import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import com.kaushalvasava.apps.taskapp.TaskDatabase
actual class DriverFactory(private val context: Context){
actual fun createDriver(): SqlDriver {
return AndroidSqliteDriver(TaskDatabase.Schema, context, "task_database.db")
return AndroidSqliteDriver(
TaskDatabase.Schema, context, "TaskDatabase.db"
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kaushalvasava.apps.taskapp.datasource

import com.squareup.sqldelight.db.SqlDriver
import app.cash.sqldelight.db.SqlDriver

expect class DriverFactory {
fun createDriver(): SqlDriver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package database.dao
package com.kaushalvasava.apps.taskapp.datasource.dao

import com.kaushalvasava.apps.taskapp.TaskDatabase
import com.kaushalvasava.apps.taskapp.datasource.model.Task2
import com.kaushalvasava.apps.taskapp.util.toTask2
import database.model.Task2
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import task_database.db.TaskDatabase

fun TaskDatabase.setTask(task: Task2) {
return taskQueries.insertTask(
Expand All @@ -22,9 +20,11 @@ fun TaskDatabase.deleteTask(id: Long) {
}

fun TaskDatabase.getTasksList(): List<Task2> {
return this.taskQueries.getTasks().executeAsList().map {
it.toTask2()
}
return this.taskQueries.getTasks().executeAsList()
.sortedByDescending { it.date }
.sortedByDescending { it.isImportant }.map {
it.toTask2()
}
}

fun TaskDatabase.updateTask(task: Task2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package database.model
package com.kaushalvasava.apps.taskapp.datasource.model

import kotlinx.datetime.Clock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import app.cash.sqldelight.db.SqlDriver
import com.kaushalvasava.apps.taskapp.ui.components.TaskScreen
import com.squareup.sqldelight.db.SqlDriver
import dev.icerock.moko.mvvm.compose.getViewModel
import dev.icerock.moko.mvvm.compose.viewModelFactory

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import com.squareup.sqldelight.db.SqlDriver
import database.dao.deleteTask
import database.dao.getTasksList
import database.dao.setTask
import database.dao.updateTask
import database.model.Task2
import app.cash.sqldelight.db.SqlDriver
import com.kaushalvasava.apps.taskapp.TaskDatabase
import com.kaushalvasava.apps.taskapp.datasource.dao.deleteTask
import com.kaushalvasava.apps.taskapp.datasource.dao.getTasksList
import com.kaushalvasava.apps.taskapp.datasource.dao.setTask
import com.kaushalvasava.apps.taskapp.datasource.dao.updateTask
import com.kaushalvasava.apps.taskapp.datasource.model.Task2
import dev.icerock.moko.mvvm.viewmodel.ViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import task_database.db.TaskDatabase

class TaskViewModel(driver: SqlDriver) : ViewModel() {
val tasks = MutableStateFlow<List<Task2>>(emptyList())
Expand All @@ -21,25 +21,23 @@ class TaskViewModel(driver: SqlDriver) : ViewModel() {
getTasks()
}

fun addTask(task: Task2) {
private fun getTasks() {
viewModelScope.launch(Dispatchers.IO) {
database.setTask(task)
tasks.value = database.getTasksList()
}
}

fun deleteTask(id: Long) {
fun addTask(task: Task2) {
viewModelScope.launch(Dispatchers.IO) {
database.deleteTask(id)
database.setTask(task)
tasks.value = database.getTasksList()
}
}

private fun getTasks() {
fun deleteTask(id: Long) {
viewModelScope.launch(Dispatchers.IO) {
database.deleteTask(id)
tasks.value = database.getTasksList()
.sortedByDescending { it.date }
.sortedByDescending { it.isImportant }
}
}

Expand Down
Loading

0 comments on commit b3bd320

Please sign in to comment.