old王讲课的第二天

本文介绍了如何在Android项目中运用饿汉模式和懒汉模式的单例设计,以及使用Retrofit进行API调用、Gson进行数据解析、RxJava处理异步操作,同时涉及到OkHttp的日志拦截器和生命周期管理工具如RxLifecycle。
摘要由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=trueviewBinding {    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​

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值