|
@@ -68,7 +68,7 @@ class GuestAccessHelper(
|
|
|
viewModel.allowGuestsViewState.observe(lifecycleOwner){uiState ->
|
|
|
when(uiState){
|
|
|
is ConversationInfoViewModel.AllowGuestsUIState.Success ->{
|
|
|
- if(uiState.result){
|
|
|
+ if(uiState.allow){
|
|
|
showAllOptions()
|
|
|
}else{
|
|
|
hideAllOptions()
|
|
@@ -91,8 +91,8 @@ class GuestAccessHelper(
|
|
|
val isChecked = binding.guestAccessView.passwordProtectionSwitch.isChecked
|
|
|
binding.guestAccessView.passwordProtectionSwitch.isChecked = !isChecked
|
|
|
if (isChecked) {
|
|
|
- conversationsRepository.password("", conversation.token!!).subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread()).subscribe(PasswordResultObserver(false))
|
|
|
+ viewModel.setPassword("",conversation.token)
|
|
|
+ passwordObserver(false,"")
|
|
|
} else {
|
|
|
showPasswordDialog()
|
|
|
}
|
|
@@ -104,6 +104,38 @@ class GuestAccessHelper(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun passwordObserver(passwordSet:Boolean, password:String){
|
|
|
+ viewModel.passwordViewState.observe(lifecycleOwner){uiState ->
|
|
|
+ when(uiState){
|
|
|
+ is ConversationInfoViewModel.PasswordUiState.Success ->{
|
|
|
+ val weakPassword = password.trim().length < 8
|
|
|
+ binding.guestAccessView.passwordProtectionSwitch.isChecked = passwordSet && weakPassword
|
|
|
+ if (weakPassword && passwordSet) {
|
|
|
+ val builder = MaterialAlertDialogBuilder(activity)
|
|
|
+ builder.apply {
|
|
|
+ setTitle(R.string.nc_guest_access_password_weak_alert_title)
|
|
|
+ setMessage(R.string.nc_weak_password)
|
|
|
+ setPositiveButton("OK") { _, _ ->
|
|
|
+ }
|
|
|
+ }
|
|
|
+ createDialog(builder)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ is ConversationInfoViewModel.PasswordUiState.Error ->{
|
|
|
+ val exception = uiState.message
|
|
|
+ val message = context.getString(R.string.nc_guest_access_password_failed)
|
|
|
+ Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
|
|
|
+ Log.e(TAG, exception)
|
|
|
+
|
|
|
+ }
|
|
|
+ is ConversationInfoViewModel.PasswordUiState.None ->{
|
|
|
+ //unused atm
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private fun showPasswordDialog() {
|
|
|
val builder = MaterialAlertDialogBuilder(activity)
|
|
|
builder.apply {
|
|
@@ -113,10 +145,8 @@ class GuestAccessHelper(
|
|
|
setTitle(R.string.nc_guest_access_password_dialog_title)
|
|
|
setPositiveButton(R.string.nc_ok) { _, _ ->
|
|
|
val password = dialogPassword.password.text.toString()
|
|
|
- conversationsRepository.password(password, conversation.token!!)
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(PasswordResultObserver(true))
|
|
|
+ viewModel.setPassword(password, conversation.token)
|
|
|
+ passwordObserver(true, password)
|
|
|
}
|
|
|
setNegativeButton(R.string.nc_cancel) { _, _ ->
|
|
|
binding.guestAccessView.passwordProtectionSwitch.isChecked = false
|