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