MVVM-Day2

本文介绍了在Android项目中使用懒汉模式和饿汉模式实现单例,以及如何集成Retrofit、OkHttp、Gson等库进行API调用、数据解析和适配器使用,展示了相关依赖管理和组件的配置。
摘要由CSDN通过智能技术生成

复习单例模式:

懒汉模式:

饿汉模式:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值