From 40aa0175d09e77657dd210e49203c951aa8d59cc Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 29 Oct 2021 16:54:54 +0300 Subject: [PATCH] Code review fixes. --- changelog.d/4367.feature | 1 + vector/src/main/AndroidManifest.xml | 2 +- .../im/vector/app/core/di/FragmentModule.kt | 2 +- .../app/core/di/MavericksViewModelModule.kt | 2 +- .../features/navigation/DefaultNavigator.kt | 10 ++++--- .../create}/CreatePollAction.kt | 2 +- .../create}/CreatePollActivity.kt | 11 ++------ .../create}/CreatePollController.kt | 2 +- .../create}/CreatePollFragment.kt | 9 +++---- .../create}/CreatePollViewEvents.kt | 2 +- .../create}/CreatePollViewModel.kt | 27 +++++-------------- .../create}/CreatePollViewState.kt | 5 ++-- .../layout/view_attachment_type_selector.xml | 1 + 13 files changed, 31 insertions(+), 45 deletions(-) create mode 100644 changelog.d/4367.feature rename vector/src/main/java/im/vector/app/features/{createpoll => poll/create}/CreatePollAction.kt (96%) rename vector/src/main/java/im/vector/app/features/{createpoll => poll/create}/CreatePollActivity.kt (80%) rename vector/src/main/java/im/vector/app/features/{createpoll => poll/create}/CreatePollController.kt (98%) rename vector/src/main/java/im/vector/app/features/{createpoll => poll/create}/CreatePollFragment.kt (94%) rename vector/src/main/java/im/vector/app/features/{createpoll => poll/create}/CreatePollViewEvents.kt (95%) rename vector/src/main/java/im/vector/app/features/{createpoll => poll/create}/CreatePollViewModel.kt (83%) rename vector/src/main/java/im/vector/app/features/{createpoll => poll/create}/CreatePollViewState.kt (87%) diff --git a/changelog.d/4367.feature b/changelog.d/4367.feature new file mode 100644 index 0000000000..04db0bd6be --- /dev/null +++ b/changelog.d/4367.feature @@ -0,0 +1 @@ +Poll Feature - Create Poll Screen \ No newline at end of file diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index cf8e1b92da..01d7630678 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -339,7 +339,7 @@ - + diff --git a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt index cd4c902693..afae1d6038 100644 --- a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt b/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt index b6ed46cbc7..c1275904e2 100644 --- a/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index b1bbf645d6..63a61a8b3f 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -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) } diff --git a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollAction.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollAction.kt similarity index 96% rename from vector/src/main/java/im/vector/app/features/createpoll/CreatePollAction.kt rename to vector/src/main/java/im/vector/app/features/poll/create/CreatePollAction.kt index 0812248487..182750fbd2 100644 --- a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollAction.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollAction.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollActivity.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollActivity.kt similarity index 80% rename from vector/src/main/java/im/vector/app/features/createpoll/CreatePollActivity.kt rename to vector/src/main/java/im/vector/app/features/poll/create/CreatePollActivity.kt index 14dcca2f87..c57f479177 100644 --- a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollActivity.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollActivity.kt @@ -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( diff --git a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollController.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollController.kt similarity index 98% rename from vector/src/main/java/im/vector/app/features/createpoll/CreatePollController.kt rename to vector/src/main/java/im/vector/app/features/poll/create/CreatePollController.kt index 7fa9831c94..d361db13f8 100644 --- a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollController.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollController.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollFragment.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollFragment.kt similarity index 94% rename from vector/src/main/java/im/vector/app/features/createpoll/CreatePollFragment.kt rename to vector/src/main/java/im/vector/app/features/poll/create/CreatePollFragment.kt index c456669215..50854a3740 100644 --- a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollFragment.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollFragment.kt @@ -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(), CreatePollController.Callback { private val viewModel: CreatePollViewModel by activityViewModel() diff --git a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewEvents.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewEvents.kt similarity index 95% rename from vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewEvents.kt rename to vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewEvents.kt index 288e5dad01..fa06deea6e 100644 --- a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewEvents.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewModel.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewModel.kt similarity index 83% rename from vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewModel.kt rename to vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewModel.kt index 657ffbf2e8..b9a8ef4336 100644 --- a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewModel.kt @@ -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 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 } } diff --git a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewState.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewState.kt similarity index 87% rename from vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewState.kt rename to vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewState.kt index e1639af01c..24281bdd4e 100644 --- a/vector/src/main/java/im/vector/app/features/createpoll/CreatePollViewState.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewState.kt @@ -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) { "" } ) } diff --git a/vector/src/main/res/layout/view_attachment_type_selector.xml b/vector/src/main/res/layout/view_attachment_type_selector.xml index 22ed6ec0e9..e5948edc2c 100644 --- a/vector/src/main/res/layout/view_attachment_type_selector.xml +++ b/vector/src/main/res/layout/view_attachment_type_selector.xml @@ -171,6 +171,7 @@ android:layout_margin="16dp" android:baselineAligned="false" android:orientation="horizontal" + android:visibility="gone" android:weightSum="3">