Delete temporary file if user cancel room setting change
This commit is contained in:
parent
be2c4597de
commit
4887f678c5
@ -106,7 +106,6 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||||||
private fun doReset() {
|
private fun doReset() {
|
||||||
setState {
|
setState {
|
||||||
// Delete temporary file with the avatar
|
// Delete temporary file with the avatar
|
||||||
// TODO BMA Do this also in the other PR
|
|
||||||
avatarUri?.let { tryOrNull { it.toFile().delete() }}
|
avatarUri?.let { tryOrNull { it.toFile().delete() }}
|
||||||
|
|
||||||
CreateRoomViewState(
|
CreateRoomViewState(
|
||||||
|
@ -27,4 +27,5 @@ sealed class RoomSettingsAction : VectorViewModelAction {
|
|||||||
data class SetRoomCanonicalAlias(val newCanonicalAlias: String) : RoomSettingsAction()
|
data class SetRoomCanonicalAlias(val newCanonicalAlias: String) : RoomSettingsAction()
|
||||||
object EnableEncryption : RoomSettingsAction()
|
object EnableEncryption : RoomSettingsAction()
|
||||||
object Save : RoomSettingsAction()
|
object Save : RoomSettingsAction()
|
||||||
|
object Cancel : RoomSettingsAction()
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,11 @@ class RoomSettingsFragment @Inject constructor(
|
|||||||
viewModel.observeViewEvents {
|
viewModel.observeViewEvents {
|
||||||
when (it) {
|
when (it) {
|
||||||
is RoomSettingsViewEvents.Failure -> showFailure(it.throwable)
|
is RoomSettingsViewEvents.Failure -> showFailure(it.throwable)
|
||||||
is RoomSettingsViewEvents.Success -> showSuccess()
|
RoomSettingsViewEvents.Success -> showSuccess()
|
||||||
|
RoomSettingsViewEvents.GoBack -> {
|
||||||
|
ignoreChanges = true
|
||||||
|
vectorBaseActivity.onBackPressed()
|
||||||
|
}
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,8 +222,7 @@ class RoomSettingsFragment @Inject constructor(
|
|||||||
.setTitle(R.string.dialog_title_warning)
|
.setTitle(R.string.dialog_title_warning)
|
||||||
.setMessage(R.string.warning_unsaved_change)
|
.setMessage(R.string.warning_unsaved_change)
|
||||||
.setPositiveButton(R.string.warning_unsaved_change_discard) { _, _ ->
|
.setPositiveButton(R.string.warning_unsaved_change_discard) { _, _ ->
|
||||||
ignoreChanges = true
|
viewModel.handle(RoomSettingsAction.Cancel)
|
||||||
vectorBaseActivity.onBackPressed()
|
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
|
@ -25,4 +25,5 @@ import im.vector.app.core.platform.VectorViewEvents
|
|||||||
sealed class RoomSettingsViewEvents : VectorViewEvents {
|
sealed class RoomSettingsViewEvents : VectorViewEvents {
|
||||||
data class Failure(val throwable: Throwable) : RoomSettingsViewEvents()
|
data class Failure(val throwable: Throwable) : RoomSettingsViewEvents()
|
||||||
object Success : RoomSettingsViewEvents()
|
object Success : RoomSettingsViewEvents()
|
||||||
|
object GoBack : RoomSettingsViewEvents()
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package im.vector.app.features.roomprofile.settings
|
package im.vector.app.features.roomprofile.settings
|
||||||
|
|
||||||
|
import androidx.core.net.toFile
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
@ -27,6 +28,7 @@ import im.vector.app.features.powerlevel.PowerLevelsObservableFactory
|
|||||||
import io.reactivex.Completable
|
import io.reactivex.Completable
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
@ -146,9 +148,20 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
||||||
is RoomSettingsAction.SetRoomCanonicalAlias -> setState { copy(newCanonicalAlias = action.newCanonicalAlias) }
|
is RoomSettingsAction.SetRoomCanonicalAlias -> setState { copy(newCanonicalAlias = action.newCanonicalAlias) }
|
||||||
is RoomSettingsAction.Save -> saveSettings()
|
is RoomSettingsAction.Save -> saveSettings()
|
||||||
|
is RoomSettingsAction.Cancel -> cancel()
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun cancel() {
|
||||||
|
// Maybe delete the pending avatar
|
||||||
|
withState {
|
||||||
|
(it.avatarAction as? RoomSettingsViewState.AvatarAction.UpdateAvatar)
|
||||||
|
?.let { tryOrNull { it.newAvatarUri.toFile().delete() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
_viewEvents.post(RoomSettingsViewEvents.GoBack)
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveSettings() = withState { state ->
|
private fun saveSettings() = withState { state ->
|
||||||
postLoading(true)
|
postLoading(true)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user