Commit dbd26437 authored by Valere's avatar Valere

Dismiss allow bottomsheet before accountdata API callback

Cleaning
parent 58ca8256
......@@ -75,9 +75,6 @@ class WidgetActivity : VectorAppCompatActivity() {
.commit()
}
}
WidgetState.CLOSING_WIDGET -> {
}
}
}
......
......@@ -49,7 +49,6 @@ class RoomWidgetFragment : VectorBaseMvRxFragment() {
@BindView(R.id.webview_error_text)
lateinit var errorText: TextView
@BindView(R.id.widget_progress_bar)
lateinit var webProgressBar: ProgressBar
......@@ -203,9 +202,6 @@ class RoomWidgetFragment : VectorBaseMvRxFragment() {
}
}
}
WidgetState.CLOSING_WIDGET -> {
// showWaitingView()
}
}
}
......
......@@ -85,17 +85,17 @@ class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() {
@OnClick(R.id.bottom_sheet_widget_permission_decline_button)
fun doDecline() {
viewModel.blockWidget {
dismiss()
sharedActivityViewModel.doFinish()
}
viewModel.blockWidget()
//optimistic dismiss
dismiss()
sharedActivityViewModel.doFinish()
}
@OnClick(R.id.bottom_sheet_widget_permission_continue_button)
fun doAccept() {
viewModel.allowWidget {
dismiss()
}
viewModel.allowWidget()
//optimistic dismiss
dismiss()
}
@Parcelize
......
......@@ -23,6 +23,7 @@ import im.vector.Matrix
import im.vector.R
import im.vector.widgets.Widget
import org.matrix.androidsdk.MXSession
import org.matrix.androidsdk.core.Log
import org.matrix.androidsdk.core.callback.ApiCallback
import org.matrix.androidsdk.core.model.MatrixError
import java.net.URL
......@@ -70,45 +71,46 @@ class RoomWidgetPermissionViewModel(val session: MXSession, val widget: Widget,
}
}
fun allowWidget(onFinished: (() -> Unit)) {
fun allowWidget(onFinished: (() -> Unit)? = null) {
session.integrationManager.setWidgetAllowed(widget.widgetEvent?.eventId
?: "", true, object : ApiCallback<Void?> {
override fun onSuccess(info: Void?) {
onFinished()
onFinished?.invoke()
}
override fun onUnexpectedError(e: Exception?) {
//TODO.. make the button with a loading state?
override fun onUnexpectedError(e: Exception) {
Log.e(LOG_TAG, e.message)
}
override fun onNetworkError(e: Exception?) {
//TODO.. make the button with a loading state?
override fun onNetworkError(e: Exception) {
Log.e(LOG_TAG, e.message)
}
override fun onMatrixError(e: MatrixError?) {
//TODO.. make the button with a loading state?
override fun onMatrixError(e: MatrixError) {
Log.e(LOG_TAG, e.message)
}
})
}
fun blockWidget(onFinished: (() -> Unit)) {
fun blockWidget(onFinished: (() -> Unit)? = null) {
session.integrationManager.setWidgetAllowed(widget.widgetEvent?.eventId
?: "", false, object : ApiCallback<Void?> {
override fun onSuccess(info: Void?) {
onFinished()
onFinished?.invoke()
}
override fun onUnexpectedError(e: Exception?) {
//TODO.. make the button with a loading state?
override fun onUnexpectedError(e: Exception) {
Log.e(LOG_TAG, e.message)
}
override fun onNetworkError(e: Exception?) {
//TODO.. make the button with a loading state?
override fun onNetworkError(e: Exception) {
Log.e(LOG_TAG, e.message)
}
override fun onMatrixError(e: MatrixError?) {
//TODO.. make the button with a loading state?
override fun onMatrixError(e: MatrixError) {
Log.e(LOG_TAG, e.message)
}
})
......@@ -116,6 +118,8 @@ class RoomWidgetPermissionViewModel(val session: MXSession, val widget: Widget,
companion object : MvRxViewModelFactory<RoomWidgetPermissionViewModel, RoomWidgetPermissionViewState> {
val LOG_TAG = RoomWidgetPermissionViewModel::class.simpleName
override fun create(viewModelContext: ViewModelContext, state: RoomWidgetPermissionViewState): RoomWidgetPermissionViewModel? {
val args = viewModelContext.args<RoomWidgetPermissionBottomSheet.FragArgs>()
val session = Matrix.getMXSession(viewModelContext.activity, args.mxId)
......
......@@ -36,8 +36,7 @@ import org.matrix.androidsdk.features.integrationmanager.IntegrationManager
enum class WidgetState {
UNKWNOWN,
WIDGET_NOT_ALLOWED,
WIDGET_ALLOWED,
CLOSING_WIDGET
WIDGET_ALLOWED
}
data class RoomWidgetViewModelState(
......@@ -55,8 +54,6 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
companion object : MvRxViewModelFactory<RoomWidgetViewModel, RoomWidgetViewModelState> {
const val NAVIGATE_FINISH = "NAVIGATE_FINISH"
//private val LOG_TAG = KeysBackupSetupSharedViewModel::class.java.name
override fun create(viewModelContext: ViewModelContext, state: RoomWidgetViewModelState): RoomWidgetViewModel? {
return (viewModelContext.activity.intent?.extras?.getSerializable(WidgetActivity.EXTRA_WIDGET_ID) as? Widget)?.let {
......@@ -184,11 +181,6 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
AlertDialog.Builder(context)
.setMessage(R.string.widget_delete_message_confirmation)
.setPositiveButton(R.string.remove) { _, _ ->
// showWaitingView()
setState {
copy(status = WidgetState.CLOSING_WIDGET)
}
widgetsManager?.closeWidget(session, room, widget.widgetId, object : ApiCallback<Void> {
override fun onSuccess(info: Void?) {
......@@ -197,10 +189,6 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
private fun onError(errorMessage: String) {
toastMessageEvent.postValue(LiveEvent(errorMessage))
//TODO should not be handled with this state
setState {
copy(status = WidgetState.WIDGET_ALLOWED)
}
}
override fun onNetworkError(e: Exception) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment