diff options
author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-09-04 12:06:55 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-04 12:06:55 +0530 |
commit | e731943437861f2eeac4d8a442f512065be2a0e7 (patch) | |
tree | f38e1fcb4fd3623cc9b2f203f0ec9a7b35b760bd | |
parent | b7f58cfb6e832cb4fdfbfaf59a134ac383ff7487 (diff) |
Revamp onboarding logic (#1068)
-rw-r--r-- | .idea/codeStyles/Project.xml | 1 | ||||
-rw-r--r-- | app/src/main/AndroidManifest.xml | 4 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt | 203 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt | 166 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.kt | 24 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt | 10 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt | 6 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt | 6 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_onboarding.xml (renamed from app/src/main/res/layout/fragment_to_clone_or_not.xml) | 0 | ||||
-rw-r--r-- | app/src/main/res/values-cs/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-es/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-fr/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-pt-rBR/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-ru/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 2 |
15 files changed, 233 insertions, 194 deletions
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index b82dc0ea..f1b342f5 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -55,6 +55,7 @@ </indentOptions> </codeStyleSettings> <codeStyleSettings language="XML"> + <option name="WRAP_ON_TYPING" value="0" /> <indentOptions> <option name="CONTINUATION_INDENT_SIZE" value="4" /> </indentOptions> diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a9fa83d7..034124f9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,6 +33,10 @@ android:label="@string/app_name" /> <activity + android:name=".OnboardingActivity" + android:configChanges="orientation|screenSize" /> + + <activity android:name=".LaunchActivity" android:configChanges="orientation|screenSize" android:label="@string/app_name" diff --git a/app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt b/app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt new file mode 100644 index 00000000..d2f19b7a --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt @@ -0,0 +1,203 @@ +/* + * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package com.zeapo.pwdstore + +import android.Manifest +import android.content.Intent +import android.os.Bundle +import androidx.activity.result.contract.ActivityResultContracts.RequestPermission +import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.edit +import com.github.ajalt.timberkt.d +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.zeapo.pwdstore.databinding.ActivityOnboardingBinding +import com.zeapo.pwdstore.git.BaseGitActivity +import com.zeapo.pwdstore.git.GitServerConfigActivity +import com.zeapo.pwdstore.utils.PasswordRepository +import com.zeapo.pwdstore.utils.PreferenceKeys +import com.zeapo.pwdstore.utils.checkRuntimePermission +import com.zeapo.pwdstore.utils.getString +import com.zeapo.pwdstore.utils.listFilesRecursively +import com.zeapo.pwdstore.utils.sharedPrefs +import com.zeapo.pwdstore.utils.viewBinding +import java.io.File + +class OnboardingActivity : AppCompatActivity() { + + private val binding by viewBinding(ActivityOnboardingBinding::inflate) + private val settings by lazy { applicationContext.sharedPrefs } + private val sortOrder: PasswordRepository.PasswordSortOrder + get() = PasswordRepository.PasswordSortOrder.getSortOrder(settings) + + private val cloneAction = registerForActivityResult(StartActivityForResult()) { result -> + if (result.resultCode == RESULT_OK) { + settings.edit { putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, true) } + finish() + } + } + + private val repositoryInitAction = registerForActivityResult(StartActivityForResult()) { result -> + if (result.resultCode == RESULT_OK) { + initializeRepositoryInfo() + finish() + } + } + + private val externalDirectorySelectAction = registerForActivityResult(StartActivityForResult()) { result -> + if (result.resultCode == RESULT_OK) { + if (checkExternalDirectory()) { + finish() + } else { + createRepository() + } + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + supportActionBar?.hide() + setContentView(binding.root) + binding.settingsButton.setOnClickListener { + startActivity(Intent(this, UserPreference::class.java)) + } + binding.localDirectoryButton.setOnClickListener { + MaterialAlertDialogBuilder(this) + .setTitle(resources.getString(R.string.location_dialog_title)) + .setMessage(resources.getString(R.string.location_dialog_create_text)) + .setPositiveButton(resources.getString(R.string.location_hidden)) { _, _ -> + createRepoInHiddenDir() + } + .setNegativeButton(resources.getString(R.string.location_sdcard)) { _, _ -> + createRepoFromExternalDir() + } + .show() + } + binding.cloneFromServerButton.setOnClickListener { + cloneToHiddenDir() + } + } + + /** + * Clones a remote Git repository to the app's private directory + */ + private fun cloneToHiddenDir() { + settings.edit { putBoolean(PreferenceKeys.GIT_EXTERNAL, false) } + cloneAction.launch(Intent(this, GitServerConfigActivity::class.java).apply { + putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE) + }) + } + + /** + * Initializes an empty repository in the app's private directory + */ + private fun createRepoInHiddenDir() { + settings.edit { + putBoolean(PreferenceKeys.GIT_EXTERNAL, false) + remove(PreferenceKeys.GIT_EXTERNAL_REPO) + } + initializeRepositoryInfo() + finish() + } + + /** + * Initializes an empty repository in a selected directory if one does not already exist + */ + private fun createRepoFromExternalDir() { + settings.edit { putBoolean(PreferenceKeys.GIT_EXTERNAL, true) } + val externalRepo = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) + if (externalRepo == null) { + if (!checkRuntimePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + registerForActivityResult(RequestPermission()) { granted -> + if (granted) { + externalDirectorySelectAction.launch(Intent(this, UserPreference::class.java).apply { + putExtra("operation", "git_external") + }) + } + }.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) + } + } else { + MaterialAlertDialogBuilder(this) + .setTitle(resources.getString(R.string.directory_selected_title)) + .setMessage(resources.getString(R.string.directory_selected_message, externalRepo)) + .setPositiveButton(resources.getString(R.string.use)) { _, _ -> + if (!checkRuntimePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + registerForActivityResult(RequestPermission()) { granted -> + if (granted) { + initializeRepositoryInfo() + } + }.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) + } else { + initializeRepositoryInfo() + } + } + .setNegativeButton(resources.getString(R.string.change)) { _, _ -> + if (!checkRuntimePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + registerForActivityResult(RequestPermission()) { granted -> + if (granted) { + repositoryInitAction.launch(Intent(this, UserPreference::class.java).apply { + putExtra("operation", "git_external") + }) + } + }.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) + } + } + .show() + } + } + + private fun checkExternalDirectory(): Boolean { + if (settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false) && + settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) != null) { + val externalRepoPath = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) + val dir = externalRepoPath?.let { File(it) } + if (dir != null && // The directory could be opened + dir.exists() && // The directory exists + dir.isDirectory && // The directory, is really a directory + dir.listFilesRecursively().isNotEmpty() && // The directory contains files + // The directory contains a non-zero number of password files + PasswordRepository.getPasswords(dir, PasswordRepository.getRepositoryDirectory(), sortOrder).isNotEmpty() + ) { + PasswordRepository.closeRepository() + return true + } + } + return false + } + + private fun createRepository() { + val localDir = PasswordRepository.getRepositoryDirectory() + try { + check(localDir.exists() || localDir.mkdir()) { "Failed to create directory!" } + PasswordRepository.createRepository(localDir) + if (!PasswordRepository.isInitialized) { + PasswordRepository.initialize() + } + if (File(localDir.absolutePath + "/.gpg-id").createNewFile()) { + settings.edit { putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, true) } + } else { + throw IllegalStateException("Failed to initialize repository state.") + } + } catch (e: Exception) { + e.printStackTrace() + if (!localDir.delete()) { + d { "Failed to delete local repository: $localDir" } + } + } + } + + private fun initializeRepositoryInfo() { + val externalRepo = settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false) + val externalRepoPath = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) + if (externalRepo && !checkRuntimePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + return + } + if (externalRepo && externalRepoPath != null) { + if (checkExternalDirectory()) return + } + createRepository() + } +} diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index 7f8c4e55..56a6b949 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -8,7 +8,6 @@ import android.Manifest import android.annotation.SuppressLint import android.content.Context import android.content.Intent -import android.content.pm.PackageManager import android.content.pm.ShortcutInfo.Builder import android.content.pm.ShortcutManager import android.graphics.drawable.Icon @@ -26,7 +25,6 @@ import androidx.activity.viewModels import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView.OnQueryTextListener -import androidx.core.content.ContextCompat import androidx.core.content.edit import androidx.core.content.getSystemService import androidx.fragment.app.FragmentManager @@ -54,16 +52,13 @@ import com.zeapo.pwdstore.git.config.GitSettings import com.zeapo.pwdstore.ui.dialogs.FolderCreationDialogFragment import com.zeapo.pwdstore.utils.PasswordItem import com.zeapo.pwdstore.utils.PasswordRepository -import com.zeapo.pwdstore.utils.PasswordRepository.Companion.closeRepository -import com.zeapo.pwdstore.utils.PasswordRepository.Companion.createRepository -import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getPasswords import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepository import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirectory import com.zeapo.pwdstore.utils.PasswordRepository.Companion.initialize import com.zeapo.pwdstore.utils.PasswordRepository.Companion.isInitialized -import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.getSortOrder import com.zeapo.pwdstore.utils.PreferenceKeys import com.zeapo.pwdstore.utils.base64 +import com.zeapo.pwdstore.utils.checkRuntimePermission import com.zeapo.pwdstore.utils.commitChange import com.zeapo.pwdstore.utils.contains import com.zeapo.pwdstore.utils.getString @@ -94,43 +89,9 @@ class PasswordStore : BaseGitActivity() { ViewModelProvider.AndroidViewModelFactory(application) } - private val cloneAction = registerForActivityResult(StartActivityForResult()) { result -> + private val listRefreshAction = registerForActivityResult(StartActivityForResult()) { result -> if (result.resultCode == RESULT_OK) { - settings.edit { putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, true) } - } - } - - private val repositoryInitAction = registerForActivityResult(StartActivityForResult()) { result -> - if (result.resultCode == RESULT_OK) { - initializeRepositoryInfo() - } - } - - private val directoryChangeAction = registerForActivityResult(StartActivityForResult()) { result -> - if (result.resultCode == RESULT_OK) { - if (settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false) && - settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) != null) { - val externalRepoPath = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) - val dir = externalRepoPath?.let { File(it) } - if (dir != null && - dir.exists() && - dir.isDirectory && - dir.listFilesRecursively().isNotEmpty() && - getPasswords(dir, getRepositoryDirectory(), sortOrder).isNotEmpty()) { - closeRepository() - checkLocalRepository() - return@registerForActivityResult - } - } - checkPermissionsAndCloneAction.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) - } - } - - private val checkPermissionsAndCloneAction = registerForActivityResult(RequestPermission()) { granted -> - if (granted) { - val intent = Intent(activity, GitServerConfigActivity::class.java) - intent.putExtra(REQUEST_ARG_OP, REQUEST_CLONE) - cloneAction.launch(intent) + refreshPasswordList() } } @@ -160,9 +121,7 @@ class PasswordStore : BaseGitActivity() { // prevent attempt to create password list fragment var savedInstance = savedInstanceState if (savedInstanceState != null && (!settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false) || - ContextCompat.checkSelfPermission( - activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED)) { + !checkRuntimePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE))) { savedInstance = null } super.onCreate(savedInstance) @@ -229,7 +188,7 @@ class PasswordStore : BaseGitActivity() { override fun onResume() { super.onResume() if (settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false)) { - hasRequiredStoragePermissions(true) + hasRequiredStoragePermissions() } else { checkLocalRepository() } @@ -361,47 +320,6 @@ class PasswordStore : BaseGitActivity() { searchItem.collapseActionView() } - private fun createRepository() { - if (!isInitialized) { - initialize() - } - val localDir = getRepositoryDirectory() - try { - check(localDir.mkdir()) { "Failed to create directory!" } - createRepository(localDir) - if (File(localDir.absolutePath + "/.gpg-id").createNewFile()) { - settings.edit { putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, true) } - } else { - throw IllegalStateException("Failed to initialize repository state.") - } - } catch (e: Exception) { - e.printStackTrace() - if (!localDir.delete()) { - d { "Failed to delete local repository" } - } - return - } - checkLocalRepository() - } - - private fun initializeRepositoryInfo() { - val externalRepo = settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false) - val externalRepoPath = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) - if (externalRepo && !hasRequiredStoragePermissions()) { - return - } - if (externalRepo && externalRepoPath != null) { - val dir = File(externalRepoPath) - if (dir.exists() && dir.isDirectory && - getPasswords(dir, getRepositoryDirectory(), sortOrder).isNotEmpty()) { - closeRepository() - checkLocalRepository() - return // if not empty, just show me the passwords! - } - } - createRepository() - } - private fun runGitOperation(operation: Int) = lifecycleScope.launch { launchGitOperation(operation).fold( success = { refreshPasswordList() }, @@ -413,10 +331,8 @@ class PasswordStore : BaseGitActivity() { * Validates if storage permission is granted, and requests for it if not. The return value * is true if the permission has been granted. */ - private fun hasRequiredStoragePermissions(checkLocalRepo: Boolean = false): Boolean { - val cloning = supportFragmentManager.findFragmentByTag("ToCloneOrNot") != null - return if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED && !cloning) { + private fun hasRequiredStoragePermissions(): Boolean { + return if (!checkRuntimePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { Snackbar.make( findViewById(R.id.main_layout), getString(R.string.access_sdcard_text), @@ -432,8 +348,7 @@ class PasswordStore : BaseGitActivity() { } false } else { - if (checkLocalRepo) - checkLocalRepository() + checkLocalRepository() true } } @@ -478,11 +393,7 @@ class PasswordStore : BaseGitActivity() { } } } else { - supportActionBar!!.hide() - supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) - supportFragmentManager.commit { - replace(R.id.main_layout, ToCloneOrNot(), "ToCloneOrNot") - } + startActivity(Intent(this, OnboardingActivity::class.java)) } } @@ -821,60 +732,6 @@ class PasswordStore : BaseGitActivity() { } } - fun initRepository(operation: Int) { - closeRepository() - MaterialAlertDialogBuilder(this) - .setTitle(resources.getString(R.string.location_dialog_title)) - .setMessage(resources.getString(R.string.location_dialog_text)) - .setPositiveButton(resources.getString(R.string.location_hidden)) { _, _ -> - settings.edit { putBoolean(PreferenceKeys.GIT_EXTERNAL, false) } - when (operation) { - NEW_REPO_BUTTON -> initializeRepositoryInfo() - CLONE_REPO_BUTTON -> { - val intent = Intent(activity, GitServerConfigActivity::class.java) - intent.putExtra(REQUEST_ARG_OP, REQUEST_CLONE) - cloneAction.launch(intent) - } - } - } - .setNegativeButton(resources.getString(R.string.location_sdcard)) { _, _ -> - settings.edit { putBoolean(PreferenceKeys.GIT_EXTERNAL, true) } - val externalRepo = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO) - if (externalRepo == null) { - val intent = Intent(activity, UserPreference::class.java) - intent.putExtra("operation", "git_external") - when (operation) { - NEW_REPO_BUTTON -> repositoryInitAction.launch(intent) - CLONE_REPO_BUTTON -> directoryChangeAction.launch(intent) - } - } else { - MaterialAlertDialogBuilder(activity) - .setTitle(resources.getString(R.string.directory_selected_title)) - .setMessage(resources.getString(R.string.directory_selected_message, externalRepo)) - .setPositiveButton(resources.getString(R.string.use)) { _, _ -> - when (operation) { - NEW_REPO_BUTTON -> initializeRepositoryInfo() - CLONE_REPO_BUTTON -> { - val intent = Intent(activity, GitServerConfigActivity::class.java) - intent.putExtra(REQUEST_ARG_OP, REQUEST_CLONE) - cloneAction.launch(intent) - } - } - } - .setNegativeButton(resources.getString(R.string.change)) { _, _ -> - val intent = Intent(activity, UserPreference::class.java) - intent.putExtra("operation", "git_external") - when (operation) { - NEW_REPO_BUTTON -> repositoryInitAction.launch(intent) - CLONE_REPO_BUTTON -> directoryChangeAction.launch(intent) - } - } - .show() - } - } - .show() - } - fun matchPasswordWithApp(item: PasswordItem) { val path = item.file .absolutePath @@ -886,14 +743,9 @@ class PasswordStore : BaseGitActivity() { finish() } - private val sortOrder: PasswordRepository.PasswordSortOrder - get() = getSortOrder(settings) - companion object { const val REQUEST_ARG_PATH = "PATH" - const val CLONE_REPO_BUTTON = 401 - const val NEW_REPO_BUTTON = 402 private fun isPrintable(c: Char): Boolean { val block = UnicodeBlock.of(c) return (!Character.isISOControl(c) && diff --git a/app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.kt b/app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.kt deleted file mode 100644 index 66a450f0..00000000 --- a/app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ -package com.zeapo.pwdstore - -import android.content.Intent -import android.os.Bundle -import android.view.View -import androidx.fragment.app.Fragment -import com.zeapo.pwdstore.databinding.FragmentToCloneOrNotBinding -import com.zeapo.pwdstore.utils.viewBinding - -class ToCloneOrNot : Fragment(R.layout.fragment_to_clone_or_not) { - - private val binding by viewBinding(FragmentToCloneOrNotBinding::bind) - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - binding.settingsButton.setOnClickListener { startActivity(Intent(requireContext(), UserPreference::class.java)) } - binding.localDirectoryButton.setOnClickListener { (requireActivity() as PasswordStore).initRepository(PasswordStore.NEW_REPO_BUTTON) } - binding.cloneFromServerButton.setOnClickListener { (requireActivity() as PasswordStore).initRepository(PasswordStore.CLONE_REPO_BUTTON) } - } -} diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt index 27cd6379..d867b4db 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt @@ -124,7 +124,10 @@ class GitServerConfigActivity : BaseGitActivity() { } snackbar.dismiss() launchGitOperation(REQUEST_CLONE).fold( - success = ::finishOnSuccessHandler, + success = { + setResult(RESULT_OK) + finish() + }, failure = ::finishAfterPromptOnErrorHandler, ) } @@ -159,7 +162,10 @@ class GitServerConfigActivity : BaseGitActivity() { } lifecycleScope.launch { launchGitOperation(REQUEST_CLONE).fold( - success = ::finishOnSuccessHandler, + success = { + setResult(RESULT_OK) + finish() + }, failure = ::finishAfterPromptOnErrorHandler, ) } diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt index eea69dc4..ab78e98f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt @@ -8,6 +8,7 @@ import android.app.KeyguardManager import android.content.ClipboardManager import android.content.Context import android.content.SharedPreferences +import android.content.pm.PackageManager import android.os.Build import android.util.Base64 import android.util.TypedValue @@ -17,6 +18,7 @@ import android.view.inputmethod.InputMethodManager import androidx.annotation.IdRes import androidx.annotation.RequiresApi import androidx.appcompat.app.AlertDialog +import androidx.core.content.ContextCompat import androidx.core.content.getSystemService import androidx.fragment.app.FragmentActivity import androidx.preference.PreferenceManager @@ -131,6 +133,10 @@ suspend fun FragmentActivity.commitChange( }.execute() } +fun FragmentActivity.checkRuntimePermission(permission: String): Boolean { + return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED +} + /** * Extension function for [AlertDialog] that requests focus for the * view whose id is [id]. Solution based on a StackOverflow diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt index 73660fca..3d0d4606 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -20,7 +20,6 @@ import org.eclipse.jgit.transport.URIish open class PasswordRepository protected constructor() { - @Suppress("Unused") enum class PasswordSortOrder(val comparator: Comparator<PasswordItem>) { FOLDER_FIRST(Comparator { p1: PasswordItem, p2: PasswordItem -> @@ -93,10 +92,7 @@ open class PasswordRepository protected constructor() { @JvmStatic fun isGitRepo(): Boolean { if (repository != null) { - // Check if remote exists - return repository!!.config.getSubsections("remote").isNotEmpty() && - repository!!.objectDatabase.exists() && - repository!!.allRefs.isNotEmpty() + return repository!!.objectDatabase.exists() } return false } diff --git a/app/src/main/res/layout/fragment_to_clone_or_not.xml b/app/src/main/res/layout/activity_onboarding.xml index f2c6f797..f2c6f797 100644 --- a/app/src/main/res/layout/fragment_to_clone_or_not.xml +++ b/app/src/main/res/layout/activity_onboarding.xml diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index b7769e53..8252cffd 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -51,7 +51,6 @@ <string name="clone">Klonovat ze serveru</string> <string name="initialize">Použít místní adresář</string> <string name="location_dialog_title">Umístění úložiště</string> - <string name="location_dialog_text">Zvolte kde vytvořit, nebo kam klonovat vaše úložiště hesel.</string> <string name="location_sdcard">SD-Karta</string> <string name="location_hidden">Skryté (Preferováno)</string> <string name="external_repository_dialog_title">Vyberte kam ukládat hesla</string> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index c781f7aa..39e9ebc3 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -46,7 +46,6 @@ <string name="clone">Clonar desde servidor</string> <string name="initialize">Usar directorio local</string> <string name="location_dialog_title">Ubicación del repositorio</string> - <string name="location_dialog_text">Selecciona dónde crear o clonar tu repositorio de contraseñas.</string> <string name="location_sdcard">Tarjeta SD</string> <string name="location_hidden">Oculto (Recomendado)</string> <string name="external_repository_dialog_title">Selecciona dónde almacenar tus contraseñas</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index e97fd1fb..43801b81 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -52,7 +52,6 @@ <string name="clone">Cloner depuis le serveur</string> <string name="initialize">Utiliser un répertoire local</string> <string name="location_dialog_title">Location du répertoire</string> - <string name="location_dialog_text">Sélectionnez l\'emplacement de création ou de clonage de votre répertoire de mots de passe.</string> <string name="location_sdcard">Carte SD</string> <string name="location_hidden">Caché (Préféré)</string> <string name="external_repository_dialog_title">Choisissez où sauvegarder les mots de passe</string> diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 535267c7..9b7150e5 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -61,7 +61,6 @@ <string name="clone">Clonar do servidor</string> <string name="initialize">Usar diretório local</string> <string name="location_dialog_title">Local do repositório</string> - <string name="location_dialog_text">Selecione onde criar ou clonar o repositório da sua senha.</string> <string name="location_sdcard">Cartão SD</string> <string name="location_hidden">Oculto (preferencial)</string> <string name="external_repository_dialog_title">Escolha onde armazenar as senhas</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 291429bc..134f834a 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -54,7 +54,6 @@ <string name="clone">Клонировать с сервера</string> <string name="initialize">Использовать локальную директорию</string> <string name="location_dialog_title">Расположение репозитория</string> - <string name="location_dialog_text">Укажите где создать/клонироввать ваш репозиторий с паролями.</string> <string name="location_sdcard">SD-Карта</string> <string name="location_hidden">Скрытый (Предпочтительно)</string> <string name="external_repository_dialog_title">Выберете где хранить пароли</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 99ff2223..53140e6c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,7 +77,7 @@ <string name="clone">Clone from server</string> <string name="initialize">Use local directory</string> <string name="location_dialog_title">Repository location</string> - <string name="location_dialog_text">Select where to create or clone your password repository.</string> + <string name="location_dialog_create_text">Select where to create your password repository</string> <string name="location_sdcard">SD-Card</string> <string name="location_hidden">Hidden (Preferred)</string> <string name="external_repository_dialog_title">Choose where to store the passwords</string> |