From bee20ac44a6b03082ee85cb52db4d8f32e2dd899 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 24 Apr 2020 02:05:07 +0530 Subject: Better detect uninitialized repositories and offer to clone (#738) * PasswordRepository: more comprehensive check for valid repository * PasswordFragment: Give 'repo uninitialized' Snackbar some purpose in life * GitOperationActivity: finish immediately when an unhandled request code is used * PasswordFragment: Make uninitialized repo Snackbar indefinite * spotless Signed-off-by: Harsh Shandilya --- app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt | 10 ++++++++-- .../main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt | 4 ++++ .../main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt | 4 +++- app/src/main/res/values/strings.xml | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt index 2b1551fa..1b9d3f9c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt @@ -26,6 +26,7 @@ import com.google.android.material.snackbar.Snackbar import com.zeapo.pwdstore.databinding.PasswordRecyclerViewBinding import com.zeapo.pwdstore.git.BaseGitActivity import com.zeapo.pwdstore.git.GitOperationActivity +import com.zeapo.pwdstore.git.GitServerConfigActivity import com.zeapo.pwdstore.ui.OnOffItemAnimator import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter import com.zeapo.pwdstore.ui.dialogs.ItemCreationBottomSheet @@ -69,8 +70,13 @@ class PasswordFragment : Fragment() { swipeRefresher = binding.swipeRefresher swipeRefresher.setOnRefreshListener { if (!PasswordRepository.isGitRepo()) { - Snackbar.make(binding.root, getString(R.string.clone_git_repo), Snackbar.LENGTH_SHORT) - .show() + Snackbar.make(binding.root, getString(R.string.clone_git_repo), Snackbar.LENGTH_INDEFINITE) + .setAction(R.string.clone_button) { + val intent = Intent(context, GitServerConfigActivity::class.java) + intent.putExtra(BaseGitActivity.REQUEST_ARG_OP, BaseGitActivity.REQUEST_CLONE) + startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE) + } + .show() swipeRefresher.isRefreshing = false } else { val intent = Intent(context, GitOperationActivity::class.java) diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt index ec73dae6..37f5e35c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt @@ -20,6 +20,10 @@ open class GitOperationActivity : BaseGitActivity() { REQUEST_PULL -> syncRepository(REQUEST_PULL) REQUEST_PUSH -> syncRepository(REQUEST_PUSH) REQUEST_SYNC -> syncRepository(REQUEST_SYNC) + else -> { + setResult(RESULT_CANCELED) + finish() + } } } 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 bfe101a5..b2367431 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -80,7 +80,9 @@ open class PasswordRepository protected constructor() { fun isGitRepo(): Boolean { if (repository != null) { // Check if remote exists - return repository!!.config.getSubsections("remote").isNotEmpty() + return repository!!.config.getSubsections("remote").isNotEmpty() && + repository!!.objectDatabase.exists() && + repository!!.allRefs.isNotEmpty() } return false } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bc7f0a6f..33c0b103 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -100,7 +100,7 @@ Email email Please enter a valid email address - Clone! + Clone Name @@ -344,7 +344,7 @@ Open search bar when app is launched Password Generator Tap here to clear clipboard - Clone a git repository to sync changes + The repository must be cloned before syncing changes. App theme Light Dark -- cgit v1.2.3