All Projects → BrianSpace → Android App Architecture Mvvm Databinding

BrianSpace / Android App Architecture Mvvm Databinding

Licence: apache-2.0
A simple but complete project (in both Java & Kotlin) to demonstrate the Android application architecture with MVVM pattern, a client app for The Movie DB Web API. Dagger2 is used for dependency injection and RxJava is used for RFP (Reactive Functional Programming).

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Android App Architecture Mvvm Databinding

Android Mvvm Rxjava2 Dagger2
This repository contains a detailed sample application that uses MVVM as its presentation layer pattern. Essential dependencies are Dagger2 with Dagger-android, RxJava2 with RxAndroid, Room, Retrofit and Espresso.
Stars: ✭ 50 (-27.54%)
Mutual labels:  rxjava2, dagger2, dependency-injection, android-development, room-persistence-library
Android Mvp Mvvm Flytour
🔥🔥🔥 FlyTour是Android MVVM+MVP+Dagger2+Retrofit+RxJava+组件化+插件组成的双编码架构+双工程架构+双语言Android应用开发框架,通过不断的升级迭代该框架已经有了十个不同的版本,5.0之前工程架构采用gradle配置实现组件化,5.0之后的工程架构采用VirtualAPK实现了插件化,5.0之前采用Java编码实现,5.0之后采用Kotlin编码实现,编码架构由MVVM和MVP组成,工程架构和编码架构及编码语言开发者可根据自己具体的项目实际需求去决定选择使用,该框架是Android组件化、Android插件化、Android MVP架构、Android MVVM架构的集大成者,帮助你快速的搭建自己的App项目开发框架,以便把主要的精…
Stars: ✭ 2,948 (+4172.46%)
Mutual labels:  rxjava2, dagger2, mvvm, databinding
Instant Weather
An Android weather application implemented using the MVVM pattern, Retrofit2, Dagger2, LiveData, ViewModel, Coroutines, Room, Navigation Components, Data Binding and some other libraries from the Android Jetpack.
Stars: ✭ 473 (+585.51%)
Mutual labels:  dagger2, dependency-injection, databinding, room-persistence-library
Mvvmarms
Android MVVM Architecture Components based on MVPArms and Android Architecture Components.
Stars: ✭ 425 (+515.94%)
Mutual labels:  rxjava2, dagger2, mvvm, databinding
Paonet
【MVVM+RxJava2+AspectJ】泡网第三方客户端,网站主页:http://www.jcodecraeer.com/index.php
Stars: ✭ 374 (+442.03%)
Mutual labels:  rxjava2, mvvm, databinding, room-persistence-library
Weather-Guru-MVP
Sample Material-design Android weather application build with MVP architectural approach using Dagger2, RxJava2, Retrofit2, Event-Bus, GreenDao, Butterknife, Lottie etc.
Stars: ✭ 15 (-78.26%)
Mutual labels:  android-development, mockito, dagger2, rxjava2
BESTV
Android TV App powered by TMDb. It is a easy way to find the best TV content, the top movies, series... all of that in your TV.
Stars: ✭ 49 (-28.99%)
Mutual labels:  dependency-injection, mockito, dagger2, rxjava2
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 (-73.91%)
Mutual labels:  rxjava2, dagger2, mvvm, room-persistence-library
Wanandroid
🏄 基于Architecture Components dependencies (Lifecycles,LiveData,ViewModel,Room)构建的WanAndroid开源项目。 你值得拥有的MVVM快速开发框架:https://github.com/jenly1314/MVVMFrame
Stars: ✭ 410 (+494.2%)
Mutual labels:  dagger2, mvvm, databinding
Theatre
Pet project using Clean Architecture + MVVM + Reactive Extensions + Android Architecture Components. The data are fetched from LondonTheatreDirect API. 🎭
Stars: ✭ 577 (+736.23%)
Mutual labels:  rxjava2, dagger2, mvvm
Exchange Rates Mvvm
Sample Android project which incorporates MVVM, databinding, RxJava2, Dagger2 and Clean Architecture approach.
Stars: ✭ 43 (-37.68%)
Mutual labels:  rxjava2, mvvm, databinding
Mvvmsmart
基于谷歌最新AAC架构,MVVM设计模式的一套快速开发库,整合ViewModel+Lifecycles+Navigation+DataBinding+LiveData+Okhttp+Retrofit+RxJava+Glide等主流模块,满足日常开发需求。使用该框架可以快速开发高质量、易维护的Android应用。 项目组会持续维护,请放心使用.欢迎Start并Fork交流.
Stars: ✭ 382 (+453.62%)
Mutual labels:  rxjava2, mvvm, databinding
Applocker
🔐 Open source app locker, vault, call blocker application
Stars: ✭ 321 (+365.22%)
Mutual labels:  rxjava2, dagger2, mvvm
Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+9739.13%)
Mutual labels:  rxjava2, mvvm, databinding
Kotlin Android Scaffolding
An android project structure using kotlin and most common libraries.
Stars: ✭ 53 (-23.19%)
Mutual labels:  rxjava2, dagger2, android-development
Marvelheroes
❤️ A sample Marvel heroes application based on MVVM (ViewModel, Coroutines, LiveData, Room, Repository, Koin) architecture.
Stars: ✭ 826 (+1097.1%)
Mutual labels:  mvvm, dependency-injection, databinding
Blockchain Tracker
A blockchain market tracking app. Example implementation of reactive clean architecture and testing.
Stars: ✭ 30 (-56.52%)
Mutual labels:  dagger2, mvvm, databinding
Kodein Mvvm
Example app using Kodein for dependency injection with MVVM and Architecture Components
Stars: ✭ 26 (-62.32%)
Mutual labels:  mvvm, dependency-injection, databinding
Tdcapp
Sample app which access the TDC (The Developer's Conference) REST API.
Stars: ✭ 55 (-20.29%)
Mutual labels:  rxjava2, mvvm, mockito
Tvflix
TvFlix android app using Dagger Hilt, Coroutines, Flow, KTX, Jetpack(Room, ViewModel, Paging3, Lifecycle) based on MVVM architecture purely written in Kotlin
Stars: ✭ 286 (+314.49%)
Mutual labels:  dagger2, mockito, databinding

Android App Architecture Demo - MVVM with databinding (Java version) [Kotlin version] [中文版]

This is a sample project to demonstrate the Android application architecture with MVVM pattern, a simple client for The Movie DB web API.

Note: you will need an API key if you would like to run the application, see Get started.

Table of Contents

Why MVVM?

For client application development, MVVM is better than other MV* patterns like MVC or MVP.

Why? Because a view model, as the extra abstraction of the view's data and behavior, has a higher abstraction level than other MV* patterns. Furthermore, view models are totally decoupled from views through databinding. The higher abstraction level and more complete decoupling lead to a cleaner architecture.

Any benefit comes with a cost, the abstraction and separation are not free. For projects that are complex enough, these initial cost will pay off soon. But for simple applications, it may be overkill.

For this demo project, using MVVM seems a little bit over engineering. But my purpose here is to demonstrate with a working example that is not too simple, and dealing with real problems in a real project. Furthermore, for a project whose goal is a full featured application like the client for "The Movie DB", this will be a good start.

Screenshots

Now Playing Page Movie Details Page Favorites

Application Introduction

The application has the following features:

  • The main page has three tabs: Now Playing, Favorite and Settings.
  • The Now Playing tab displays the movies now playing.
    • Each movie is shown as a poster picture in the grid, with rating stars and favorite state icon on top of it.
    • You can pull down the list to refresh and pull up at the end to load the next page.
  • The Favorite tab shows the local favorite list and has the same functionality as the Now Playing tab.
  • Clicking on the movie poster will navigate to the movie details page, in which additional details like backdrop image, tagline and similar movies will be shown.
    • The float action button in the page shows a progress circle animation while loading and the favorite state icons will show after loading. You can click the favorite icon to add to or remove from local favorite movie list.
    • You can pull up the similar movies list to load the next page.
  • In settings page, you can clear the cached HTTP responses, images, as well as local favorites.

Application Architecture

Architecture Layers

  • Dependency
    • Unidirectional dependency from top-down. Lower layers communicate with upper layers through various notification means:
      • View Models notify UI through databinding.
      • Models notify View Models through observable notification events.
      • Repository layer just returns values through RxJava event sources to Models.
    • Dependencies are injected by the DI (dependency injection) framework. View Models layer and Models layer components are all unit testable.
  • View models layer should have no dependency on UI components, and depend on Android as less as possible. (Current dependencies are the Android databinding framework, AndroidSchedulers from RxAndroid, and SparseArray.)
  • Models layer is the domain model for the application and should be UI and platform independent, i.e. depend on neither the interaction/UI design nor the Android platform. (Currently it depends on SparseArray just for performance reason, and can be replaced if needed.)
  • Repository layer is the abstraction for data access to local storage (Shared Preferences, SQLite databases) and external Web APIs.

Major Components

Most of the classe names are obvious. For those not so obvious:

Design decisions for the application

  1. Model-View-ViewModel (MVVM) architecture: which takes advantage of the native Android data-binding support.
  2. Decouple with Dependency Injection: using Dagger-2.
  3. Asynchrony: I/O operations should run in background with RxJava+RxAndroid.
  4. Activity navigation: URI based, decouple the activities. Implemented in NavigationHelper.
  5. Object Lifecycle
    • Entities in model layer are saved in the EntityStore (as WeakReferences to prevent memory leaks) which ensures the uniqueness (one object instance for each movie) so that different views of the same entity can be kept in sync through change notifications.
    • View models have the same lifetime as the corresponding views. They have one to one mapping to the views displayed. Otherwise the different lifetime will be very confusing and cause more problems than benefits (believe me, I tried that in the beginning).

Module/Directory Structure (Development View)

As the development view of the application architecture, it is an essential part to have a clear separation into modules and directory structure (packages in Java).

  • Modules division
    • app: main application module.
    • lib-common: common functionality
    • lib-databinding: databinding support
    • lib-widgets: reusable UI widgets
  • Directory structure in App module
    • di: dependency injection
      • components: Component and Subcomponent for Dagger.
      • modules: Module for Dagger.
      • qualifiers: qualification specifiers for dependency injection.
    • models: Model layer classes.
    • repository: data access layer
      • data: value objects used for JSON deserialization.
      • local: local storage, including SharedPreferences and SQLite databases.
      • util: utility classes.
      • web: to access Web API of TMDb.
    • ui: UI layer classes.
      • activity: Activities in the application.
      • databinding: BindingAdapters for databinding.
      • fragment: Fragments in the application.
      • nav: utility class NavigationHelper.
      • view: application related UI controls.
    • viewmodels: View Model layer classes.
  • Directory structure in Common module
    • objstore: object store
    • observable: observable pattern implementation for objects and collections.
    • util: utility classes.
  • Directory structure in Databinding module
    • adapter: list adapter for RecyclerView, supporting binding to ObservableList.
    • message: display notifications through databinding, so that view model can show notifications (Toast for now) without depending on UI controls.
  • Directory structure in Widgets module
    • behaviors: behaviors for CoordinatorLayout.
    • utils: utility classes. ImageLoader for now.
    • widgets: project independent, reusable UI controls.

Get started

Clone the project with submodules

Since the project has a submodule, you need to clone with --recurse-submodules parameter, or run git submodule update --init --recursive later to clone also the submodules.

Prepare TMDb API key

Before you can run the application, you need to register a developer account following the TMDb introductions and get the API key. Then add the API key in the project's gradle.properties file:

# API Key for the TMDb API
API_KEY="xxxxx"

Reference: https://developers.themoviedb.org/3/getting-started/authentication

Reusable Components

Project independent reusable components are developed in separate modules.

Common

  • Observables: enable obsever registrations (with weak references) and event notifications.
  • ObjectStore and ModelObjectStore: thread-safe object store which ensures that only one object will be associated with one key.

Data Binding

UI Layer

  • DynamicGridView: RecyclerView based Grid view that can automatically adjust number of columns based on available width and specified cell width. Gaps between cells are carefully caculated so that they are spanned evenly, while the header can occupy the full width.
  • FixedAspectRatioImage: AppCompatImageView with fixed aspect ratio (set through an attribut).
  • ImageLoader: load image with Glide. Can load image after the ImageView is measured.
  • AutoHideWhenScrollDownBehavior: A CoordinatorLayout behavior for the target view (e.g. BottomNavigationView) to auto hide when scroll down.

External Libraries/Frameworks/Widgets

The usage of the following well know libraries/frameworks/widgets are demonstrated in this project:

Code Quality

In order to ensure the code quality, the following project is use (as a submodule) in this application:

Notes

The signing configs comes from the project's gradle.properties file. You should add the following if you would like to sign the APK with your own key:

# signingConfigs for release build
RELEASE_STORE_FILE=xxx.xxx
RELEASE_STORE_PASSWORD=xxx
RELEASE_KEY_ALIAS=xxx
RELEASE_KEY_PASSWORD=xxx

License

Copyright (C) 2018, Brian He

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].