mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Code review cleaning
This commit is contained in:
parent
52f0d8a1d2
commit
bc120da985
@ -20,7 +20,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
@ -29,7 +28,6 @@ import im.vector.app.R
|
||||
import im.vector.app.core.di.ScreenComponent
|
||||
import im.vector.app.core.extensions.toMvRxBundle
|
||||
import im.vector.app.core.platform.SimpleFragmentActivity
|
||||
import im.vector.app.features.spaces.create.BetaWarningBottomSheet
|
||||
import im.vector.app.features.spaces.create.ChoosePrivateSpaceTypeFragment
|
||||
import im.vector.app.features.spaces.create.ChooseSpaceTypeFragment
|
||||
import im.vector.app.features.spaces.create.CreateSpaceAction
|
||||
@ -42,7 +40,7 @@ import im.vector.app.features.spaces.create.SpaceTopology
|
||||
import im.vector.app.features.spaces.create.SpaceType
|
||||
import javax.inject.Inject
|
||||
|
||||
class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Factory, BetaWarningBottomSheet.InteractionListener {
|
||||
class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Factory {
|
||||
|
||||
@Inject lateinit var viewModelFactory: CreateSpaceViewModel.Factory
|
||||
|
||||
@ -53,29 +51,8 @@ class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Fac
|
||||
|
||||
val viewModel: CreateSpaceViewModel by viewModel()
|
||||
|
||||
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
|
||||
override fun onFragmentAttached(fm: FragmentManager, f: Fragment, context: Context) {
|
||||
when (f) {
|
||||
is BetaWarningBottomSheet -> {
|
||||
f.interactionListener = this@SpaceCreationActivity
|
||||
}
|
||||
}
|
||||
super.onFragmentAttached(fm, f, context)
|
||||
}
|
||||
|
||||
override fun onFragmentDetached(fm: FragmentManager, f: Fragment) {
|
||||
when (f) {
|
||||
is BetaWarningBottomSheet -> {
|
||||
f.interactionListener = null
|
||||
}
|
||||
}
|
||||
super.onFragmentDetached(fm, f)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
|
||||
if (isFirstCreation()) {
|
||||
when (withState(viewModel) { it.step }) {
|
||||
CreateSpaceState.Step.ChooseType -> {
|
||||
@ -94,11 +71,6 @@ class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Fac
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun initUiAndData() {
|
||||
super.initUiAndData()
|
||||
|
||||
@ -206,8 +178,4 @@ class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Fac
|
||||
}
|
||||
|
||||
override fun create(initialState: CreateSpaceState): CreateSpaceViewModel = viewModelFactory.create(initialState)
|
||||
|
||||
override fun betaWarningOnContinueAnyway() {
|
||||
viewModel.handle(CreateSpaceAction.ConfirmBetaWarning)
|
||||
}
|
||||
}
|
||||
|
@ -20,33 +20,27 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
|
||||
import im.vector.app.databinding.BottomSheetSpaceCreatePrivateWarningBinding
|
||||
|
||||
class BetaWarningBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetSpaceCreatePrivateWarningBinding>() {
|
||||
|
||||
interface InteractionListener {
|
||||
fun betaWarningOnContinueAnyway()
|
||||
}
|
||||
|
||||
var interactionListener: InteractionListener? = null
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?) =
|
||||
BottomSheetSpaceCreatePrivateWarningBinding.inflate(inflater, container, false)
|
||||
|
||||
override val showExpanded = true
|
||||
|
||||
override fun onDetach() {
|
||||
interactionListener = null
|
||||
super.onDetach()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
views.continueButton.debouncedClicks {
|
||||
interactionListener?.betaWarningOnContinueAnyway()
|
||||
setFragmentResult(REQUEST_KEY, Bundle.EMPTY)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val REQUEST_KEY = "BetaWarningBottomSheet"
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.setFragmentResultListener
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.onClick
|
||||
@ -38,6 +39,13 @@ class ChoosePrivateSpaceTypeFragment @Inject constructor(
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?) =
|
||||
FragmentSpaceCreateChoosePrivateModelBinding.inflate(layoutInflater, container, false)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setFragmentResultListener(BetaWarningBottomSheet.REQUEST_KEY) { _, _ ->
|
||||
sharedViewModel.handle(CreateSpaceAction.SetSpaceTopology(SpaceTopology.MeAndTeammates))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
@ -52,14 +60,6 @@ class ChoosePrivateSpaceTypeFragment @Inject constructor(
|
||||
sharedViewModel.subscribe { state ->
|
||||
views.accessInfoHelpText.text = stringProvider.getString(R.string.create_spaces_make_sure_access, state.name ?: "")
|
||||
}
|
||||
|
||||
sharedViewModel.observeViewEvents {
|
||||
when (it) {
|
||||
CreateSpaceEvents.OnConfirmBetaWarning -> {
|
||||
sharedViewModel.handle(CreateSpaceAction.SetSpaceTopology(SpaceTopology.MeAndTeammates))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
||||
|
@ -29,5 +29,4 @@ sealed class CreateSpaceAction : VectorViewModelAction {
|
||||
object NextFromDefaultRooms : CreateSpaceAction()
|
||||
data class DefaultRoomNameChanged(val index: Int, val name: String) : CreateSpaceAction()
|
||||
data class SetSpaceTopology(val topology: SpaceTopology) : CreateSpaceAction()
|
||||
object ConfirmBetaWarning : CreateSpaceAction()
|
||||
}
|
||||
|
@ -27,5 +27,4 @@ sealed class CreateSpaceEvents : VectorViewEvents {
|
||||
data class FinishSuccess(val spaceId: String, val defaultRoomId: String?, val topology: SpaceTopology?) : CreateSpaceEvents()
|
||||
data class ShowModalError(val errorMessage: String) : CreateSpaceEvents()
|
||||
object HideModalLoading : CreateSpaceEvents()
|
||||
object OnConfirmBetaWarning : CreateSpaceEvents()
|
||||
}
|
||||
|
@ -118,9 +118,6 @@ class CreateSpaceViewModel @AssistedInject constructor(
|
||||
is CreateSpaceAction.SetSpaceTopology -> {
|
||||
handleSetTopology(action)
|
||||
}
|
||||
CreateSpaceAction.ConfirmBetaWarning -> {
|
||||
_viewEvents.post(CreateSpaceEvents.OnConfirmBetaWarning)
|
||||
}
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user