Commit 295dc1c5 authored by Valere's avatar Valere

Code review

parent a7a6595a
......@@ -45,8 +45,6 @@ data class RoomWidgetViewModelState(
val formattedURL: Async<String> = Uninitialized,
val webviewLoadedUrl: Async<String> = Uninitialized,
val widgetName: String = "",
val authorName: String? = null,
val authorId: String? = null,
val canManageWidgets: Boolean = false
) : MvRxState
......@@ -62,6 +60,12 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
} ?: super.create(viewModelContext, state)
}
override fun initialState(viewModelContext: ViewModelContext): RoomWidgetViewModelState? {
return (viewModelContext.activity.intent?.extras?.getSerializable(WidgetActivity.EXTRA_WIDGET_ID) as? Widget)?.let {
RoomWidgetViewModelState(widgetName = it.humanName)
}
}
}
var navigateEvent: MutableLiveData<LiveEvent<String>> = MutableLiveData()
......@@ -87,9 +91,6 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
}
init {
setState {
copy(widgetName = widget.humanName)
}
configure()
session?.integrationManager?.addListener(object : IntegrationManager.IntegrationManagerManagerListener {
......@@ -164,7 +165,7 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
val isAllowed = session
?.integrationManager
?.getKnownWidgetPermissions()
?.findLast { it.stateEventId == widget.widgetEvent.eventId }
?.find { it.stateEventId == widget.widgetEvent.eventId }
?.allowed
?: false
......
......@@ -19,7 +19,6 @@ import android.app.Activity
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import android.widget.ProgressBar
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
......@@ -48,8 +47,8 @@ class AcceptTermsFragment : VectorBaseFragment(), TermsController.Listener {
@BindView(R.id.terms_bottom_accept)
lateinit var acceptButton: Button
@BindView(R.id.termsLoadingIndicator)
lateinit var progressBar: ProgressBar
@BindView(R.id.waitOverlay)
lateinit var waitingModalOverlay: ViewGroup
@BindView(R.id.termsBottomBar)
lateinit var bottomBar: ViewGroup
......@@ -73,10 +72,10 @@ class AcceptTermsFragment : VectorBaseFragment(), TermsController.Listener {
when (terms) {
is MxAsync.Loading -> {
bottomBar.isVisible = false
progressBar.isVisible = true
waitingModalOverlay.isVisible = true
}
is MxAsync.Error -> {
progressBar.isVisible = false
waitingModalOverlay.isVisible = false
terms.stringResId.let { stringRes ->
AlertDialog.Builder(requireActivity())
.setMessage(stringRes)
......@@ -88,20 +87,23 @@ class AcceptTermsFragment : VectorBaseFragment(), TermsController.Listener {
}
is MxAsync.Success -> {
updateState(terms.value)
progressBar.isVisible = false
waitingModalOverlay.isVisible = false
bottomBar.isVisible = true
acceptButton.isEnabled = terms.value.all { it.accepted }
}
else -> {
waitingModalOverlay.isVisible = false
}
}
})
viewModel.acceptTerms.observe(this, Observer { request ->
when (request) {
is MxAsync.Loading -> {
progressBar.isVisible = true
waitingModalOverlay.isVisible = true
}
is MxAsync.Error -> {
progressBar.isVisible = false
waitingModalOverlay.isVisible = false
request.stringResId.let { stringRes ->
AlertDialog.Builder(requireActivity())
.setMessage(stringRes)
......@@ -110,9 +112,14 @@ class AcceptTermsFragment : VectorBaseFragment(), TermsController.Listener {
}
}
is MxAsync.Success -> {
waitingModalOverlay.isVisible = false
activity?.setResult(Activity.RESULT_OK)
activity?.finish()
}
else -> {
waitingModalOverlay.isVisible = false
}
}
})
}
......
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.widgets;
import org.matrix.androidsdk.core.model.MatrixError;
/**
* Widget error code
*/
public class WidgetError extends MatrixError {
public static final String WIDGET_NOT_ENOUGH_POWER_ERROR_CODE = "WIDGET_NOT_ENOUGH_POWER_ERROR_CODE";
public static final String WIDGET_CREATION_FAILED_ERROR_CODE = "WIDGET_CREATION_FAILED_ERROR_CODE";
/**
* Create a widget error
*
* @param code the error code (see XX_ERROR_CODE)
* @param detailedErrorDescription the detailed error description
*/
public WidgetError(String code, String detailedErrorDescription) {
errcode = code;
error = detailedErrorDescription;
}
}
......@@ -82,25 +82,6 @@ public class WidgetsManager {
return config.getUiUrl();
}
/**
* Widget error code
*/
public static class WidgetError extends MatrixError {
public static final String WIDGET_NOT_ENOUGH_POWER_ERROR_CODE = "WIDGET_NOT_ENOUGH_POWER_ERROR_CODE";
public static final String WIDGET_CREATION_FAILED_ERROR_CODE = "WIDGET_CREATION_FAILED_ERROR_CODE";
/**
* Create a widget error
*
* @param code the error code (see XX_ERROR_CODE)
* @param detailedErrorDescription the detailed error description
*/
public WidgetError(String code, String detailedErrorDescription) {
errcode = code;
error = detailedErrorDescription;
}
}
/**
* Pending widget creation callback
......
......@@ -44,15 +44,23 @@
android:text="@string/accept" />
</LinearLayout>
<ProgressBar
android:id="@+id/termsLoadingIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
<LinearLayout
android:id="@+id/waitOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
tools:visibility="visible">
<ProgressBar
android:id="@+id/termsLoadingIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:visibility="visible" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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