Cc-based Android MVVM componentization implementation

MVVM

There are many articles on the web that introduce MVVM, which I will not elaborate on here

componentization

Componentized solutions are commonly used

1. CC
  • wiki
  • CC framework practice (1) : Implement the function of entering the target interface after successful login
  • CC framework practice (2) : Componentization of Fragments and Views
  • CC Framework Practice (3): Make jsBridge more elegant
2. Get DDComponentForAndroid
  • Android thorough componentization scheme practice
  • Discussion on Android componentization
  • Principle explanation article Android thorough componentization scheme practice
  • Android fully componentized Demo is released
3. ModularizationArchitecture
  • Android Architecture Thinking (modular, multi-process)
  • ModularizationArchitecture tutorial
4. Ali Arouter
  • Open source best practice: Arouter, the page routing framework for the Android platform
5. Componentization scheme of Jumei
  • The practice of jumei componentization
  • Router: a single, componentized, plug-in fully supported routing framework
6. ActivityRouter
  • ActivityRouter Routing framework: Annotates the URL to open an Activity
  • Start the Activity from the URL

These are some common componentization solutions, and some related articles

A comparison of the use of the six componentization schemes: github.com/luckybilly/…

Finally, the CC framework is used for componentized development

No picture, no truth

So let’s start coding

Create a host project

This step is the same as normal project creation,

File-> New-> NewProject Modifies the build.gradle File

ext.mainApp = true/ / set totrueApply from: rootproject.file ('mufeng-cc-settings.gradle')

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion rootProject.compileVersion
    defaultConfig {
        applicationId "com.mufeng.mufengdiary"
        minSdkVersion rootProject.minVersion
        targetSdkVersion rootProject.compileVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding {
        enabled = true}}Copy the code

Create the base library component

In the project it is packaged based on the MVVM design pattern + Databinding + Kotlin and some common base libraries

C. Introduce CC componentization to create Module template

This step is optional. This template is modified according to the project template created by AndroidStudio. It can quickly build CC componentized Module components

Template download address: click me to download

How to use this template:

  1. Download this template file
  2. Unzip the files into the directory \android-studio\plugins\android\lib\templates\gradle-projects
  3. Restart AndroidStudio

Note: students can also modify this template by themselves, after modification, must restart to take effect

Good! The template plug-in is successfully installed

Create the Module template from the component template

Directly above

Once the component is created, you need to do the following

  1. Add a component to start the Activity
  2. Add a Component that implements the IComponent interface and implements two methods for the use of CC
  3. Add it in the build.gradle file of the host component
dependencies {
    addComponent 'login'
}
Copy the code

This has achieved simple componentized development

Source code address: github.com/hanlin19900…

Technical knowledge used in the project

  • MVVM
  • Databinding
  • kotlin
  • CC component solution
  • AndroidX
  • RxJava buckets
  • RxBinding
  • Rxpermissions
  • ViewModel
  • LiveData
  • AndroidAutoSize(Screen Adaptation solution)
  • Autodispose
  • BottomBarLayout
  • Xpopup
  • RecyclerView-Adapter

Thank you

  • Github.com/luckybilly/…
  • Mvvm-rhine: Github client for MVVM+Jetpack
  • goldze / MVVMHabit