Skip to content

Commit

Permalink
Fix #2658, #299: Replace builder() with Factory in SingleTypeBuilder …
Browse files Browse the repository at this point in the history
…and MultiTypeBuilder (#4412)

* Replace builder() with Factory in SingleTypeBuilder and MultiTypeBuilder.

* Fix failing tests after refactor, Create Fragment for DragDropTestActivity.kt.

* Inject the BindableAdapter.kt factory into the fragment and listview instances.

* Inject the BindableAdapter.kt factory into the fragment and listview instances.

* Inject the BindableAdapter.kt factory into the fragment and listview instances.

* Inject the BindableAdapter.kt factory into the fragment and listview instances.

* Add 'androidx.work:work-testing:2.4.0' in androidTestImplementation to fix tests.

* Fix lint formatting issue in updated files.

* Fix some of the failing tests after fixing #2658.

* Fix some of the failing tests after fixing #2658.

* Fix more failing tests for #2658.

* Refactor StatePlayerRecyclerViewAssembler.kt to inject MultiTypeAdapterFactory

* Fix failing tests due to missed refactor of QuestionPlayerFragmentPresenter.kt to inject MultiTypeAdapter Factory.

* More updates as part of refactoring for issue #2658.

* Refactor PromotedStoryListView.kt BindableAdapterTest.kt classes to provide Adapter through injection for isuue #2658.

* Fix issues as advised by code review.

* Fix issue causing some of failing tests.

* Fix issue causing some of failing tests.

* Revert unused resources, to fix Static check test failure.

* Add KDocs to implemented public functions, to fix KDocs Static check test failure.

* Add exemption for test to DragDropTestFragmentPresenter and DragDropTestFragment since they are actual test classes.

* Fix nits and updates as advised during code review.

* Fix nits and updates as advised during code review.

* Fix nits and updates as advised during code review.

* Updates issues as advised on code review, fix some of the failing tests.

* Fix failing tests.

* Fix more failing tests by reverting DragDropSortInteractionView.kt and SelectionInteractionView.kt to initial state.

* Update multiple field namings for consistency as advised by code reviewer.

* Fix failing tests and revert from previous fix, which could not be used in alpha.

* Fix out-of-order binding for selection, drop/drop.

* Post-merge fixes.

Mainly, this fixing previous code as well as image region selection
(which whose breakage could only be detected via manually playing the
image region selection and by running the interaction's corresponding
test suite on Espresso, both of which caught different sets of issues).

The PR includes some cleanup work as well.

* Fix lint issues after resolving merge conflicts on CI and add lessons_chapter_view.xml which is not available on my branch even after several sync's causing build errors.

* Revert deleted deltas.

* Remove lessons_chapter_view.xml since it is no longer required.

Co-authored-by: Ben Henning <[email protected]>
  • Loading branch information
KevinGitonga and BenHenning authored Oct 4, 2022
1 parent f096b1d commit 8594c9d
Show file tree
Hide file tree
Showing 56 changed files with 929 additions and 899 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import javax.inject.Inject
@FragmentScope
class AdministratorControlsFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment
private val fragment: Fragment,
private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory
) {
private lateinit var binding: AdministratorControlsFragmentBinding
private lateinit var linearLayoutManager: LinearLayoutManager
Expand Down Expand Up @@ -77,8 +78,8 @@ class AdministratorControlsFragmentPresenter @Inject constructor(
/** Returns the recycler view adapter for the controls panel in administrator controls fragment. */
private fun createRecyclerViewAdapter(isMultipane: Boolean):
BindableAdapter<AdministratorControlsItemViewModel> {
return BindableAdapter.MultiTypeBuilder
.newBuilder<AdministratorControlsItemViewModel, ViewType> { viewModel ->
return multiTypeBuilderFactory
.create<AdministratorControlsItemViewModel, ViewType> { viewModel ->
viewModel.isMultipane.set(isMultipane)
when (viewModel) {
is AdministratorControlsGeneralViewModel -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import javax.inject.Inject
/** Presenter for arranging [ProfileAndDeviceIdFragment]'s UI. */
class ProfileAndDeviceIdFragmentPresenter @Inject constructor(
private val fragment: Fragment,
private val profileListViewModelFactory: ProfileListViewModel.Factory
private val profileListViewModelFactory: ProfileListViewModel.Factory,
private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory
) {

private lateinit var binding: ProfileAndDeviceIdFragmentBinding

/** Handles [ProfileAndDeviceIdFragment]'s creation flow. */
Expand All @@ -38,16 +40,15 @@ class ProfileAndDeviceIdFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<ProfileListItemViewModel> {
return BindableAdapter.MultiTypeBuilder
.newBuilder<ProfileListItemViewModel, ProfileListItemViewType> { viewModel ->
when (viewModel) {
is DeviceIdItemViewModel -> ProfileListItemViewType.DEVICE_ID
is ProfileLearnerIdItemViewModel -> ProfileListItemViewType.LEARNER_ID
is SyncStatusItemViewModel -> ProfileListItemViewType.SYNC_STATUS
else -> error("Encountered unexpected view model: $viewModel")
}
return multiTypeBuilderFactory.create<ProfileListItemViewModel,
ProfileListItemViewType> { viewModel ->
when (viewModel) {
is DeviceIdItemViewModel -> ProfileListItemViewType.DEVICE_ID
is ProfileLearnerIdItemViewModel -> ProfileListItemViewType.LEARNER_ID
is SyncStatusItemViewModel -> ProfileListItemViewType.SYNC_STATUS
else -> error("Encountered unexpected view model: $viewModel")
}
.setLifecycleOwner(fragment)
}
.registerViewDataBinder(
viewType = ProfileListItemViewType.DEVICE_ID,
inflateDataBinding = ProfileListDeviceIdItemBinding::inflate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import javax.inject.Inject
class CompletedStoryListFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModelProvider: ViewModelProvider<CompletedStoryListViewModel>
private val viewModelProvider: ViewModelProvider<CompletedStoryListViewModel>,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) {

private lateinit var binding: CompletedStoryListFragmentBinding
Expand Down Expand Up @@ -52,8 +53,7 @@ class CompletedStoryListFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<CompletedStoryItemViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<CompletedStoryItemViewModel>()
return singleTypeBuilderFactory.create<CompletedStoryItemViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = CompletedStoryItemBinding::inflate,
setViewModel = CompletedStoryItemBinding::setViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import javax.inject.Inject
@FragmentScope
class DeveloperOptionsFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment
private val fragment: Fragment,
private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory
) {

private lateinit var binding: DeveloperOptionsFragmentBinding
Expand Down Expand Up @@ -59,28 +60,27 @@ class DeveloperOptionsFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<DeveloperOptionsItemViewModel> {
return BindableAdapter.MultiTypeBuilder
.newBuilder<DeveloperOptionsItemViewModel, ViewType> { viewModel ->
when (viewModel) {
is DeveloperOptionsModifyLessonProgressViewModel -> {
viewModel.itemIndex.set(0)
ViewType.VIEW_TYPE_MODIFY_LESSON_PROGRESS
}
is DeveloperOptionsViewLogsViewModel -> {
viewModel.itemIndex.set(1)
ViewType.VIEW_TYPE_VIEW_LOGS
}
is DeveloperOptionsOverrideAppBehaviorsViewModel -> {
viewModel.itemIndex.set(2)
ViewType.VIEW_TYPE_OVERRIDE_APP_BEHAVIORS
}
is DeveloperOptionsTestParsersViewModel -> {
viewModel.itemIndex.set(3)
ViewType.VIEW_TYPE_TEST_PARSERS
}
else -> throw IllegalArgumentException("Encountered unexpected view model: $viewModel")
return multiTypeBuilderFactory.create<DeveloperOptionsItemViewModel, ViewType> { viewModel ->
when (viewModel) {
is DeveloperOptionsModifyLessonProgressViewModel -> {
viewModel.itemIndex.set(0)
ViewType.VIEW_TYPE_MODIFY_LESSON_PROGRESS
}
is DeveloperOptionsViewLogsViewModel -> {
viewModel.itemIndex.set(1)
ViewType.VIEW_TYPE_VIEW_LOGS
}
is DeveloperOptionsOverrideAppBehaviorsViewModel -> {
viewModel.itemIndex.set(2)
ViewType.VIEW_TYPE_OVERRIDE_APP_BEHAVIORS
}
is DeveloperOptionsTestParsersViewModel -> {
viewModel.itemIndex.set(3)
ViewType.VIEW_TYPE_TEST_PARSERS
}
else -> throw IllegalArgumentException("Encountered unexpected view model: $viewModel")
}
}
.registerViewDataBinder(
viewType = ViewType.VIEW_TYPE_MODIFY_LESSON_PROGRESS,
inflateDataBinding = DeveloperOptionsModifyLessonProgressViewBinding::inflate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ForceNetworkTypeFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val networkConnectionUtil: Optional<NetworkConnectionDebugUtil>,
private val viewModelProvider: ViewModelProvider<ForceNetworkTypeViewModel>
private val viewModelProvider: ViewModelProvider<ForceNetworkTypeViewModel>,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) {

private lateinit var binding: ForceNetworkTypeFragmentBinding
Expand Down Expand Up @@ -60,8 +61,7 @@ class ForceNetworkTypeFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<NetworkTypeItemViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<NetworkTypeItemViewModel>()
return singleTypeBuilderFactory.create<NetworkTypeItemViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = ForceNetworkTypeNetworkItemViewBinding::inflate,
setViewModel = this::bindNetworkItemView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class MarkChaptersCompletedFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModel: MarkChaptersCompletedViewModel,
private val modifyLessonProgressController: ModifyLessonProgressController
private val modifyLessonProgressController: ModifyLessonProgressController,
private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory
) : ChapterSelector {
private lateinit var binding: MarkChaptersCompletedFragmentBinding
private lateinit var linearLayoutManager: LinearLayoutManager
Expand Down Expand Up @@ -92,14 +93,14 @@ class MarkChaptersCompletedFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<MarkChaptersCompletedItemViewModel> {
return BindableAdapter.MultiTypeBuilder
.newBuilder<MarkChaptersCompletedItemViewModel, ViewType> { viewModel ->
when (viewModel) {
is StorySummaryViewModel -> ViewType.VIEW_TYPE_STORY
is ChapterSummaryViewModel -> ViewType.VIEW_TYPE_CHAPTER
else -> throw IllegalArgumentException("Encountered unexpected view model: $viewModel")
}
return multiTypeBuilderFactory.create<MarkChaptersCompletedItemViewModel,
ViewType> { viewModel ->
when (viewModel) {
is StorySummaryViewModel -> ViewType.VIEW_TYPE_STORY
is ChapterSummaryViewModel -> ViewType.VIEW_TYPE_CHAPTER
else -> throw IllegalArgumentException("Encountered unexpected view model: $viewModel")
}
}
.registerViewDataBinder(
viewType = ViewType.VIEW_TYPE_STORY,
inflateDataBinding = MarkChaptersCompletedStorySummaryViewBinding::inflate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class MarkStoriesCompletedFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModel: MarkStoriesCompletedViewModel,
private val modifyLessonProgressController: ModifyLessonProgressController
private val modifyLessonProgressController: ModifyLessonProgressController,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) : StorySelector {
private lateinit var binding: MarkStoriesCompletedFragmentBinding
private lateinit var linearLayoutManager: LinearLayoutManager
Expand Down Expand Up @@ -91,8 +92,7 @@ class MarkStoriesCompletedFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<StorySummaryViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<StorySummaryViewModel>()
return singleTypeBuilderFactory.create<StorySummaryViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = MarkStoriesCompletedStorySummaryViewBinding::inflate,
setViewModel = this::bindStorySummaryView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class MarkTopicsCompletedFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModel: MarkTopicsCompletedViewModel,
private val modifyLessonProgressController: ModifyLessonProgressController
private val modifyLessonProgressController: ModifyLessonProgressController,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) : TopicSelector {
private lateinit var binding: MarkTopicsCompletedFragmentBinding
private lateinit var linearLayoutManager: LinearLayoutManager
Expand Down Expand Up @@ -88,8 +89,7 @@ class MarkTopicsCompletedFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<TopicViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<TopicViewModel>()
return singleTypeBuilderFactory.create<TopicViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = MarkTopicsCompletedTopicViewBinding::inflate,
setViewModel = this::bindTopicSummaryView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import javax.inject.Inject
class ViewEventLogsFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModelProvider: ViewModelProvider<ViewEventLogsViewModel>
private val viewModelProvider: ViewModelProvider<ViewEventLogsViewModel>,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) {

private lateinit var binding: ViewEventLogsFragmentBinding
Expand Down Expand Up @@ -56,8 +57,7 @@ class ViewEventLogsFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<EventLogItemViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<EventLogItemViewModel>()
return singleTypeBuilderFactory.create<EventLogItemViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = ViewEventLogsEventLogItemViewBinding::inflate,
setViewModel = ViewEventLogsEventLogItemViewBinding::setViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import org.oppia.android.app.settings.profile.ProfileResetPinFragment
import org.oppia.android.app.shim.IntentFactoryShimModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.story.StoryFragment
import org.oppia.android.app.testing.DragDropTestFragment
import org.oppia.android.app.testing.ExplorationTestActivityPresenter
import org.oppia.android.app.testing.ImageRegionSelectionTestFragment
import org.oppia.android.app.topic.TopicFragment
Expand Down Expand Up @@ -114,6 +115,7 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto
fun inject(conceptCardFragment: ConceptCardFragment)
fun inject(developerOptionsFragment: DeveloperOptionsFragment)
fun inject(downloadsTabFragment: DownloadsTabFragment)
fun inject(dragDropTestFragment: DragDropTestFragment)
fun inject(exitProfileDialogFragment: ExitProfileDialogFragment)
fun inject(explorationFragment: ExplorationFragment)
fun inject(explorationManagerFragment: ExplorationManagerFragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import javax.inject.Inject
class HelpFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModelProvider: ViewModelProvider<HelpListViewModel>
private val viewModelProvider: ViewModelProvider<HelpListViewModel>,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) {
private lateinit var binding: HelpFragmentBinding

Expand Down Expand Up @@ -48,8 +49,7 @@ class HelpFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<HelpItemViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<HelpItemViewModel>()
return singleTypeBuilderFactory.create<HelpItemViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = HelpItemBinding::inflate,
setViewModel = HelpItemBinding::setViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import javax.inject.Inject
class FAQListFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModelProvider: ViewModelProvider<FAQListViewModel>
private val viewModelProvider: ViewModelProvider<FAQListViewModel>,
private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory
) {
private lateinit var binding: FaqListFragmentBinding

Expand All @@ -48,14 +49,13 @@ class FAQListFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<FAQItemViewModel> {
return BindableAdapter.MultiTypeBuilder
.newBuilder<FAQItemViewModel, ViewType> { viewModel ->
when (viewModel) {
is FAQHeaderViewModel -> ViewType.VIEW_TYPE_HEADER
is FAQContentViewModel -> ViewType.VIEW_TYPE_CONTENT
else -> throw IllegalArgumentException("Encountered unexpected view model: $viewModel")
}
return multiTypeBuilderFactory.create<FAQItemViewModel, ViewType> { viewModel ->
when (viewModel) {
is FAQHeaderViewModel -> ViewType.VIEW_TYPE_HEADER
is FAQContentViewModel -> ViewType.VIEW_TYPE_CONTENT
else -> throw IllegalArgumentException("Encountered unexpected view model: $viewModel")
}
}
.registerViewDataBinder(
viewType = ViewType.VIEW_TYPE_HEADER,
inflateDataBinding = FaqItemHeaderBinding::inflate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import javax.inject.Inject
class LicenseListFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val resourceHandler: AppLanguageResourceHandler
private val resourceHandler: AppLanguageResourceHandler,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) {
private lateinit var binding: LicenseListFragmentBinding

Expand Down Expand Up @@ -51,8 +52,7 @@ class LicenseListFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<LicenseItemViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<LicenseItemViewModel>()
return singleTypeBuilderFactory.create<LicenseItemViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = LicenseItemBinding::inflate,
setViewModel = LicenseItemBinding::setViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import javax.inject.Inject
class ThirdPartyDependencyListFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val viewModelProvider: ViewModelProvider<ThirdPartyDependencyListViewModel>
private val viewModelProvider: ViewModelProvider<ThirdPartyDependencyListViewModel>,
private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory
) {
private lateinit var binding: ThirdPartyDependencyListFragmentBinding

Expand Down Expand Up @@ -50,8 +51,7 @@ class ThirdPartyDependencyListFragmentPresenter @Inject constructor(
}

private fun createRecyclerViewAdapter(): BindableAdapter<ThirdPartyDependencyItemViewModel> {
return BindableAdapter.SingleTypeBuilder
.newBuilder<ThirdPartyDependencyItemViewModel>()
return singleTypeBuilderFactory.create<ThirdPartyDependencyItemViewModel>()
.registerViewDataBinderWithSameModelType(
inflateDataBinding = ThirdPartyDependencyItemBinding::inflate,
setViewModel = ThirdPartyDependencyItemBinding::setViewModel
Expand Down
Loading

0 comments on commit 8594c9d

Please sign in to comment.