复习单例模式:
懒汉模式:
饿汉模式:
1.Entity包内创建实体类FoodEntity
2.在Http包中创建Api接口(Observable被观察者):
3.创建RetrifitManager类
OkHttpClient书写日志拦截器:
4.Model包中创建FoodModel类:
5.在ViewModel包中创建FoodViewModel(要创建一个布局):
6.在Adapter包中创建适配器:
7.在View包中创建Activity:
用到的依赖:
maven { url 'https://jitpack.io' } maven { url "https://maven.aliyun.com/repository/public" } android.enableJetifier=true viewBinding { enabled = true } dataBinding { enabled = true }
implementation 'com.google.code.gson:gson:2.8.0'//gson依赖 //RxJava依赖:主要用于消息传递 implementation 'io.reactivex.rxjava2:rxjava:2.2.8' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' //Retrofit依赖 implementation 'com.squareup.retrofit2:retrofit:2.4.0' //Gson converter gson解析 implementation 'com.squareup.retrofit2:converter-gson:2.4.0' //RxJava2 Adapter implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0" //okhttp implementation 'com.squareup.okhttp3:okhttp:3.4.1' implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1' //rxlifecycle异步线程生命周期管理 implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1' //rxpermissions implementation 'com.github.tbruyelle:rxpermissions:0.10.2' implementation 'com.github.bumptech.glide:glide:4.11.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.0'//万能适配器 implementation 'com.android.support:recyclerview-v7:30.0.0'//recyclerview