Code review fixes.
This commit is contained in:
parent
a5a3a817e1
commit
40aa0175d0
|
@ -0,0 +1 @@
|
|||
Poll Feature - Create Poll Screen
|
|
@ -339,7 +339,7 @@
|
|||
<activity android:name=".features.spaces.manage.SpaceManageActivity" />
|
||||
<activity android:name=".features.spaces.people.SpacePeopleActivity" />
|
||||
<activity android:name=".features.spaces.leave.SpaceLeaveAdvancedActivity" />
|
||||
<activity android:name=".features.createpoll.CreatePollActivity" />
|
||||
<activity android:name=".features.poll.create.CreatePollActivity" />
|
||||
|
||||
<!-- Services -->
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import dagger.hilt.android.components.ActivityComponent
|
|||
import dagger.multibindings.IntoMap
|
||||
import im.vector.app.features.attachments.preview.AttachmentsPreviewFragment
|
||||
import im.vector.app.features.contactsbook.ContactsBookFragment
|
||||
import im.vector.app.features.createpoll.CreatePollFragment
|
||||
import im.vector.app.features.poll.create.CreatePollFragment
|
||||
import im.vector.app.features.crypto.keysbackup.settings.KeysBackupSettingsFragment
|
||||
import im.vector.app.features.crypto.quads.SharedSecuredStorageKeyFragment
|
||||
import im.vector.app.features.crypto.quads.SharedSecuredStoragePassphraseFragment
|
||||
|
|
|
@ -26,7 +26,7 @@ import im.vector.app.features.call.conference.JitsiCallViewModel
|
|||
import im.vector.app.features.call.transfer.CallTransferViewModel
|
||||
import im.vector.app.features.contactsbook.ContactsBookViewModel
|
||||
import im.vector.app.features.createdirect.CreateDirectRoomViewModel
|
||||
import im.vector.app.features.createpoll.CreatePollViewModel
|
||||
import im.vector.app.features.poll.create.CreatePollViewModel
|
||||
import im.vector.app.features.crypto.keysbackup.settings.KeysBackupSettingsViewModel
|
||||
import im.vector.app.features.crypto.quads.SharedSecureStorageViewModel
|
||||
import im.vector.app.features.crypto.recover.BootstrapSharedViewModel
|
||||
|
|
|
@ -40,8 +40,9 @@ import im.vector.app.features.call.conference.JitsiCallViewModel
|
|||
import im.vector.app.features.call.conference.VectorJitsiActivity
|
||||
import im.vector.app.features.call.transfer.CallTransferActivity
|
||||
import im.vector.app.features.createdirect.CreateDirectRoomActivity
|
||||
import im.vector.app.features.createpoll.CreatePollActivity
|
||||
import im.vector.app.features.createpoll.CreatePollArgs
|
||||
import im.vector.app.features.poll.create.CreatePollActivity
|
||||
import im.vector.app.features.poll.create.CreatePollArgs
|
||||
import im.vector.app.features.poll.create.CreatePollViewModel
|
||||
import im.vector.app.features.crypto.keysbackup.settings.KeysBackupManageActivity
|
||||
import im.vector.app.features.crypto.keysbackup.setup.KeysBackupSetupActivity
|
||||
import im.vector.app.features.crypto.recover.BootstrapBottomSheet
|
||||
|
@ -501,7 +502,10 @@ class DefaultNavigator @Inject constructor(
|
|||
}
|
||||
|
||||
override fun openCreatePoll(context: Context, roomId: String) {
|
||||
val intent = CreatePollActivity.getIntent(context, CreatePollArgs(roomId = roomId))
|
||||
val intent = CreatePollActivity.getIntent(
|
||||
context,
|
||||
CreatePollArgs(roomId = roomId, minOptionsCount = CreatePollViewModel.MIN_OPTIONS_COUNT)
|
||||
)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.createpoll
|
||||
package im.vector.app.features.poll.create
|
||||
|
||||
import im.vector.app.core.platform.VectorViewModelAction
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.createpoll
|
||||
package im.vector.app.features.poll.create
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -23,23 +23,16 @@ import android.view.View
|
|||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.addFragment
|
||||
import im.vector.app.core.platform.SimpleFragmentActivity
|
||||
import javax.inject.Inject
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class CreatePollActivity : SimpleFragmentActivity(), CreatePollViewModel.Factory {
|
||||
|
||||
var currentRoomId: String? = null
|
||||
@Inject lateinit var createPollViewModelFactory: CreatePollViewModel.Factory
|
||||
|
||||
override fun create(initialState: CreatePollViewState) = createPollViewModelFactory.create(initialState)
|
||||
class CreatePollActivity : SimpleFragmentActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
views.toolbar.visibility = View.GONE
|
||||
|
||||
val createPollArgs: CreatePollArgs? = intent?.extras?.getParcelable(EXTRA_CREATE_POLL_ARGS)
|
||||
currentRoomId = createPollArgs?.roomId
|
||||
|
||||
if (isFirstCreation()) {
|
||||
addFragment(
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.createpoll
|
||||
package im.vector.app.features.poll.create
|
||||
|
||||
import android.view.Gravity
|
||||
import com.airbnb.epoxy.EpoxyController
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.createpoll
|
||||
package im.vector.app.features.poll.create
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
|
@ -23,7 +23,6 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.configureWith
|
||||
|
@ -34,12 +33,12 @@ import javax.inject.Inject
|
|||
|
||||
@Parcelize
|
||||
data class CreatePollArgs(
|
||||
val roomId: String
|
||||
val roomId: String,
|
||||
val minOptionsCount: Int
|
||||
) : Parcelable
|
||||
|
||||
class CreatePollFragment @Inject constructor(
|
||||
private val controller: CreatePollController,
|
||||
val createPollViewModelFactory: CreatePollViewModel.Factory
|
||||
private val controller: CreatePollController
|
||||
) : VectorBaseFragment<FragmentCreatePollBinding>(), CreatePollController.Callback {
|
||||
|
||||
private val viewModel: CreatePollViewModel by activityViewModel()
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.createpoll
|
||||
package im.vector.app.features.poll.create
|
||||
|
||||
import im.vector.app.core.platform.VectorViewEvents
|
||||
|
|
@ -14,12 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.createpoll
|
||||
package im.vector.app.features.poll.create
|
||||
|
||||
import com.airbnb.mvrx.ActivityViewModelContext
|
||||
import com.airbnb.mvrx.FragmentViewModelContext
|
||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||
import com.airbnb.mvrx.ViewModelContext
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
|
@ -42,17 +39,7 @@ class CreatePollViewModel @AssistedInject constructor(
|
|||
|
||||
companion object : MavericksViewModelFactory<CreatePollViewModel, CreatePollViewState> by hiltMavericksViewModelFactory() {
|
||||
|
||||
private const val REQUIRED_MIN_OPTION_COUNT = 2
|
||||
}
|
||||
|
||||
init {
|
||||
// Initialize with REQUIRED_MIN_OPTION_COUNT default empty options
|
||||
setState {
|
||||
copy(
|
||||
question = "",
|
||||
options = List(REQUIRED_MIN_OPTION_COUNT) { "" }
|
||||
)
|
||||
}
|
||||
const val MIN_OPTIONS_COUNT = 2
|
||||
}
|
||||
|
||||
override fun handle(action: CreatePollAction) {
|
||||
|
@ -68,13 +55,13 @@ class CreatePollViewModel @AssistedInject constructor(
|
|||
private fun handleOnCreatePoll() = withState { state ->
|
||||
val nonEmptyOptions = state.options.filter { it.isNotEmpty() }
|
||||
when {
|
||||
state.question.isEmpty() -> {
|
||||
state.question.isEmpty() -> {
|
||||
_viewEvents.post(CreatePollViewEvents.EmptyQuestionError)
|
||||
}
|
||||
nonEmptyOptions.size < REQUIRED_MIN_OPTION_COUNT -> {
|
||||
_viewEvents.post(CreatePollViewEvents.NotEnoughOptionsError(requiredOptionsCount = REQUIRED_MIN_OPTION_COUNT))
|
||||
nonEmptyOptions.size < MIN_OPTIONS_COUNT -> {
|
||||
_viewEvents.post(CreatePollViewEvents.NotEnoughOptionsError(requiredOptionsCount = MIN_OPTIONS_COUNT))
|
||||
}
|
||||
else -> {
|
||||
else -> {
|
||||
room.sendPoll(state.question, state.options)
|
||||
_viewEvents.post(CreatePollViewEvents.Success)
|
||||
}
|
||||
|
@ -122,6 +109,6 @@ class CreatePollViewModel @AssistedInject constructor(
|
|||
|
||||
private fun canCreatePoll(state: CreatePollViewState): Boolean {
|
||||
return state.question.isNotEmpty() &&
|
||||
state.options.filter { it.isNotEmpty() }.size >= REQUIRED_MIN_OPTION_COUNT
|
||||
state.options.filter { it.isNotEmpty() }.size >= MIN_OPTIONS_COUNT
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.createpoll
|
||||
package im.vector.app.features.poll.create
|
||||
|
||||
import com.airbnb.mvrx.MavericksState
|
||||
|
||||
|
@ -26,7 +26,8 @@ data class CreatePollViewState(
|
|||
) : MavericksState {
|
||||
|
||||
constructor(args: CreatePollArgs) : this(
|
||||
roomId = args.roomId
|
||||
roomId = args.roomId,
|
||||
options = List(args.minOptionsCount) { "" }
|
||||
)
|
||||
}
|
||||
|
|
@ -171,6 +171,7 @@
|
|||
android:layout_margin="16dp"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:weightSum="3">
|
||||
|
||||
<LinearLayout
|
||||
|
|
Loading…
Reference in New Issue