mirror of
https://github.com/android-password-store/Android-Password-Store.git
synced 2026-04-24 17:00:13 +02:00
Use BottomSheet in place of Snackbar for longer messages (#1157)
This commit is contained in:
parent
6c1e41ba10
commit
3981638e0f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Bottom sheet title" />
|
||||
|
|
|
|||
|
|
@ -329,8 +329,8 @@
|
|||
<string name="connection_mode_openkeychain" translatable="false">OpenKeychain</string>
|
||||
<string name="git_server_config_save_success">Successfully saved configuration</string>
|
||||
<string name="git_server_config_save_error">The provided repository URL is not valid</string>
|
||||
<string name="git_server_config_save_missing_username_https">Please specify the HTTPS username in the form https://username@example.com/…</string>
|
||||
<string name="git_server_config_save_missing_username_ssh">Please specify the SSH username in the form username@example.com:…</string>
|
||||
<string name="git_server_config_save_missing_username_https">Please specify the HTTPS username in the form https://username@example.com/username/…</string>
|
||||
<string name="git_server_config_save_missing_username_ssh">Please specify the SSH username in the form username@example.com:username/…</string>
|
||||
<string name="git_server_config_save_auth_mode_mismatch">Valid authentication modes for %1$s: %2$s</string>
|
||||
<string name="git_operation_wrong_passphrase">Wrong passphrase</string>
|
||||
<string name="git_operation_wrong_password">Wrong password</string>
|
||||
|
|
|
|||
Loading…
Reference in a new issue