diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index e5afee0617e8c61f2f40aa0e8b490565bfe4c086..d0cc17b265288a8ba6f6c692542e6c6ee4ef0a4e 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -36,28 +36,6 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* - * Quasseldroid - Quassel client for Android - * - * Copyright (c) 2018 Janne Koschinski - * Copyright (c) 2018 Ken Børge Viktil - * Copyright (c) 2018 Magnus Fjell - * Copyright (c) 2018 Martin Sandsmark - * Copyright (c) 2018 The Quassel Project - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3 as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - import org.gradle.api.Project import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.kotlin.dsl.* diff --git a/malheur/build.gradle.kts b/malheur/build.gradle.kts index 92d078e957e21ebd24d505a0c6991da33cb8ba9a..5874f08e3a37a56c37a00a1605460e13ec270dca 100644 --- a/malheur/build.gradle.kts +++ b/malheur/build.gradle.kts @@ -36,28 +36,6 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* - * Quasseldroid - Quassel client for Android - * - * Copyright (c) 2018 Janne Koschinski - * Copyright (c) 2018 Ken Børge Viktil - * Copyright (c) 2018 Magnus Fjell - * Copyright (c) 2018 Martin Sandsmark - * Copyright (c) 2018 The Quassel Project - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3 as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - plugins { id("com.android.library") kotlin("android") diff --git a/persistence/src/main/java/de/kuschku/quasseldroid/persistence/AccountDatabase.kt b/persistence/src/main/java/de/kuschku/quasseldroid/persistence/AccountDatabase.kt index 3f12044cbd90ece94e1634e7bafa6723f2c1ce28..ae7e85f7c8649d322de3b2fccbad93eaee896656 100644 --- a/persistence/src/main/java/de/kuschku/quasseldroid/persistence/AccountDatabase.kt +++ b/persistence/src/main/java/de/kuschku/quasseldroid/persistence/AccountDatabase.kt @@ -73,8 +73,7 @@ abstract class AccountDatabase : RoomDatabase() { database = Room.databaseBuilder( context.applicationContext, AccountDatabase::class.java, DATABASE_NAME - ) - .build() + ).allowMainThreadQueries().build() } } } diff --git a/persistence/src/main/java/de/kuschku/quasseldroid/persistence/LegacyAccountDatabase.kt b/persistence/src/main/java/de/kuschku/quasseldroid/persistence/LegacyAccountDatabase.kt new file mode 100644 index 0000000000000000000000000000000000000000..963e77f031ddeb052329b2a9763f95472efe0011 --- /dev/null +++ b/persistence/src/main/java/de/kuschku/quasseldroid/persistence/LegacyAccountDatabase.kt @@ -0,0 +1,103 @@ +/* + * Quasseldroid - Quassel client for Android + * + * Copyright (c) 2018 Janne Koschinski + * Copyright (c) 2018 The Quassel Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package de.kuschku.quasseldroid.persistence + +import android.arch.persistence.db.SupportSQLiteDatabase +import android.arch.persistence.room.* +import android.arch.persistence.room.migration.Migration +import android.content.Context + +@Database(entities = [(LegacyAccountDatabase.Account::class)], version = 4) +abstract class LegacyAccountDatabase : RoomDatabase() { + abstract fun accounts(): AccountDao + + @Entity + data class Account( + @PrimaryKey + var id: Long, + var host: String, + var port: Int, + var user: String, + var pass: String, + var name: String + ) + + @Dao + interface AccountDao { + @Query("SELECT * FROM account") + fun all(): List<Account> + } + + object Creator { + private var database: LegacyAccountDatabase? = null + + // For Singleton instantiation + private val LOCK = Any() + + fun init(context: Context): LegacyAccountDatabase { + if (database == null) { + synchronized(LOCK) { + if (database == null) { + database = Room.databaseBuilder( + context.applicationContext, + LegacyAccountDatabase::class.java, DATABASE_NAME + ).addMigrations( + object : Migration(0, 1) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE IF EXISTS cores") + database.execSQL("create table cores (_id integer primary key autoincrement, name text not null, server text not null, port integer not null);") + + database.execSQL("DROP TABLE IF EXISTS user") + database.execSQL("CREATE TABLE user(userid integer primary key autoincrement, username text not null, password text not null, coreid integer not null unique, foreign key(coreid) references cores(_id) ON DELETE CASCADE ON UPDATE CASCADE)") + } + }, + object : Migration(1, 2) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE IF EXISTS cores") + database.execSQL("create table cores (_id integer primary key autoincrement, name text not null, server text not null, port integer not null);") + + database.execSQL("DROP TABLE IF EXISTS user") + database.execSQL("CREATE TABLE user(userid integer primary key autoincrement, username text not null, password text not null, coreid integer not null unique, foreign key(coreid) references cores(_id) ON DELETE CASCADE ON UPDATE CASCADE)") + } + }, + object : Migration(2, 3) { + override fun migrate(database: SupportSQLiteDatabase) = Unit + }, + object : Migration(3, 4) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("CREATE TABLE IF NOT EXISTS `Account` (`id` INTEGER NOT NULL, `host` TEXT NOT NULL, `port` INTEGER NOT NULL, `user` TEXT NOT NULL, `pass` TEXT NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY(`id`))") + database.execSQL("INSERT INTO Account (id, host, port, user, pass, name) SELECT _id AS id, server, port, coalesce(username, ''), coalesce(password, ''), name FROM cores LEFT JOIN user ON user.coreid = cores._id") + + database.execSQL("DROP TABLE IF EXISTS cores") + database.execSQL("DROP TABLE IF EXISTS user") + } + } + ).allowMainThreadQueries().build() + } + } + } + return database!! + } + } + + companion object { + const val DATABASE_NAME = "data" + } +} diff --git a/viewmodel/build.gradle.kts b/viewmodel/build.gradle.kts index 026e5d4a3170c42b9ef66835c6dff12c03c4d65d..6a24107d6bb3d2a99fafc13541123c37af5547bd 100644 --- a/viewmodel/build.gradle.kts +++ b/viewmodel/build.gradle.kts @@ -36,28 +36,6 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* - * Quasseldroid - Quassel client for Android - * - * Copyright (c) 2018 Janne Koschinski - * Copyright (c) 2018 Ken Børge Viktil - * Copyright (c) 2018 Magnus Fjell - * Copyright (c) 2018 Martin Sandsmark - * Copyright (c) 2018 The Quassel Project - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3 as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - plugins { id("com.android.library") kotlin("android")