Skip to content

MVVM Clean Architecture using Jetpack Compose, Kotlin, Retrofit, Coroutines, Flow, StateFlow, Dagger-Hilt, WorkManager, Room, Unit test and etc

Notifications You must be signed in to change notification settings

sagrawal2418/NewsApp-MVVM-Architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clean-MVVM-NewsApp

Architecture

An Android application built using Clean + MVVM architecture.

Major Highlights.

  • MVVM Architecture - For structuring code to separate business logic from UI concerns, promoting a clean app development environment.
  • Offline-First - Approach to app design that prioritizes device-side data management for robust offline usability.
  • StateFlow - Kotlin's state management tool that builds on Flow to make data streams lifecycle-aware.
  • Coroutines - For asynchronous programming, allowing network and heavy computations to be handled smoothly.
  • Unit Testing - For validating each component functions correctly in isolation.
  • UI Testing - For ensuring the user interface works as expected across different devices and configurations.
  • Kotlin - As a programming language.
  • Jetpack Compose - Modern toolkit for building native UI.
  • AndroidX Browser - Library for integrating web content using Chrome Custom Tabs.
  • Paging - For handling large data sets smoothly.
  • Work Manager - For managing background tasks.
  • LiveData - Lifecycle aware Observable data holder class.
  • ViewModel - To manage UI-related data in a lifecycle conscious way.
  • Flow - For handling asynchronous data streams within Android applications.
  • Retrofit - For making network calls.
  • Dagger-Hilt - For dependency injection specifically tailored for Android.
  • Room database - To cache the response for offline access.
  • C++ - Used to securely store and retrieve the base URL and API key, enhancing the security of the app’s configuration.

Description

NewsApp-MVVM-Architecture demonstrates Clean Architecture and MVVM in Android development. This app uses Kotlin, Retrofit2, Room, and Kotlin Flow, and uses C++ for secure configuration management. It’s an ideal resource to improve skills in building secure, robust Android applications.

Architecture

Architecture

Features Implemented.

App Features

  • Fetching News: Utilizes Retrofit to retrieve the latest news updates efficiently.
  • Pagination: Implemented via the Paging library to manage data loading in manageable chunks, enhancing performance.
  • Top Headlines News: Highlights the most important news, making them accessible at a glance.
  • News Based on Source: Allows users to filter news content based on their preferred news outlets.
  • News Based on Country Selection: Enables filtering news by country, catering to geo-specific audiences.
  • News Based on Language Selection: Supports multiple languages, allowing users to receive news in their preferred language.
  • Instant Search: Enhanced by Kotlin Flow operators for real-time search capabilities:
    • Debounce: Minimizes API call overload by pausing for a set time frame before executing the search.
    • Filter: Ensures only relevant results pass through the search query.
    • DistinctUntilChanged: Prevents duplicate results from being shown to the user.
    • FlatMapLatest: Ensures only the latest search inputs are considered for fetching data.
  • Offline Support: Integrates Room database for caching articles, enabling offline reading.
  • WorkManager for Periodic News Fetching: Uses WorkManager to schedule background updates of news data at regular intervals.
  • Testing Frameworks:
    • Unit Tests: Ensures that individual components function correctly, utilizing frameworks like JUnit.
    • Mockito: Facilitates mocking objects in tests to isolate and focus on the component being tested.
    • Espresso: Automates UI tests to ensure the app performs as expected on a device.
    • Turbine: A testing library for Kotlin Flows that simplifies the process of asserting flow emissions.

Complete Project Structure

Project Structure

Screenshots

NewsApp NewsApp NewsApp NewsApp NewsApp

Steps to build the app

  • Create your API key at News API
  • Navigate to the nativelib directory in your project structure.
  • Open the newsapp.cpp file.
  • Locate the getData method:
    static std::string getData(bool debugMode) {
        std::string app_secret = "Null";
        if (debugMode) {
            app_secret = "ba07a65dfd724ffd8481044578ae0cb8"; // Local API
        } else {
            app_secret = "ba07a65dfd724ffd8481044578ae0cb8"; // Live API
        }
        return app_secret;
    }
    
  • Replace the placeholder API key (ba07a65dfd724ffd8481044578ae0cb8) with your actual API key for both the local and live environments as needed.
  • Build and run the app.

Donation

If this project help you reduce time to develop, you can buy me a cup of coffee :)

Buy Me A Coffee

Thank you!