summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorashoksinghal <ashoksinghal1990@gmail.com>2020-10-17 22:09:34 +0530
committerGitHub <noreply@github.com>2020-10-17 22:09:34 +0530
commit3981638e0f8d714567f6a3c3a25dc54599263af2 (patch)
tree4148e109a1c0b7eb75b24e24be120a2a7edf8d36 /app/src/main/java
parent6c1e41ba1050c92f4b615f7e857e0d085120a242 (diff)
Use BottomSheet in place of Snackbar for longer messages (#1157)
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt10
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt15
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt20
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/ui/dialogs/BasicBottomSheet.kt28
4 files changed, 51 insertions, 22 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
index 7c1dae9b..ee87f272 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
@@ -24,7 +24,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.github.michaelbull.result.fold
import com.github.michaelbull.result.runCatching
import com.github.michaelbull.result.onFailure
-import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.databinding.PasswordRecyclerViewBinding
import com.zeapo.pwdstore.git.BaseGitActivity
import com.zeapo.pwdstore.git.GitServerConfigActivity
@@ -32,6 +31,7 @@ import com.zeapo.pwdstore.git.config.AuthMode
import com.zeapo.pwdstore.git.config.GitSettings
import com.zeapo.pwdstore.ui.OnOffItemAnimator
import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter
+import com.zeapo.pwdstore.ui.dialogs.BasicBottomSheet
import com.zeapo.pwdstore.ui.dialogs.ItemCreationBottomSheet
import com.zeapo.pwdstore.utils.PasswordItem
import com.zeapo.pwdstore.utils.PasswordRepository
@@ -87,11 +87,13 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) {
requireStore().refreshPasswordList()
binding.swipeRefresher.isRefreshing = false
} else if (!PasswordRepository.isGitRepo()) {
- Snackbar.make(binding.root, getString(R.string.clone_git_repo), Snackbar.LENGTH_INDEFINITE)
- .setAction(R.string.clone_button) {
+ BasicBottomSheet.Builder(requireContext())
+ .setMessageRes(R.string.clone_git_repo)
+ .setPositiveButtonClickListener(getString(R.string.clone_button)) {
swipeResult.launch(GitServerConfigActivity.createCloneIntent(requireContext()))
}
- .show()
+ .build()
+ .show(requireActivity().supportFragmentManager, "NOT_A_GIT_REPO")
binding.swipeRefresher.isRefreshing = false
} else {
// When authentication is set to AuthMode.None then the only git operation we can
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
index b7ada287..edfd78b3 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt
@@ -46,6 +46,7 @@ import com.zeapo.pwdstore.crypto.PasswordCreationActivity
import com.zeapo.pwdstore.git.BaseGitActivity
import com.zeapo.pwdstore.git.config.AuthMode
import com.zeapo.pwdstore.git.config.GitSettings
+import com.zeapo.pwdstore.ui.dialogs.BasicBottomSheet
import com.zeapo.pwdstore.ui.dialogs.FolderCreationDialogFragment
import com.zeapo.pwdstore.ui.onboarding.activity.OnboardingActivity
import com.zeapo.pwdstore.utils.PasswordItem
@@ -373,17 +374,13 @@ class PasswordStore : BaseGitActivity() {
*/
private fun hasRequiredStoragePermissions(): Boolean {
return if (!isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
- Snackbar.make(
- findViewById(R.id.main_layout),
- getString(R.string.access_sdcard_text),
- Snackbar.LENGTH_INDEFINITE
- ).run {
- setAction(getString(R.string.snackbar_action_grant)) {
+ BasicBottomSheet.Builder(this)
+ .setMessageRes(R.string.access_sdcard_text)
+ .setPositiveButtonClickListener(getString(R.string.snackbar_action_grant)) {
storagePermissionRequest.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
- dismiss()
}
- show()
- }
+ .build()
+ .show(supportFragmentManager, "STORAGE_PERMISSION_MISSING")
false
} else {
checkLocalRepository()
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 4b220be5..364dcc1a 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
@@ -115,10 +115,25 @@ class GitServerConfigActivity : BaseGitActivity() {
GitSettings.UpdateConnectionSettingsResult.FailedToParseUrl -> {
Snackbar.make(binding.root, getString(R.string.git_server_config_save_error), Snackbar.LENGTH_LONG).show()
}
+
is GitSettings.UpdateConnectionSettingsResult.MissingUsername -> {
when (updateResult.newProtocol) {
- Protocol.Https -> Snackbar.make(binding.root, getString(R.string.git_server_config_save_missing_username_https), Snackbar.LENGTH_LONG).show()
- Protocol.Ssh -> Snackbar.make(binding.root, getString(R.string.git_server_config_save_missing_username_ssh), Snackbar.LENGTH_LONG).show()
+ Protocol.Https ->
+ BasicBottomSheet.Builder(this)
+ .setTitleRes(R.string.ssh_scheme_needed_title)
+ .setMessageRes(R.string.git_server_config_save_missing_username_https)
+ .setPositiveButtonClickListener {
+ }
+ .build()
+ .show(supportFragmentManager, "HTTPS_MISSING_USERNAME")
+ Protocol.Ssh ->
+ BasicBottomSheet.Builder(this)
+ .setTitleRes(R.string.ssh_scheme_needed_title)
+ .setMessageRes(R.string.git_server_config_save_missing_username_ssh)
+ .setPositiveButtonClickListener {
+ }
+ .build()
+ .show(supportFragmentManager, "SSH_MISSING_USERNAME")
}
}
GitSettings.UpdateConnectionSettingsResult.Valid -> {
@@ -201,7 +216,6 @@ class GitServerConfigActivity : BaseGitActivity() {
// Silently delete & replace the lone .git folder if it exists
if (localDir.exists() && localDirFiles.size == 1 && localDirFiles[0].name == ".git") {
localDir.deleteRecursively()
-
}
}.onFailure { e ->
e(e)
diff --git a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/BasicBottomSheet.kt b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/BasicBottomSheet.kt
index 5f79baf8..6f028009 100644
--- a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/BasicBottomSheet.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/BasicBottomSheet.kt
@@ -28,8 +28,10 @@ import com.zeapo.pwdstore.utils.viewBinding
* API through [Builder] to create a similar UI, just at the bottom of the screen.
*/
class BasicBottomSheet private constructor(
- val title: String,
+ val title: String?,
val message: String,
+ val positiveButtonLabel: String?,
+ val negativeButtonLabel: String?,
val positiveButtonClickListener: View.OnClickListener?,
val negativeButtonClickListener: View.OnClickListener?,
) : BottomSheetDialogFragment() {
@@ -65,9 +67,15 @@ class BasicBottomSheet private constructor(
peekHeight = 0
addBottomSheetCallback(bottomSheetCallback)
}
- binding.bottomSheetTitle.text = title
+ if (!title.isNullOrEmpty()) {
+ binding.bottomSheetTitle.isVisible = true
+ binding.bottomSheetTitle.text = title
+ }
binding.bottomSheetMessage.text = message
if (positiveButtonClickListener != null) {
+ positiveButtonLabel?.let { buttonLbl ->
+ binding.bottomSheetOkButton.text = buttonLbl
+ }
binding.bottomSheetOkButton.isVisible = true
binding.bottomSheetOkButton.setOnClickListener {
positiveButtonClickListener.onClick(it)
@@ -76,6 +84,9 @@ class BasicBottomSheet private constructor(
}
if (negativeButtonClickListener != null) {
binding.bottomSheetCancelButton.isVisible = true
+ negativeButtonLabel?.let { buttonLbl ->
+ binding.bottomSheetCancelButton.text = buttonLbl
+ }
binding.bottomSheetCancelButton.setOnClickListener {
negativeButtonClickListener.onClick(it)
dismiss()
@@ -98,6 +109,8 @@ class BasicBottomSheet private constructor(
private var title: String? = null
private var message: String? = null
+ private var positiveButtonLabel: String? = null
+ private var negativeButtonLabel: String? = null
private var positiveButtonClickListener: View.OnClickListener? = null
private var negativeButtonClickListener: View.OnClickListener? = null
@@ -121,22 +134,25 @@ class BasicBottomSheet private constructor(
return this
}
- fun setPositiveButtonClickListener(listener: View.OnClickListener): Builder {
+ fun setPositiveButtonClickListener(buttonLabel: String? = null, listener: View.OnClickListener): Builder {
this.positiveButtonClickListener = listener
+ this.positiveButtonLabel = buttonLabel
return this
}
- fun setNegativeButtonClickListener(listener: View.OnClickListener): Builder {
+ fun setNegativeButtonClickListener(buttonLabel: String? = null, listener: View.OnClickListener): Builder {
this.negativeButtonClickListener = listener
+ this.negativeButtonLabel = buttonLabel
return this
}
fun build(): BasicBottomSheet {
- require(title != null) { "Title needs to be set" }
require(message != null) { "Message needs to be set" }
return BasicBottomSheet(
- title!!,
+ title,
message!!,
+ positiveButtonLabel,
+ negativeButtonLabel,
positiveButtonClickListener,
negativeButtonClickListener
)