mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-01-04 09:39:56 -06:00
added file unique id
account sorting in alphabatical order
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.yogeshpaliyal.keypass.data.AccountModel
|
||||
import com.yogeshpaliyal.keypass.db.DbDao
|
||||
import com.yogeshpaliyal.keypass.utils.getRandomString
|
||||
|
||||
|
||||
/*
|
||||
@@ -17,7 +18,7 @@ import com.yogeshpaliyal.keypass.db.DbDao
|
||||
*/
|
||||
@Database(
|
||||
entities = [AccountModel::class],
|
||||
version = 3, exportSchema = false
|
||||
version = 4, exportSchema = false
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
@@ -33,34 +34,22 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
|
||||
synchronized(this) {
|
||||
|
||||
|
||||
_instance = Room.databaseBuilder(
|
||||
MyApplication.instance,
|
||||
AppDatabase::class.java,
|
||||
MyApplication.instance.getString(R.string.app_name)
|
||||
).addCallback(object : Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
}
|
||||
|
||||
override fun onDestructiveMigration(db: SupportSQLiteDatabase) {
|
||||
super.onDestructiveMigration(db)
|
||||
onCreate(db)
|
||||
}
|
||||
|
||||
})
|
||||
/* .addMigrations(object : Migration(3, 4) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
val cursor = database.query("SELECT * FROM account")
|
||||
while(cursor.moveToNext()) {
|
||||
val id = cursor.getLong(cursor.getColumnIndex("id"))
|
||||
val password = cursor.getLong(cursor.getColumnIndex("password"))
|
||||
//-- Hash your password --//
|
||||
database.execSQL("UPDATE account SET password = hashedPassword WHERE id = $id;")
|
||||
).addMigrations(object : Migration(3, 4) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE `account` ADD COLUMN `unique_id` TEXT")
|
||||
database.query("select id,unique_id from `account` where unique_id IS NULL")
|
||||
?.use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getInt(0)
|
||||
database.execSQL("update `medias` set `file_unique_id` = '${getRandomString()}' where `id` = '$id'")
|
||||
}
|
||||
}
|
||||
}
|
||||
})*/
|
||||
}
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.yogeshpaliyal.keypass.data
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.yogeshpaliyal.universal_adapter.model.BaseDiffUtil
|
||||
|
||||
|
||||
@@ -13,25 +14,43 @@ import com.yogeshpaliyal.universal_adapter.model.BaseDiffUtil
|
||||
* created on 30-01-2021 20:38
|
||||
*/
|
||||
@Entity(tableName = "account")
|
||||
class AccountModel(
|
||||
data class AccountModel(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
@SerializedName("id")
|
||||
var id: Long? = null,
|
||||
|
||||
@ColumnInfo(name = "title")
|
||||
@SerializedName("title")
|
||||
var title: String? = null,
|
||||
|
||||
@ColumnInfo(name = "unique_id")
|
||||
@SerializedName("unique_id")
|
||||
var uniqueId: String? = null,
|
||||
|
||||
@ColumnInfo(name = "username")
|
||||
@SerializedName("username")
|
||||
var username: String? = null,
|
||||
|
||||
@ColumnInfo(name = "password")
|
||||
@SerializedName("password")
|
||||
var password: String? = null,
|
||||
|
||||
@ColumnInfo(name = "site")
|
||||
@SerializedName("site")
|
||||
var site: String? = null,
|
||||
|
||||
@ColumnInfo(name = "notes")
|
||||
@SerializedName("notes")
|
||||
var notes: String? = null,
|
||||
|
||||
@ColumnInfo(name = "tags")
|
||||
@SerializedName("tags")
|
||||
var tags: String? = null
|
||||
) : BaseDiffUtil {
|
||||
|
||||
fun getInitials() = (title?.firstOrNull() ?: username?.firstOrNull() ?: site?.firstOrNull() ?: notes?.firstOrNull() ?: 'K').toString()
|
||||
fun getInitials() = (title?.firstOrNull() ?: username?.firstOrNull() ?: site?.firstOrNull()
|
||||
?: notes?.firstOrNull() ?: 'K').toString()
|
||||
|
||||
override fun getDiffId(): Any? {
|
||||
return id
|
||||
|
||||
@@ -25,19 +25,19 @@ abstract class DbDao {
|
||||
abstract fun insertOrUpdateAccount(accountModel: List<AccountModel>)
|
||||
|
||||
|
||||
@Query("SELECT * from account")
|
||||
@Query("SELECT * FROM account ORDER BY title ASC")
|
||||
abstract fun getAllAccounts() : Flow<List<AccountModel>>
|
||||
|
||||
@Query("SELECT * from account where tags = :tag")
|
||||
@Query("SELECT * FROM account WHERE tags = :tag ORDER BY title ASC")
|
||||
abstract fun getAllAccounts(tag: String) : Flow<List<AccountModel>>
|
||||
|
||||
@Query("SELECT * from account where id = :id")
|
||||
@Query("SELECT * FROM account WHERE id = :id")
|
||||
abstract fun getAccount(id: Long?) : AccountModel?
|
||||
|
||||
@Query("SELECT DISTINCT tags from account")
|
||||
@Query("SELECT DISTINCT tags FROM account")
|
||||
abstract fun getTags() : Flow<List<String>>
|
||||
|
||||
@Query("DELETE from account where id = :id")
|
||||
@Query("DELETE from account WHERE id = :id")
|
||||
abstract fun deleteAccount(id: Long?)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user