mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-01-11 01:09:42 -06:00
Fixes
This commit is contained in:
@@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.yogeshpaliyal.common.AppDatabase
|
||||
import com.yogeshpaliyal.common.constants.AccountType
|
||||
import com.yogeshpaliyal.common.data.AccountModel
|
||||
import com.yogeshpaliyal.common.utils.Event
|
||||
@@ -14,7 +15,8 @@ import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AddTOTPViewModel @Inject constructor(private val appDatabase: com.yogeshpaliyal.common.AppDatabase) : ViewModel() {
|
||||
class AddTOTPViewModel @Inject constructor(private val appDatabase: AppDatabase) :
|
||||
ViewModel() {
|
||||
|
||||
private val _goBack = MutableLiveData<Event<Unit>>()
|
||||
val goBack: LiveData<Event<Unit>> = _goBack
|
||||
|
||||
@@ -27,10 +27,11 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val CHOOSE_BACKUPS_LOCATION_REQUEST_CODE = 26212
|
||||
private const val CHOOSE_RESTORE_FILE_REQUEST_CODE = 26213
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MySettingsFragment : PreferenceFragmentCompat() {
|
||||
private val CHOOSE_BACKUPS_LOCATION_REQUEST_CODE = 26212
|
||||
private val CHOOSE_RESTORE_FILE_REQUEST_CODE = 26213
|
||||
|
||||
@Inject
|
||||
lateinit var appDb: com.yogeshpaliyal.common.AppDatabase
|
||||
|
||||
@@ -11,6 +11,11 @@ import com.yogeshpaliyal.common.db.DbDao
|
||||
* https://techpaliyal.com
|
||||
* created on 30-01-2021 20:37
|
||||
*/
|
||||
|
||||
const val DB_VERSION_3 = 3
|
||||
const val DB_VERSION_4 = 4
|
||||
const val DB_VERSION_5 = 5
|
||||
|
||||
@Database(
|
||||
entities = [AccountModel::class],
|
||||
version = 5, exportSchema = false
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.net.Uri
|
||||
import androidx.room.withTransaction
|
||||
import com.google.gson.Gson
|
||||
import com.yogeshpaliyal.common.AppDatabase
|
||||
import com.yogeshpaliyal.common.DB_VERSION_3
|
||||
import com.yogeshpaliyal.common.DB_VERSION_5
|
||||
import com.yogeshpaliyal.common.constants.AccountType
|
||||
import com.yogeshpaliyal.common.data.BackupData
|
||||
import com.yogeshpaliyal.common.utils.getRandomString
|
||||
@@ -44,18 +46,18 @@ suspend fun AppDatabase.restoreBackup(
|
||||
|
||||
val restoredFile = try {
|
||||
EncryptionHelper.doCryptoDecrypt(key, contentResolver.openInputStream(fileUri))
|
||||
} catch (e: Exception) {
|
||||
} catch (e: CryptoException) {
|
||||
e.printStackTrace()
|
||||
return@withContext false
|
||||
}
|
||||
|
||||
return@withContext Gson().fromJson(restoredFile, BackupData::class.java)?.let { data ->
|
||||
if (data.version == 3) {
|
||||
if (data.version == DB_VERSION_3) {
|
||||
for (datum in data.data) {
|
||||
getRandomString().also { datum.uniqueId = it }
|
||||
}
|
||||
}
|
||||
if (data.version < 5) {
|
||||
if (data.version < DB_VERSION_5) {
|
||||
for (datum in data.data) {
|
||||
datum.type = AccountType.DEFAULT
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ import javax.crypto.spec.SecretKeySpec
|
||||
* https://yogeshpaliyal.com
|
||||
* created on 07-02-2021 18:50
|
||||
*/
|
||||
|
||||
private const val BUFFER_SIZE = 4096
|
||||
|
||||
object EncryptionHelper {
|
||||
private const val ALGORITHM = "AES"
|
||||
private const val TRANSFORMATION = "AES/CBC/PKCS5Padding"
|
||||
@@ -47,7 +50,7 @@ object EncryptionHelper {
|
||||
outputFile?.use {
|
||||
val outputStream = it
|
||||
CipherOutputStream(outputStream, cipher).use {
|
||||
inputStream.copyTo(it, 4096)
|
||||
inputStream.copyTo(it, BUFFER_SIZE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import androidx.room.Room
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.yogeshpaliyal.common.AppDatabase
|
||||
import com.yogeshpaliyal.common.DB_VERSION_3
|
||||
import com.yogeshpaliyal.common.DB_VERSION_4
|
||||
import com.yogeshpaliyal.common.DB_VERSION_5
|
||||
import com.yogeshpaliyal.common.R
|
||||
import com.yogeshpaliyal.common.utils.getRandomString
|
||||
import dagger.Module
|
||||
@@ -25,7 +28,7 @@ object AppModule {
|
||||
context,
|
||||
AppDatabase::class.java,
|
||||
context.getString(R.string.app_name)
|
||||
).addMigrations(object : Migration(3, 4) {
|
||||
).addMigrations(object : Migration(DB_VERSION_3, DB_VERSION_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")
|
||||
@@ -36,7 +39,7 @@ object AppModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addMigrations(object : Migration(4, 5) {
|
||||
}).addMigrations(object : Migration(DB_VERSION_4, DB_VERSION_5) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE `account` ADD COLUMN `type` INT DEFAULT 0")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.yogeshpaliyal.keypasscompose.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
@Suppress
|
||||
|
||||
val Purple200 = Color(0xFFBB86FC)
|
||||
val Purple500 = Color(0xFF6200EE)
|
||||
val Purple700 = Color(0xFF3700B3)
|
||||
|
||||
Reference in New Issue
Block a user