Skip to content

A Kotlin-based offline-first news app using MVVM. It fetches data via Retrofit and Moshi, caches it with Room, and updates the UI using LiveData, ViewModel, Coroutines, Data Binding, and FastAdapter.

Notifications You must be signed in to change notification settings

Shoaibkhalid65/NewsApp

Repository files navigation

🗞️ Offline-First News App

A modern Kotlin-based Android news app that follows the MVVM architecture and emphasizes offline-first functionality. The app fetches news data from a REST API, displays it in a responsive UI, and stores it locally using Room, allowing users to access news even without an internet connection.

✨ Features

  • 📡 Fetches latest news articles from an API
  • 💾 Offline-first: Caches data using Room for offline access
  • ⚡ Smooth and efficient UI with FastAdapter
  • 🔁 Automatic updates with LiveData and Coroutines
  • 🔍 View articles in detail or in a web view
  • 🔐 Proper architecture with separation of concerns

🛠️ Tech Stack

Layer Libraries/Technologies
Language Kotlin
Architecture MVVM, LiveData, ViewModel, Data Binding
Networking Retrofit, Moshi, Kotlin Coroutines
Local Storage Room
UI Components FastAdapter, Material Components
Utilities Android KTX, Lifecycle Components

📦 Project Structure

com.gshoai998.newsapp
├── model
│   ├── api
│   │   ├── ApiService.kt
│   │   └── RetrofitClient.kt
│   ├── database
│   │   ├── NewsDAO.kt
│   │   └── NewsDatabase.kt
│   ├── DataClasses.kt         # Data models for API and DB
├── repo
│   └── NewsRepository.kt      # Repository managing data sources
├── utils
│   ├── Constants.kt
│   └── NetworkUtils.kt
├── view
│   ├── activities
│   │   ├── MainActivity.kt
│   │   ├── OfflineActivity.kt
│   │   ├── ArticleDetailActivity.kt
│   │   └── ArticleWebViewActivity.kt
│   ├── ArticleItem.kt         # FastAdapter item for displaying articles
│   ├── BindingAdapters.kt     # Custom Data Binding adapters
│   └── viewModel
│       ├── NewsViewModel.kt
│       └── NewsViewModelFactory.kt

🚀 Getting Started

Prerequisites

  • Android Studio Giraffe or later
  • Android SDK 33+
  • Kotlin 1.9+
  • Internet connection (for initial API calls)

Setup Instructions

  1. Clone the repository:

    git clone https://github.com/Shoaibkhalid65/NewsApp.git
    cd OfflineNewsApp
  2. Open in Android Studio

    • File > Open > Select the project directory
  3. Add your API key

    If the API requires a key, add it in a secure place like local.properties or use a BuildConfig field.

  4. Build and Run

    • Select a device/emulator and click Run ▶️

📸 Video

newsapp_vid.mp4

📚 Architecture Overview

This app uses the MVVM pattern to ensure a clean separation of concerns:

  • Model (Data layer): Handles networking (Retrofit + Moshi) and local storage (Room).
  • ViewModel: Exposes observable data using LiveData and handles logic with Coroutines.
  • View: Activities and layout files bind to data using Data Binding and FastAdapter for smooth list rendering.

🤝 Contributing

Contributions are welcome! If you'd like to improve something or report a bug:

  1. Fork the repository
  2. Create a feature/bugfix branch
  3. Push your changes and open a Pull Request

📄 License

This project is licensed under the MIT License.


🙌 Credits

Developed by Muhammad Shoaib Khalid Inspired by clean architecture and modern Android development practices.


About

A Kotlin-based offline-first news app using MVVM. It fetches data via Retrofit and Moshi, caches it with Room, and updates the UI using LiveData, ViewModel, Coroutines, Data Binding, and FastAdapter.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages