summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAditya Wasan <adityawasan55@gmail.com>2020-03-07 21:54:34 +0530
committerGitHub <noreply@github.com>2020-03-07 21:54:34 +0530
commit65b8e77f92ba8464f3bf1d00dc6449c5b0d1aebe (patch)
treefbd4264edb1703a27b0c363f50e33df509a602b0 /app/src/main/java
parent29f124a0bcd900aa131e30dbe0452dcd53f21af2 (diff)
Show snackbar when git repo is not initialized (#651)
Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt18
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt9
2 files changed, 17 insertions, 10 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
index 56018995..a6c7bc67 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
@@ -18,8 +18,8 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
-import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton
+import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.git.GitActivity
import com.zeapo.pwdstore.ui.adapters.PasswordRecyclerAdapter
import com.zeapo.pwdstore.utils.PasswordItem
@@ -48,7 +48,7 @@ class PasswordFragment : Fragment() {
private lateinit var recyclerView: RecyclerView
private lateinit var listener: OnFragmentInteractionListener
private lateinit var settings: SharedPreferences
- private lateinit var swipe_refresher: SwipeRefreshLayout
+ private lateinit var swipeRefresher: SwipeRefreshLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -66,13 +66,11 @@ class PasswordFragment : Fragment() {
val view = inflater.inflate(R.layout.password_recycler_view, container, false)
// use a linear layout manager
val layoutManager = LinearLayoutManager(requireContext())
- swipe_refresher = view.findViewById(R.id.swipe_refresher)
- swipe_refresher.setOnRefreshListener {
- if (!PasswordRepository.isInitialized) {
- MaterialAlertDialogBuilder(requireContext())
- .setMessage(getString(R.string.creation_dialog_text))
- .setPositiveButton(getString(R.string.dialog_ok), null).show()
- swipe_refresher.isRefreshing = false
+ swipeRefresher = view.findViewById(R.id.swipe_refresher)
+ swipeRefresher.setOnRefreshListener {
+ if (!PasswordRepository.isGitRepo()) {
+ Snackbar.make(view, getString(R.string.clone_git_repo), Snackbar.LENGTH_SHORT).show()
+ swipeRefresher.isRefreshing = false
} else {
val intent = Intent(context, GitActivity::class.java)
intent.putExtra("Operation", GitActivity.REQUEST_SYNC)
@@ -145,7 +143,7 @@ class PasswordFragment : Fragment() {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- swipe_refresher.isRefreshing = false
+ swipeRefresher.isRefreshing = false
}
/** clears the adapter content and sets it back to the root view */
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 8030d976..8947f43a 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt
@@ -76,6 +76,15 @@ open class PasswordRepository protected constructor() {
get() = repository != null
@JvmStatic
+ fun isGitRepo(): Boolean {
+ if (repository != null) {
+ // Check if remote exists
+ return repository!!.config.getSubsections("remote").isNotEmpty() ?: false
+ }
+ return false
+ }
+
+ @JvmStatic
@Throws(Exception::class)
fun createRepository(localDir: File) {
localDir.delete()