Thanks to visit codestin.com
Credit goes to github.com

Skip to content

raymondfx/android-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Android App

A modern Android application built with Jetpack Compose that demonstrates secure authentication patterns, network monitoring, and comprehensive testing strategies.

✨ Features

Authentication & Security

  • 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

User Experience

  • 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

πŸ—οΈ Architecture

Tech Stack

  • 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

Project Structure

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

πŸ”§ Implementation Details

Authentication Repository (AuthRepository.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 validation
  • saveAuthToken(token): Stores JWT token securely
  • getAuthToken(): Retrieves stored token
  • clearAuthToken(): Removes token on logout
  • saveRememberMe(remember): Manages persistence preference

Login ViewModel (LoginViewModel.kt)

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

Network Monitor (NetworkMonitor.kt)

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

πŸ§ͺ Testing Strategy

Unit Tests Coverage

The project includes comprehensive unit tests covering:

AuthRepository Tests (AuthRepositoryTest.kt)

  • βœ… Valid credential authentication
  • βœ… Invalid username/password handling
  • βœ… Empty field validation
  • βœ… Token storage and retrieval
  • βœ… Remember Me preference management
  • βœ… SharedPreferences integration

LoginViewModel Tests (LoginViewModelTest.kt)

  • βœ… 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

Network Monitor Tests (NetworkMonitorTest.kt)

  • βœ… Connectivity state tracking
  • βœ… Network callback handling
  • βœ… Internet capability verification

Testing Technologies

  • 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

πŸš€ Getting Started

Prerequisites

  • Android Studio Arctic Fox or later
  • Android SDK 24+ (minimum)
  • Kotlin 1.9+

Setup Instructions

  1. Clone the repository

    git clone <repository-url>
    cd LoyaltyPoints
  2. Open in Android Studio

    • Open Android Studio
    • Select "Open an existing project"
    • Navigate to the project directory
  3. Build the project

    ./gradlew build
  4. Run tests

    ./gradlew test
  5. Install on device/emulator

    ./gradlew installDebug

Demo Credentials

πŸ§ͺ Running Tests

Unit Tests

# Run all unit tests
./gradlew test

# Run specific test class
./gradlew test --tests="*AuthRepositoryTest*"

# Run with coverage
./gradlew testDebugUnitTestCoverageReport

Instrumented Tests

# Run all instrumented tests
./gradlew connectedAndroidTest

# Run on specific device
./gradlew connectedDebugAndroidTest

πŸ”’ Security Features

Authentication Security

  • Input Sanitization: Username trimming and validation
  • Rate Limiting: Progressive lockout mechanism
  • Session Management: Secure token storage
  • Offline Protection: Prevents authentication without network

Data Protection

  • SharedPreferences: Secure local storage
  • Token Isolation: Separate storage keys
  • Auto-cleanup: Token removal on logout

🎨 UI/UX Design

Material Design 3

  • Theme System: Light/dark theme support ready
  • Typography: Consistent text styles
  • Color Scheme: Emirates brand colors
  • Component Library: Material 3 components

Accessibility

  • Screen Reader Support: Semantic content descriptions
  • Touch Targets: Minimum 48dp touch areas
  • Contrast: WCAG compliant color ratios

πŸ“ Code Quality

Architecture Principles

  • 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

Code Standards

  • 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

πŸ”„ Future Enhancements

Planned Features

  • 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

Technical Improvements

  • Dependency Injection: Migration to Dagger/Hilt
  • Database: Room integration for local storage
  • API Integration: Real backend service connection
  • CI/CD: Automated testing and deployment

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages