mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 19:05:56 +03:00
Some cleanup:
- use invalidate() from MvRx - use throttleFirst instead of debounce - remove useless observe on main thread - remove useless calls to super.invalidate()
This commit is contained in:
parent
7be3434136
commit
d125cb5c01
16 changed files with 32 additions and 81 deletions
|
@ -95,7 +95,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
|||
protected val viewModelProvider
|
||||
get() = ViewModelProvider(this, viewModelFactory)
|
||||
|
||||
// TODO Other Activity should use this also
|
||||
protected fun <T : VectorViewEvents> VectorViewModel<*, *, T>.observeViewEvents(observer: (T) -> Unit) {
|
||||
viewEvents
|
||||
.observe()
|
||||
|
|
|
@ -31,7 +31,6 @@ import im.vector.riotx.core.di.ScreenComponent
|
|||
import im.vector.riotx.core.error.ErrorFormatter
|
||||
import im.vector.riotx.core.extensions.commitTransaction
|
||||
import im.vector.riotx.core.platform.SimpleFragmentActivity
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.android.synthetic.main.activity.*
|
||||
import javax.inject.Inject
|
||||
|
@ -59,17 +58,9 @@ class SharedSecureStorageActivity : SimpleFragmentActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
toolbar.visibility = View.GONE
|
||||
|
||||
viewModel.viewEvents
|
||||
.observe()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
observeViewEvents(it)
|
||||
}
|
||||
.disposeOnDestroy()
|
||||
viewModel.observeViewEvents { observeViewEvents(it) }
|
||||
|
||||
viewModel.subscribe(this) {
|
||||
renderState(it)
|
||||
}
|
||||
viewModel.subscribe(this) { renderState(it) }
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
|
|
|
@ -22,22 +22,17 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import com.jakewharton.rxbinding3.widget.editorActionEvents
|
||||
import com.jakewharton.rxbinding3.widget.textChanges
|
||||
import im.vector.matrix.android.api.extensions.tryThis
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.utils.startImportTextFromFileIntent
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.fragment_ssss_access_from_key.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class SharedSecuredStorageKeyFragment @Inject constructor(
|
||||
private val colorProvider: ColorProvider
|
||||
) : VectorBaseFragment() {
|
||||
class SharedSecuredStorageKeyFragment @Inject constructor() : VectorBaseFragment() {
|
||||
|
||||
override fun getLayoutResId() = R.layout.fragment_ssss_access_from_key
|
||||
|
||||
|
@ -48,8 +43,7 @@ class SharedSecuredStorageKeyFragment @Inject constructor(
|
|||
ssss_restore_with_key_text.text = getString(R.string.enter_secret_storage_input_key)
|
||||
|
||||
ssss_key_enter_edittext.editorActionEvents()
|
||||
.debounce(300, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||
.subscribe {
|
||||
if (it.actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
submit()
|
||||
|
@ -102,9 +96,6 @@ class SharedSecuredStorageKeyFragment @Inject constructor(
|
|||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(sharedViewModel) { _ ->
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMPORT_FILE_REQ = 0
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import im.vector.riotx.core.extensions.showPassword
|
|||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.utils.colorizeMatchingText
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.fragment_ssss_access_from_passphrase.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
@ -58,8 +57,7 @@ class SharedSecuredStoragePassphraseFragment @Inject constructor(
|
|||
.colorizeMatchingText(key, colorProvider.getColorFromAttribute(android.R.attr.textColorLink))
|
||||
|
||||
ssss_passphrase_enter_edittext.editorActionEvents()
|
||||
.debounce(300, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||
.subscribe {
|
||||
if (it.actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
submit()
|
||||
|
|
|
@ -30,7 +30,6 @@ import im.vector.riotx.core.extensions.showPassword
|
|||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.utils.colorizeMatchingText
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.fragment_bootstrap_enter_account_password.*
|
||||
import kotlinx.android.synthetic.main.fragment_bootstrap_enter_passphrase.bootstrapDescriptionText
|
||||
import kotlinx.android.synthetic.main.fragment_bootstrap_enter_passphrase.ssss_view_show_password
|
||||
|
@ -56,8 +55,7 @@ class BootstrapAccountPasswordFragment @Inject constructor(
|
|||
bootstrapAccountPasswordEditText.hint = getString(R.string.account_password)
|
||||
|
||||
bootstrapAccountPasswordEditText.editorActionEvents()
|
||||
.debounce(300, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||
.subscribe {
|
||||
if (it.actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
submit()
|
||||
|
@ -98,8 +96,6 @@ class BootstrapAccountPasswordFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun invalidate() = withState(sharedViewModel) { state ->
|
||||
super.invalidate()
|
||||
|
||||
if (state.step is BootstrapStep.AccountPassword) {
|
||||
val isPasswordVisible = state.step.isPasswordVisible
|
||||
bootstrapAccountPasswordEditText.showPassword(isPasswordVisible, updateCursor = false)
|
||||
|
|
|
@ -31,7 +31,6 @@ import im.vector.riotx.core.extensions.showPassword
|
|||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.utils.colorizeMatchingText
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.fragment_bootstrap_enter_passphrase.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
@ -63,8 +62,7 @@ class BootstrapConfirmPassphraseFragment @Inject constructor(
|
|||
}
|
||||
|
||||
ssss_passphrase_enter_edittext.editorActionEvents()
|
||||
.debounce(300, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||
.subscribe {
|
||||
if (it.actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
submit()
|
||||
|
@ -96,15 +94,17 @@ class BootstrapConfirmPassphraseFragment @Inject constructor(
|
|||
return@withState
|
||||
}
|
||||
val passphrase = ssss_passphrase_enter_edittext.text?.toString()
|
||||
if (passphrase.isNullOrBlank()) {
|
||||
when {
|
||||
passphrase.isNullOrBlank() ->
|
||||
ssss_passphrase_enter_til.error = getString(R.string.passphrase_empty_error_message)
|
||||
} else if (passphrase != state.passphrase) {
|
||||
passphrase != state.passphrase ->
|
||||
ssss_passphrase_enter_til.error = getString(R.string.passphrase_passphrase_does_not_match)
|
||||
} else {
|
||||
else -> {
|
||||
view?.hideKeyboard()
|
||||
sharedViewModel.handle(BootstrapActions.DoInitialize(passphrase))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(sharedViewModel) { state ->
|
||||
if (state.step is BootstrapStep.ConfirmPassphrase) {
|
||||
|
|
|
@ -30,7 +30,6 @@ import im.vector.riotx.core.platform.VectorBaseFragment
|
|||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.utils.colorizeMatchingText
|
||||
import im.vector.riotx.features.settings.VectorLocale
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.fragment_bootstrap_enter_passphrase.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
@ -53,12 +52,11 @@ class BootstrapEnterPassphraseFragment @Inject constructor(
|
|||
|
||||
ssss_passphrase_enter_edittext.hint = getString(R.string.passphrase_enter_passphrase)
|
||||
withState(sharedViewModel) {
|
||||
// set initial value (usefull when coming back)
|
||||
// set initial value (useful when coming back)
|
||||
ssss_passphrase_enter_edittext.setText(it.passphrase ?: "")
|
||||
}
|
||||
ssss_passphrase_enter_edittext.editorActionEvents()
|
||||
.debounce(300, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||
.subscribe {
|
||||
if (it.actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
submit()
|
||||
|
|
|
@ -39,7 +39,6 @@ import im.vector.riotx.core.platform.VectorBaseFragment
|
|||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.utils.colorizeMatchingText
|
||||
import im.vector.riotx.core.utils.startImportTextFromFileIntent
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.fragment_bootstrap_enter_passphrase.bootstrapDescriptionText
|
||||
import kotlinx.android.synthetic.main.fragment_bootstrap_migrate_backup.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -57,12 +56,11 @@ class BootstrapMigrateBackupFragment @Inject constructor(
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
withState(sharedViewModel) {
|
||||
// set initial value (usefull when coming back)
|
||||
// set initial value (useful when coming back)
|
||||
bootstrapMigrateEditText.setText(it.passphrase ?: "")
|
||||
}
|
||||
bootstrapMigrateEditText.editorActionEvents()
|
||||
.debounce(300, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||
.subscribe {
|
||||
if (it.actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
submit()
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.view.View
|
|||
import com.airbnb.mvrx.Incomplete
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.extensions.cleanup
|
||||
|
@ -50,7 +51,6 @@ class GroupListFragment @Inject constructor(
|
|||
groupController.callback = this
|
||||
stateView.contentView = groupListView
|
||||
groupListView.configureWith(groupController)
|
||||
viewModel.subscribe { renderState(it) }
|
||||
viewModel.observeViewEvents {
|
||||
when (it) {
|
||||
is GroupListViewEvents.OpenGroupSummary -> sharedActionViewModel.post(HomeActivitySharedAction.OpenGroup)
|
||||
|
@ -64,7 +64,7 @@ class GroupListFragment @Inject constructor(
|
|||
super.onDestroyView()
|
||||
}
|
||||
|
||||
private fun renderState(state: GroupListViewState) {
|
||||
override fun invalidate() = withState(viewModel) { state ->
|
||||
when (state.asyncGroups) {
|
||||
is Incomplete -> stateView.state = StateView.State.Loading
|
||||
is Success -> stateView.state = StateView.State.Content
|
||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.riotx.features.home.room.breadcrumbs
|
|||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.extensions.cleanup
|
||||
import im.vector.riotx.core.extensions.configureWith
|
||||
|
@ -42,8 +43,6 @@ class BreadcrumbsFragment @Inject constructor(
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
setupRecyclerView()
|
||||
sharedActionViewModel = activityViewModelProvider.get(RoomDetailSharedActionViewModel::class.java)
|
||||
|
||||
breadcrumbsViewModel.subscribe { renderState(it) }
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -57,8 +56,7 @@ class BreadcrumbsFragment @Inject constructor(
|
|||
breadcrumbsController.listener = this
|
||||
}
|
||||
|
||||
// TODO Use invalidate() ?
|
||||
private fun renderState(state: BreadcrumbsViewState) {
|
||||
override fun invalidate() = withState(breadcrumbsViewModel) { state ->
|
||||
breadcrumbsController.update(state)
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,6 @@ class RoomDetailFragment @Inject constructor(
|
|||
roomToolbarContentView.debouncedClicks {
|
||||
navigator.openRoomProfile(requireActivity(), roomDetailArgs.roomId)
|
||||
}
|
||||
roomDetailViewModel.subscribe { renderState(it) }
|
||||
|
||||
sharedActionViewModel
|
||||
.observe()
|
||||
|
@ -672,7 +671,7 @@ class RoomDetailFragment @Inject constructor(
|
|||
inviteView.callback = this
|
||||
}
|
||||
|
||||
private fun renderState(state: RoomDetailViewState) {
|
||||
override fun invalidate() = withState(roomDetailViewModel) { state ->
|
||||
renderRoomSummary(state)
|
||||
val summary = state.asyncRoomSummary()
|
||||
val inviter = state.asyncInviter()
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.airbnb.mvrx.Incomplete
|
|||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
|
@ -99,7 +100,6 @@ class RoomListFragment @Inject constructor(
|
|||
setupCreateRoomButton()
|
||||
setupRecyclerView()
|
||||
sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java)
|
||||
roomListViewModel.subscribe { renderState(it) }
|
||||
roomListViewModel.observeViewEvents {
|
||||
when (it) {
|
||||
is RoomListViewEvents.Loading -> showLoading(it.message)
|
||||
|
@ -243,7 +243,7 @@ class RoomListFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun renderState(state: RoomListViewState) {
|
||||
override fun invalidate() = withState(roomListViewModel) { state ->
|
||||
when (state.asyncFilteredRooms) {
|
||||
is Incomplete -> renderLoading()
|
||||
is Success -> renderSuccess(state)
|
||||
|
|
|
@ -45,7 +45,6 @@ import im.vector.riotx.features.home.HomeActivity
|
|||
import im.vector.riotx.features.login.terms.LoginTermsFragment
|
||||
import im.vector.riotx.features.login.terms.LoginTermsFragmentArgument
|
||||
import im.vector.riotx.features.login.terms.toLocalizedLoginTerms
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.activity_login.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -103,13 +102,7 @@ open class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
updateWithState(it)
|
||||
}
|
||||
|
||||
loginViewModel.viewEvents
|
||||
.observe()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
handleLoginViewEvents(it)
|
||||
}
|
||||
.disposeOnDestroy()
|
||||
loginViewModel.observeViewEvents { handleLoginViewEvents(it) }
|
||||
}
|
||||
|
||||
protected open fun addFirstFragment() {
|
||||
|
|
|
@ -58,7 +58,6 @@ class DeviceListFragment @Inject constructor(
|
|||
|
||||
override fun invalidate() = withState(viewModel) {
|
||||
epoxyController.setData(it)
|
||||
super.invalidate()
|
||||
}
|
||||
|
||||
override fun onDeviceSelected(device: CryptoDeviceInfo) {
|
||||
|
|
|
@ -58,7 +58,6 @@ class DeviceTrustInfoActionFragment @Inject constructor(
|
|||
|
||||
override fun invalidate() = withState(viewModel) {
|
||||
epoxyController.setData(it)
|
||||
super.invalidate()
|
||||
}
|
||||
|
||||
override fun onVerifyManually(device: CryptoDeviceInfo) {
|
||||
|
|
|
@ -32,7 +32,6 @@ import im.vector.riotx.core.extensions.replaceFragment
|
|||
import im.vector.riotx.features.MainActivity
|
||||
import im.vector.riotx.features.MainActivityArgs
|
||||
import im.vector.riotx.features.login.LoginActivity
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.activity_login.*
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
@ -57,18 +56,11 @@ class SoftLogoutActivity : LoginActivity() {
|
|||
override fun initUiAndData() {
|
||||
super.initUiAndData()
|
||||
|
||||
softLogoutViewModel
|
||||
.subscribe(this) {
|
||||
softLogoutViewModel.subscribe(this) {
|
||||
updateWithState(it)
|
||||
}
|
||||
|
||||
softLogoutViewModel.viewEvents
|
||||
.observe()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
handleSoftLogoutViewEvents(it)
|
||||
}
|
||||
.disposeOnDestroy()
|
||||
softLogoutViewModel.observeViewEvents { handleSoftLogoutViewEvents(it) }
|
||||
}
|
||||
|
||||
private fun handleSoftLogoutViewEvents(softLogoutViewEvents: SoftLogoutViewEvents) {
|
||||
|
|
Loading…
Reference in a new issue