Skip to content

ulvij/TrackerApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TrackerApp - Real-Time Stock Price Tracker

A modern Android application built with Jetpack Compose that displays real-time price updates for 25 stock symbols using WebSocket communication. The app connects to a WebSocket echo server, sends mock price updates every 2 seconds, and displays live data in a clean, scrollable interface.

πŸ“Έ Preview

🎬 App Demo

TrackerApp Demo

Live demo showing real-time price updates, theme switching, and connection management

πŸ“± Screenshots

Dark Theme - Disconnected Light Theme Dark Theme - Connected
Dark theme (Disconnected) Light theme Dark theme with live updates

Key UI Features Shown:

  • 🎨 Dual Theme Support: Seamless light/dark mode with moon/sun toggle
  • πŸ”΄πŸŸ’ Connection Status: Visual indicator (red = disconnected, green = connected)
  • πŸ“Š Real-time Updates: Price changes with β–²/β–Ό indicators and percentage changes
  • 🎯 Clean Design: Material 3 with rounded cards and company logos
  • πŸ“± Sorted List: Automatically sorted by price (highest to lowest)

πŸ“± Features

  • Real-time Price Tracking: Monitor 25 major stock symbols (AAPL, GOOG, TSLA, NVDA, etc.)
  • Live WebSocket Connection: Connects to wss://ws.postman-echo.com/raw for real-time data exchange
  • Visual Price Indicators: Green ↑ for price increases, Red ↓ for decreases
  • Price Flash Animation: Visual feedback with 1-second color flash on price changes
  • Dynamic Sorting: Automatically sorts stocks by price (highest to top)
  • Connection Management: Start/Stop button with connection status indicator
  • Theme Support: Light and Dark theme with system default option
  • Clean Architecture: Multi-module structure with clear separation of concerns
  • Comprehensive Testing: Unit tests for business logic and UI tests for all Compose components

✨ Bonus Requirements (All Implemented)

All optional bonus requirements from the challenge have been implemented:

  • βœ… Price Flash Animation: Prices flash green for 1 second on increase, red on decrease
  • βœ… Comprehensive Testing: Full test coverage including Compose UI tests for all components and screens
  • βœ… Theme Support: Complete light/dark theme implementation with system default option

πŸ—οΈ Architecture

This project follows Clean Architecture with MVVM (Model-View-ViewModel) pattern in a multi-module structure:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  App (Presentation)                         β”‚
β”‚  β€’ Jetpack Compose UI                       β”‚
β”‚  β€’ ViewModels + StateFlow                   β”‚
β”‚  β€’ Immutable UI State                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Domain (Business Logic)                    β”‚
β”‚  β€’ Use Cases (Single Responsibility)        β”‚
β”‚  β€’ Repository Interfaces                    β”‚
β”‚  β€’ Domain Models                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Data (Data Layer)                          β”‚
β”‚  β€’ Repository Implementations               β”‚
β”‚  β€’ WebSocket Manager (OkHttp)               β”‚
β”‚  β€’ DataStore (Theme Persistence)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ“‹ Detailed Architecture Breakdown

Layer Responsibilities

App Module (Presentation Layer)

  • TrackerScreen & StockListItem: Compose UI components
  • TrackerViewModel & MainViewModel: State management with StateFlow
  • Observes domain use cases and exposes immutable UI state

Domain Module (Pure Kotlin)

  • Use Cases: ObserveStockPricesUseCase, StartConnectionUseCase, StopConnectionUseCase, etc.
  • Repository Interfaces: Define contracts for data operations
  • Models: Domain entities (Stock, ConnectionState)
  • Completely independent of Android framework

Data Module

  • Repositories: StockRepositoryImpl, ConnectionRepositoryImpl, ThemeRepositoryImpl
  • WebSocketManager: Handles real-time connection with OkHttp
  • StockPriceCoordinator: Generates mock price updates every 2 seconds
  • StockDataSource: 25 stock symbols with metadata

MVVM Data Flow

