All Projects → vicky7230 → Headlines

vicky7230 / Headlines

Licence: Apache-2.0 license
Simple Headlines app to showcase MVVM(Model-View-ViewModel) architecture with OFFLINE functionality in android.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Headlines

Simple-Note-App-with-Online-Storage
✍️ Simple Note Making App use Sqllite Room 🧰 for caching the notes and 📥 Firebase Database for online storage
Stars: ✭ 42 (-12.5%)
Mutual labels:  dagger2, viewmodel, mvvm-architecture, room-persistence-library
Android Mvvm Rx3 Dagger2 Navcomponent
Implemented using MVVM, LiveData, Room, RX3, Dagger2, Coil, View Binding, Navigation Component and AndroidX
Stars: ✭ 72 (+50%)
Mutual labels:  dagger2, mvvm-architecture, room-persistence-library
Base Mvvm
App built to showcase basic Android View components like ViewPager, RecyclerView(homogeneous and heterogeneous items), NavigationDrawer, Animated Vector Drawables, Collapsing Toolbar Layout etc. housed in a MVVM architecture
Stars: ✭ 18 (-62.5%)
Mutual labels:  dagger2, viewmodel, room-persistence-library
Simple-Notes-Kotlin-App
✍️ Simple Note Making App use mvvm architecture , dagger , coroutines and navigation component. Features includes 🗒️ create , edit and ❌ delete notes
Stars: ✭ 40 (-16.67%)
Mutual labels:  dagger2, viewmodel, mvvm-architecture
Clean Notes
Clean Architecture by layer
Stars: ✭ 259 (+439.58%)
Mutual labels:  dagger2, mvvm-architecture, room-persistence-library
News Sample App
A sample news app which demonstrates clean architecture and best practices for developing android app
Stars: ✭ 334 (+595.83%)
Mutual labels:  dagger2, viewmodel, mvvm-architecture
GuildWars2 APIViewer
Guild Wars 2 API Viewer: An Android application used for viewing various Guild Wars 2 API endpoint responses. Developed utilizing MVVM architecture, in conjunction with Databinding, Dagger 2, Retrofit 2, and RxJava 2.
Stars: ✭ 53 (+10.42%)
Mutual labels:  dagger2, mvvm-architecture, rxjava2-retrofit2
Movieapp Clean Architecture
Learning Project (Movie App) For Applying Android Architecture Components And Clean Architecture Using MVVM With Kotlin
Stars: ✭ 123 (+156.25%)
Mutual labels:  dagger2, viewmodel, mvvm-architecture
Vigilante
🛡️ Android security (camera/microphone dots indicators) app using Hilt, Animations, Coroutines, Material, StateFlow, Jetpack (Room, ViewModel, Paging, Security, Biometrics, Start-up) based on MVVM architecture.
Stars: ✭ 234 (+387.5%)
Mutual labels:  dagger2, mvvm-architecture, room-persistence-library
Dagger Examples
Some dagger-android examples with Retrofit2, MVVM architecture, RxJava, (Java)
Stars: ✭ 242 (+404.17%)
Mutual labels:  dagger2, mvvm-architecture, room-persistence-library
NewsApp
An app that fetches latest news, headlines
Stars: ✭ 28 (-41.67%)
Mutual labels:  viewmodel, rxjava2-retrofit2, room-persistence-library
Moneycim
Spending Tracker Application
Stars: ✭ 48 (+0%)
Mutual labels:  dagger2, mvvm-architecture, room-persistence-library
catchflicks
🎬 Kitchen sink project for learning android concepts 🎬
Stars: ✭ 12 (-75%)
Mutual labels:  dagger2, viewmodel, mvvm-architecture
Changedetection
Automatically track websites changes on Android in background.
Stars: ✭ 563 (+1072.92%)
Mutual labels:  dagger2, viewmodel, room-persistence-library
Mvvmframe
🏰 MVVMFrame for Android 是一个基于Google官方推出的Architecture Components dependencies(现在叫JetPack){ Lifecycle,LiveData,ViewModel,Room } 构建的快速开发框架。有了MVVMFrame的加持,从此构建一个MVVM模式的项目变得快捷简单。
Stars: ✭ 218 (+354.17%)
Mutual labels:  dagger2, viewmodel, mvvm-architecture
Popularmovies
🎥 Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.
Stars: ✭ 142 (+195.83%)
Mutual labels:  offline-first, viewmodel, mvvm-architecture
Clean-MVVM-NewsApp
Android News app developed using Clean + MVVM architecture
Stars: ✭ 52 (+8.33%)
Mutual labels:  viewmodel, mvvm-architecture, room-persistence-library
Kriptofolio
Free open source minimalistic cryptocurrencies portfolio app for Android.
Stars: ✭ 79 (+64.58%)
Mutual labels:  viewmodel, mvvm-architecture
DailyBugle
📰Modern MVVM Android application following single activity architecture which fetches news from 🕷️ news API. this repository contains some best practices ⚡ of android development
Stars: ✭ 17 (-64.58%)
Mutual labels:  dagger2, mvvm-architecture
ChatApp
Chat app based on Firebase tools.
Stars: ✭ 88 (+83.33%)
Mutual labels:  dagger2, mvvm-architecture

alt text

Headlines

License

Simple Headlines app to showcase MVVM(Model-View-ViewModel) architecture in android.

Get it on google play

The Model-View-ViewModel Pattern

The main components in the MVVM pattern are:

  • The View — that informs the ViewModel about the user’s actions
  • The ViewModel — exposes streams of data relevant to the View
  • The DataModel — abstracts the data source. The ViewModel works with the DataModel to get and save the data.

MVVM pattern was created to simplify the event driven programming of user interfaces.

In MVVM, ViewModel exposes streams of events to which the Views can bind to. Because of this, the ViewModel does not need to hold a reference to the View anymore. This also means that all the interfaces that the MVP pattern requires, are now dropped. View has a reference to ViewModel but ViewModel has no information about the View. The consumer of the data should know about the producer, but the producer — the ViewModel — doesn’t know, and doesn’t care, who consumes the data.

Offline functionality implementation

The app fetches the aticles from the server and saves them in Database locally when it is opened for the first time. When the user opens it next time, the app loads articles from the Database first and then makes a network request in the background, once the network request is complete, the articles on the screen are swapped with the fresh articles from the server. Doing this gives the app a snappy user experience.

In the app there are two sources of data :

  1. a Local Database(implemented through Room)
  2. a Server(implemented through Retrofit)

So the results(data) that come out of the Database are very quick because the Database is locally available on your device. But the problem with having the results purely in the local Database is that they tend to be stale. The newest form of data is available from the Server. So typically what we also want to do is execute a network request and that network request, typically network requests take a longer time to complete, but once it completes we want to take those results and swap it out with the Local Database results. Doing this gives our app a snapy experience. So the user opens the app and immediately sees the results from the local database and the network request happens in the background and as the network request completes we swap the results. So if we want to do it in rxjava, how do we do it.

Concat comes to rescue

The Concat operator concatenates the output of multiple Observables so that they act like a single Observable, with all of the items emitted by the first Observable being emitted before any of the items emitted by the second Observable (and so forth, if there are more than two).

Concat waits to subscribe to each additional Observable that you pass to it until the previous Observable completes.

So we can create two observables observables to load data from :

  1. one will load data from the Database
  2. the other will fetch the data from the server
    fun getArticlesFromDatabase(): Observable<Headlines?> {
           return Observable.defer { Observable.just(dataManager.selectArticles()) }
                   .subscribeOn(Schedulers.computation())
       }

   fun getArticlesFromNetwork(): Observable<Headlines?> {
           return dataManager.getArticles()
                   .subscribeOn(Schedulers.io())
       }

And them concat these observables and observe them :

    Observable.concat(
                   newsViewModel.getArticlesFromDatabase(),
                   newsViewModel.getArticlesFromNetwork()
           )
                   .observeOn(AndroidSchedulers.mainThread(), true)
                   .subscribe(object : Observer<Headlines?> {
                       override fun onComplete() {
                           refresh_layout.isRefreshing = false
                       }

                       override fun onSubscribe(d: Disposable) {
                           refresh_layout.isRefreshing = true
                           compositeDisposable.add(d)
                       }

                       override fun onNext(t: Headlines) {
                           articlesAdapter.addItems(t.articles as MutableList<Article>?)
                       }

                       override fun onError(e: Throwable) {
                           refresh_layout.isRefreshing = false
                           Timber.e(e.message)
                       }
                   })

Study the repository to understand the implementation completely.

License

   Copyright (C) 2018 VIPIN KUMAR

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].