• Essential Guide For Designing Your Android App Architecture: Designing Your Android App Architecture Part 3 (Dialog, ViewPager, RecyclerView, and Adapters)
  • By Janishar Ali
  • Translation from: The Gold Project
  • This article is permalink: github.com/xitu/gold-m…
  • Translator: woitaylor
  • Proofreader: Hanliuxin5 Leviding

Android MVP Architecture Essentials: Part 3 (Dialog, ViewPager, RecyclerView and Adapters)

I’m pleased that Parts 1 and 2 of the Android MVP Architecture series have been well received since their release. But also because of your suggestions and contributions, the project is better.

During this development process, many people have asked how to use dialogs and Adapter-based views in this architecture. So I’ll add to both in this blog post.

If you haven’t read the first two blogs, I highly recommend reading them before reading this one. Here is a link to the blog:

  • Building Essentials for Android MVP: Part 1
  • Building Essentials for Android MVP: Part 2
  • MindorksOpenSource/android-mvp-architectureWarehouse has a complete implementation of the framework sample code

In this article, I’ll extend the framework by adding a rating dialog and a Feed interface.

Translator: Feed refers to an RSS Feed, an encyclopaedia of feeds, and in the following translation I use Feed or RSS directly.

God is in the details

Let’s take a look at the renderings:

Rating dialog box

  1. The rating dialog box shows 5 stars, and users can choose the number of stars according to their satisfaction.
  2. If the number of stars is less than 5, we will modify the dialog to show a feedback form that asks the user for suggestions for improvement.
  3. If I have five stars. We’ll show a jump to the app store in the dialoggoogle play). Users can make comments there.
  4. The scoring information is sent to the backend server of the application.

Note: The rating dialog is not necessary from the user’s point of view, but it is important for us as developers. Therefore, the application needs to design this execution process very cleverly.

I suggest increasing the spacing between adjacent controls in the dialog box.

Feed interface

  1. This interface is going to have two subinterfaces.
  2. Subinterface 1: BlogRSSList interface.
  3. Subinterface 2: Open source codeRSSList interface.

blogRSSThe child interface

  1. Get data from the server.
  2. Fill with dataRecyclerViewIn theCardView.

The open source projectRSSThe child interface

  1. Get warehouse data from the server.
  2. This warehouse data is used to populateRecyclerViewThe inside of theCardView.

Now that we have identified the business requirements, the next step is to extend the existing architecture based on those requirements.

I’m not going to post the whole code snippet here because it’s too long. Instead, open the MVP project in a new TAB in your browser. Then we’ll switch back and forth between the two tags.

Summary:

Add the following classes

(in the project com. Mindorks. Framework. MVP. The UI. The base package inside view code)

  1. BaseDialog: in this class we addDialogTemplate code, as well as some general methods. For actual projectsDialogThis can be done by extending the base class.
  2. DialogMvpView: This interface is definedPresenterDialogsInteractive APIS.
  3. BaseViewHolder: It definesRecyclerViewBinding framework and implementationViewHolderThe ability to automatically clean up views when reused.
public abstract class BaseDialog extends DialogFragment implements DialogMvpView
Copy the code

One note about the framework.

All related functions should be grouped together in what I call the encapsulation of function points so that they are independent of each other.

Rating dialog box:

  1. This dialog can be opened through the menu list in the left drawer.
  2. Its implementation sumThe second articleFrom the blogMVPThe components are similar.

Open Project Repo in a new TAB in your browser and thoroughly explore the implementation of the scoring dialog section in your project

A little note about dialog boxes

Some applications may use a lot of small dialog boxes, in this case we can create generic MVPView, MVPPresenter and Presenter for these dialog boxes to use.

The Feed part:

  1. It’s included in this packageFeedActivityAnd it’sMVPComponents,FeedPagerAdapter.blogPackages andopensourceThe package.
  2. blogB: It’s in this bagBlogFragmentAnd it’sMVPThe component andRecyclerViewBlogAdapter.
  3. opensourceB: It’s in this bagOpenSourceFragmentAnd it’sMVPThe component andRecyclerViewOpenSourceAdapter.
  4. FragmentStatePagerAdapterUsed to createBlogFragmentOpenSourceFragment.

Never instantiate any object in any Adapter class or use the new operator to generate an object. Fetch them with the dagger injection.

OpenSourceAdapter and BlogAdapter are implementations of recyclerView. Adapter

. In this project, an empty view is displayed when no data is available. The user can click the RETRY button to retrieve the data and delete the empty view when the data is retrieved.

API data paging and network state processing is left to you as an exercise.

Now explore the code through the project, taking a closer look at the layout in the XML and how to manipulate the view through the code.

If you find it difficult or need any help or improvement, please post your question in the Mindorks community: click here to join the Mindorks Android community where we can learn from each other.


Thanks for reading this article, and if you found it helpful, don’t forget to click on ❤ below. This will help more people learn from this article.

If you want to learn more about programming, follow Me and Mindorks on Medium so you can be notified when new articles are published.

Check out all the Mindorks best articles here.

You can also friend me on Twitter, Linkedin, Github, and Facebook.

Coder’s Rock 🙂


Diggings translation project is a community for translating quality Internet technical articles from diggings English sharing articles. The content covers the fields of Android, iOS, front end, back end, blockchain, products, design, artificial intelligence and so on. For more high-quality translations, please keep paying attention to The Translation Project, official weibo and zhihu column.