File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 11# 酷欧天气Jetpack版
22酷欧天气的Jetpack版本实现,采用了MVVM架构。
33
4+ 使用
5+ build.gradle(主项目):maven { url 'https://jitpack.io ' }
6+ build.gradle(app):implementation 'com.github.AranAndroid009:Mvvm:1.0.1'
7+ 网络初始化用:继承 MvvmApplication 然后 ServiceCreator.init("http://guolin.tech/ ")
8+ 数据库使用:assets文件下创建xml
9+ 案例:<litepal >
10+ <dbname value =" passive " />
11+ <version value =" 4 " />
12+ <list >
13+ <mapping class =" com.winspread.passive5g.data.model.UserBean " />
14+ </list >
15+ <storage value =" external " />
16+ </litepal >
17+ mvvm三部曲:
18+ m: class ExampleModel : BaseViewModel()
19+ v:<layout xmlns: android ="http://schemas.android.com/apk/res/android "
20+ xmlns: bind ="http://schemas.android.com/apk/res-auto">
21+ <data >
22+ <import type =" android.view.View " />
23+ <variable name =" viewModel " type =" com.winspread.passive5g.ui.example.ExampleModel " />
24+ </data >
25+ <View
26+ android: layout_width ="match_parent"
27+ android: layout_height ="match_parent">
28+ </View >
29+ </layout >
30+ mv: class ExampleActivity :
31+ BaseActivity<ExampleModel, ActivityExampleBinding>(R.layout.activity_example) {
32+ override fun onCreate(savedInstanceState: Bundle?) {
33+ super.onCreate(savedInstanceState)
34+ // 必填
35+ binding.viewModel = viewModel
36+ binding.lifecycleOwner = this
37+ }
38+ }
39+
40+
441这里我先给出一张酷欧天气Jetpack版的架构设计图,这张图是模仿Google Codelabs的Sunshine项目画出来的。拥有良好架构设计的项目都是可以用简洁清晰的架构图表示出来的,而一个杂乱无章没有架构设计的项目则很难用架构图表示出来。
542
643<img src =" https://raw.githubusercontent.com/guolindev/coolweatherjetpack/master/images/architecture.jpg " width =" 750 " />
You can’t perform that action at this time.
0 commit comments