Ask for confirmation if the user quit the screen before creating the room
This commit is contained in:
parent
489bddec5b
commit
fffc8addcf
|
@ -19,6 +19,7 @@ package im.vector.app.features.roomdirectory.createroom
|
|||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
|
@ -26,18 +27,20 @@ import im.vector.app.R
|
|||
import im.vector.app.core.dialogs.GalleryOrCameraDialogHelper
|
||||
import im.vector.app.core.extensions.cleanup
|
||||
import im.vector.app.core.extensions.configureWith
|
||||
import im.vector.app.core.extensions.exhaustive
|
||||
import im.vector.app.core.platform.OnBackPressed
|
||||
import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.features.roomdirectory.RoomDirectorySharedAction
|
||||
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
|
||||
import im.vector.app.features.roomprofile.settings.RoomSettingsAction
|
||||
import kotlinx.android.synthetic.main.fragment_create_room.*
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class CreateRoomFragment @Inject constructor(
|
||||
private val createRoomController: CreateRoomController,
|
||||
private val colorProvider: ColorProvider
|
||||
colorProvider: ColorProvider
|
||||
) : VectorBaseFragment(),
|
||||
CreateRoomController.Listener,
|
||||
GalleryOrCameraDialogHelper.Listener,
|
||||
|
@ -58,6 +61,11 @@ class CreateRoomFragment @Inject constructor(
|
|||
createRoomClose.debouncedClicks {
|
||||
sharedActionViewModel.post(RoomDirectorySharedAction.Back)
|
||||
}
|
||||
viewModel.observeViewEvents {
|
||||
when (it) {
|
||||
CreateRoomViewEvents.Quit -> vectorBaseActivity.onBackPressed()
|
||||
}.exhaustive
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -113,9 +121,21 @@ class CreateRoomFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
||||
// TODO BMA, as per the other PR, ask the user if he has started to input elements before leaving the screen
|
||||
viewModel.handle(CreateRoomAction.Reset)
|
||||
return false
|
||||
return withState(viewModel) {
|
||||
return@withState if (!it.isEmpty()) {
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setTitle(R.string.dialog_title_warning)
|
||||
.setMessage(R.string.warning_room_not_created_yet)
|
||||
.setPositiveButton(R.string.yes) { _, _ ->
|
||||
viewModel.handle(CreateRoomAction.Reset)
|
||||
}
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.show()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(viewModel) { state ->
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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.app.features.roomdirectory.createroom
|
||||
|
||||
import im.vector.app.core.platform.VectorViewEvents
|
||||
|
||||
/**
|
||||
* Transient events for room creation screen
|
||||
*/
|
||||
sealed class CreateRoomViewEvents : VectorViewEvents {
|
||||
object Quit : CreateRoomViewEvents()
|
||||
}
|
|
@ -28,7 +28,6 @@ import com.airbnb.mvrx.ViewModelContext
|
|||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.app.core.extensions.exhaustive
|
||||
import im.vector.app.core.platform.EmptyViewEvents
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.features.raw.wellknown.getElementWellknown
|
||||
import im.vector.app.features.raw.wellknown.isE2EByDefault
|
||||
|
@ -46,7 +45,7 @@ import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
|
|||
class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: CreateRoomViewState,
|
||||
private val session: Session,
|
||||
private val rawService: RawService
|
||||
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, EmptyViewEvents>(initialState) {
|
||||
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory {
|
||||
|
@ -113,6 +112,8 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||
hsAdminHasDisabledE2E = !adminE2EByDefault
|
||||
)
|
||||
}
|
||||
|
||||
_viewEvents.post(CreateRoomViewEvents.Quit)
|
||||
}
|
||||
|
||||
private fun setAvatar(action: CreateRoomAction.SetAvatar) = setState { copy(avatarUri = action.imageUri) }
|
||||
|
|
|
@ -30,4 +30,10 @@ data class CreateRoomViewState(
|
|||
val isEncrypted: Boolean = false,
|
||||
val hsAdminHasDisabledE2E: Boolean = false,
|
||||
val asyncCreateRoomRequest: Async<String> = Uninitialized
|
||||
) : MvRxState
|
||||
) : MvRxState {
|
||||
|
||||
/**
|
||||
* Return true if there is not important input from user
|
||||
*/
|
||||
fun isEmpty() = avatarUri == null && roomName.isEmpty() && roomTopic.isEmpty()
|
||||
}
|
||||
|
|
|
@ -2632,6 +2632,7 @@
|
|||
|
||||
<!-- Universal link -->
|
||||
<string name="universal_link_malformed">The link was malformed</string>
|
||||
<string name="warning_room_not_created_yet">The room is not yet created. Cancel the room creation?</string>
|
||||
<string name="warning_unsaved_change">There are unsaved changes. Discard the changes?</string>
|
||||
<string name="warning_unsaved_change_discard">Discard changes</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue