Coder Social home page Coder Social logo

chaimabouhlel / android-news-app Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 206 KB

News Explorer Mobile App An academic project focused on developing a mobile application using a News API. This app showcases three distinct interfaces. It incorporates essential features like data retrieval, search functionality, and error management for a reliable user experience, ensuring an error-handling mechanism.

Kotlin 100.00%

android-news-app's Introduction

Android News App with MVVM, Navigation Components, Retrofit, Room, and Coroutines

This repository contains the source code for a news app that demonstrates some concepts in Android development, including the use of MVVM architecture, navigation components, Retrofit, Room, and Coroutines. The app fetches current news from the News API and provides features such as breaking news, saved news, search functionality, and more.

App Features

  • MVVM Architecture: The app follows the MVVM (Model-View-ViewModel) architecture, ensuring a clean and organized codebase structure.

  • Navigation Components: Android's Navigation Components are employed for seamless and intuitive navigation throughout the app.

  • Coroutines: Kotlin Coroutines are utilized to handle asynchronous tasks, enhancing the app's responsiveness and overall performance.

  • Retrofit: API calls to the News API are made using Retrofit, fetching the latest news data for display in the app.

  • Room Database: Room is integrated into the app for storing and retrieving saved articles locally, providing offline access to users.

  • Pagination: The breaking news section features a paginated list, dynamically loading more news items as the user scrolls down.

  • Search Functionality: Users can search for news articles based on keywords, and the app dynamically loads results from the News API.

  • Save and Delete Articles: Articles can be saved to the local Room database, and users have the option to delete them, complete with an undo functionality.

  • Floating Action Button: A floating action button is provided for users to easily save articles to their local database.

  • Internet Connectivity Handling: The app includes robust handling for internet connectivity exceptions. If there is no internet connection, a message is displayed to inform the user about the lack of internet access.

Setup

Before running the app:

  1. Obtain an API key from News API.
  2. Insert the obtained API key into the appropriate configuration file.

User Interfaces

Breaking News Screen

image

This screenshot represents the main tab: the breaking news available from the API, represented by the BreakingNewsFragment

image

This screenshot represents the article view, ArticleFragment, which is displayed on clicking on the article

image image

This screenshot represents the saved news tab: which contains the articles liked by the user. It is represented by the SavedNewsFragment. The data is stored via the room database. Liked items can be deleted by swiping.

image

image This screenshot represents the search tab, represented by the SearchFragment. We can search for news in the entire API, exploring all available news. Upon entering the search query, the app retrieves and displays news articles relevant to the specified term. The implemented pagination feature ensures that as the user scrolls down, additional news items are automatically loaded. The search functionality incorporates a deliberate delay before initiating the search, preventing an immediate flood of requests upon each keystroke.

image image

Internet Exception

image

Architectural skeleton: MVVM (Model-View-ViewModel) pattern

  • View Model (UI Package): The NewsViewModel is responsible for managing and coordinating data related to news articles. It exposes LiveData objects for Breaking News and Search News: Two MutableLiveData objects are declared: breakingNews and searchNews, representing the breaking news and search news data, respectively. It implements functions for getting breaking news and searching news, handling responses, and managing pagination. It also handles internet connectivity checks.

  • Repository (Repository Package): The NewsRepository class is responsible for fetching data from both the local database and the remote data source (API). It acts as an intermediary between the data sources (API and local database) and the rest of the application, particularly the NewsViewModel.

  • View Model Provider Factory (UI Package): NewsViewModelProviderFactory inherits from ViewModelProvider.Factory. It is a Factory class used to create instances of the NewsViewModel.

  • Activity Setup: In the News Activity, the NewsRepository and NewsViewModelProviderFactory are instantiated. The NewsViewModel is then instantiated using the ViewModelProvider with the provided factory.

  • Fragment Setup(ui.fragments): In each fragment (BreakingNewsFragment, SavedNewsFragment, SearchNewsFragment, and ArticleFragment), the NewsViewModel is instantiated in the onViewCreated method. The fragments use the ViewModelProvider and cast the activity to access the shared NewsViewModel.

  • Resource Class (util Package): This is a sealed class that we used to wrap network responses. It has three subclasses: Success (with data), Error (with an error message), and Loading (indicating a loading state). This class helps us differentiate between successful and error responses and handle loading states.

Design Decisions

  • MVVM Architecture: MVVM allows for the separation of concerns, making the codebase more modular and maintainable. LiveData and ViewModel: LiveData ensures that UI components are always up-to-date, and ViewModel survives configuration changes. Resource Class: The Resource class simplifies handling different states of a network request, making UI logic cleaner. Repository Pattern: Centralized data access through the repository, promoting a clean architecture.

Dependencies

  • Android Architecture Components (ViewModel, LiveData)
  • Room Database
  • Coroutine Extensions for Room
  • Kotlin Coroutines
  • Retrofit (to make the API calls)
  • OkHttp Logging Interceptor (to debug our API requests )
  • Navigation Component
  • Glide (to load the images from the API)

android-news-app's People

Contributors

nadakhelif avatar chaimabouhlel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.