diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2019-07-30 05:58:59 +0530 |
|---|---|---|
| committer | Harsh Shandilya <msfjarvis@gmail.com> | 2019-07-30 05:59:10 +0530 |
| commit | 80c397ef7b7b7eab19158a59cb438fbb958a9657 (patch) | |
| tree | 8553097cdaad9d70d1121f21ef34021044c6d867 /app/src/main/java/com/zeapo/pwdstore/crypto | |
| parent | f8fae4508ea858b51d11aa615fa71c12aef71db4 (diff) | |
| download | HardenedPass-80c397ef7b7b7eab19158a59cb438fbb958a9657.tar.gz HardenedPass-80c397ef7b7b7eab19158a59cb438fbb958a9657.zip | |
treewide: Reformat
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/crypto')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 96 |
1 files changed, 51 insertions, 45 deletions
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 7416945e..ca6c14e8 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -37,7 +37,11 @@ import com.zeapo.pwdstore.R import com.zeapo.pwdstore.UserPreference import com.zeapo.pwdstore.utils.Otp import kotlinx.android.synthetic.main.decrypt_layout.* -import kotlinx.android.synthetic.main.encrypt_layout.* +import kotlinx.android.synthetic.main.encrypt_layout.crypto_extra_edit +import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_category +import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_edit +import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_file_edit +import kotlinx.android.synthetic.main.encrypt_layout.generate_password import org.apache.commons.io.FileUtils import org.apache.commons.io.FilenameUtils import org.openintents.openpgp.IOpenPgpService2 @@ -75,16 +79,18 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { private val name: String by lazy { getName(fullPath) } private val lastChangedString: CharSequence by lazy { getLastChangedString( - intent.getIntExtra( - "LAST_CHANGED_TIMESTAMP", - -1 - ) + intent.getIntExtra( + "LAST_CHANGED_TIMESTAMP", + -1 + ) ) } private val relativeParentPath: String by lazy { getParentPath(fullPath, repoPath) } val settings: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) } - private val keyIDs: MutableSet<String> by lazy { settings.getStringSet("openpgp_key_ids_set", mutableSetOf()) ?: emptySet() } + private val keyIDs: MutableSet<String> by lazy { + settings.getStringSet("openpgp_key_ids_set", mutableSetOf()) ?: emptySet() + } private var mServiceConnection: OpenPgpServiceConnection? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -192,8 +198,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { val pi: PendingIntent = result.getParcelableExtra(RESULT_INTENT) try { this@PgpActivity.startIntentSenderFromChild( - this@PgpActivity, pi.intentSender, requestCode, - null, 0, 0, 0 + this@PgpActivity, pi.intentSender, requestCode, + null, 0, 0, 0 ) } catch (e: IntentSender.SendIntentException) { Log.e(TAG, "SendIntentException", e) @@ -265,8 +271,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 } ) } @@ -319,19 +325,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 { @@ -346,31 +352,31 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { val checkInflater = LayoutInflater.from(this) 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 = AlertDialog.Builder(this) 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() @@ -602,7 +608,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } private inner class HoldToShowPasswordTransformation constructor(button: Button, private val onToggle: Runnable) : - PasswordTransformationMethod(), View.OnTouchListener { + PasswordTransformationMethod(), View.OnTouchListener { private var shown = false init { @@ -673,10 +679,10 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { sendIntent.putExtra(Intent.EXTRA_TEXT, passwordEntry?.password) sendIntent.type = "text/plain" startActivity( - Intent.createChooser( - sendIntent, - resources.getText(R.string.send_plaintext_password_to) - ) + Intent.createChooser( + sendIntent, + resources.getText(R.string.send_plaintext_password_to) + ) )//Always show a picker to give the user a chance to cancel } @@ -777,8 +783,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { for (i in 0..19) { val count = i.toString() handler.postDelayed( - { clipboard.setPrimaryClip(ClipData.newPlainText(count, count)) }, - (i * 500).toLong() + { clipboard.setPrimaryClip(ClipData.newPlainText(count, count)) }, + (i * 500).toLong() ) } } @@ -815,7 +821,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { * Gets the relative path to the repository */ fun getRelativePath(fullPath: String, repositoryPath: String): String = - fullPath.replace(repositoryPath, "").replace("/+".toRegex(), "/") + fullPath.replace(repositoryPath, "").replace("/+".toRegex(), "/") /** * Gets the Parent path, relative to the repository |
