From 521f4772d797ca424dcb076359382d7a336b8de7 Mon Sep 17 00:00:00 2001 From: Aditya Wasan Date: Sat, 22 May 2021 17:51:02 +0530 Subject: [PATCH] spotless: fix formatting Signed-off-by: Aditya Wasan --- .../aps/injection/context/ContextModule.kt | 2 +- .../aps/injection/context/FilesDirPath.kt | 4 +- .../aps/injection/prefs/GitPreferences.kt | 4 +- .../aps/injection/prefs/PreferenceModule.kt | 7 +++- .../aps/injection/prefs/ProxyPreferences.kt | 4 +- .../injection/prefs/SettingsPreferences.kt | 4 +- .../aps/ui/passwords/PasswordStore.kt | 1 - .../aps/ui/settings/RepositorySettings.kt | 7 +++- .../aps/util/git/GitCommandExecutor.kt | 6 ++- .../aps/util/git/operation/GitOperation.kt | 10 ++--- .../aps/util/settings/GitSettings.kt | 11 +++--- .../aps/util/settings/MigrationsTest.kt | 39 ++++++++++++++----- 12 files changed, 61 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt index cdb0f9f13..6399781e0 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt @@ -16,4 +16,4 @@ class ContextModule { fun providesFilesDirPath(@ApplicationContext context: Context): String { return context.filesDir.path } -} \ No newline at end of file +} diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt b/app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt index 8bced2950..ec747bfe4 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt @@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.context import javax.inject.Qualifier -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class FilesDirPath \ No newline at end of file +@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class FilesDirPath diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt index c07bc65e1..749eea48f 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt @@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.prefs import javax.inject.Qualifier -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class GitPreferences \ No newline at end of file +@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class GitPreferences diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt index 41d2a30b3..537ee1add 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt @@ -17,7 +17,10 @@ import dev.msfjarvis.aps.BuildConfig @InstallIn(SingletonComponent::class) class PreferenceModule { - private fun provideBaseEncryptedPreferences(context: Context, fileName: String): SharedPreferences { + private fun provideBaseEncryptedPreferences( + context: Context, + fileName: String + ): SharedPreferences { val masterKeyAlias = MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build() return EncryptedSharedPreferences.create( @@ -49,4 +52,4 @@ class PreferenceModule { fun provideProxyPreferences(@ApplicationContext context: Context): SharedPreferences { return provideBaseEncryptedPreferences(context, "http_proxy") } -} \ No newline at end of file +} diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt index c0b430888..786087adc 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt @@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.prefs import javax.inject.Qualifier -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class ProxyPreferences \ No newline at end of file +@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class ProxyPreferences diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt index 7bd1f9b90..7bca03c8e 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt @@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.prefs import javax.inject.Qualifier -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class SettingsPreferences \ No newline at end of file +@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class SettingsPreferences 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 d2f6ca386..892289af8 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 @@ -57,7 +57,6 @@ import dev.msfjarvis.aps.util.extensions.listFilesRecursively import dev.msfjarvis.aps.util.extensions.requestInputFocusOnView import dev.msfjarvis.aps.util.extensions.sharedPrefs import dev.msfjarvis.aps.util.settings.AuthMode -import dev.msfjarvis.aps.util.settings.GitSettings import dev.msfjarvis.aps.util.settings.PreferenceKeys import dev.msfjarvis.aps.util.shortcuts.ShortcutHandler import dev.msfjarvis.aps.util.viewmodel.SearchableRepositoryViewModel diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt b/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt index a90554080..86b575330 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt @@ -42,11 +42,14 @@ import dev.msfjarvis.aps.util.settings.PreferenceKeys class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider { - private val hiltEntryPoint = EntryPointAccessors.fromApplication(activity.applicationContext, RepositorySettingsEntryPoint::class.java) + private val hiltEntryPoint = + EntryPointAccessors.fromApplication( + activity.applicationContext, + RepositorySettingsEntryPoint::class.java, + ) private val encryptedPreferences = hiltEntryPoint.encryptedPreferences() private val gitSettings = hiltEntryPoint.gitSettings() - private fun launchActivity(clazz: Class) { activity.startActivity(Intent(activity, clazz)) } diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt index 5d507dc80..be0527a21 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt @@ -34,7 +34,11 @@ class GitCommandExecutor( private val operation: GitOperation, ) { - private val hiltEntryPoint = EntryPointAccessors.fromApplication(activity.applicationContext, GitCommandExecutorEntryPoint::class.java) + private val hiltEntryPoint = + EntryPointAccessors.fromApplication( + activity.applicationContext, + GitCommandExecutorEntryPoint::class.java + ) private val gitSettings = hiltEntryPoint.gitSettings() suspend fun execute(): Result { diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt index 5a9da290d..9d2963539 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt @@ -16,7 +16,6 @@ import com.github.michaelbull.result.runCatching import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.EntryPoint import dagger.hilt.InstallIn -import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.EntryPointAccessors import dagger.hilt.components.SingletonComponent import dev.msfjarvis.aps.R @@ -31,8 +30,6 @@ import dev.msfjarvis.aps.util.git.sshj.SshKey import dev.msfjarvis.aps.util.git.sshj.SshjSessionFactory import dev.msfjarvis.aps.util.settings.AuthMode import dev.msfjarvis.aps.util.settings.GitSettings -import javax.inject.Inject -import javax.inject.Singleton import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine import kotlinx.coroutines.Dispatchers @@ -60,7 +57,11 @@ abstract class GitOperation(protected val callingActivity: FragmentActivity) { abstract val commands: Array> private val hostKeyFile = callingActivity.filesDir.resolve(".host_key") private var sshSessionFactory: SshjSessionFactory? = null - private val hiltEntryPoint = EntryPointAccessors.fromApplication(callingActivity.applicationContext, GitOperationEntryPoint::class.java) + private val hiltEntryPoint = + EntryPointAccessors.fromApplication( + callingActivity.applicationContext, + GitOperationEntryPoint::class.java + ) protected val repository = PasswordRepository.getRepository(null)!! protected val git = Git(repository) @@ -229,7 +230,6 @@ abstract class GitOperation(protected val callingActivity: FragmentActivity) { private const val CONNECT_TIMEOUT = 10 } - // Using @EntryPoint seems to be our best option here, changing this to constructor injection would require a larger refactor. @EntryPoint @InstallIn(SingletonComponent::class) interface GitOperationEntryPoint { 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 0d5801427..50b6cbfe6 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 @@ -52,16 +52,16 @@ enum class AuthMode(val pref: String) { } @Singleton -class GitSettings @Inject constructor( +class GitSettings +@Inject +constructor( @SettingsPreferences private val settings: SharedPreferences, @GitPreferences private val encryptedSettings: SharedPreferences, @ProxyPreferences private val proxySettings: SharedPreferences, @FilesDirPath private val filesDirPath: String, ) { - private val hostKeyPath by lazy(LazyThreadSafetyMode.NONE) { - "$filesDirPath/.host_key" - } + private val hostKeyPath by lazy(LazyThreadSafetyMode.NONE) { "$filesDirPath/.host_key" } var authMode get() = AuthMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH)) private set(value) { @@ -128,7 +128,8 @@ class GitSettings @Inject constructor( sealed class UpdateConnectionSettingsResult { class MissingUsername(val newProtocol: Protocol) : UpdateConnectionSettingsResult() - class AuthModeMismatch(val newProtocol: Protocol, val validModes: List) : UpdateConnectionSettingsResult() + class AuthModeMismatch(val newProtocol: Protocol, val validModes: List) : + UpdateConnectionSettingsResult() object Valid : UpdateConnectionSettingsResult() object FailedToParseUrl : UpdateConnectionSettingsResult() } diff --git a/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt index 520d51ac0..71f457ec4 100644 --- a/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt +++ b/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt @@ -59,7 +59,11 @@ class MigrationsTest { putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref) putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.Password.pref) } - runMigrations(filesDir, sharedPrefs, GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir)) + runMigrations( + filesDir, + sharedPrefs, + GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) + ) checkOldKeysAreRemoved() assertEquals( sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), @@ -77,7 +81,11 @@ class MigrationsTest { putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref) putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.SshKey.pref) } - runMigrations(filesDir, sharedPrefs, GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir)) + runMigrations( + filesDir, + sharedPrefs, + GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) + ) checkOldKeysAreRemoved(context) assertEquals( sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), @@ -95,7 +103,11 @@ class MigrationsTest { putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Https.pref) putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.None.pref) } - runMigrations(filesDir, sharedPrefs, GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir)) + runMigrations( + filesDir, + sharedPrefs, + GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) + ) checkOldKeysAreRemoved(context) assertEquals( sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), @@ -106,7 +118,11 @@ class MigrationsTest { @Test fun verifyHiddenFoldersMigrationIfDisabled() { sharedPrefs.edit { clear() } - runMigrations(filesDir, sharedPrefs, GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir)) + runMigrations( + filesDir, + sharedPrefs, + GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) + ) assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)) assertEquals(false, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) } @@ -117,7 +133,11 @@ class MigrationsTest { clear() putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true) } - runMigrations(filesDir, sharedPrefs, GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir)) + runMigrations( + filesDir, + sharedPrefs, + GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) + ) assertEquals(false, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)) assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) } @@ -128,11 +148,12 @@ class MigrationsTest { clear() putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true) } - runMigrations(filesDir, sharedPrefs, GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir)) - assertEquals( - true, - sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false) + runMigrations( + filesDir, + sharedPrefs, + GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) ) + assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)) assertFalse(sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X)) } }