Codestyle cleanup

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-03-20 14:13:54 +05:30 committed by Aditya Wasan
parent 0aeb51efa4
commit 793abd690d
12 changed files with 68 additions and 61 deletions

View file

@ -148,6 +148,7 @@ class ClipboardService : Service() {
} }
} }
} }
companion object { companion object {
private const val ACTION_CLEAR = "ACTION_CLEAR_CLIPBOARD" private const val ACTION_CLEAR = "ACTION_CLEAR_CLIPBOARD"
private const val ACTION_START = "ACTION_START_CLIPBOARD_TIMER" private const val ACTION_START = "ACTION_START_CLIPBOARD_TIMER"

View file

@ -115,9 +115,9 @@ class PasswordStore : AppCompatActivity() {
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) {
val snack = Snackbar.make( val snack = Snackbar.make(
findViewById(R.id.main_layout), findViewById(R.id.main_layout),
getString(R.string.access_sdcard_text), getString(R.string.access_sdcard_text),
Snackbar.LENGTH_INDEFINITE) Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.dialog_ok) { .setAction(R.string.dialog_ok) {
ActivityCompat.requestPermissions( ActivityCompat.requestPermissions(
activity, activity,
@ -614,9 +614,9 @@ class PasswordStore : AppCompatActivity() {
} }
REQUEST_CODE_SELECT_FOLDER -> { REQUEST_CODE_SELECT_FOLDER -> {
Timber.tag(TAG) 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( 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"))) val target = File(requireNotNull(data.getStringExtra("SELECTED_FOLDER_PATH")))

View file

@ -123,7 +123,8 @@ class UserPreference : AppCompatActivity() {
OpenPgpUtils.convertKeyIdToHex(java.lang.Long.valueOf(s)) 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 // see if the autofill service is enabled and check the preference accordingly
autoFillEnablePreference?.isChecked = callingActivity.isServiceEnabled autoFillEnablePreference?.isChecked = callingActivity.isServiceEnabled
@ -332,12 +333,12 @@ class UserPreference : AppCompatActivity() {
val prefPwgenType = findPreference<ListPreference>("pref_key_pwgen_type") val prefPwgenType = findPreference<ListPreference>("pref_key_pwgen_type")
showHideDependentPrefs(prefPwgenType?.value, prefIsCustomDict, prefCustomDictPicker) showHideDependentPrefs(prefPwgenType?.value, prefIsCustomDict, prefCustomDictPicker)
prefPwgenType?.onPreferenceChangeListener = ChangeListener() { _, newValue -> prefPwgenType?.onPreferenceChangeListener = ChangeListener { _, newValue ->
showHideDependentPrefs(newValue, prefIsCustomDict, prefCustomDictPicker) showHideDependentPrefs(newValue, prefIsCustomDict, prefCustomDictPicker)
true true
} }
prefIsCustomDict?.onPreferenceChangeListener = ChangeListener() { _, newValue -> prefIsCustomDict?.onPreferenceChangeListener = ChangeListener { _, newValue ->
if (!(newValue as Boolean)) { if (!(newValue as Boolean)) {
val customDictFile = File(context.filesDir, XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE) val customDictFile = File(context.filesDir, XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE)
if (customDictFile.exists()) { if (customDictFile.exists()) {
@ -688,7 +689,7 @@ class UserPreference : AppCompatActivity() {
@JvmStatic @JvmStatic
private fun setCustomDictSummary(customDictPref: Preference?, uri: Uri) { private fun setCustomDictSummary(customDictPref: Preference?, uri: Uri) {
val fileName = uri.path?.substring(uri.path?.lastIndexOf(":")!! + 1) val fileName = uri.path?.substring(uri.path?.lastIndexOf(":")!! + 1)
customDictPref?.setSummary("Selected dictionary: " + fileName) customDictPref?.summary = "Selected dictionary: " + fileName
} }
} }
} }

View file

@ -313,8 +313,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
null null
} else { } else {
HoldToShowPasswordTransformation( HoldToShowPasswordTransformation(
crypto_password_toggle_show, crypto_password_toggle_show,
Runnable { crypto_password_show.text = entry.password } Runnable { crypto_password_show.text = entry.password }
) )
} }
@ -367,19 +367,19 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
if (entry.hasTotp()) { if (entry.hasTotp()) {
crypto_copy_otp.setOnClickListener { crypto_copy_otp.setOnClickListener {
copyOtpToClipBoard( copyOtpToClipBoard(
Otp.calculateCode( Otp.calculateCode(
entry.totpSecret, entry.totpSecret,
Date().time / (1000 * entry.totpPeriod), Date().time / (1000 * entry.totpPeriod),
entry.totpAlgorithm, entry.totpAlgorithm,
entry.digits) entry.digits)
) )
} }
crypto_otp_show.text = crypto_otp_show.text =
Otp.calculateCode( Otp.calculateCode(
entry.totpSecret, entry.totpSecret,
Date().time / (1000 * entry.totpPeriod), Date().time / (1000 * entry.totpPeriod),
entry.totpAlgorithm, entry.totpAlgorithm,
entry.digits) entry.digits)
} else { } else {
// we only want to calculate and show HOTP if the user requests it // we only want to calculate and show HOTP if the user requests it
crypto_copy_otp.setOnClickListener { crypto_copy_otp.setOnClickListener {
@ -394,31 +394,31 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val checkInflater = LayoutInflater.from(this@PgpActivity) val checkInflater = LayoutInflater.from(this@PgpActivity)
val checkLayout = checkInflater.inflate(R.layout.otp_confirm_layout, null) val checkLayout = checkInflater.inflate(R.layout.otp_confirm_layout, null)
val rememberCheck: CheckBox = val rememberCheck: CheckBox =
checkLayout.findViewById(R.id.hotp_remember_checkbox) checkLayout.findViewById(R.id.hotp_remember_checkbox)
val dialogBuilder = MaterialAlertDialogBuilder(this@PgpActivity) val dialogBuilder = MaterialAlertDialogBuilder(this@PgpActivity)
dialogBuilder.setView(checkLayout) dialogBuilder.setView(checkLayout)
dialogBuilder.setMessage(R.string.dialog_update_body) dialogBuilder.setMessage(R.string.dialog_update_body)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.dialog_update_positive) { _, _ -> .setPositiveButton(R.string.dialog_update_positive) { _, _ ->
run { run {
calculateAndCommitHotp(entry) calculateAndCommitHotp(entry)
if (rememberCheck.isChecked) { 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() val editor = settings.edit()
editor.putBoolean("hotp_remember_check", true) editor.putBoolean("hotp_remember_check", true)
editor.putBoolean("hotp_remember_choice", true) editor.putBoolean("hotp_remember_choice", false)
editor.apply() 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() val updateDialog = dialogBuilder.create()
updateDialog.setTitle(R.string.dialog_update_title) updateDialog.setTitle(R.string.dialog_update_title)
updateDialog.show() updateDialog.show()
@ -606,7 +606,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
RESULT_CODE_SUCCESS -> { RESULT_CODE_SUCCESS -> {
try { try {
val ids = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS) val ids = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS)
?: LongArray(0) ?: LongArray(0)
val keys = ids.map { it.toString() }.toSet() val keys = ids.map { it.toString() }.toSet()
// use Long // use Long

View file

@ -658,6 +658,7 @@ open class GitActivity : AppCompatActivity() {
const val REQUEST_INIT = 104 const val REQUEST_INIT = 104
const val EDIT_SERVER = 105 const val EDIT_SERVER = 105
const val REQUEST_SYNC = 106 const val REQUEST_SYNC = 106
@Suppress("Unused") @Suppress("Unused")
const val REQUEST_CREATE = 107 const val REQUEST_CREATE = 107
const val EDIT_GIT_CONFIG = 108 const val EDIT_GIT_CONFIG = 108

View file

@ -34,7 +34,7 @@ class XkpwdDictionary(context: Context) {
} }
if (lines.isEmpty()) { 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) { for (word in lines) {

View file

@ -43,7 +43,7 @@ class ShowSshKeyFragment : DialogFragment() {
b.setOnClickListener { b.setOnClickListener {
val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("public key", publicKey.text.toString()) val clip = ClipData.newPlainText("public key", publicKey.text.toString())
clipboard.setPrimaryClip(clip) clipboard.primaryClip = clip
} }
} }
return ad return ad

View file

@ -87,7 +87,8 @@ abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList<P
// Replace the contents of a view (invoked by the layout manager) // Replace the contents of a view (invoked by the layout manager)
override fun onBindViewHolder(holder: ViewHolder, position: Int) { 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 pass = values[position]
val showHidden = settings?.getBoolean("show_hidden_folders", false) ?: false val showHidden = settings?.getBoolean("show_hidden_folders", false) ?: false
holder.name.text = pass.toString() holder.name.text = pass.toString()

View file

@ -31,7 +31,7 @@ class PasswordGeneratorDialogFragment : DialogFragment() {
val monoTypeface = Typeface.createFromAsset(callingActivity.assets, "fonts/sourcecodepro.ttf") val monoTypeface = Typeface.createFromAsset(callingActivity.assets, "fonts/sourcecodepro.ttf")
builder.setView(view) builder.setView(view)
val prefs = requireActivity().applicationContext 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.numerals)?.isChecked = !prefs.getBoolean("0", false)
view.findViewById<CheckBox>(R.id.symbols)?.isChecked = prefs.getBoolean("y", false) view.findViewById<CheckBox>(R.id.symbols)?.isChecked = prefs.getBoolean("y", false)

View file

@ -79,7 +79,7 @@ open class PasswordRepository protected constructor() {
fun isGitRepo(): Boolean { fun isGitRepo(): Boolean {
if (repository != null) { if (repository != null) {
// Check if remote exists // Check if remote exists
return repository!!.config.getSubsections("remote").isNotEmpty() ?: false return repository!!.config.getSubsections("remote").isNotEmpty()
} }
return false return false
} }

View file

@ -9,10 +9,13 @@ import androidx.biometric.BiometricPrompt
internal sealed class AuthenticationResult { internal sealed class AuthenticationResult {
internal data class Success(val cryptoObject: BiometricPrompt.CryptoObject?) : internal data class Success(val cryptoObject: BiometricPrompt.CryptoObject?) :
AuthenticationResult() AuthenticationResult()
internal data class RecoverableError(val code: Int, val message: CharSequence) : internal data class RecoverableError(val code: Int, val message: CharSequence) :
AuthenticationResult() AuthenticationResult()
internal data class UnrecoverableError(val code: Int, val message: CharSequence) : internal data class UnrecoverableError(val code: Int, val message: CharSequence) :
AuthenticationResult() AuthenticationResult()
internal object Failure : AuthenticationResult() internal object Failure : AuthenticationResult()
internal object Cancelled : AuthenticationResult() internal object Cancelled : AuthenticationResult()
} }

View file

@ -63,16 +63,16 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor(
val set = AnimatorSet() val set = AnimatorSet()
set.playTogether(animations) set.playTogether(animations)
set.addListener( set.addListener(
onStart = { onStart = {
if (expanded) { if (expanded) {
child.isVisible = true child.isVisible = true
}
},
onEnd = {
if (!expanded) {
child.isInvisible = true
}
} }
},
onEnd = {
if (!expanded) {
child.isInvisible = true
}
}
) )
return set return set
} }
@ -97,10 +97,10 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor(
val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 1f) val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 1f)
val animators = child.children.zip(delays) { view, delay -> val animators = child.children.zip(delays) { view, delay ->
ObjectAnimator.ofPropertyValuesHolder( ObjectAnimator.ofPropertyValuesHolder(
view, view,
scaleXHolder, scaleXHolder,
scaleYHolder, scaleYHolder,
alphaHolder alphaHolder
).apply { ).apply {
duration = EXPAND_DURATION duration = EXPAND_DURATION
startDelay = delay startDelay = delay
@ -124,10 +124,10 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor(
val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 0f) val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 0f)
val animators = child.children.zip(delays) { view, delay -> val animators = child.children.zip(delays) { view, delay ->
ObjectAnimator.ofPropertyValuesHolder( ObjectAnimator.ofPropertyValuesHolder(
view, view,
scaleXHolder, scaleXHolder,
scaleYHolder, scaleYHolder,
alphaHolder alphaHolder
).apply { ).apply {
duration = COLLAPSE_DURATION duration = COLLAPSE_DURATION
startDelay = delay startDelay = delay