Coder Social home page Coder Social logo

todo's Introduction

本分支是 fork 自 googlesamples 的 android-architecture,主要用以与其他分支做对比。

todo-mvp

This version of the app is called todo-mvp, and provides a foundation for other samples in this project. The sample aims to:

  • Provide a basic Model-View-Presenter (MVP) architecture without using any architectural frameworks.
  • Act as a reference point for comparing and contrasting the other samples in this project.

Note: This project uses the following naming convention, across all repository branches, to distinguish between View classes and MVP views:

  • "Android View" refers to the android.view.View class.
  • The view that receives commands from a presenter in MVP, is referred to as "view".

What you need

Before exploring this sample, you might find it useful to familiarize yourself with the following topics:

  • The MVP architecture

The todo-mvp sample uses the following dependencies:

  • Common Android support libraries - Packages in the com.android.support.* namespace provide backwards compatibility and other features.
  • Android Testing Support Library - A framework used to support UI tests, using both Espresso, and AndroidJUnitRunner.
  • Mockito - A mocking framework used to implement unit tests.
  • Guava - A set of core libraries for Java by Google, commonly used in Android apps.

Designing the app

All versions of the Android Blueprints app include the same common features in a simple to-do type app. The app consists of four UI screens:

  • Tasks - Used to manage a list of tasks.
  • TaskDetail - Used to read or delete a task.
  • AddEditTask - Used to create or edit tasks.
  • Statistics - Displays statistics related to tasks.

In this version of the app, as well as other versions based on it, each screen is implemented using the following classes and interfaces:

  • A contract class which defines the connection between the view and the presenter.
  • An Activity which creates fragments and presenters.
  • A Fragment which implements the view interface.
  • A presenter which implements the presenter interface in the corresponding contract.

A presenter typically hosts business logic associated with a particular feature, and the corresponding view handles the Android UI work. The view contains almost no logic; it converts the presenter's commands to UI actions, and listens for user actions, which are then passed to the presenter.

Implementing the app

Each version of the app implements the same features using a different approach to showcase and contrast a variety of architectural designs. For example, this version takes the following approaches to solving common implementation questions:

  • This sample uses product flavors to replace modules at compile time, providing fake data for both manual and automated testing.
  • This version uses callbacks to handle asynchronous tasks.

Notice also in the following illustration that this version of the app uses fragments, and this is for two reasons:

  • The use of both activities and fragments allows for a better separation of concerns which compliments this implementation of MVP. In this version of the app, the Activity is the overall controller which creates and connects views and presenters.
  • The use of fragments supports tablet layouts or UI screens with multiple views.

Illustration of the MVP architechture for this version of the app.

This version of the app includes a number of unit tests which cover presenters, repositories, and data sources. The sample also includes UI tests, that rely on fake data, and are faciliated by dependency injection to provide fake modules. For more information on using dependency injection to faciliate testing, see Leveraging product flavors in Android Studio for hermetic testing.

Maintaining the app

This sample includes classes and interfaces, such as presenters and contracts, that increase the number of lines of code compared to more traditional projects that do not make use of a particular architecture.

The table below summarizes the amount of code used to implement this version of the app. You can use it as a basis for comparison with similar tables provided for each of the other samples in this project.

Language Number of files Blank lines Comment lines Lines of code
Java 46 1075 1451 3451
XML 34 97 337 601
Total 80 1172 1788 4052

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.