View (Compose) ──► ViewModel ──► Use Case ──► Repository Interface
                      β”‚                               β”‚
                 StateFlow β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                      β”‚
                                          Repository Impl ──► WebSocket/DataStore

Key Benefits: Separation of concerns β€’ Testability β€’ Scalability β€’ Maintainability

Dependency Injection: Hilt with @HiltViewModel and @Singleton scopes
State Management: StateFlow for reactive UI β€’ Immutable state β€’ Unidirectional data flow

πŸš€ How to Run the Project

Prerequisites

  • Android Studio: Ladybug | 2024.2.1 or newer
  • JDK: Java 17 (included in Android Studio)
  • Minimum SDK: API 24 (Android 7.0)
  • Target SDK: API 36 (Android 15)

Steps to Build and Run

  1. Clone the repository:

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

    • Launch Android Studio
    • Select "Open an existing project"
    • Navigate to the TrackerApp directory and select it
  3. Sync Gradle:

    • Android Studio should automatically trigger a Gradle sync
    • If not, click "File" β†’ "Sync Project with Gradle Files"
    • Wait for dependencies to download (first sync may take a few minutes)
  4. Run on Emulator or Device:

    • Emulator: Create an AVD (Android Virtual Device) via "Device Manager"
      • Recommended: Pixel 5 or newer with API 34+
    • Physical Device: Enable USB debugging in Developer Options
    • Click the green "Run" button (▢️) or press Shift + F10
  5. Verify the App:

    • The app should launch with 25 stock symbols displayed
    • Tap the "Start" button in the top bar to begin real-time updates
    • Observe prices updating every 2 seconds with animations
    • Check the connection indicator (●) showing Connected/Disconnected status

Alternative: Build from Command Line

# Build debug APK
./gradlew assembleDebug

# Install on connected device
./gradlew installDebug

# Run all tests
./gradlew test

# Run connected tests (requires device/emulator)
./gradlew connectedAndroidTest

Troubleshooting

  • Build fails: Ensure you have Java 17 configured in Android Studio settings
  • Dependencies not downloading: Check your internet connection and proxy settings
  • WebSocket not connecting: Verify network permissions and internet access
  • App crashes on start: Check Logcat for stack traces; ensure minimum SDK 24

πŸ§ͺ Testing

Comprehensive test coverage at all layers with JUnit 4, MockK, Turbine, and Compose Testing.

# Run all tests
./gradlew test                    # Unit tests
./gradlew connectedAndroidTest    # UI tests (requires device/emulator)

Coverage Summary:

  • βœ… Unit Tests: ViewModels β€’ Repositories β€’ Business Logic β€’ UI State
  • βœ… UI Tests: Screen interactions β€’ Component rendering β€’ Animations β€’ State changes
πŸ“‹ Detailed Test Coverage

Unit Tests (8 test classes)

  • ViewModels: TrackerViewModelTest, MainViewModelTest
  • Repositories: StockRepositoryImplTest, ConnectionRepositoryImplTest, ThemeRepositoryImplTest
  • Business Logic: StockPriceCoordinatorTest, WebSocketManagerTest
  • UI State: TrackerUIStateTest

UI Tests - Instrumented (4 test classes)

  • Screens: TrackerScreenTest - Full screen interaction and state verification
  • Components: StockListItemTest, TopBarTest, ConnectionStatusIndicatorTest

Testing Tools

  • JUnit 4 + MockK for mocking β€’ Turbine for Flow testing
  • Coroutines Test for suspend functions β€’ Compose Testing with semantic matchers
  • Test Tags for reliable UI element identification

πŸ’‘ Design Decisions

πŸ“‹ Key Assumptions
  1. Mock Data: Random price generation ($50-$500 range, Β±5% changes) for demo purposes
  2. Echo Server: Using Postman Echo Server; production would use real stock API
  3. Stock List: Fixed 25 major tech/financial stocks (extensible in future)
  4. Connectivity: Requires internet; basic error handling, no offline mode
  5. Persistence: Only theme preference saved; prices reset on restart (intentional)
