aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-04-24 02:05:07 +0530
committerGitHub <noreply@github.com>2020-04-24 02:05:07 +0530
commitbee20ac44a6b03082ee85cb52db4d8f32e2dd899 (patch)
tree2ea352ba193d34d6f85d0f8d177627f9e5eff5a4 /app/src/main/java/com
parenta5437c480ab189e0a6af86aae638e2e67d091831 (diff)
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 <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt10
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt4
3 files changed, 15 insertions, 3 deletions
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
}