all: reformat with ktfmt 0.36

This commit is contained in:
Harsh Shandilya 2022-04-25 10:47:02 +05:30
parent 11720e9542
commit aaf6ceb8ec
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
34 changed files with 637 additions and 614 deletions

View file

@ -42,7 +42,8 @@ object PasswordRepository {
private fun initializeRepository(repositoryDir: File) {
val builder = FileRepositoryBuilder()
repository =
runCatching { builder.setGitDir(repositoryDir).build() }.getOrElse { e ->
runCatching { builder.setGitDir(repositoryDir).build() }
.getOrElse { e ->
e.printStackTrace()
null
}

View file

@ -117,7 +117,8 @@ class AutofillPublisherChangedActivity : AppCompatActivity() {
packageManager.getApplicationLabel(appInfo)
)
val currentHash = computeCertificatesHash(this@AutofillPublisherChangedActivity, appPackage)
val currentHash =
computeCertificatesHash(this@AutofillPublisherChangedActivity, appPackage)
warningAppAdvancedInfo.text =
getString(
R.string.oreo_autofill_warning_publisher_advanced_info_template,

View file

@ -411,7 +411,10 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
File(repoRoot, directory.text.toString()).findTillRoot(".gpg-id", repoRoot)
?: File(repoRoot, ".gpg-id").apply { createNewFile() }
val gpgIdentifiers =
gpgIdentifierFile.readLines().filter { it.isNotBlank() }.map { line ->
gpgIdentifierFile
.readLines()
.filter { it.isNotBlank() }
.map { line ->
GpgIdentifier.fromString(line)
?: run {
// The line being empty means this is most likely an empty `.gpg-id`
@ -503,8 +506,10 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
// associate the new password name with the last name's timestamp in
// history
val preference = getSharedPreferences("recent_password_history", Context.MODE_PRIVATE)
val oldFilePathHash = "$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg".base64()
val preference =
getSharedPreferences("recent_password_history", Context.MODE_PRIVATE)
val oldFilePathHash =
"$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg".base64()
val timestamp = preference.getString(oldFilePathHash)
if (timestamp != null) {
preference.edit {
@ -522,7 +527,8 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
)
if (shouldGeneratePassword) {
val directoryStructure = AutofillPreferences.directoryStructure(applicationContext)
val directoryStructure =
AutofillPreferences.directoryStructure(applicationContext)
val entry = passwordEntryFactory.create(content.encodeToByteArray())
returnIntent.putExtra(RETURN_EXTRA_PASSWORD, entry.password)
val username = entry.username ?: directoryStructure.getUsernameFor(file)
@ -552,7 +558,10 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
if (editing) R.string.git_commit_edit_text else R.string.git_commit_add_text
lifecycleScope.launch {
commitChange(
resources.getString(commitMessageRes, getLongName(fullPath, repoPath, editName))
resources.getString(
commitMessageRes,
getLongName(fullPath, repoPath, editName)
)
)
.onSuccess {
setResult(RESULT_OK, returnIntent)

View file

@ -368,7 +368,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

View file

@ -48,8 +48,7 @@ class PasswordGeneratorDialogFragment : DialogFragment() {
val monoTypeface = Typeface.createFromAsset(callingActivity.assets, "fonts/sourcecodepro.ttf")
val prefs =
requireActivity()
.applicationContext
.getSharedPreferences("PasswordGenerator", Context.MODE_PRIVATE)
.applicationContext.getSharedPreferences("PasswordGenerator", Context.MODE_PRIVATE)
builder.setView(binding.root)
@ -102,8 +101,8 @@ class PasswordGeneratorDialogFragment : DialogFragment() {
val passwordLength = getLength()
setPrefs(requireContext(), passwordOptions, passwordLength)
passwordField.text =
runCatching { PasswordGenerator.generate(passwordOptions, passwordLength) }.getOrElse {
exception ->
runCatching { PasswordGenerator.generate(passwordOptions, passwordLength) }
.getOrElse { exception ->
val errorText =
when (exception) {
is MaxIterationsExceededException ->

View file

@ -64,9 +64,8 @@ class SelectFolderFragment : Fragment(R.layout.password_recycler_view) {
override fun onFragmentInteraction(item: PasswordItem) {
if (item.type == PasswordItem.TYPE_CATEGORY) {
model.navigateTo(item.file, listMode = ListMode.DirectoriesOnly)
(requireActivity() as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(
true
)
(requireActivity() as AppCompatActivity)
.supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
}
}

View file

@ -88,9 +88,8 @@ class GitConfigActivity : BaseGitActivity() {
binding.gitAbortRebase.alpha = if (needsAbort) 1.0f else 0.5f
}
binding.gitLog.setOnClickListener {
runCatching { startActivity(Intent(this, GitLogActivity::class.java)) }.onFailure { ex ->
logcat(ERROR) { "Failed to start GitLogActivity\n${ex}" }
}
runCatching { startActivity(Intent(this, GitLogActivity::class.java)) }
.onFailure { ex -> logcat(ERROR) { "Failed to start GitLogActivity\n${ex}" } }
}
binding.gitAbortRebase.setOnClickListener {
lifecycleScope.launch {

View file

@ -292,9 +292,8 @@ class PasswordStore : BaseGitActivity() {
.setPositiveButton(resources.getString(R.string.dialog_ok), null)
when (id) {
R.id.user_pref -> {
runCatching { startActivity(Intent(this, SettingsActivity::class.java)) }.onFailure { e ->
e.printStackTrace()
}
runCatching { startActivity(Intent(this, SettingsActivity::class.java)) }
.onFailure { e -> e.printStackTrace() }
}
R.id.git_push -> {
if (!PasswordRepository.isInitialized) {
@ -618,9 +617,7 @@ class PasswordStore : BaseGitActivity() {
fun matchPasswordWithApp(item: PasswordItem) {
val path =
item
.file
.absolutePath
item.file.absolutePath
.replace(PasswordRepository.getRepositoryDirectory().toString() + "/", "")
.replace(".gpg", "")
val data = Intent()

View file

@ -42,9 +42,10 @@ class ProxySelectorActivity : AppCompatActivity() {
with(binding) {
proxyHost.setText(proxyPrefs.getString(PreferenceKeys.PROXY_HOST))
proxyUser.setText(proxyPrefs.getString(PreferenceKeys.PROXY_USERNAME))
proxyPrefs.getInt(PreferenceKeys.PROXY_PORT, -1).takeIf { it != -1 }?.let {
proxyPort.setText("$it")
}
proxyPrefs
.getInt(PreferenceKeys.PROXY_PORT, -1)
.takeIf { it != -1 }
?.let { proxyPort.setText("$it") }
proxyPassword.setText(proxyPrefs.getString(PreferenceKeys.PROXY_PASSWORD))
save.setOnClickListener { saveSettings() }
proxyHost.doOnTextChanged { text, _, _, _ ->
@ -70,18 +71,22 @@ class ProxySelectorActivity : AppCompatActivity() {
private fun saveSettings() {
proxyPrefs.edit {
binding.proxyHost.text?.toString()?.takeIf { it.isNotEmpty() }.let {
gitSettings.proxyHost = it
}
binding.proxyUser.text?.toString()?.takeIf { it.isNotEmpty() }.let {
gitSettings.proxyUsername = it
}
binding.proxyPort.text?.toString()?.takeIf { it.isNotEmpty() }?.let {
gitSettings.proxyPort = it.toInt()
}
binding.proxyPassword.text?.toString()?.takeIf { it.isNotEmpty() }.let {
gitSettings.proxyPassword = it
}
binding.proxyHost.text
?.toString()
?.takeIf { it.isNotEmpty() }
.let { gitSettings.proxyHost = it }
binding.proxyUser.text
?.toString()
?.takeIf { it.isNotEmpty() }
.let { gitSettings.proxyUsername = it }
binding.proxyPort.text
?.toString()
?.takeIf { it.isNotEmpty() }
?.let { gitSettings.proxyPort = it.toInt() }
binding.proxyPassword.text
?.toString()
?.takeIf { it.isNotEmpty() }
.let { gitSettings.proxyPassword = it }
}
proxyUtils.setDefaultProxy()
Handler(Looper.getMainLooper()).postDelayed(500) { finish() }

View file

@ -107,7 +107,9 @@ class AutofillMatcher {
val matchedFiles =
matchPreferences.getStringSet(matchesKey(formOrigin), emptySet())!!.map { File(it) }
return Ok(
matchedFiles.filter { it.exists() }.also { validFiles ->
matchedFiles
.filter { it.exists() }
.also { validFiles ->
matchPreferences.edit {
putStringSet(matchesKey(formOrigin), validFiles.map { it.absolutePath }.toSet())
}

View file

@ -34,7 +34,8 @@ fun File.contains(other: File): Boolean {
if (!isDirectory) return false
if (!other.exists()) return false
val relativePath =
runCatching { other.relativeTo(this) }.getOrElse {
runCatching { other.relativeTo(this) }
.getOrElse {
return false
}
// Direct containment is equivalent to the relative path being equal to the filename.

View file

@ -25,7 +25,8 @@ private fun commits(): Iterable<RevCommit> {
logcat(TAG, ERROR) { "Could not access git repository" }
return listOf()
}
return runCatching { Git(repo).log().call() }.getOrElse { e ->
return runCatching { Git(repo).log().call() }
.getOrElse { e ->
logcat(TAG, ERROR) { e.asLog("Failed to obtain git commits") }
listOf()
}

View file

@ -316,13 +316,18 @@ object SshKey {
private object KeystoreNativeKeyProvider : KeyProvider {
override fun getPublic(): PublicKey =
runCatching { androidKeystore.sshPublicKey!! }.getOrElse { error ->
runCatching { androidKeystore.sshPublicKey!! }
.getOrElse { error ->
logcat { error.asLog() }
throw IOException("Failed to get public key '$KEYSTORE_ALIAS' from Android Keystore", error)
throw IOException(
"Failed to get public key '$KEYSTORE_ALIAS' from Android Keystore",
error
)
}
override fun getPrivate(): PrivateKey =
runCatching { androidKeystore.sshPrivateKey!! }.getOrElse { error ->
runCatching { androidKeystore.sshPrivateKey!! }
.getOrElse { error ->
logcat { error.asLog() }
throw IOException(
"Failed to access private key '$KEYSTORE_ALIAS' from Android Keystore",
@ -336,7 +341,8 @@ object SshKey {
private object KeystoreWrappedEd25519KeyProvider : KeyProvider {
override fun getPublic(): PublicKey =
runCatching { parseSshPublicKey(sshPublicKey!!)!! }.getOrElse { error ->
runCatching { parseSshPublicKey(sshPublicKey!!)!! }
.getOrElse { error ->
logcat { error.asLog() }
throw IOException("Failed to get the public key for wrapped ed25519 key", error)
}

View file

@ -93,9 +93,8 @@ private fun makeTofuHostKeyVerifier(hostKeyFile: File): HostKeyVerifier {
return object : HostKeyVerifier {
override fun verify(hostname: String?, port: Int, key: PublicKey?): Boolean {
val digest =
runCatching { SecurityUtils.getMessageDigest("SHA-256") }.getOrElse { e ->
throw SSHRuntimeException(e)
}
runCatching { SecurityUtils.getMessageDigest("SHA-256") }
.getOrElse { e -> throw SSHRuntimeException(e) }
digest.update(PlainBuffer().putPublicKey(key).compactData)
val digestData = digest.digest()
val hostKeyEntry = "SHA256:${Base64.encodeToString(digestData, Base64.NO_WRAP)}"

View file

@ -140,7 +140,8 @@ constructor(
newBranch: String
): UpdateConnectionSettingsResult {
val parsedUrl =
runCatching { URIish(newUrl) }.getOrElse {
runCatching { URIish(newUrl) }
.getOrElse {
return UpdateConnectionSettingsResult.FailedToParseUrl
}
val newProtocol =

View file

@ -229,9 +229,8 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel
.filter { it.first > 0 }
.toList()
.sortedWith(
compareByDescending<Pair<Int, PasswordItem>> { it.first }.thenBy(itemComparator) {
it.second
}
compareByDescending<Pair<Int, PasswordItem>> { it.first }
.thenBy(itemComparator) { it.second }
)
.map { it.second }
}

View file

@ -105,7 +105,10 @@ internal class SingleFieldMatcher(
}
override fun match(fields: List<FormField>, alreadyMatched: List<FormField>): List<FormField>? {
return fields.minus(alreadyMatched).filter { take(it, alreadyMatched) }.let { contestants ->
return fields
.minus(alreadyMatched)
.filter { take(it, alreadyMatched) }
.let { contestants ->
when (contestants.size) {
1 -> return@let listOf(contestants.single())
0 -> return@let null

View file

@ -251,8 +251,7 @@ public fun getInstalledBrowsersWithAutofillSupportLevel(
.map { it to getBrowserAutofillSupportLevel(context, it.activityInfo.packageName) }
.filter { it.first.isDefault || it.second != BrowserAutofillSupportLevel.None }
.map {
context
.packageManager
context.packageManager
.getApplicationLabel(it.first.activityInfo.applicationInfo)
.toString() to it.second
}

View file

@ -182,9 +182,10 @@ internal class FormField(
// Basic type detection for HTML fields
private val htmlTag = node.htmlInfo?.tag
private val htmlAttributes: Map<String, String> =
node.htmlInfo?.attributes?.filter { it.first != null && it.second != null }?.associate {
Pair(it.first.lowercase(Locale.US), it.second.lowercase(Locale.US))
}
node.htmlInfo
?.attributes
?.filter { it.first != null && it.second != null }
?.associate { Pair(it.first.lowercase(Locale.US), it.second.lowercase(Locale.US)) }
?: emptyMap()
private val htmlAttributesDebug = htmlAttributes.entries.joinToString { "${it.key}=${it.value}" }
private val htmlInputType = htmlAttributes["type"]

View file

@ -32,9 +32,9 @@ afterEvaluate {
}
}
// disable kapt tasks for unit tests
tasks.matching { it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin") }.configureEach {
enabled = false
}
tasks
.matching { it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin") }
.configureEach { enabled = false }
fun Project.hasDaggerCompilerDependency(): Boolean {
return configurations.any {

View file

@ -79,17 +79,17 @@ constructor(
when (id) {
is GpgIdentifier.KeyId -> {
val keyIdMatch =
keys.map { key -> key to tryGetId(key) }.firstOrNull { (_, keyId) ->
keyId?.id == id.id
}
keys
.map { key -> key to tryGetId(key) }
.firstOrNull { (_, keyId) -> keyId?.id == id.id }
keyIdMatch?.first
}
is GpgIdentifier.UserId -> {
val selector = SelectUserId.byEmail(id.email)
val userIdMatch =
keys.map { key -> key to tryParseKeyring(key) }.firstOrNull { (_, keyRing) ->
selector.firstMatch(keyRing) != null
}
keys
.map { key -> key to tryParseKeyring(key) }
.firstOrNull { (_, keyRing) -> selector.firstMatch(keyRing) != null }
userIdMatch?.first
}
}