βš–οΈ Architecture Trade-offs
Decision Benefits βœ… Costs ❌ Rationale
Multi-module Architecture Clean separation, maintainable, scalable More boilerplate, setup time Production-ready structure
WebSocket vs Polling Real-time, low latency, less bandwidth Complex management, battery Required by challenge, better UX
Single StateFlow Atomic updates, simpler testing Potential recomposition overhead @Immutable enables smart recomposition
Price Gen in Data Layer Pure domain, easy API swap Slightly impure data layer Demo-appropriate, swappable
Coordinator Pattern Centralized timing control Couples generation + network Cleaner lifecycle management
No Caching/Room Simpler, always fresh data No offline support Sufficient for demo scope
Hilt DI Type-safe, less boilerplate Longer build times Industry standard
StateFlow over LiveData Compose-friendly, coroutine integration Less mature ecosystem Modern approach
Comprehensive Testing High confidence, early bug detection Time investment, build overhead Quality assurance priority
Simple Error Handling Focused on core functionality Limited user feedback Demo scope, extensible

πŸ› οΈ Technology Stack

Category Technology
Language Kotlin 2.2.21
UI Framework Jetpack Compose (BOM 2025.11.01)
Architecture MVVM + Clean Architecture
Dependency Injection Hilt 2.57.2
Async Kotlin Coroutines 1.10.2
Networking OkHttp 5.3.2 (WebSocket)
JSON Gson 2.13.2
Storage DataStore Preferences 1.1.1
Image Loading Coil (if logos are displayed)
Testing JUnit 4, MockK 1.14.6, Turbine 1.2.1
Build System Gradle 8.13.1 with Kotlin DSL

πŸ“‚ Project Structure

TrackerApp/
β”œβ”€β”€ app/           # UI Layer (Compose, ViewModels, 3 unit tests, 4 UI tests)
β”œβ”€β”€ domain/        # Business Logic (Use Cases, Repository Interfaces)
└── data/          # Data Layer (Repositories, WebSocket, DataStore, 5 tests)
πŸ“‹ Detailed File Structure
app/
β”œβ”€β”€ src/main/java/com/tracker/app/
β”‚   β”œβ”€β”€ TrackerApplication.kt        # Hilt application
β”‚   β”œβ”€β”€ base/BaseViewModel.kt
β”‚   β”œβ”€β”€ ui/
β”‚   β”‚   β”œβ”€β”€ MainActivity.kt          # Entry point
β”‚   β”‚   β”œβ”€β”€ MainViewModel.kt         # Theme management
β”‚   β”‚   β”œβ”€β”€ components/              # StockListItem, TopBar, etc.
β”‚   β”‚   β”œβ”€β”€ screen/                  # TrackerScreen + ViewModel + UIState
β”‚   β”‚   β”œβ”€β”€ theme/                   # Compose theme
β”‚   β”‚   └── model/                   # UI models
β”‚   └── tools/PriceFlashAnimation.kt
β”œβ”€β”€ src/test/                        # 3 unit tests
└── src/androidTest/                 # 4 UI tests

domain/src/main/java/com/tracker/domain/
β”œβ”€β”€ base/                            # BaseUseCase, BaseFlowUseCase
β”œβ”€β”€ connection/                      # 3 use cases + ConnectionState model
β”œβ”€β”€ stock/                           # ObserveStockPricesUseCase + Stock model
β”œβ”€β”€ theme/                           # 2 theme use cases
β”œβ”€β”€ error/                           # ErrorConverter
└── di/DomainModule.kt

data/
β”œβ”€β”€ src/main/java/com/tracker/data/
β”‚   β”œβ”€β”€ connection/                  # WebSocketManager + ConnectionRepositoryImpl
β”‚   β”œβ”€β”€ stock/                       # StockDataSource + Coordinator + RepositoryImpl
β”‚   β”œβ”€β”€ theme/                       # ThemeRepositoryImpl (DataStore)
β”‚   └── di/DataModule.kt
└── src/test/                        # 5 unit tests


About

Tracker App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages