app: use unsafeLazy everywhere
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
6388bc7ac9
commit
0027710465
18 changed files with 44 additions and 48 deletions
|
@ -14,6 +14,7 @@ import dev.msfjarvis.aps.Application
|
|||
import dev.msfjarvis.aps.data.password.PasswordItem
|
||||
import dev.msfjarvis.aps.util.extensions.getString
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.settings.PasswordSortOrder
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import java.io.File
|
||||
|
@ -55,7 +56,7 @@ object PasswordRepository {
|
|||
}
|
||||
|
||||
private var repository: Repository? = null
|
||||
private val settings by lazy(LazyThreadSafetyMode.NONE) { Application.instance.sharedPrefs }
|
||||
private val settings by unsafeLazy { Application.instance.sharedPrefs }
|
||||
private val filesDir
|
||||
get() = Application.instance.filesDir
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import dev.msfjarvis.aps.ui.crypto.PasswordCreationActivity
|
|||
import dev.msfjarvis.aps.util.autofill.AutofillMatcher
|
||||
import dev.msfjarvis.aps.util.autofill.AutofillPreferences
|
||||
import dev.msfjarvis.aps.util.autofill.AutofillResponseBuilder
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import java.io.File
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
|
@ -89,7 +90,7 @@ class AutofillSaveActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private val formOrigin by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val formOrigin by unsafeLazy {
|
||||
val shouldMatchApp: String? = intent.getStringExtra(EXTRA_SHOULD_MATCH_APP)
|
||||
val shouldMatchWeb: String? = intent.getStringExtra(EXTRA_SHOULD_MATCH_WEB)
|
||||
if (shouldMatchApp != null && shouldMatchWeb == null) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import dev.msfjarvis.aps.util.extensions.clipboard
|
|||
import dev.msfjarvis.aps.util.extensions.getString
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.snackbar
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.services.ClipboardService
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import java.io.File
|
||||
|
@ -42,20 +43,20 @@ import org.openintents.openpgp.OpenPgpError
|
|||
open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
|
||||
/** Full path to the repository */
|
||||
val repoPath by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra("REPO_PATH")!! }
|
||||
val repoPath by unsafeLazy { intent.getStringExtra("REPO_PATH")!! }
|
||||
|
||||
/** Full path to the password file being worked on */
|
||||
val fullPath by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra("FILE_PATH")!! }
|
||||
val fullPath by unsafeLazy { intent.getStringExtra("FILE_PATH")!! }
|
||||
|
||||
/**
|
||||
* Name of the password file
|
||||
*
|
||||
* Converts personal/auth.foo.org/john_doe@example.org.gpg to john_doe.example.org
|
||||
*/
|
||||
val name: String by lazy(LazyThreadSafetyMode.NONE) { File(fullPath).nameWithoutExtension }
|
||||
val name: String by unsafeLazy { File(fullPath).nameWithoutExtension }
|
||||
|
||||
/** [SharedPreferences] instance used by subclasses to persist settings */
|
||||
val settings: SharedPreferences by lazy(LazyThreadSafetyMode.NONE) { sharedPrefs }
|
||||
val settings: SharedPreferences by unsafeLazy { sharedPrefs }
|
||||
|
||||
/**
|
||||
* Handle to the [OpenPgpApi] instance that is used by subclasses to interface with OpenKeychain.
|
||||
|
|
|
@ -22,6 +22,7 @@ import dev.msfjarvis.aps.data.password.FieldItem
|
|||
import dev.msfjarvis.aps.databinding.DecryptLayoutBinding
|
||||
import dev.msfjarvis.aps.injection.password.PasswordEntryFactory
|
||||
import dev.msfjarvis.aps.ui.adapters.FieldItemAdapter
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.extensions.viewBinding
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
@ -44,9 +45,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
|
|||
private val binding by viewBinding(DecryptLayoutBinding::inflate)
|
||||
@Inject lateinit var passwordEntryFactory: PasswordEntryFactory
|
||||
|
||||
private val relativeParentPath by lazy(LazyThreadSafetyMode.NONE) {
|
||||
getParentPath(fullPath, repoPath)
|
||||
}
|
||||
private val relativeParentPath by unsafeLazy { getParentPath(fullPath, repoPath) }
|
||||
private var passwordEntry: PasswordEntry? = null
|
||||
|
||||
private val userInteractionRequiredResult =
|
||||
|
|
|
@ -44,6 +44,7 @@ import dev.msfjarvis.aps.util.extensions.commitChange
|
|||
import dev.msfjarvis.aps.util.extensions.getString
|
||||
import dev.msfjarvis.aps.util.extensions.isInsideRepository
|
||||
import dev.msfjarvis.aps.util.extensions.snackbar
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.extensions.viewBinding
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import java.io.ByteArrayInputStream
|
||||
|
@ -63,24 +64,14 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
|
|||
private val binding by viewBinding(PasswordCreationActivityBinding::inflate)
|
||||
@Inject lateinit var passwordEntryFactory: PasswordEntryFactory
|
||||
|
||||
private val suggestedName by lazy(LazyThreadSafetyMode.NONE) {
|
||||
intent.getStringExtra(EXTRA_FILE_NAME)
|
||||
}
|
||||
private val suggestedPass by lazy(LazyThreadSafetyMode.NONE) {
|
||||
intent.getStringExtra(EXTRA_PASSWORD)
|
||||
}
|
||||
private val suggestedExtra by lazy(LazyThreadSafetyMode.NONE) {
|
||||
intent.getStringExtra(EXTRA_EXTRA_CONTENT)
|
||||
}
|
||||
private val shouldGeneratePassword by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val suggestedName by unsafeLazy { intent.getStringExtra(EXTRA_FILE_NAME) }
|
||||
private val suggestedPass by unsafeLazy { intent.getStringExtra(EXTRA_PASSWORD) }
|
||||
private val suggestedExtra by unsafeLazy { intent.getStringExtra(EXTRA_EXTRA_CONTENT) }
|
||||
private val shouldGeneratePassword by unsafeLazy {
|
||||
intent.getBooleanExtra(EXTRA_GENERATE_PASSWORD, false)
|
||||
}
|
||||
private val editing by lazy(LazyThreadSafetyMode.NONE) {
|
||||
intent.getBooleanExtra(EXTRA_EDITING, false)
|
||||
}
|
||||
private val oldFileName by lazy(LazyThreadSafetyMode.NONE) {
|
||||
intent.getStringExtra(EXTRA_FILE_NAME)
|
||||
}
|
||||
private val editing by unsafeLazy { intent.getBooleanExtra(EXTRA_EDITING, false) }
|
||||
private val oldFileName by unsafeLazy { intent.getStringExtra(EXTRA_FILE_NAME) }
|
||||
private var oldCategory: String? = null
|
||||
private var copy: Boolean = false
|
||||
private var encryptionIntent: Intent = Intent()
|
||||
|
|
|
@ -17,6 +17,7 @@ import dev.msfjarvis.aps.ui.git.config.GitServerConfigActivity
|
|||
import dev.msfjarvis.aps.util.extensions.finish
|
||||
import dev.msfjarvis.aps.util.extensions.performTransactionWithBackStack
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.extensions.viewBinding
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
|
||||
|
@ -24,9 +25,7 @@ class CloneFragment : Fragment(R.layout.fragment_clone) {
|
|||
|
||||
private val binding by viewBinding(FragmentCloneBinding::bind)
|
||||
|
||||
private val settings by lazy(LazyThreadSafetyMode.NONE) {
|
||||
requireActivity().applicationContext.sharedPrefs
|
||||
}
|
||||
private val settings by unsafeLazy { requireActivity().applicationContext.sharedPrefs }
|
||||
|
||||
private val cloneAction =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
|
|
|
@ -22,6 +22,7 @@ import dev.msfjarvis.aps.util.extensions.commitChange
|
|||
import dev.msfjarvis.aps.util.extensions.finish
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.snackbar
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.extensions.viewBinding
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import java.io.File
|
||||
|
@ -32,9 +33,7 @@ import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
|||
|
||||
class KeySelectionFragment : Fragment(R.layout.fragment_key_selection) {
|
||||
|
||||
private val settings by lazy(LazyThreadSafetyMode.NONE) {
|
||||
requireActivity().applicationContext.sharedPrefs
|
||||
}
|
||||
private val settings by unsafeLazy { requireActivity().applicationContext.sharedPrefs }
|
||||
private val binding by viewBinding(FragmentKeySelectionBinding::bind)
|
||||
|
||||
private val gpgKeySelectAction =
|
||||
|
|
|
@ -28,6 +28,7 @@ import dev.msfjarvis.aps.util.extensions.isPermissionGranted
|
|||
import dev.msfjarvis.aps.util.extensions.listFilesRecursively
|
||||
import dev.msfjarvis.aps.util.extensions.performTransactionWithBackStack
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.extensions.viewBinding
|
||||
import dev.msfjarvis.aps.util.settings.PasswordSortOrder
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
|
@ -35,10 +36,8 @@ import java.io.File
|
|||
|
||||
class RepoLocationFragment : Fragment(R.layout.fragment_repo_location) {
|
||||
|
||||
private val settings by lazy(LazyThreadSafetyMode.NONE) {
|
||||
requireActivity().applicationContext.sharedPrefs
|
||||
}
|
||||
private val directorySelectIntent by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val settings by unsafeLazy { requireActivity().applicationContext.sharedPrefs }
|
||||
private val directorySelectIntent by unsafeLazy {
|
||||
Intent(requireContext(), DirectorySelectionActivity::class.java)
|
||||
}
|
||||
private val binding by viewBinding(FragmentRepoLocationBinding::bind)
|
||||
|
|
|
@ -18,6 +18,7 @@ import dev.msfjarvis.aps.R
|
|||
import dev.msfjarvis.aps.databinding.ActivityProxySelectorBinding
|
||||
import dev.msfjarvis.aps.util.extensions.getEncryptedProxyPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.getString
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.extensions.viewBinding
|
||||
import dev.msfjarvis.aps.util.proxy.ProxyUtils
|
||||
import dev.msfjarvis.aps.util.settings.GitSettings
|
||||
|
@ -34,9 +35,7 @@ class ProxySelectorActivity : AppCompatActivity() {
|
|||
@Inject lateinit var proxyUtils: ProxyUtils
|
||||
|
||||
private val binding by viewBinding(ActivityProxySelectorBinding::inflate)
|
||||
private val proxyPrefs by lazy(LazyThreadSafetyMode.NONE) {
|
||||
applicationContext.getEncryptedProxyPrefs()
|
||||
}
|
||||
private val proxyPrefs by unsafeLazy { applicationContext.getEncryptedProxyPrefs() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
|
@ -23,13 +23,14 @@ import de.Maxr1998.modernpreferences.preferences.choice.SelectionItem
|
|||
import dev.msfjarvis.aps.R
|
||||
import dev.msfjarvis.aps.util.extensions.getString
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.pwgenxkpwd.XkpwdDictionary
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import java.io.File
|
||||
|
||||
class PasswordSettings(private val activity: FragmentActivity) : SettingsProvider {
|
||||
|
||||
private val sharedPrefs by lazy(LazyThreadSafetyMode.NONE) { activity.sharedPrefs }
|
||||
private val sharedPrefs by unsafeLazy { activity.sharedPrefs }
|
||||
private val storeCustomXkpwdDictionaryAction =
|
||||
activity.registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||
if (uri == null) return@registerForActivityResult
|
||||
|
|
|
@ -37,12 +37,13 @@ import dev.msfjarvis.aps.ui.sshkeygen.SshKeyImportActivity
|
|||
import dev.msfjarvis.aps.util.extensions.getString
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.snackbar
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.settings.GitSettings
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
|
||||
class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider {
|
||||
|
||||
private val hiltEntryPoint by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val hiltEntryPoint by unsafeLazy {
|
||||
EntryPointAccessors.fromApplication(
|
||||
activity.applicationContext,
|
||||
RepositorySettingsEntryPoint::class.java,
|
||||
|
|
|
@ -67,4 +67,4 @@ fun <T : ViewBinding> Fragment.viewBinding(viewBindingFactory: (View) -> T) =
|
|||
|
||||
inline fun <T : ViewBinding> AppCompatActivity.viewBinding(
|
||||
crossinline bindingInflater: (LayoutInflater) -> T
|
||||
) = lazy(LazyThreadSafetyMode.NONE) { bindingInflater.invoke(layoutInflater) }
|
||||
) = unsafeLazy { bindingInflater.invoke(layoutInflater) }
|
||||
|
|
|
@ -16,6 +16,7 @@ import dagger.hilt.android.EntryPointAccessors
|
|||
import dagger.hilt.components.SingletonComponent
|
||||
import dev.msfjarvis.aps.R
|
||||
import dev.msfjarvis.aps.util.extensions.snackbar
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.git.GitException.PullException
|
||||
import dev.msfjarvis.aps.util.git.GitException.PushException
|
||||
import dev.msfjarvis.aps.util.git.operation.GitOperation
|
||||
|
@ -34,7 +35,7 @@ class GitCommandExecutor(
|
|||
private val operation: GitOperation,
|
||||
) {
|
||||
|
||||
private val hiltEntryPoint by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val hiltEntryPoint by unsafeLazy {
|
||||
EntryPointAccessors.fromApplication(
|
||||
activity.applicationContext,
|
||||
GitCommandExecutorEntryPoint::class.java
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.github.michaelbull.result.runCatching
|
|||
import dev.msfjarvis.aps.data.repo.PasswordRepository
|
||||
import dev.msfjarvis.aps.util.extensions.hash
|
||||
import dev.msfjarvis.aps.util.extensions.time
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.revwalk.RevCommit
|
||||
|
||||
|
@ -39,7 +40,7 @@ class GitLogModel {
|
|||
// This is because the commit graph is walked from HEAD to the last commit to obtain.
|
||||
// Additionally, tests with 1000 commits in the log have not produced a significant delay in the
|
||||
// user experience.
|
||||
private val cache: MutableList<GitCommit> by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val cache: MutableList<GitCommit> by unsafeLazy {
|
||||
commits()
|
||||
.map { GitCommit(it.hash, it.shortMessage, it.authorIdent.name, it.time) }
|
||||
.toMutableList()
|
||||
|
|
|
@ -6,6 +6,7 @@ package dev.msfjarvis.aps.util.git.operation
|
|||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dev.msfjarvis.aps.R
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.git.sshj.ContinuationContainerActivity
|
||||
import org.eclipse.jgit.api.RebaseCommand
|
||||
import org.eclipse.jgit.api.ResetCommand
|
||||
|
@ -28,7 +29,7 @@ class BreakOutOfDetached(callingActivity: ContinuationContainerActivity) :
|
|||
git.checkout().setName(remoteBranch),
|
||||
)
|
||||
|
||||
override val commands by lazy(LazyThreadSafetyMode.NONE) {
|
||||
override val commands by unsafeLazy {
|
||||
if (merging) {
|
||||
// We need to run some non-command operations first
|
||||
repository.writeMergeCommitMsg(null)
|
||||
|
|
|
@ -25,6 +25,7 @@ import dev.msfjarvis.aps.R
|
|||
import dev.msfjarvis.aps.util.extensions.getEncryptedGitPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.getString
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
@ -50,7 +51,7 @@ private const val PROVIDER_ANDROID_KEY_STORE = "AndroidKeyStore"
|
|||
private const val KEYSTORE_ALIAS = "sshkey"
|
||||
private const val ANDROIDX_SECURITY_KEYSET_PREF_NAME = "androidx_sshkey_keyset_prefs"
|
||||
|
||||
private val androidKeystore: KeyStore by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val androidKeystore: KeyStore by unsafeLazy {
|
||||
KeyStore.getInstance(PROVIDER_ANDROID_KEY_STORE).apply { load(null) }
|
||||
}
|
||||
|
||||
|
@ -118,7 +119,7 @@ object SshKey {
|
|||
set(value) =
|
||||
context.sharedPrefs.edit { putString(PreferenceKeys.GIT_REMOTE_KEY_TYPE, value?.value) }
|
||||
|
||||
private val isStrongBoxSupported by lazy(LazyThreadSafetyMode.NONE) {
|
||||
private val isStrongBoxSupported by unsafeLazy {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
context.packageManager.hasSystemFeature(PackageManager.FEATURE_STRONGBOX_KEYSTORE)
|
||||
else false
|
||||
|
|
|
@ -61,7 +61,7 @@ constructor(
|
|||
@FilesDirPath private val filesDirPath: String,
|
||||
) {
|
||||
|
||||
private val hostKeyPath by lazy(LazyThreadSafetyMode.NONE) { "$filesDirPath/.host_key" }
|
||||
private val hostKeyPath = "$filesDirPath/.host_key"
|
||||
var authMode
|
||||
get() = AuthMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH))
|
||||
private set(value) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import dev.msfjarvis.aps.data.repo.PasswordRepository
|
|||
import dev.msfjarvis.aps.util.autofill.AutofillPreferences
|
||||
import dev.msfjarvis.aps.util.autofill.DirectoryStructure
|
||||
import dev.msfjarvis.aps.util.extensions.sharedPrefs
|
||||
import dev.msfjarvis.aps.util.extensions.unsafeLazy
|
||||
import dev.msfjarvis.aps.util.settings.PasswordSortOrder
|
||||
import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
||||
import dev.sphericalkat.sublimefuzzy.Fuzzy
|
||||
|
@ -120,7 +121,7 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel
|
|||
|
||||
private val root
|
||||
get() = PasswordRepository.getRepositoryDirectory()
|
||||
private val settings by lazy(LazyThreadSafetyMode.NONE) { application.sharedPrefs }
|
||||
private val settings by unsafeLazy { application.sharedPrefs }
|
||||
private val showHiddenContents
|
||||
get() = settings.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)
|
||||
private val defaultSearchMode
|
||||
|
|
Loading…
Reference in a new issue