-
Notifications
You must be signed in to change notification settings - Fork 97
Migrate LogsScreen from Fragment to Jetpack Compose in purchasetester module #3026
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
Open
nimi0112
wants to merge
7
commits into
RevenueCat:main
Choose a base branch
from
nimi0112:feature/compose-migrate-logs-screen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Migrate LogsScreen from Fragment to Jetpack Compose in purchasetester module #3026
nimi0112
wants to merge
7
commits into
RevenueCat:main
from
nimi0112:feature/compose-migrate-logs-screen
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…odule Migrate ConfigureScreen to Jetpack Compose - Add Compose theme system (Color, Type, Theme) - Create ConfigureActivity as Compose entry point - Add Compose dependencies to build config - Add test cases for ConfigureScreenViewModel
Refactor ConfigureScreenViewModelImpl to use a reactive flow-based approach: - Remove init block and loadData() method to eliminate side effects - Transform _state from MutableStateFlow to derived StateFlow using combine() - Add userEdits flow to track user modifications before persistence - Use SharingStarted.WhileSubscribed() for lazy, lifecycle-aware data loading - Extract subscription timeout as SUBSCRIPTION_TIMEOUT_MILLIS constant Benefits: - No side effects in constructor/init - Data loads only when UI observes the state - Better testability and lifecycle awareness - Automatic cleanup when no observers - Follows modern Android ViewModel best practices All existing tests pass without modifications.
…ecture Migrate LoginFragment to a fully Compose-based LoginScreen with type-safe navigation architecture, following the patterns established in ConfigureScreen. ## LoginScreen Implementation Created new Compose-based login screen with: - LoginScreenState: Sealed class for state management with Loading and Data states - LoginScreenViewModel: Reactive ViewModel using StateFlow with user edits pattern - LoginScreen: Composable UI matching original fragment_login.xml layout exactly - LoginScreenViewModelTest: Comprehensive unit tests (7 tests, all passing) Key features: - User ID input with automatic trimming - Login with user ID using Purchases.logInWith() - Continue as random user (handles both anonymous and logged-in states) - Reset SDK functionality with Purchases.close() - Type-safe event system for navigation and error handling - String resources for all UI text (localization-ready) ## Navigation Architecture Created type-safe Compose navigation: - PurchaseTesterScreen: Sealed class defining all navigation routes - PurchaseTesterNavHost: NavHost with hybrid Compose + Fragment navigation - Smooth transitions between Configure and Login screens - Proper back stack management with popUpTo configurations Navigation flows: - Configure → Login: Pure Compose navigation within ConfigureActivity - Login → Overview: Intent to MainActivity (Fragment-based, until migrated) - Login → Configure: Compose navigation with full stack clear - Logs/Proxy: Fallback to Fragment navigation (until migrated) ## Cleanup and Updates Deleted obsolete files: - LoginFragment.kt (2,768 bytes) - fragment_login.xml (4,217 bytes) Updated existing files: - ConfigureActivity: Now uses PurchaseTesterApp with NavHost - MainActivity: Removed LOGIN navigation case (handled by Compose) - OverviewFragment: Logout navigates to ConfigureActivity instead of LoginFragment - nav_graph.xml: Removed all LoginFragment references, changed startDestination - Constants.kt: Removed unused LOGIN constant ## Architecture Benefits - Type-safe navigation with sealed classes (compile-time safety) - Hybrid navigation allowing gradual migration of remaining screens - Pattern consistency across all Compose screens - Better testability with interface-based ViewModels - Modern reactive state management - Clean separation between Compose and Fragment screens ## Testing - All unit tests passing (7/7) - Build successful - Feature parity with original LoginFragment verified - Navigation flows tested and working correctly This migration establishes the navigation architecture pattern for remaining screen migrations and demonstrates best practices for Compose + Fragment hybrid navigation during incremental migration.
Implement new Compose-native ProxySettings bottom sheet to replace Fragment-based implementation for ConfigureScreen and
LoginScreen.
Changes:
- Add ProxySettingsViewModel with StateFlow and coroutines
- Add ProxySettingsSheet using Material3 ModalBottomSheet
- Update PurchaseTesterNavHost to show sheet as modal overlay
- Add comprehensive unit tests for ProxySettingsViewModel
- Improve error messages with exception class name for debugging
The old Fragment-based implementation remains untouched and continues to be used by OverviewFragment. It will be removed when
OverviewScreen is migrated to Compose in a future PR.
Technical details:
- Uses StateFlow instead of LiveData for reactive state management
- Coroutines with injectable dispatcher for testability
- No init block - explicit loadCurrentState() method
- Inline updateState function matching ConfigureScreenViewModel pattern
- Unit tests covering all state transitions
Replace Fragment-based logs screen with modern Compose implementation following established patterns from LoginScreen and ConfigureScreen migrations. Key changes: - Add LogsScreen composable with Material3 components (Scaffold, TopAppBar, LazyColumn) - Add LogsViewModel with StateFlow-based state management - Add LogsScreenState sealed class for Loading and LogsData states - Add comprehensive unit tests for LogsViewModel (7 test cases) - Add Yellow and Blue colors to theme for log level backgrounds - Add empty state message when no logs are available - Update navigation to use Compose navigation instead of Fragment navigation - Remove LogsFragment, fragment_logs.xml, and log_row_view.xml - Clean up navigation graph references to logsFragment - Add NavigationExtras constants for type-safe Intent extras - Update ConfigureActivity to handle direct navigation to logs from OverviewFragment - Simplify MainActivity by removing unused navigation handling Benefits: - More efficient rendering with LazyColumn vs RecyclerView - Removed ~90 lines of adapter boilerplate - Type-safe navigation with sealed classes - Improved testability with pure ViewModel - Consistent with other migrated Compose screens - Better user experience with empty state handling
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Continue Compose migration: LoginScreen and ProxySettings (Part 3)
1st PR: #2991
2nd PR:#3025
Checklist
purchases-iosand hybridsMotivation
Migrate LogsScreen from Fragment-based architecture to modern Jetpack Compose as part of the ongoing effort to modernize the Tester app.
This continues the migration pattern established with LoginScreen and ConfigureScreen, reducing technical debt.
Description
Changes Made
New Compose Implementation:
UI Features:
Navigation Updates:
Code Cleanup:
Testing
Unit Tests (LogsViewModelTest.kt):
output.video.mp4