Commit a7a6595a authored by Valere's avatar Valere

Prompt to accept IM terms if needed

parent 9060afff
......@@ -18,6 +18,7 @@
package im.vector.activity
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Color
......@@ -26,9 +27,13 @@ import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import com.airbnb.mvrx.viewModel
import im.vector.R
import im.vector.activity.util.TERMS_REQUEST_CODE
import im.vector.contacts.ContactsManager
import im.vector.fragments.roomwidgets.*
import im.vector.ui.themes.ThemeUtils
import im.vector.widgets.Widget
import org.matrix.androidsdk.core.callback.ApiCallback
import org.matrix.androidsdk.features.terms.TermsManager
/*
* This class displays a widget
......
......@@ -16,6 +16,8 @@
package im.vector.fragments.roomwidgets
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.os.Build
import android.os.Bundle
......@@ -35,9 +37,12 @@ import androidx.lifecycle.Observer
import butterknife.BindView
import com.airbnb.mvrx.*
import im.vector.R
import im.vector.activity.ReviewTermsActivity
import im.vector.activity.util.TERMS_REQUEST_CODE
import im.vector.fragments.VectorBaseMvRxFragment
import im.vector.ui.themes.ThemeUtils
import im.vector.util.openUrlInExternalBrowser
import org.matrix.androidsdk.features.terms.TermsManager
class RoomWidgetFragment : VectorBaseMvRxFragment() {
......@@ -67,6 +72,26 @@ class RoomWidgetFragment : VectorBaseMvRxFragment() {
mWidgetWebView?.isVisible = true
}
})
viewModel.termsNotSignedEvent.observe(this, Observer { termsEvent ->
termsEvent?.getContentIfNotHandled()?.let {
viewModel.widgetsManager?.uiUrl?.let { uiUrl ->
startActivityForResult(ReviewTermsActivity.intent(requireContext(),
TermsManager.ServiceType.IntegrationManager, uiUrl, it.token),
TERMS_REQUEST_CODE)
}
}
})
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == TERMS_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
viewModel.refreshAfterTermsAccepted()
} else {
viewModel.doFinish()
}
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
......
......@@ -32,6 +32,7 @@ import org.matrix.androidsdk.core.callback.ApiCallback
import org.matrix.androidsdk.core.model.MatrixError
import org.matrix.androidsdk.data.Room
import org.matrix.androidsdk.features.integrationmanager.IntegrationManager
import org.matrix.androidsdk.features.terms.TermsNotSignedException
enum class WidgetState {
UNKWNOWN,
......@@ -64,6 +65,7 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
}
var navigateEvent: MutableLiveData<LiveEvent<String>> = MutableLiveData()
var termsNotSignedEvent: MutableLiveData<LiveEvent<TermsNotSignedException>> = MutableLiveData()
var loadWebURLEvent: MutableLiveData<LiveEvent<String>> = MutableLiveData()
var toastMessageEvent: MutableLiveData<LiveEvent<String>> = MutableLiveData()
......@@ -212,6 +214,10 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
navigateEvent.postValue(LiveEvent(NAVIGATE_FINISH))
}
fun refreshAfterTermsAccepted() {
onWidgetAllowed()
}
private fun onWidgetAllowed(applicationContext: Context = VectorApp.getInstance().applicationContext) {
setState {
......@@ -251,7 +257,11 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
}
override fun onUnexpectedError(e: Exception) {
onError(e.localizedMessage)
if (e is TermsNotSignedException) {
termsNotSignedEvent.postValue(LiveEvent(e))
} else {
onError(e.localizedMessage)
}
}
})
} else {
......
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