diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-03-20 14:13:54 +0530 |
---|---|---|
committer | Aditya Wasan <adityawasan55@gmail.com> | 2020-03-20 14:48:53 +0530 |
commit | 793abd690d8aa68ba3a97f4465a55560ac7dbb1f (patch) | |
tree | 8f59ff469a1e292c2779fdc44a0f229fcb967c58 /app/src/main | |
parent | 0aeb51efa444223cddcb3a89f66f2410675b47af (diff) |
Codestyle cleanup
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main')
12 files changed, 68 insertions, 61 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt b/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt index eb41d374..c7c5ee84 100644 --- a/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt +++ b/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt @@ -148,6 +148,7 @@ class ClipboardService : Service() { } } } + companion object { private const val ACTION_CLEAR = "ACTION_CLEAR_CLIPBOARD" private const val ACTION_START = "ACTION_START_CLIPBOARD_TIMER" diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index f0e5645a..e4c94a56 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -115,9 +115,9 @@ class PasswordStore : AppCompatActivity() { != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) { val snack = Snackbar.make( - findViewById(R.id.main_layout), - getString(R.string.access_sdcard_text), - Snackbar.LENGTH_INDEFINITE) + findViewById(R.id.main_layout), + getString(R.string.access_sdcard_text), + Snackbar.LENGTH_INDEFINITE) .setAction(R.string.dialog_ok) { ActivityCompat.requestPermissions( activity, @@ -614,9 +614,9 @@ class PasswordStore : AppCompatActivity() { } REQUEST_CODE_SELECT_FOLDER -> { Timber.tag(TAG) - .d("Moving passwords to ${data!!.getStringExtra("SELECTED_FOLDER_PATH")}") + .d("Moving passwords to ${data!!.getStringExtra("SELECTED_FOLDER_PATH")}") Timber.tag(TAG).d( - TextUtils.join(", ", requireNotNull(data.getStringArrayListExtra("Files"))) + TextUtils.join(", ", requireNotNull(data.getStringArrayListExtra("Files"))) ) val target = File(requireNotNull(data.getStringExtra("SELECTED_FOLDER_PATH"))) diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt index 24ed62df..2a8f584d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt @@ -123,7 +123,8 @@ class UserPreference : AppCompatActivity() { OpenPgpUtils.convertKeyIdToHex(java.lang.Long.valueOf(s)) } } - openkeystoreIdPreference?.isVisible = sharedPreferences.getString("ssh_openkeystore_keyid", null)?.isNotEmpty() ?: false + openkeystoreIdPreference?.isVisible = sharedPreferences.getString("ssh_openkeystore_keyid", null)?.isNotEmpty() + ?: false // see if the autofill service is enabled and check the preference accordingly autoFillEnablePreference?.isChecked = callingActivity.isServiceEnabled @@ -332,12 +333,12 @@ class UserPreference : AppCompatActivity() { val prefPwgenType = findPreference<ListPreference>("pref_key_pwgen_type") showHideDependentPrefs(prefPwgenType?.value, prefIsCustomDict, prefCustomDictPicker) - prefPwgenType?.onPreferenceChangeListener = ChangeListener() { _, newValue -> + prefPwgenType?.onPreferenceChangeListener = ChangeListener { _, newValue -> showHideDependentPrefs(newValue, prefIsCustomDict, prefCustomDictPicker) true } - prefIsCustomDict?.onPreferenceChangeListener = ChangeListener() { _, newValue -> + prefIsCustomDict?.onPreferenceChangeListener = ChangeListener { _, newValue -> if (!(newValue as Boolean)) { val customDictFile = File(context.filesDir, XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE) if (customDictFile.exists()) { @@ -688,7 +689,7 @@ class UserPreference : AppCompatActivity() { @JvmStatic private fun setCustomDictSummary(customDictPref: Preference?, uri: Uri) { val fileName = uri.path?.substring(uri.path?.lastIndexOf(":")!! + 1) - customDictPref?.setSummary("Selected dictionary: " + fileName) + customDictPref?.summary = "Selected dictionary: " + fileName } } } diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt index 9e4a7130..6f09ca5a 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -313,8 +313,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { null } else { HoldToShowPasswordTransformation( - crypto_password_toggle_show, - Runnable { crypto_password_show.text = entry.password } + crypto_password_toggle_show, + Runnable { crypto_password_show.text = entry.password } ) } @@ -367,19 +367,19 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { if (entry.hasTotp()) { crypto_copy_otp.setOnClickListener { copyOtpToClipBoard( - Otp.calculateCode( - entry.totpSecret, - Date().time / (1000 * entry.totpPeriod), - entry.totpAlgorithm, - entry.digits) + Otp.calculateCode( + entry.totpSecret, + Date().time / (1000 * entry.totpPeriod), + entry.totpAlgorithm, + entry.digits) ) } crypto_otp_show.text = - Otp.calculateCode( - entry.totpSecret, - Date().time / (1000 * entry.totpPeriod), - entry.totpAlgorithm, - entry.digits) + Otp.calculateCode( + entry.totpSecret, + Date().time / (1000 * entry.totpPeriod), + entry.totpAlgorithm, + entry.digits) } else { // we only want to calculate and show HOTP if the user requests it crypto_copy_otp.setOnClickListener { @@ -394,31 +394,31 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { val checkInflater = LayoutInflater.from(this@PgpActivity) val checkLayout = checkInflater.inflate(R.layout.otp_confirm_layout, null) val rememberCheck: CheckBox = - checkLayout.findViewById(R.id.hotp_remember_checkbox) + checkLayout.findViewById(R.id.hotp_remember_checkbox) val dialogBuilder = MaterialAlertDialogBuilder(this@PgpActivity) dialogBuilder.setView(checkLayout) dialogBuilder.setMessage(R.string.dialog_update_body) - .setCancelable(false) - .setPositiveButton(R.string.dialog_update_positive) { _, _ -> - run { - calculateAndCommitHotp(entry) - if (rememberCheck.isChecked) { + .setCancelable(false) + .setPositiveButton(R.string.dialog_update_positive) { _, _ -> + run { + calculateAndCommitHotp(entry) + if (rememberCheck.isChecked) { + val editor = settings.edit() + editor.putBoolean("hotp_remember_check", true) + editor.putBoolean("hotp_remember_choice", true) + editor.apply() + } + } + } + .setNegativeButton(R.string.dialog_update_negative) { _, _ -> + run { + calculateHotp(entry) val editor = settings.edit() editor.putBoolean("hotp_remember_check", true) - editor.putBoolean("hotp_remember_choice", true) + editor.putBoolean("hotp_remember_choice", false) editor.apply() } } - } - .setNegativeButton(R.string.dialog_update_negative) { _, _ -> - run { - calculateHotp(entry) - val editor = settings.edit() - editor.putBoolean("hotp_remember_check", true) - editor.putBoolean("hotp_remember_choice", false) - editor.apply() - } - } val updateDialog = dialogBuilder.create() updateDialog.setTitle(R.string.dialog_update_title) updateDialog.show() @@ -606,7 +606,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { RESULT_CODE_SUCCESS -> { try { val ids = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS) - ?: LongArray(0) + ?: LongArray(0) val keys = ids.map { it.toString() }.toSet() // use Long diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.kt index 19cbfbfc..6341fbe1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.kt @@ -658,6 +658,7 @@ open class GitActivity : AppCompatActivity() { const val REQUEST_INIT = 104 const val EDIT_SERVER = 105 const val REQUEST_SYNC = 106 + @Suppress("Unused") const val REQUEST_CREATE = 107 const val EDIT_GIT_CONFIG = 108 diff --git a/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/XkpwdDictionary.kt b/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/XkpwdDictionary.kt index 27f8fbd0..6a3fbcc3 100644 --- a/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/XkpwdDictionary.kt +++ b/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/XkpwdDictionary.kt @@ -34,7 +34,7 @@ class XkpwdDictionary(context: Context) { } if (lines.isEmpty()) { - lines = context.getResources().openRawResource(R.raw.xkpwdict).bufferedReader().readLines() + lines = context.resources.openRawResource(R.raw.xkpwdict).bufferedReader().readLines() } for (word in lines) { diff --git a/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt b/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt index e3395d41..7182aac0 100644 --- a/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt @@ -43,7 +43,7 @@ class ShowSshKeyFragment : DialogFragment() { b.setOnClickListener { val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clip = ClipData.newPlainText("public key", publicKey.text.toString()) - clipboard.setPrimaryClip(clip) + clipboard.primaryClip = clip } } return ad diff --git a/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt b/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt index 858cba4a..fc9c84bc 100644 --- a/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt +++ b/app/src/main/java/com/zeapo/pwdstore/ui/adapters/EntryRecyclerAdapter.kt @@ -87,7 +87,8 @@ abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList<P // Replace the contents of a view (invoked by the layout manager) override fun onBindViewHolder(holder: ViewHolder, position: Int) { - settings = settings ?: PreferenceManager.getDefaultSharedPreferences(holder.view.context.applicationContext) + settings = settings + ?: PreferenceManager.getDefaultSharedPreferences(holder.view.context.applicationContext) val pass = values[position] val showHidden = settings?.getBoolean("show_hidden_folders", false) ?: false holder.name.text = pass.toString() diff --git a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt index 26b6190f..77c54f6f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt @@ -31,7 +31,7 @@ class PasswordGeneratorDialogFragment : DialogFragment() { val monoTypeface = Typeface.createFromAsset(callingActivity.assets, "fonts/sourcecodepro.ttf") builder.setView(view) val prefs = requireActivity().applicationContext - .getSharedPreferences("PasswordGenerator", Context.MODE_PRIVATE) + .getSharedPreferences("PasswordGenerator", Context.MODE_PRIVATE) view.findViewById<CheckBox>(R.id.numerals)?.isChecked = !prefs.getBoolean("0", false) view.findViewById<CheckBox>(R.id.symbols)?.isChecked = prefs.getBoolean("y", false) diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt index 8947f43a..1cf8fea0 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -79,7 +79,7 @@ open class PasswordRepository protected constructor() { fun isGitRepo(): Boolean { if (repository != null) { // Check if remote exists - return repository!!.config.getSubsections("remote").isNotEmpty() ?: false + return repository!!.config.getSubsections("remote").isNotEmpty() } return false } diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/auth/AuthenticationResult.kt b/app/src/main/java/com/zeapo/pwdstore/utils/auth/AuthenticationResult.kt index b6f8de73..6bde6360 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/auth/AuthenticationResult.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/auth/AuthenticationResult.kt @@ -9,10 +9,13 @@ import androidx.biometric.BiometricPrompt internal sealed class AuthenticationResult { internal data class Success(val cryptoObject: BiometricPrompt.CryptoObject?) : AuthenticationResult() + internal data class RecoverableError(val code: Int, val message: CharSequence) : AuthenticationResult() + internal data class UnrecoverableError(val code: Int, val message: CharSequence) : AuthenticationResult() + internal object Failure : AuthenticationResult() internal object Cancelled : AuthenticationResult() } diff --git a/app/src/main/java/com/zeapo/pwdstore/widget/fab/EmitExpandableTransformationBehaviour.kt b/app/src/main/java/com/zeapo/pwdstore/widget/fab/EmitExpandableTransformationBehaviour.kt index 57fa7d4e..6cefda14 100644 --- a/app/src/main/java/com/zeapo/pwdstore/widget/fab/EmitExpandableTransformationBehaviour.kt +++ b/app/src/main/java/com/zeapo/pwdstore/widget/fab/EmitExpandableTransformationBehaviour.kt @@ -63,16 +63,16 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor( val set = AnimatorSet() set.playTogether(animations) set.addListener( - onStart = { - if (expanded) { - child.isVisible = true + onStart = { + if (expanded) { + child.isVisible = true + } + }, + onEnd = { + if (!expanded) { + child.isInvisible = true + } } - }, - onEnd = { - if (!expanded) { - child.isInvisible = true - } - } ) return set } @@ -97,10 +97,10 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor( val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 1f) val animators = child.children.zip(delays) { view, delay -> ObjectAnimator.ofPropertyValuesHolder( - view, - scaleXHolder, - scaleYHolder, - alphaHolder + view, + scaleXHolder, + scaleYHolder, + alphaHolder ).apply { duration = EXPAND_DURATION startDelay = delay @@ -124,10 +124,10 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor( val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 0f) val animators = child.children.zip(delays) { view, delay -> ObjectAnimator.ofPropertyValuesHolder( - view, - scaleXHolder, - scaleYHolder, - alphaHolder + view, + scaleXHolder, + scaleYHolder, + alphaHolder ).apply { duration = COLLAPSE_DURATION startDelay = delay |