Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Multiple Choice Task] Fix UI bugs in multiple choice selectors #2899

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

shobhitagarwal1612
Copy link
Member

Fixes #2893

Updates UX as per figma mocks

@gino-m PTAL?

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 42.52874% with 50 lines in your changes missing coverage. Please review.

Project coverage is 61.90%. Comparing base (94c1ea7) to head (06ca789).

Files with missing lines Patch % Lines
...ion/tasks/multiplechoice/MultipleChoiceItemView.kt 35.21% 36 Missing and 10 partials ⚠️
...tasks/multiplechoice/MultipleChoiceTaskFragment.kt 66.66% 0 Missing and 3 partials ⚠️
...asks/multiplechoice/MultipleChoiceTaskViewModel.kt 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2899      +/-   ##
============================================
- Coverage     62.22%   61.90%   -0.33%     
+ Complexity     1205     1204       -1     
============================================
  Files           267      268       +1     
  Lines          6380     6441      +61     
  Branches        882      897      +15     
============================================
+ Hits           3970     3987      +17     
- Misses         1863     1898      +35     
- Partials        547      556       +9     
Files with missing lines Coverage Δ
...lection/tasks/multiplechoice/MultipleChoiceItem.kt 100.00% <100.00%> (ø)
...asks/multiplechoice/MultipleChoiceTaskViewModel.kt 92.18% <83.33%> (-0.46%) ⬇️
...tasks/multiplechoice/MultipleChoiceTaskFragment.kt 69.23% <66.66%> (+4.52%) ⬆️
...ion/tasks/multiplechoice/MultipleChoiceItemView.kt 35.21% <35.21%> (ø)

Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please paste a screenshot into the PR desc when you can. Thanks!

Copy link
Collaborator

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about taking this opportunity to migrate it to jetpack compose?

@shobhitagarwal1612
Copy link
Member Author

Marking this as draft. Working towards migrating the task's UI to compose.

@shobhitagarwal1612 shobhitagarwal1612 marked this pull request as draft December 9, 2024 03:23
@shobhitagarwal1612 shobhitagarwal1612 force-pushed the ashobhit/2893/choice-ux branch 2 times, most recently from 2adc6a8 to 459bee0 Compare December 19, 2024 11:47
@shobhitagarwal1612 shobhitagarwal1612 marked this pull request as ready for review December 20, 2024 06:51
@auto-assign auto-assign bot requested a review from anandwana001 December 20, 2024 06:51
@shobhitagarwal1612
Copy link
Member Author

@gino-m This is now ready for another pass! Migrated the UI to compose and updated styling & unit tests.

Comment on lines +46 to +48
isLastIndex: Boolean = false,
toggleItem: (item: MultipleChoiceItem) -> Unit = {},
otherValueChanged: (text: String) -> Unit = {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about have state and events

something like

val _multiplaeChoiceState = MutableStateFlow<MultiplaeChoiceData>(MultiplaeChoiceData())
val _multiplaeChoiceEvent = MutableSharedFlow<MultiplaeChoiceEvents>()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any benefits to using sharedFlow in this case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. all events can be managed at a single place
  2. can also prevent the double click
  3. no multiple parameters to compose functions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but the tests started failing after that. Can we handle that separately?

RadioButton(
modifier = Modifier.testTag(MultipleChoiceTestTags.SELECT_MULTIPLE_RADIO),
selected = item.isSelected,
onClick = { toggleItem(item) },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then we can emit like

multiplaeChoiceEvent(MultiplaeChoiceEvent.ToggleClick(item))

*/
package com.google.android.ground.ui.datacollection.tasks.multiplechoice

object MultipleChoiceTestTags {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need object, right?
we can keep constants as is

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, wrapping this under object makes it easier to use the constants

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easier to use but object MultipleChoiceTestTags will create a extra memory, object creation

in terms of using, we can directly write MULTIPLE_CHOICE_LIST no object name reference required

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MultipleChoiceTestTags is a singleton, so the memory for the object reference is minimal, if not zero if optimized out by the compiler.

Copy link
Collaborator

@gino-m gino-m Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Gemini, top-level declarations are preferred in Kotlin, but haven't validated this yet:

While you can technically use a Kotlin object as a namespace, it's generally not the recommended approach. Here's why:

Why not to use objects as namespaces:
  • Top-level declarations are preferred: Kotlin encourages the use of top-level functions and properties, which naturally provide a way to organize code into logical units without creating unnecessary objects.
  • Readability and maintainability: Using objects as namespaces can make your code harder to read and understand. Top-level declarations are more straightforward and easier to locate.
  • File facade issues (JVM): On the JVM, Kotlin compiles top-level declarations into a file facade class. If you use objects as namespaces, you might encounter naming conflicts with these generated classes.
Recommended alternatives:
  • Top-level functions and properties: The preferred way to group related code is to use top-level functions and properties within the same file.
  • Packages: For larger projects, use packages to organize your code into meaningful modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Data collection form] UI bugs in multiple choice selectors
4 participants