diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-06-09 13:51:29 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 13:51:29 +0530 |
commit | 426fc924fba28ec898681ad7f7010456554f061e (patch) | |
tree | 195eac25c605a89f4e239578d685928a64675ee0 /app/src/main/java/dev/msfjarvis | |
parent | f968b21bf665975e17ad9b03bcff652000e96ec4 (diff) |
Upgrade ktfmt (#1942)
* build-logic: upgrade ktfmt
* all: reformat
Diffstat (limited to 'app/src/main/java/dev/msfjarvis')
17 files changed, 65 insertions, 38 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/Application.kt b/app/src/main/java/dev/msfjarvis/aps/Application.kt index 0c7def1c..6aa6e53b 100644 --- a/app/src/main/java/dev/msfjarvis/aps/Application.kt +++ b/app/src/main/java/dev/msfjarvis/aps/Application.kt @@ -42,7 +42,8 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere override fun onCreate() { super.onCreate() instance = this - if (BuildConfig.ENABLE_DEBUG_FEATURES || + if ( + BuildConfig.ENABLE_DEBUG_FEATURES || prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false) ) { LogcatLogger.install(AndroidLogcatLogger(DEBUG)) diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillDecryptActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillDecryptActivity.kt index 4a40a5e0..b5052049 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillDecryptActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillDecryptActivity.kt @@ -195,7 +195,8 @@ class AutofillDecryptActivity : AppCompatActivity() { return null } .onSuccess { result -> - return when (val resultCode = + return when ( + val resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR) ) { OpenPgpApi.RESULT_CODE_SUCCESS -> { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterView.kt b/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterView.kt index b0dfa6ec..89f1a733 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterView.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterView.kt @@ -204,7 +204,8 @@ class AutofillFilterView : AppCompatActivity() { } // Switch RecyclerView out for a "no results" message if the new list is empty and // the message is not yet shown (and vice versa). - if ((list.isEmpty() && rvPasswordSwitcher.nextView.id == rvPasswordEmpty.id) || + if ( + (list.isEmpty() && rvPasswordSwitcher.nextView.id == rvPasswordEmpty.id) || (list.isNotEmpty() && rvPasswordSwitcher.nextView.id == rvPassword.id) ) { rvPasswordSwitcher.showNext() diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt index 113c3bb6..b1f11dfa 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt @@ -274,7 +274,8 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB // Allow the user to quickly switch between storing the username as the filename or // in the encrypted extras. This only makes sense if the directory structure is // FileBased. - if (suggestedName == null && + if ( + suggestedName == null && AutofillPreferences.directoryStructure(this@PasswordCreationActivity) == DirectoryStructure.FileBased ) { @@ -418,9 +419,8 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB GpgIdentifier.fromString(line) ?: run { // The line being empty means this is most likely an empty `.gpg-id` - // file - // we created. Skip the validation so we can make the user add a real - // ID. + // file we created. Skip the validation so we can make the user add a + // real ID. if (line.isEmpty()) return@run if (line.removePrefix("0x").matches("[a-fA-F0-9]{8}".toRegex())) { snackbar(message = resources.getString(R.string.short_key_ids_unsupported)) @@ -488,7 +488,8 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB // Additionally, if we were editing and the incoming and outgoing // filenames differ, it means we renamed. Ensure that the target // doesn't already exist to prevent an accidental overwrite. - if ((!editing || (editing && suggestedName != file.nameWithoutExtension)) && + if ( + (!editing || (editing && suggestedName != file.nameWithoutExtension)) && file.exists() ) { snackbar(message = getString(R.string.password_creation_duplicate_error)) @@ -535,7 +536,8 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB returnIntent.putExtra(RETURN_EXTRA_USERNAME, username) } - if (directoryInputLayout.isVisible && + if ( + directoryInputLayout.isVisible && directoryInputLayout.isEnabled && oldFileName != null ) { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivityV2.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivityV2.kt index b435b6e7..5792c892 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivityV2.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivityV2.kt @@ -204,7 +204,8 @@ class PasswordCreationActivityV2 : BasePgpActivity() { // Allow the user to quickly switch between storing the username as the filename or // in the encrypted extras. This only makes sense if the directory structure is // FileBased. - if (suggestedName == null && + if ( + suggestedName == null && AutofillPreferences.directoryStructure(this@PasswordCreationActivityV2) == DirectoryStructure.FileBased ) { @@ -368,8 +369,8 @@ class PasswordCreationActivityV2 : BasePgpActivity() { // Additionally, if we were editing and the incoming and outgoing // filenames differ, it means we renamed. Ensure that the target // doesn't already exist to prevent an accidental overwrite. - if ((!editing || (editing && suggestedName != file.nameWithoutExtension)) && - file.exists() + if ( + (!editing || (editing && suggestedName != file.nameWithoutExtension)) && file.exists() ) { snackbar(message = getString(R.string.password_creation_duplicate_error)) return@runCatching @@ -407,7 +408,8 @@ class PasswordCreationActivityV2 : BasePgpActivity() { returnIntent.putExtra(RETURN_EXTRA_USERNAME, username) } - if (directoryInputLayout.isVisible && + if ( + directoryInputLayout.isVisible && directoryInputLayout.isEnabled && oldFileName != null ) { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderFragment.kt b/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderFragment.kt index 54fd2892..cae55ba1 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderFragment.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderFragment.kt @@ -65,7 +65,8 @@ class SelectFolderFragment : Fragment(R.layout.password_recycler_view) { if (item.type == PasswordItem.TYPE_CATEGORY) { model.navigateTo(item.file, listMode = ListMode.DirectoriesOnly) (requireActivity() as AppCompatActivity) - .supportActionBar?.setDisplayHomeAsUpEnabled(true) + .supportActionBar + ?.setDisplayHomeAsUpEnabled(true) } } } diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt index e44e3e3c..614d9a52 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt @@ -152,7 +152,8 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { private fun isExplicitlyUserInitiatedError(throwable: Throwable): Boolean { var cause: Throwable? = throwable while (cause != null) { - if (cause is SSHException && cause.disconnectReason == DisconnectReason.AUTH_CANCELLED_BY_USER + if ( + cause is SSHException && cause.disconnectReason == DisconnectReason.AUTH_CANCELLED_BY_USER ) return true cause = cause.cause @@ -170,11 +171,13 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { // exceptions. // Also, SSHJ's UserAuthException about exhausting available authentication methods hides // more useful exceptions. - while ((rootCause is org.eclipse.jgit.errors.TransportException || - rootCause is org.eclipse.jgit.api.errors.TransportException || - rootCause is org.eclipse.jgit.api.errors.InvalidRemoteException || - (rootCause is UserAuthException && - rootCause.message == "Exhausted available authentication methods"))) { + while ( + (rootCause is org.eclipse.jgit.errors.TransportException || + rootCause is org.eclipse.jgit.api.errors.TransportException || + rootCause is org.eclipse.jgit.api.errors.InvalidRemoteException || + (rootCause is UserAuthException && + rootCause.message == "Exhausted available authentication methods")) + ) { rootCause = rootCause.cause ?: break } return rootCause diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt index e713a54e..93f104fb 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt @@ -140,7 +140,8 @@ class GitServerConfigActivity : BaseGitActivity() { .show(supportFragmentManager, "SSH_SCHEME_WARNING") return@setOnClickListener } - when (val updateResult = + when ( + val updateResult = gitSettings.updateConnectionSettingsIfValid( newAuthMode = newAuthMode, newUrl = binding.serverUrl.text.toString().trim(), @@ -230,7 +231,8 @@ class GitServerConfigActivity : BaseGitActivity() { val localDir = requireNotNull(PasswordRepository.getRepositoryDirectory()) val localDirFiles = localDir.listFiles() ?: emptyArray() // Warn if non-empty folder unless it's a just-initialized store that has just a .git folder - if (localDir.exists() && + if ( + localDir.exists() && localDirFiles.isNotEmpty() && !(localDirFiles.size == 1 && localDirFiles[0].name == ".git") ) { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt index 117d1d49..c70f0b5a 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt @@ -303,7 +303,8 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { listener = object : OnFragmentInteractionListener { override fun onFragmentInteraction(item: PasswordItem) { - if (settings.getString(PreferenceKeys.SORT_ORDER) == + if ( + settings.getString(PreferenceKeys.SORT_ORDER) == PasswordSortOrder.RECENTLY_USED.name ) { // save the time when password was used diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt index 84bef7bb..0ee42896 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt @@ -182,7 +182,8 @@ class PasswordStore : BaseGitActivity() { override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { // open search view on search key, or Ctr+F - if ((keyCode == KeyEvent.KEYCODE_SEARCH || + if ( + (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_F && event.isCtrlPressed) && !searchItem.isActionViewExpanded ) { searchItem.expandActionView() @@ -353,7 +354,8 @@ class PasswordStore : BaseGitActivity() { if (localDir != null && settings.getBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, false)) { logcat { "Check, dir: ${localDir.absolutePath}" } // do not push the fragment if we already have it - if (getPasswordFragment() == null || settings.getBoolean(PreferenceKeys.REPO_CHANGED, false) + if ( + getPasswordFragment() == null || settings.getBoolean(PreferenceKeys.REPO_CHANGED, false) ) { settings.edit { putBoolean(PreferenceKeys.REPO_CHANGED, false) } val args = Bundle() diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt index 63abdf7c..dec0c135 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt @@ -127,7 +127,8 @@ class SshKeyGenActivity : AppCompatActivity() { this@SshKeyGenActivity, R.string.biometric_prompt_title_ssh_keygen ) { result -> - // Do not cancel on failed attempts as these are handled by the authenticator UI. + // Do not cancel on failed attempts as these are handled by the + // authenticator UI. if (result !is Result.Retry) cont.resume(result) } } diff --git a/app/src/main/java/dev/msfjarvis/aps/util/auth/BiometricAuthenticator.kt b/app/src/main/java/dev/msfjarvis/aps/util/auth/BiometricAuthenticator.kt index 50f11b5b..38ff812a 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/auth/BiometricAuthenticator.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/auth/BiometricAuthenticator.kt @@ -87,7 +87,8 @@ object BiometricAuthenticator { BiometricPrompt.ERROR_UNABLE_TO_PROCESS -> { Result.Retry } - // We cover all guaranteed values above, but [errorCode] is still an Int at the end of + // We cover all guaranteed values above, but [errorCode] is still an Int + // at the end of // the day so a // catch-all else will always be required. else -> { diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/OpenKeychainKeyProvider.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/OpenKeychainKeyProvider.kt index 349e70e5..8436d1ce 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/OpenKeychainKeyProvider.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/OpenKeychainKeyProvider.kt @@ -145,7 +145,8 @@ class OpenKeychainKeyProvider private constructor(val activity: ContinuationCont } private suspend fun parseResult(request: Request, result: Intent): ApiResponse { - return when (result.getIntExtra( + return when ( + result.getIntExtra( SshAuthenticationApi.EXTRA_RESULT_CODE, SshAuthenticationApi.RESULT_CODE_ERROR ) @@ -196,8 +197,8 @@ class OpenKeychainKeyProvider private constructor(val activity: ContinuationCont privateKey = object : OpenKeychainPrivateKey { override suspend fun sign(challenge: ByteArray, hashAlgorithm: Int) = - when (val signingResponse = - executeApiRequest(SigningRequest(challenge, keyId, hashAlgorithm)) + when ( + val signingResponse = executeApiRequest(SigningRequest(challenge, keyId, hashAlgorithm)) ) { is ApiResponse.Success -> (signingResponse.response as SigningResponse).signature is ApiResponse.GeneralError -> throw signingResponse.exception diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshKey.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshKey.kt index 67e063a4..ea96af53 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshKey.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshKey.kt @@ -209,7 +209,8 @@ object SshKey { // The file must have more than 2 lines, and the first and last line must have private key // markers. - if (lines.size < 2 || + if ( + lines.size < 2 || !Regex("BEGIN .* PRIVATE KEY").containsMatchIn(lines.first()) || !Regex("END .* PRIVATE KEY").containsMatchIn(lines.last()) ) @@ -349,9 +350,12 @@ object SshKey { override fun getPrivate(): PrivateKey = runCatching { - // The current MasterKey API does not allow getting a reference to an existing one - // without specifying the KeySpec for a new one. However, the value for passed here - // for `requireAuthentication` is not used as the key already exists at this point. + // The current MasterKey API does not allow getting a reference to an existing + // one + // without specifying the KeySpec for a new one. However, the value for passed + // here + // for `requireAuthentication` is not used as the key already exists at this + // point. val encryptedPrivateKeyFile = runBlocking { getOrCreateWrappedPrivateKeyFile(false) } val rawPrivateKey = encryptedPrivateKeyFile.openFileInput().use { it.readBytes() } EdDSAPrivateKey( diff --git a/app/src/main/java/dev/msfjarvis/aps/util/settings/GitSettings.kt b/app/src/main/java/dev/msfjarvis/aps/util/settings/GitSettings.kt index 8cbf84d9..4f5187c4 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/settings/GitSettings.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/settings/GitSettings.kt @@ -150,7 +150,8 @@ constructor( in listOf("ssh", null) -> Protocol.Ssh else -> return UpdateConnectionSettingsResult.FailedToParseUrl } - if ((newAuthMode != AuthMode.None && newProtocol != Protocol.Https) && + if ( + (newAuthMode != AuthMode.None && newProtocol != Protocol.Https) && parsedUrl.user.isNullOrBlank() ) return UpdateConnectionSettingsResult.MissingUsername(newProtocol) diff --git a/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt b/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt index b90856b1..b96e538f 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt @@ -77,7 +77,8 @@ private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences, gitSettin remove(PreferenceKeys.GIT_REMOTE_USERNAME) remove(PreferenceKeys.GIT_REMOTE_PROTOCOL) } - if (url == null || + if ( + url == null || gitSettings.updateConnectionSettingsIfValid( newAuthMode = gitSettings.authMode, newUrl = url, @@ -99,7 +100,8 @@ private fun migrateToHideAll(sharedPrefs: SharedPreferences) { private fun migrateToSshKey(filesDirPath: String, sharedPrefs: SharedPreferences) { val privateKeyFile = File(filesDirPath, ".ssh_key") - if (sharedPrefs.contains(PreferenceKeys.USE_GENERATED_KEY) && + if ( + sharedPrefs.contains(PreferenceKeys.USE_GENERATED_KEY) && !SshKey.exists && privateKeyFile.exists() ) { diff --git a/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt b/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt index ecf5f1ca..9c4dc4f4 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt @@ -42,7 +42,8 @@ class UriTotpFinder @Inject constructor() : TotpFinder { private fun getQueryParameter(content: String, parameterName: String): String? { content.split("\n".toRegex()).forEach { line -> val uri = Uri.parse(line) - if (line.startsWith(TotpFinder.TOTP_FIELDS[0]) && uri.getQueryParameter(parameterName) != null + if ( + line.startsWith(TotpFinder.TOTP_FIELDS[0]) && uri.getQueryParameter(parameterName) != null ) { return uri.getQueryParameter(parameterName) } |