mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-01-22 03:19:55 -06:00
lint improvements
This commit is contained in:
@@ -15,7 +15,6 @@ import javax.inject.Inject
|
||||
@HiltAndroidApp
|
||||
class MyApplication : Application(), Configuration.Provider {
|
||||
|
||||
|
||||
@Inject
|
||||
lateinit var workerFactory: HiltWorkerFactory
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.yogeshpaliyal.keypass.constants
|
||||
|
||||
annotation class AccountType(){
|
||||
companion object{
|
||||
annotation class AccountType() {
|
||||
companion object {
|
||||
const val DEFAULT = 1 // used to store password and user information
|
||||
const val TOTP = 2 // used to store Time base - One time Password
|
||||
/* const val HOTP = 3
|
||||
|
||||
@@ -2,4 +2,4 @@ package com.yogeshpaliyal.keypass.constants
|
||||
|
||||
object IntentKeys {
|
||||
const val SCANNED_TEXT = "scanned_text"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ package com.yogeshpaliyal.keypass.constants
|
||||
|
||||
object RequestCodes {
|
||||
const val SCANNER = 342
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,18 +60,18 @@ data class AccountModel(
|
||||
) : BaseDiffUtil, UniversalViewType {
|
||||
|
||||
fun getInitials() = (
|
||||
title?.firstOrNull() ?: username?.firstOrNull() ?: site?.firstOrNull()
|
||||
title?.firstOrNull() ?: username?.firstOrNull() ?: site?.firstOrNull()
|
||||
?: notes?.firstOrNull() ?: 'K'
|
||||
).toString()
|
||||
).toString()
|
||||
|
||||
override fun getDiffId(): Any? {
|
||||
return id
|
||||
}
|
||||
|
||||
override fun getDiffBody(): Any? {
|
||||
return if(type == AccountType.TOTP){
|
||||
return if (type == AccountType.TOTP) {
|
||||
super.getDiffBody()
|
||||
}else{
|
||||
} else {
|
||||
Gson().toJson(this)
|
||||
}
|
||||
}
|
||||
@@ -80,5 +80,5 @@ data class AccountModel(
|
||||
|
||||
fun getTOtpProgress() = TOTPHelper.getProgress().toInt()
|
||||
|
||||
override fun getLayoutId(): Int = if(type == AccountType.TOTP) R.layout.item_totp else R.layout.item_accounts
|
||||
override fun getLayoutId(): Int = if (type == AccountType.TOTP) R.layout.item_totp else R.layout.item_accounts
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ data class TOtpModel(
|
||||
@SerializedName("account_name")
|
||||
val accountName: String? = null
|
||||
|
||||
) :BaseDiffUtil, UniversalViewType {
|
||||
) : BaseDiffUtil, UniversalViewType {
|
||||
override fun getLayoutId() = R.layout.item_totp
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ abstract class DbDao {
|
||||
abstract suspend fun insertOrUpdateAccount(vararg accountModel: AccountModel)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract suspend fun insertOrUpdateAccount(accountModel: List<AccountModel>)
|
||||
abstract suspend fun insertOrUpdateAccount(accountModel: List<AccountModel>)
|
||||
|
||||
@Query("SELECT * FROM account ORDER BY title ASC")
|
||||
abstract fun getAllAccounts(): LiveData<List<AccountModel>>
|
||||
|
||||
@@ -6,7 +6,6 @@ import androidx.room.Room
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.yogeshpaliyal.keypass.AppDatabase
|
||||
import com.yogeshpaliyal.keypass.MyApplication
|
||||
import com.yogeshpaliyal.keypass.R
|
||||
import com.yogeshpaliyal.keypass.utils.MySharedPreferences
|
||||
import com.yogeshpaliyal.keypass.utils.getRandomString
|
||||
@@ -39,11 +38,10 @@ object AppModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addMigrations(object : Migration(4,5){
|
||||
}).addMigrations(object : Migration(4, 5) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE `account` ADD COLUMN `type` INT DEFAULT 0")
|
||||
}
|
||||
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import com.yogeshpaliyal.keypass.databinding.ActivityAddTotpactivityBinding
|
||||
import com.yogeshpaliyal.keypass.utils.TOTPHelper
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AddTOTPActivity : AppCompatActivity() {
|
||||
|
||||
@@ -63,22 +62,27 @@ class AddTOTPActivity : AppCompatActivity() {
|
||||
IntentIntegrator(this).setPrompt("").initiateScan()
|
||||
}
|
||||
|
||||
mViewModel.error.observe(this, Observer {
|
||||
it?.getContentIfNotHandled()?.let {
|
||||
Snackbar.make(binding.root, it, Snackbar.LENGTH_SHORT).show()
|
||||
mViewModel.error.observe(
|
||||
this,
|
||||
Observer {
|
||||
it?.getContentIfNotHandled()?.let {
|
||||
Snackbar.make(binding.root, it, Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
mViewModel.goBack.observe(this, Observer {
|
||||
it.getContentIfNotHandled()?.let {
|
||||
onBackPressed()
|
||||
mViewModel.goBack.observe(
|
||||
this,
|
||||
Observer {
|
||||
it.getContentIfNotHandled()?.let {
|
||||
onBackPressed()
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
binding.btnSave.setOnClickListener {
|
||||
mViewModel.saveAccount(accountId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
@@ -94,7 +98,6 @@ class AddTOTPActivity : AppCompatActivity() {
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
|
||||
private fun deleteAccount() {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(getString(R.string.delete_account_title))
|
||||
@@ -133,7 +136,6 @@ class AddTOTPActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
if (requestCode == IntentIntegrator.REQUEST_CODE && resultCode == RESULT_OK) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import javax.inject.Inject
|
||||
@HiltViewModel
|
||||
class AddTOTPViewModel @Inject constructor(private val appDatabase: AppDatabase) : ViewModel() {
|
||||
|
||||
|
||||
private val _goBack = MutableLiveData<Event<Unit>>()
|
||||
val goBack: LiveData<Event<Unit>> = _goBack
|
||||
|
||||
@@ -28,7 +27,7 @@ class AddTOTPViewModel @Inject constructor(private val appDatabase: AppDatabase)
|
||||
|
||||
val accountName = MutableLiveData<String>("")
|
||||
|
||||
fun loadOldAccount(accountId: String?){
|
||||
fun loadOldAccount(accountId: String?) {
|
||||
accountId ?: return
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
@@ -78,5 +77,4 @@ class AddTOTPViewModel @Inject constructor(private val appDatabase: AppDatabase)
|
||||
onDeleted()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ class ScannerActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityScannerBinding
|
||||
|
||||
|
||||
private val REQUEST_CAM_PERMISSION = 432
|
||||
|
||||
companion object {
|
||||
@@ -36,11 +35,8 @@ class ScannerActivity : AppCompatActivity() {
|
||||
binding.toolbar.setNavigationOnClickListener {
|
||||
onBackPressed()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
@@ -54,8 +50,6 @@ class ScannerActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun isAllRequestGranted(grantResults: IntArray) =
|
||||
grantResults.all { it == PackageManager.PERMISSION_GRANTED }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,15 +43,12 @@ class DashboardViewModel @Inject constructor(application: Application, val appDb
|
||||
reloadData()
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun reloadData(){
|
||||
private fun reloadData() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
while (true){
|
||||
while (true) {
|
||||
delay(1000)
|
||||
mediator.postValue(appDao.getAllAccounts(keyword.value, tag.value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ class HomeFragment : Fragment() {
|
||||
|
||||
val mListener = object : AccountsClickListener<AccountModel> {
|
||||
override fun onItemClick(view: View, model: AccountModel) {
|
||||
if (model.type == AccountType.TOTP){
|
||||
if (model.type == AccountType.TOTP) {
|
||||
AddTOTPActivity.start(context, model.uniqueId)
|
||||
}else {
|
||||
} else {
|
||||
DetailActivity.start(context, model.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ class BottomNavDrawerFragment :
|
||||
}
|
||||
|
||||
override fun onNavMenuItemClicked(item: NavigationModelItem.NavMenuItem) {
|
||||
//mViewModel.setNavigationMenuItemChecked(item.id)
|
||||
// mViewModel.setNavigationMenuItemChecked(item.id)
|
||||
close()
|
||||
navigationListeners.forEach { it.onNavMenuItemClicked(item) }
|
||||
}
|
||||
|
||||
@@ -5,23 +5,23 @@ package com.yogeshpaliyal.keypass.utils
|
||||
|
||||
open class Event<out T>(private val content: T) {
|
||||
|
||||
var hasBeenHandled = false
|
||||
private set // Allow external read but not write
|
||||
var hasBeenHandled = false
|
||||
private set // Allow external read but not write
|
||||
|
||||
/**
|
||||
* Returns the content and prevents its use again.
|
||||
*/
|
||||
fun getContentIfNotHandled(): T? {
|
||||
return if (hasBeenHandled) {
|
||||
null
|
||||
} else {
|
||||
hasBeenHandled = true
|
||||
content
|
||||
/**
|
||||
* Returns the content and prevents its use again.
|
||||
*/
|
||||
fun getContentIfNotHandled(): T? {
|
||||
return if (hasBeenHandled) {
|
||||
null
|
||||
} else {
|
||||
hasBeenHandled = true
|
||||
content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content, even if it's already been handled.
|
||||
*/
|
||||
fun peekContent(): T = content
|
||||
}
|
||||
/**
|
||||
* Returns the content, even if it's already been handled.
|
||||
*/
|
||||
fun peekContent(): T = content
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyProperties
|
||||
import androidx.security.crypto.EncryptedSharedPreferences
|
||||
import androidx.security.crypto.MasterKey
|
||||
import com.yogeshpaliyal.keypass.MyApplication
|
||||
|
||||
class MySharedPreferences(context: Context) {
|
||||
private val masterKeyAlias = MasterKey.Builder(context).also {
|
||||
|
||||
Reference in New Issue
Block a user