Pusher: add a menu to force a refresh of the local data
This commit is contained in:
parent
13036a5933
commit
a29ec7b0be
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.riotx.features.settings.push
|
||||
|
||||
import im.vector.riotx.core.platform.VectorViewModelAction
|
||||
|
||||
sealed class PushGatewayAction : VectorViewModelAction {
|
||||
object Refresh : PushGatewayAction()
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package im.vector.riotx.features.settings.push
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
@ -38,6 +39,19 @@ class PushGatewaysFragment @Inject constructor(
|
||||
|
||||
private val viewModel: PushGatewaysViewModel by fragmentViewModel(PushGatewaysViewModel::class)
|
||||
|
||||
override fun getMenuRes() = R.menu.menu_push_gateways
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.refresh -> {
|
||||
viewModel.handle(PushGatewayAction.Refresh)
|
||||
true
|
||||
}
|
||||
else ->
|
||||
super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
(activity as? VectorBaseActivity)?.supportActionBar?.setTitle(R.string.settings_notifications_targets)
|
||||
|
@ -27,7 +27,7 @@ import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.pushers.Pusher
|
||||
import im.vector.matrix.rx.RxSession
|
||||
import im.vector.riotx.core.platform.EmptyAction
|
||||
import im.vector.riotx.core.extensions.exhaustive
|
||||
import im.vector.riotx.core.platform.EmptyViewEvents
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
|
||||
@ -37,7 +37,7 @@ data class PushGatewayViewState(
|
||||
|
||||
class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState: PushGatewayViewState,
|
||||
private val session: Session)
|
||||
: VectorViewModel<PushGatewayViewState, EmptyAction, EmptyViewEvents>(initialState) {
|
||||
: VectorViewModel<PushGatewayViewState, PushGatewayAction, EmptyViewEvents>(initialState) {
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory {
|
||||
@ -55,6 +55,8 @@ class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState:
|
||||
|
||||
init {
|
||||
observePushers()
|
||||
// Force a refresh
|
||||
session.refreshPushers()
|
||||
}
|
||||
|
||||
private fun observePushers() {
|
||||
@ -65,7 +67,13 @@ class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState:
|
||||
}
|
||||
}
|
||||
|
||||
override fun handle(action: EmptyAction) {
|
||||
// No op
|
||||
override fun handle(action: PushGatewayAction) {
|
||||
when (action) {
|
||||
is PushGatewayAction.Refresh -> handleRefresh()
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
private fun handleRefresh() {
|
||||
session.refreshPushers()
|
||||
}
|
||||
}
|
||||
|
11
vector/src/main/res/menu/menu_push_gateways.xml
Normal file
11
vector/src/main/res/menu/menu_push_gateways.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/refresh"
|
||||
android:icon="@drawable/ic_refresh_cw"
|
||||
android:title="@string/refresh"
|
||||
app:showAsAction="always" />
|
||||
|
||||
</menu>
|
@ -18,7 +18,7 @@
|
||||
<string name="settings_when_rooms_are_upgraded">When rooms are upgraded</string>
|
||||
<string name="settings_troubleshoot_title">Troubleshoot</string>
|
||||
<string name="settings_notification_advanced_summary_riotx">Set notification importance by event</string>
|
||||
|
||||
<string name="refresh">Refresh</string>
|
||||
<!-- END Strings added by Benoit -->
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user