Skip to content

Instantly share code, notes, and snippets.

View tmaxxdd's full-sized avatar
💻
In my mind, 🍺 in my heart

Tomasz Kądziołka tmaxxdd

💻
In my mind, 🍺 in my heart
View GitHub Profile
sourceSets {
...
val androidMain by getting {
dependencies {
implementation("androidx.activity:activity-compose:1.7.2")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.core:core-ktx:1.10.1")
}
kotlin {
...
sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
kotlin {
// Android
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
}
dependencyResolutionManagement {
repositories {
plugins {
kotlin("multiplatform") version "1.9.0"
}
kotlin {
// Targets
// Source Sets
}
@Entity
public class Product {
// productId, name, price, @Ignore image
@TypeConverters(value = SQLTypeConverters.class)
@ColumnInfo(defaultValue = "CURRENT_TIMESTAMP")
public Date timestamp;
public Product(long productId, String name, double price) {
this.productId = productId;
this.name = name;
public class SQLTypeConverters {
@TypeConverter
public Date fromTimestamp(String value) {
Date defaultDate = new Date();
SimpleDateFormat format = new SimpleDateFormat();
try {
return value.equals("") ? defaultDate : format.parse(value);
} catch (ParseException e) {
e.printStackTrace();
@Entity
public class Product {
// ... productId, name, price, @Ignore image
@ColumnInfo(defaultValue = "CURRENT_TIMESTAMP")
public String timestamp;
public Product(long productId, String name, double price) {
this.productId = productId;
this.name = name;
this.price = price;
Room
.databaseBuilder(this, Database.class, "database")
.addMigrations(Migrations.MIGRATION_1_2)
.fallbackToDestructiveMigration()
.build();
public class Migrations {
public static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE user ADD COLUMN professionOwnerId INTEGER NOT NULL DEFAULT 1");
}
};
}