spotless: fix formatting
Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
This commit is contained in:
parent
d45bb753cf
commit
521f4772d7
12 changed files with 61 additions and 38 deletions
|
@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.context
|
||||||
|
|
||||||
import javax.inject.Qualifier
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
@Qualifier
|
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class FilesDirPath
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class FilesDirPath
|
|
||||||
|
|
|
@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.prefs
|
||||||
|
|
||||||
import javax.inject.Qualifier
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
@Qualifier
|
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class GitPreferences
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class GitPreferences
|
|
||||||
|
|
|
@ -17,7 +17,10 @@ import dev.msfjarvis.aps.BuildConfig
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
class PreferenceModule {
|
class PreferenceModule {
|
||||||
|
|
||||||
private fun provideBaseEncryptedPreferences(context: Context, fileName: String): SharedPreferences {
|
private fun provideBaseEncryptedPreferences(
|
||||||
|
context: Context,
|
||||||
|
fileName: String
|
||||||
|
): SharedPreferences {
|
||||||
val masterKeyAlias =
|
val masterKeyAlias =
|
||||||
MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build()
|
MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build()
|
||||||
return EncryptedSharedPreferences.create(
|
return EncryptedSharedPreferences.create(
|
||||||
|
|
|
@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.prefs
|
||||||
|
|
||||||
import javax.inject.Qualifier
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
@Qualifier
|
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class ProxyPreferences
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class ProxyPreferences
|
|
||||||
|
|
|
@ -2,6 +2,4 @@ package dev.msfjarvis.aps.injection.prefs
|
||||||
|
|
||||||
import javax.inject.Qualifier
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
@Qualifier
|
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class SettingsPreferences
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class SettingsPreferences
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ import dev.msfjarvis.aps.util.extensions.listFilesRecursively
|
||||||
import dev.msfjarvis.aps.util.extensions.requestInputFocusOnView
|
import dev.msfjarvis.aps.util.extensions.requestInputFocusOnView
|
||||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||||
import dev.msfjarvis.aps.util.settings.AuthMode
|
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.settings.PreferenceKeys
|
||||||
import dev.msfjarvis.aps.util.shortcuts.ShortcutHandler
|
import dev.msfjarvis.aps.util.shortcuts.ShortcutHandler
|
||||||
import dev.msfjarvis.aps.util.viewmodel.SearchableRepositoryViewModel
|
import dev.msfjarvis.aps.util.viewmodel.SearchableRepositoryViewModel
|
||||||
|
|
|
@ -42,11 +42,14 @@ import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||||
|
|
||||||
class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider {
|
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 encryptedPreferences = hiltEntryPoint.encryptedPreferences()
|
||||||
private val gitSettings = hiltEntryPoint.gitSettings()
|
private val gitSettings = hiltEntryPoint.gitSettings()
|
||||||
|
|
||||||
|
|
||||||
private fun <T : FragmentActivity> launchActivity(clazz: Class<T>) {
|
private fun <T : FragmentActivity> launchActivity(clazz: Class<T>) {
|
||||||
activity.startActivity(Intent(activity, clazz))
|
activity.startActivity(Intent(activity, clazz))
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,11 @@ class GitCommandExecutor(
|
||||||
private val operation: GitOperation,
|
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()
|
private val gitSettings = hiltEntryPoint.gitSettings()
|
||||||
|
|
||||||
suspend fun execute(): Result<Unit, Throwable> {
|
suspend fun execute(): Result<Unit, Throwable> {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import com.github.michaelbull.result.runCatching
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.EntryPoint
|
import dagger.hilt.EntryPoint
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import dagger.hilt.android.EntryPointAccessors
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import dev.msfjarvis.aps.R
|
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.git.sshj.SshjSessionFactory
|
||||||
import dev.msfjarvis.aps.util.settings.AuthMode
|
import dev.msfjarvis.aps.util.settings.AuthMode
|
||||||
import dev.msfjarvis.aps.util.settings.GitSettings
|
import dev.msfjarvis.aps.util.settings.GitSettings
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -60,7 +57,11 @@ abstract class GitOperation(protected val callingActivity: FragmentActivity) {
|
||||||
abstract val commands: Array<GitCommand<out Any>>
|
abstract val commands: Array<GitCommand<out Any>>
|
||||||
private val hostKeyFile = callingActivity.filesDir.resolve(".host_key")
|
private val hostKeyFile = callingActivity.filesDir.resolve(".host_key")
|
||||||
private var sshSessionFactory: SshjSessionFactory? = null
|
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 repository = PasswordRepository.getRepository(null)!!
|
||||||
protected val git = Git(repository)
|
protected val git = Git(repository)
|
||||||
|
@ -229,7 +230,6 @@ abstract class GitOperation(protected val callingActivity: FragmentActivity) {
|
||||||
private const val CONNECT_TIMEOUT = 10
|
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
|
@EntryPoint
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
interface GitOperationEntryPoint {
|
interface GitOperationEntryPoint {
|
||||||
|
|
|
@ -52,16 +52,16 @@ enum class AuthMode(val pref: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class GitSettings @Inject constructor(
|
class GitSettings
|
||||||
|
@Inject
|
||||||
|
constructor(
|
||||||
@SettingsPreferences private val settings: SharedPreferences,
|
@SettingsPreferences private val settings: SharedPreferences,
|
||||||
@GitPreferences private val encryptedSettings: SharedPreferences,
|
@GitPreferences private val encryptedSettings: SharedPreferences,
|
||||||
@ProxyPreferences private val proxySettings: SharedPreferences,
|
@ProxyPreferences private val proxySettings: SharedPreferences,
|
||||||
@FilesDirPath private val filesDirPath: String,
|
@FilesDirPath private val filesDirPath: String,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val hostKeyPath by lazy(LazyThreadSafetyMode.NONE) {
|
private val hostKeyPath by lazy(LazyThreadSafetyMode.NONE) { "$filesDirPath/.host_key" }
|
||||||
"$filesDirPath/.host_key"
|
|
||||||
}
|
|
||||||
var authMode
|
var authMode
|
||||||
get() = AuthMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH))
|
get() = AuthMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH))
|
||||||
private set(value) {
|
private set(value) {
|
||||||
|
@ -128,7 +128,8 @@ class GitSettings @Inject constructor(
|
||||||
|
|
||||||
sealed class UpdateConnectionSettingsResult {
|
sealed class UpdateConnectionSettingsResult {
|
||||||
class MissingUsername(val newProtocol: Protocol) : UpdateConnectionSettingsResult()
|
class MissingUsername(val newProtocol: Protocol) : UpdateConnectionSettingsResult()
|
||||||
class AuthModeMismatch(val newProtocol: Protocol, val validModes: List<AuthMode>) : UpdateConnectionSettingsResult()
|
class AuthModeMismatch(val newProtocol: Protocol, val validModes: List<AuthMode>) :
|
||||||
|
UpdateConnectionSettingsResult()
|
||||||
object Valid : UpdateConnectionSettingsResult()
|
object Valid : UpdateConnectionSettingsResult()
|
||||||
object FailedToParseUrl : UpdateConnectionSettingsResult()
|
object FailedToParseUrl : UpdateConnectionSettingsResult()
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,11 @@ class MigrationsTest {
|
||||||
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
||||||
putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.Password.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()
|
checkOldKeysAreRemoved()
|
||||||
assertEquals(
|
assertEquals(
|
||||||
sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
|
sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
|
||||||
|
@ -77,7 +81,11 @@ class MigrationsTest {
|
||||||
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
||||||
putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.SshKey.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)
|
checkOldKeysAreRemoved(context)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
|
sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
|
||||||
|
@ -95,7 +103,11 @@ class MigrationsTest {
|
||||||
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Https.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Https.pref)
|
||||||
putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.None.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)
|
checkOldKeysAreRemoved(context)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
|
sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
|
||||||
|
@ -106,7 +118,11 @@ class MigrationsTest {
|
||||||
@Test
|
@Test
|
||||||
fun verifyHiddenFoldersMigrationIfDisabled() {
|
fun verifyHiddenFoldersMigrationIfDisabled() {
|
||||||
sharedPrefs.edit { clear() }
|
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(true, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true))
|
||||||
assertEquals(false, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false))
|
assertEquals(false, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false))
|
||||||
}
|
}
|
||||||
|
@ -117,7 +133,11 @@ class MigrationsTest {
|
||||||
clear()
|
clear()
|
||||||
putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)
|
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(false, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false))
|
||||||
assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false))
|
assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false))
|
||||||
}
|
}
|
||||||
|
@ -128,11 +148,12 @@ class MigrationsTest {
|
||||||
clear()
|
clear()
|
||||||
putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true)
|
putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true)
|
||||||
}
|
}
|
||||||
runMigrations(filesDir, sharedPrefs, GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir))
|
runMigrations(
|
||||||
assertEquals(
|
filesDir,
|
||||||
true,
|
sharedPrefs,
|
||||||
sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)
|
GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir)
|
||||||
)
|
)
|
||||||
|
assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false))
|
||||||
assertFalse(sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X))
|
assertFalse(sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue