From 65b8e77f92ba8464f3bf1d00dc6449c5b0d1aebe Mon Sep 17 00:00:00 2001 From: Aditya Wasan Date: Sat, 7 Mar 2020 21:54:34 +0530 Subject: Show snackbar when git repo is not initialized (#651) Signed-off-by: Aditya Wasan --- .../main/java/com/zeapo/pwdstore/PasswordFragment.kt | 18 ++++++++---------- .../com/zeapo/pwdstore/utils/PasswordRepository.kt | 9 +++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'app/src/main/java') 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 @@ -75,6 +75,15 @@ open class PasswordRepository protected constructor() { val isInitialized: Boolean 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) { -- cgit v1.2.3