Skip to content

[Draft] Replace tasks fragment with pure compose screens within DataCollection fragment #3635

Draft
shobhitagarwal1612 wants to merge 10 commits intomasterfrom
tasks-pager-compose
Draft

[Draft] Replace tasks fragment with pure compose screens within DataCollection fragment #3635
shobhitagarwal1612 wants to merge 10 commits intomasterfrom
tasks-pager-compose

Conversation

@shobhitagarwal1612
Copy link
Member

Fixes #

@... PTAL?

- Remove `DataCollectionViewPagerAdapter` and its associated factory.
- Introduce `TaskPager` Composable using `HorizontalPager` to manage task transitions.
- Implement `TaskFragmentProvider` to encapsulate fragment creation logic previously held in the adapter.
- Update `DataCollectionFragment` to use `ComposeView` for the main task display, integrating with `TaskPager`.
- Use `AndroidView` and `FragmentContainerView` within the pager to host existing task fragments.
- Add logic to `DataCollectionFragment.onCreate` to clean up child fragments on configuration changes, preventing view attachment errors.
- Simplify progress bar updates by removing the `shouldAnimate` flag and always using animated transitions.
- Replace `TaskFragmentProvider` and individual task fragments (`Text`, `Date`, `Number`, `Photo`, `MultipleChoice`, `Time`, `Instruction`, `DrawArea`, `DropPin`, `CaptureLocation`) with Compose-based screen functions.
- Introduce `TaskContainer` as a unified Compose component to handle task layout, headers, footers, and common dialog logic (LOI naming and instructions).
- Migrate task-specific logic, such as photo capture, location permissions, and dialog handling, into their respective Composable screens.
- Update `TaskPager` to switch between tasks by rendering the new Composable screens instead of inflating fragments.
- Update `DataCollectionFragment` to provide necessary dependencies (permissions, popups, and map fragment providers) to the new Compose hierarchy.
- Standardize header and instruction handling across all task types within the Compose architecture.
- Rename various `*TaskFragment.kt` files to `*TaskScreen.kt` for Consistency (Number, MultipleChoice, CaptureLocation, Text, DrawArea, DropPin, Instruction).
- Refactor `PhotoTaskFragment.kt` and `PhotoTaskScreen.kt` into a unified `PhotoTaskScreen.kt` and move the UI content to `PhotoTaskContent.kt`.
- Refactor `TimeTaskFragment.kt` and `TimeTaskScreen.kt` into a unified `TimeTaskScreen.kt` and move the input field to `TimeTaskField.kt`.
- Rename `DateTaskScreen` to `DateTaskField` and update `DateTaskFragment` to use the new component name.
- Update `PhotoTaskScreenTest` to reflect the renaming of `PhotoTaskScreen` to `PhotoTaskContent`.
- Split `TaskContainer` into a stateful parent and a stateless `TaskContainerUi` Composable to improve testability and separation of concerns.
- Move event handling logic (e.g., `handleNext`, `handleButtonClick`, `handleLoiNameConfirm`) into the parent `TaskContainer`.
- Pass simplified state values and callbacks (e.g., `initialNameValue`, `onButtonClicked`) as parameters to `TaskContainerUi`.
- Optimize conditional rendering of `InstructionsDialog` and `LoiNameDialog` using standard Kotlin idioms like `takeIf`.
- Refactor footer position tracking to use a callback provided by the parent.
- Update `TaskPager` to use `animateScrollToPage` instead of `scrollToPage` for smoother task transitions.
- Refactor task screen selection logic in `TaskPager` to use `when` expressions on `taskViewModel` types instead of `task.type`, eliminating redundant type casting.
- Reorder parameters in `DataCollectionFragment` and `TaskPager` for better consistency.
- Add an explicit error message for unhandled task ViewModel types.
…d CompositionLocals

- Introduce `TaskScreenEnvironment` data class to encapsulate common dependencies like view models, fragment managers, and map fragment providers.
- Update all task screens (Photo, Number, MultipleChoice, Location, Text, Date, Time, Instruction) to accept `TaskScreenEnvironment` instead of individual dependency parameters.
- Introduce `LocalPermissionsManager` and `LocalEphemeralPopups` using `CompositionLocalProvider` to provide global utilities to the Composable hierarchy.
- Simplify `TaskPager` and `DataCollectionFragment` by passing the new environment object and using `CompositionLocalProvider` for UI-related dependencies.
- Relocate `DateTaskScreen` from `DateTaskFragment.kt` (logic remains the same).
…mpose

- Create a new `@Composable` component `FragmentContainer` to handle the boilerplate of embedding Android `Fragment`s within a Compose UI using `AndroidView` and `FragmentContainerView`.
- Refactor `CaptureLocationTaskScreen`, `DrawAreaTaskScreen`, and `DropPinTaskScreen` to use the new `FragmentContainer` for displaying map-based task fragments.
- Simplify fragment transaction logic by centralizing argument passing and fragment manager interactions within `FragmentContainer`.
- Remove unused imports and legacy view-binding code from the refactored task screens.
- Centralize action handling logic in `DataCollectionViewModel#onAction`, moving it out of `TaskContainer`.
- Relocate LOI name dialog confirmation and dismissal logic to `DataCollectionViewModel`.
- Move instruction dialog state management into `AbstractTaskViewModel`, providing `showInstructionsDialog()` and `dismissInstructionsDialog()` methods.
- Introduce an `instructionsDialogShown` property in `AbstractTaskViewModel` to track and persist the shown state, implemented in `DropPinTaskViewModel` and `DrawAreaTaskViewModel`.
- Simplify `TaskContainer` and task screens (`DrawAreaTaskScreen`, `DropPinTaskScreen`) by delegating dialog state and actions to their respective ViewModels.
- Remove redundant instruction dialog handling from `AbstractTaskFragment`.
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.

1 participant