mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-01-08 16:37:39 -06:00
spotless issues resolved
This commit is contained in:
@@ -13,7 +13,7 @@ import javax.inject.Inject
|
||||
* created on 22-01-2021 22:41
|
||||
*/
|
||||
@HiltAndroidApp
|
||||
class MyApplication : Application(), Configuration.Provider {
|
||||
class MyApplication : Application(), Configuration.Provider {
|
||||
|
||||
companion object {
|
||||
lateinit var instance: MyApplication
|
||||
@@ -21,7 +21,6 @@ class MyApplication : Application(), Configuration.Provider {
|
||||
@Inject
|
||||
lateinit var workerFactory: HiltWorkerFactory
|
||||
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
instance = this
|
||||
@@ -33,5 +32,4 @@ class MyApplication : Application(), Configuration.Provider {
|
||||
.setWorkerFactory(workerFactory)
|
||||
.build()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
@@ -17,7 +16,6 @@ import com.yogeshpaliyal.keypass.AppDatabase
|
||||
import com.yogeshpaliyal.keypass.R
|
||||
import com.yogeshpaliyal.keypass.databinding.BackupActivityBinding
|
||||
import com.yogeshpaliyal.keypass.databinding.LayoutBackupKeypharseBinding
|
||||
import com.yogeshpaliyal.keypass.db_helper.createBackup
|
||||
import com.yogeshpaliyal.keypass.utils.*
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -81,7 +79,6 @@ class BackupActivity : AppCompatActivity() {
|
||||
if (it.canUserAccessBackupDirectory(sp)) {
|
||||
val selectedDirectory = Uri.parse(getBackupDirectory(sp))
|
||||
backup(selectedDirectory)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,9 +107,9 @@ class BackupActivity : AppCompatActivity() {
|
||||
return super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
|
||||
fun backup(selectedDirectory: Uri){
|
||||
fun backup(selectedDirectory: Uri) {
|
||||
lifecycleScope.launch {
|
||||
context.backupAccounts(sp, appDb,selectedDirectory)?.let { keyPair ->
|
||||
context.backupAccounts(sp, appDb, selectedDirectory)?.let { keyPair ->
|
||||
if (keyPair.first) {
|
||||
val binding = LayoutBackupKeypharseBinding.inflate(layoutInflater)
|
||||
binding.txtCode.text = getOrCreateBackupKey(sp).second
|
||||
@@ -149,11 +146,11 @@ class BackupActivity : AppCompatActivity() {
|
||||
findPreference<Preference>(getString(R.string.settings_stop_backup))?.isVisible = isBackupEnabled
|
||||
|
||||
findPreference<Preference>(getString(R.string.settings_auto_backup))?.isVisible = isBackupEnabled
|
||||
findPreference<Preference>(getString(R.string.settings_auto_backup))?.summary = if(isAutoBackupEnabled) getString(R.string.enabled) else getString(R.string.disabled)
|
||||
findPreference<Preference>(getString(R.string.settings_auto_backup))?.summary = if (isAutoBackupEnabled) getString(R.string.enabled) else getString(R.string.disabled)
|
||||
|
||||
findPreference<PreferenceCategory>(getString(R.string.settings_cat_auto_backup))?.isVisible = isBackupEnabled && isAutoBackupEnabled
|
||||
|
||||
findPreference<Preference>(getString(R.string.settings_override_auto_backup))?.summary = if(sp.overrideAutoBackup()) getString(R.string.enabled) else getString(R.string.disabled)
|
||||
findPreference<Preference>(getString(R.string.settings_override_auto_backup))?.summary = if (sp.overrideAutoBackup()) getString(R.string.enabled) else getString(R.string.disabled)
|
||||
|
||||
findPreference<Preference>(getString(R.string.settings_create_backup))?.isVisible = isBackupEnabled
|
||||
findPreference<Preference>(getString(R.string.settings_create_backup))?.summary = getString(R.string.last_backup_date, getBackupTime(sp).formatCalendar("dd MMM yyyy hh:mm aa"))
|
||||
@@ -198,8 +195,6 @@ class BackupActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun changeBackupFolder() {
|
||||
startBackup()
|
||||
}
|
||||
@@ -212,7 +207,7 @@ class BackupActivity : AppCompatActivity() {
|
||||
clearBackupKey(sp)
|
||||
setBackupDirectory(sp, "")
|
||||
setBackupTime(sp, -1)
|
||||
sp.apply {
|
||||
sp.apply {
|
||||
setOverrideAutoBackup(false)
|
||||
setAutoBackupEnabled(false)
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ import javax.inject.Inject
|
||||
* created on 31-01-2021 11:52
|
||||
*/
|
||||
@HiltViewModel
|
||||
class DetailViewModel @Inject constructor(val app: Application, val appDb: AppDatabase,val sp: SharedPreferences) : AndroidViewModel(app) {
|
||||
class DetailViewModel @Inject constructor(val app: Application, val appDb: AppDatabase, val sp: SharedPreferences) : AndroidViewModel(app) {
|
||||
|
||||
private val _accountModel by lazy { MutableLiveData<AccountModel>() }
|
||||
val accountModel : LiveData<AccountModel> = _accountModel
|
||||
val accountModel: LiveData<AccountModel> = _accountModel
|
||||
|
||||
fun loadAccount(accountId: Long?) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
@@ -35,7 +35,7 @@ class DetailViewModel @Inject constructor(val app: Application, val appDb: AppDa
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteAccount(onExecCompleted : ()->Unit){
|
||||
fun deleteAccount(onExecCompleted: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
accountModel.value?.let {
|
||||
withContext(Dispatchers.IO) {
|
||||
@@ -47,7 +47,7 @@ class DetailViewModel @Inject constructor(val app: Application, val appDb: AppDa
|
||||
}
|
||||
}
|
||||
|
||||
fun insertOrUpdate(onExecCompleted : ()->Unit){
|
||||
fun insertOrUpdate(onExecCompleted: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
accountModel.value?.let {
|
||||
withContext(Dispatchers.IO) {
|
||||
@@ -59,7 +59,7 @@ class DetailViewModel @Inject constructor(val app: Application, val appDb: AppDa
|
||||
}
|
||||
}
|
||||
|
||||
private fun autoBackup(){
|
||||
private fun autoBackup() {
|
||||
app.executeAutoBackup(sp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ fun getRandomString(sizeOfRandomString: Int): String {
|
||||
val sb = StringBuilder(sizeOfRandomString)
|
||||
for (i in 0 until sizeOfRandomString) sb.append(
|
||||
ALLOWED_CHARACTERS[
|
||||
random.nextInt(
|
||||
ALLOWED_CHARACTERS.length
|
||||
)
|
||||
random.nextInt(
|
||||
ALLOWED_CHARACTERS.length
|
||||
)
|
||||
]
|
||||
)
|
||||
return sb.toString()
|
||||
@@ -38,7 +38,6 @@ fun Context?.canUserAccessBackupDirectory(sp: SharedPreferences): Boolean {
|
||||
return backupDirectory != null && backupDirectory.exists() && backupDirectory.canRead() && backupDirectory.canWrite()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Pair (Boolean to check if backup is for first time, is backup is for first time show user alert to save encryption key)
|
||||
* Second Value contains the encryption key
|
||||
@@ -46,23 +45,23 @@ fun Context?.canUserAccessBackupDirectory(sp: SharedPreferences): Boolean {
|
||||
suspend fun Context?.backupAccounts(
|
||||
sp: SharedPreferences,
|
||||
appDb: AppDatabase,
|
||||
selectedDirectory: Uri, fileName: String? = null
|
||||
selectedDirectory: Uri,
|
||||
fileName: String? = null
|
||||
): Pair<Boolean, String>? {
|
||||
|
||||
this ?: return null
|
||||
|
||||
val keyPair = getOrCreateBackupKey(sp)
|
||||
|
||||
val fileName = (fileName ?: "key_pass_backup_${System.currentTimeMillis()}")+".keypass"
|
||||
|
||||
val fileName = (fileName ?: "key_pass_backup_${System.currentTimeMillis()}") + ".keypass"
|
||||
|
||||
val directory = DocumentFile.fromTreeUri(this, selectedDirectory)
|
||||
var docFile = directory?.findFile(fileName)
|
||||
if (docFile == null)
|
||||
docFile = DocumentFile.fromTreeUri(this, selectedDirectory)?.createFile(
|
||||
"*/*",
|
||||
fileName)
|
||||
|
||||
"*/*",
|
||||
fileName
|
||||
)
|
||||
|
||||
val response = appDb.createBackup(
|
||||
keyPair.second,
|
||||
|
||||
@@ -18,7 +18,8 @@ import kotlinx.coroutines.withContext
|
||||
|
||||
@HiltWorker
|
||||
class AutoBackupWorker @AssistedInject constructor(
|
||||
@Assisted val appContext: Context, @Assisted params: WorkerParameters,
|
||||
@Assisted val appContext: Context,
|
||||
@Assisted params: WorkerParameters,
|
||||
val appDatabase: AppDatabase,
|
||||
val sp: SharedPreferences
|
||||
) :
|
||||
@@ -39,4 +40,4 @@ class AutoBackupWorker @AssistedInject constructor(
|
||||
Result.success()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import com.yogeshpaliyal.keypass.utils.isAutoBackupEnabled
|
||||
|
||||
fun Context?.executeAutoBackup(sp: SharedPreferences){
|
||||
fun Context?.executeAutoBackup(sp: SharedPreferences) {
|
||||
this ?: return
|
||||
|
||||
if (sp.isAutoBackupEnabled()) {
|
||||
@@ -16,4 +16,4 @@ fun Context?.executeAutoBackup(sp: SharedPreferences){
|
||||
WorkManager.getInstance(this.applicationContext)
|
||||
.enqueueUniqueWork("AutoBackupWorker", ExistingWorkPolicy.KEEP, work)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user