A modern Android application built with Jetpack Compose that demonstrates secure authentication patterns, network monitoring, and comprehensive testing strategies.
- Secure Login System: Email-based authentication with demo credentials
- Account Protection: Automatic lockout after 3 failed attempts (30-second cooldown)
- Session Management: "Remember Me" functionality with secure token storage
- Real-time Validation: Input validation for email format and password strength
- Offline Detection: Graceful handling of network connectivity issues
- Modern UI: Built with Jetpack Compose and Material Design 3
- Responsive Design: Edge-to-edge display with proper padding
- Loading States: Visual feedback during authentication
- Error Handling: Clear error messages with attempt counters
- Language: Kotlin
- UI Framework: Jetpack Compose
- Architecture Pattern: MVVM (Model-View-ViewModel)
- Dependency Injection: Manual DI (ready for Dagger/Hilt)
- Async Operations: Kotlin Coroutines + Flow
- Testing: JUnit 4, Mockito, Kotlin Test
app/src/main/java/com/emirates/loyaltypoints/
βββ MainActivity.kt # Entry point and navigation logic
βββ data/
β βββ repository/
β β βββ AuthRepository.kt # Authentication business logic
β βββ network/
β βββ NetworkMonitor.kt # Network connectivity monitoring
βββ presentation/
β βββ login/
β β βββ LoginViewModel.kt # Login state management
β β βββ LoginUiState.kt # UI state definitions
β β βββ LoginScreen.kt # Login UI components
β βββ home/
β βββ HomeScreen.kt # Post-login dashboard
βββ ui/theme/ # Material Design theme
βββ Color.kt
βββ Theme.kt
βββ Type.kt
The AuthRepositoryImpl
class provides:
- Demo Credentials:
[email protected]
/password123
- Token Management: Secure storage using SharedPreferences
- Input Validation: Empty field checks and credential validation
- Simulated Network Delay: 1.5-second delay for realistic UX
Key Methods:
login(credentials)
: Authenticates user with validationsaveAuthToken(token)
: Stores JWT token securelygetAuthToken()
: Retrieves stored tokenclearAuthToken()
: Removes token on logoutsaveRememberMe(remember)
: Manages persistence preference
Comprehensive state management with:
- Real-time Validation: Email format and password length checks
- Lockout Mechanism: 3-attempt limit with 30-second countdown
- Network Awareness: Automatic offline detection and handling
- Unidirectional Data Flow: Events β State updates β UI reactions
Key Features:
- Input validation: Email regex and 6+ character passwords
- Account lockout: Progressive failure counting with timer
- Auto-login: Checks for existing valid sessions
- Error handling: User-friendly messages with attempt counters
Real-time connectivity tracking:
- Reactive Monitoring: Flow-based network state changes
- Multiple Transports: WiFi and cellular network support
- Internet Capability: Verifies actual internet access, not just connection
- Callback Management: Proper registration and cleanup
The project includes comprehensive unit tests covering:
- β Valid credential authentication
- β Invalid username/password handling
- β Empty field validation
- β Token storage and retrieval
- β Remember Me preference management
- β SharedPreferences integration
- β Input validation and button state management
- β Successful login navigation
- β Failure count and lockout mechanism
- β Timer countdown functionality
- β Offline state handling
- β Remember Me token persistence
- β Auto-login with existing tokens
- β Error message lifecycle
- β Connectivity state tracking
- β Network callback handling
- β Internet capability verification
- JUnit 4: Core testing framework
- Mockito: Mock object creation and verification
- Kotlin Test: Kotlin-specific assertions
- Coroutines Test: Async operation testing with
runTest
- StandardTestDispatcher: Deterministic coroutine execution
- Android Studio Arctic Fox or later
- Android SDK 24+ (minimum)
- Kotlin 1.9+
-
Clone the repository
git clone <repository-url> cd LoyaltyPoints
-
Open in Android Studio
- Open Android Studio
- Select "Open an existing project"
- Navigate to the project directory
-
Build the project
./gradlew build
-
Run tests
./gradlew test
-
Install on device/emulator
./gradlew installDebug
- Username:
[email protected]
- Password:
password123
# Run all unit tests
./gradlew test
# Run specific test class
./gradlew test --tests="*AuthRepositoryTest*"
# Run with coverage
./gradlew testDebugUnitTestCoverageReport
# Run all instrumented tests
./gradlew connectedAndroidTest
# Run on specific device
./gradlew connectedDebugAndroidTest
- Input Sanitization: Username trimming and validation
- Rate Limiting: Progressive lockout mechanism
- Session Management: Secure token storage
- Offline Protection: Prevents authentication without network
- SharedPreferences: Secure local storage
- Token Isolation: Separate storage keys
- Auto-cleanup: Token removal on logout
- Theme System: Light/dark theme support ready
- Typography: Consistent text styles
- Color Scheme: Emirates brand colors
- Component Library: Material 3 components
- Screen Reader Support: Semantic content descriptions
- Touch Targets: Minimum 48dp touch areas
- Contrast: WCAG compliant color ratios
- Single Responsibility: Each class has one clear purpose
- Dependency Inversion: Interface-based abstractions
- Testability: Constructor injection for easy mocking
- Immutability: Data classes and StateFlow for state
- Comprehensive Documentation: KDoc comments on all public APIs
- Error Handling: Graceful failure management
- Resource Management: Proper cleanup and lifecycle handling
- Performance: Efficient state updates and memory usage
- Biometric Authentication: Fingerprint/face unlock
- Multi-factor Authentication: SMS/email verification
- Points Dashboard: Interactive loyalty points display
- Transaction History: Detailed points earning/spending
- Offline Support: Local data caching
- Dependency Injection: Migration to Dagger/Hilt
- Database: Room integration for local storage
- API Integration: Real backend service connection
- CI/CD: Automated testing and deployment