- 1.项目简介
- 2.开发环境概述
- 3.项目架构
- 4.项目目录结构
- 5.项目包结构
- 6.如何运行
- 6.1.可选配置
- 7.依赖框架
- 8.项目效果
- 主界面/歌单详情/播放界面
- API接口数据规范
- 9.详情API响应格式
- 列表API响应格式
- 加密API响应格式
1.项目简介
这是一门使用Java语言,从0开发一个Android平台,接近企业级的项目(我的云音乐),课程包含了基础内容,高级内容,项目封装,项目重构等知识;因为这是项目课程;所以不会深入到源码讲解某个知识点,以及原理,但会粗略的讲解下基础原理;主要是讲解如何使用系统功能,流行的第三方框架,第三方服务,完成接近企业级商业级项目,目的是让大家,学到真正的企业级项目开发技术。
2.开发环境概述2022年5月开发完成的,所以全部都是最新的,平均每3年会重新制作,现在已经是第三版了。
JDK17 Android 12/13 最低兼容版本:Android 6.0 Android Studio 2021.13.项目架构
大部分模块采用MVC,商城列表和商城详情采用MVVM,Jetpack官方组件。
4.项目目录结构├── MyCloudMusicAndroidJava │ ├── LRecyclerview //第三方Recyclerview框架 │ ├── LetterIndexView //类似微信通讯录字母索引 │ ├── app //云音乐项目 │ ├── build.gradle │ ├── common.gradle //通用项目配置文件 │ ├── config //配置目录,例如签名 │ ├── glidepalette //Glide画板,用来从网络图片提取颜色 │ ├── gradle │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ ├── keystore.properties │ ├── local.properties │ ├── settings.gradle │ ├── super-j //公用Java语言扩展 │ ├── super-player-tencent //腾讯开源的超级播放器 │ ├── super-speech-baidu //百度语音识别5.项目包结构
├── courses │ └── mymusic //主项目包 │ ├── AppContext.java │ ├── MainActivity.java │ ├── activity //通用界面 │ ├── adapter //通用适配器 │ ├── component //模块 │ │ ├── about //关于 │ │ ├── ad //广告 │ │ ├── ... │ ├── config //配置目录 │ ├── exception //通用自定义异常 │ ├── fragment │ ├── manager │ ├── model │ ├── repository //数据仓库 │ ├── service //服务 │ ├── util //常用工具类 │ ├── view //自定义View ├── selector //选择器 └── superui //通用UI框架6.如何运行
用最新AS打开MyCloudMusicAndroidJava目录,然后等待完全编译成功,因为是企业级项目,所以第三方依赖很多,同时代码量也很多,所以必须要确认完全编译成功,才能运行。
6.1.可选配置如果也有配套服务端源码,可以在Config.java中修改服务器API地址,资源地址;其他的第三方信息,QQ登陆,微信登陆/支付,支付宝支付,阿里云OSS等信息也可以修改为自己的。
7.依赖框架内容太多,只列出部分。
//分页组件版本 //这里可以查看最新版本:https://developer.android.google.cn/jetpack/androidx/releases/paging def paging_version = "3.1.1" //添加所有libs目录里面的jar,aar implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) //官方兼容组件,像AppCompatActivity就是该依赖里面的 implementation 'androidx.appcompat:appcompat:1.4.1' //Material Design组件,像FloatingActionButton就是该依赖里面的 implementation 'com.google.android.material:material:1.4.0' //官方提供的约束布局,像ConstraintLayout就是该依赖里面的 implementation 'androidx.constraintlayout:constraintlayout:2.1.0' //UI框架,主要是用他的工具类,也可以单独拷贝出来 //https://qmuiteam.com/android/get-started implementation 'com.qmuiteam:qmui:2.0.1' //动态处理权限 //https://github.com/permissions-dispatcher/PermissionsDispatcher implementation "com.github.permissions-dispatcher:permissionsdispatcher:4.8.0" annotationProcessor "com.github.permissions-dispatcher:permissionsdispatcher-processor:4.8.0" //api:依赖会传递到其他应用本模块的项目 implementation project(path: ':super-j') ... //使用gson解析json //https://github.com/google/gson implementation 'com.google.code.gson:gson:2.9.0' //适配retrofit使用gson解析 //版本要和retrofit一样 implementation 'com.squareup.retrofit2:converter-gson:2.9.0' //适配retrofit支持rxjava implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0' //使用了Android响应式编程 //RxJava和RxAndroid区别? //简单来说:就是RxAndroid在RxJava的基础上 //优化了一些功能 //增强了Android特有的功能 //https://github.com/ReactiveX/RxAndroid implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' //endregion //apache common lang3工具包 //提供了StringUtils等这样的类 //http://commons.apache.org/proper/commons-lang/ implementation 'org.apache.commons:commons-lang3:3.8' //集合工具类 // https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 implementation 'org.apache.commons:commons-collections4:+' //通用IO相关工具类 //http://commons.apache.org/proper/commons-io/ implementation 'commons-io:commons-io:2.0' //通过OkHttp的拦截器机制 //实现在应用通知栏显示网络请求功能 //https://github.com/ChuckerTeam/chucker debugImplementation "com.github.chuckerteam.chucker:library:3.5.2" releaseImplementation "com.github.chuckerteam.chucker:library-no-op:3.5.2" //类似TabLayout的控件 //https://github.com/H07000223/FlycoTabLayout implementation 'io.github.h07000223:flycoTabLayout:3.0.0' //封装了RecyclerView //提供更高层次的接口 //https://github.com/CymChad/BaseRecyclerViewAdapterHelper implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:+' //自动释放RxJava相关资源 //https://github.com/uber/AutoDispose implementation "com.uber.autodispose2:autodispose-androidx-lifecycle:2.1.1" //banner轮播图框架 //https://github.com/youth5201314/banner implementation 'io.github.youth5201314:banner:2.2.2' //图片加载框架,还引用他目的是,coil有些功能不好实现 //https://github.com/bumptech/glide implementation 'com.github.bumptech.glide:glide:+' annotationProcessor 'com.github.bumptech.glide:compiler:+' implementation 'androidx.recyclerview:recyclerview:1.2.1' //给控件添加未读消息数红点 //https://github.com/bingoogolapple/BGABadgeView-Android implementation 'com.github.bingoogolapple.BGABadgeView-Android:api:1.2.0' annotationProcessor 'com.github.bingoogolapple.BGABadgeView-Android:compiler:1.2.0' //webview进度条 //https://github.com/youlookwhat/WebProgress implementation 'com.github.youlookwhat:WebProgress:1.2.0' //日志框架 //https://github.com/JakeWharton/timber implementation 'com.jakewharton.timber:timber:5.0.1' //跨界面通信框架 //https://github.com/greenrobot/EventBus implementation 'org.greenrobot:eventbus:3.3.1' //输入框右侧有清空按钮,类似iOS //https://github.com/Cielsk/clearable-edittext implementation 'com.github.Cielsk:clearable-edittext:0.0.8' //类似滴滴出行验证码输入框控件 //https://github.com/jenly1314/SplitEditText // implementation 'com.king.view:splitedittext:+' //给任意控件添加闪光效果 //这里主要用到广告界面,打开广告按钮 //https://github.com/facebook/shimmer-android implementation 'com.facebook.shimmer:shimmer:0.5.0' //腾讯官方播放器,可以播放其他地址视频,不是说一定要播放腾讯点播服务的视频 //com.tencent.liteav:LiteAVSDK_Player:播放器核心 //super-player-tencent:更上层的接口和功能,例如:弹幕,滑动进度,滑动调整音量 //https://cloud.tencent.com/document/product/881/20213 implementation project(path: ':super-player-tencent') //更方便的使用glide和palette //https://github.com/florent37/GlidePalette // implementation 'com.github.florent37:glidepalette:+' implementation project(path: ':glidepalette') implementation "androidx.media:media:+" //和Glide配合处理图片 //可以实现很多效果 //模糊;圆角;圆 //我们这里是用它实现模糊效果 //https://github.com/wasabeef/glide-transformations implementation 'jp.wasabeef:glide-transformations:+' //圆形图片控件 //https://github.com/hdodenhof/CircleImageView implementation 'de.hdodenhof:circleimageview:+' //下载框架 //https://github.com/ixuea/android-downloader implementation 'com.ixuea:android-downloader:3.0.0' //更方便的日期时间,运算,解析格式化框架 //https://www.joda.org/joda-time/index.html implementation 'joda-time:joda-time:+' //emoji支持库,Android官方提供的Emoji兼容库,用来兼容低版本,高版本不需要使用该兼容库也可以 //官方提供的Eemoji组件是基于Unicode,也就是字体,所以在不同系统版本,以及不同平台显示的样式可能不一样 //如果要想实现类似微信,QQ,钉钉等主流软件的Emoji实现可以学习我们【商业级微聊项目】课程(http://www.ixuea.com/courses/19) //其实就是使用图片实现emoji,就是图文混排效果,类似商品详情描述那样实现 implementation 'androidx.emoji:emoji-appcompat:+' //emoji控件 implementation 'androidx.emoji:emoji-bundled:+' //region 下拉刷新,上来加载更多 //下拉刷新框架 //https://github.com/scwang90/SmartRefreshLayout implementation 'io.github.scwang90:refresh-layout-kernel:2.0.5' implementation 'io.github.scwang90:refresh-header-classics:2.0.5' //经典刷新头 implementation 'io.github.scwang90:refresh-footer-classics:2.0.5' //经典加载头 //endregion //视频播放框架 //https://github.com/CarGuo/GSYVideoPlayer //完整版引入 implementation 'com.github.CarGuo.GSYVideoPlayer:GSYVideoPlayer:v8.2.0-release-jitpack' //对Recyclerview进行了,使用更方便 //https://github.com/jdsjlzx/LRecyclerView implementation project(path: ':LRecyclerview') //官方设置组件 implementation 'androidx.preference:preference:1.1.1' //类似微信图片预览框架 //https://github.com/wanglu1209/PhotoViewer implementation 'com.github.wanglu1209:PhotoViewer:0.50' //Google实现的Java核心工具类 //相对于Apache的工具包来说 //Apache更多的用在Java Web项目 //而Guava在Android中用的更多 //具体的性能这里就不比较了 //大家感兴趣可以搜索下 //https://github.com/google/guava implementation 'com.google.guava:guava:31.1-android' //图片选择 //https://github.com/LuckSiege/PictureSelector implementation 'io.github.lucksiege:pictureselector:v3.0.9' implementation 'io.github.lucksiege:compress:v3.0.9' implementation 'io.github.lucksiege:ucrop:v3.0.9' //阿里云oss //官方文档:https://help.aliyun.com/document_detail/32043.html //sdk地址:https://github.com/aliyun/aliyun-oss-android-sdk implementation 'com.aliyun.dpa:oss-android-sdk:+' //高德地图,这里引用的是3d //https://lbs.amap.com/api/android-sdk/guide/create-project/android-studio-create-project#gradle_sdk implementation 'com.amap.api:3dmap:+' //定位功能 implementation 'com.amap.api:location:+' //搜索 implementation 'com.amap.api:search:latest.integration' //RecyclerView 下拉刷新/加载更多、item点击/长按、头布局/尾布局/状态布局、万能分割线、Skeleton骨架图、极简adapter、嵌套滑动置顶 //使用该框架需要使用它提供的ByRecyclerView控件,所以依赖性比较强,但很多功能直接集成了,也更方便 //https://github.com/youlookwhat/ByRecyclerView //骨架实现内部引用了:https://github.com/team-supercharge/ShimmerLayout //对于普通view,可以按照该框架主页介绍的使用,在用户详情顶部就是用这种方式实现 implementation 'com.github.youlookwhat:ByRecyclerView:1.3.1' //中文转拼音 //https://github.com/belerweb/pinyin4j implementation 'com.belerweb:pinyin4j:+' //类似微信联系人界面右侧字母索引 //https://github.com/lgdcoder/LetterIndexView implementation project(path: ':LetterIndexView') //二维码生成扫描框架 //https://github.com/jenly1314/ZXingLite implementation 'com.github.jenly1314:ZXingLite:2.1.1' //可以嵌套的RadioGroup //https://github.com/fodroid/XRadioGroup implementation 'com.github.fodroid:XRadioGroup:1.5' //https://developer.android.google.cn/training/dependency-injection/hilt-android implementation "com.google.dagger:hilt-android:2.38.1" annotationProcessor "com.google.dagger:hilt-compiler:2.38.1" //Jetpack中的分页组件 //https://developer.android.google.cn/topic/libraries/architecture/paging/v3-overview implementation "androidx.paging:paging-runtime-ktx:$paging_version" //Paging RxJava3支持,因为我们项目用的Java,所以无法使用Kotlin,所以就用RxJava implementation "androidx.paging:paging-rxjava3:$paging_version" //指示器 //https://github.com/hackware1993/MagicIndicator implementation 'com.github.hackware1993:MagicIndicator:1.7.0' //百度语音相关技术,目前主要用在收货地址编辑界面,语音输入收货地址 //https://ai.baidu.com/ai-doc/SPEECH/Pkgt4wwdx#%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97 implementation project(path: ':super-speech-baidu') //TextView显示富文本,目前主要用在商品详情界面,显示富文本商品描述 //https://github.com/wangchenyan/html-text implementation 'com.github.wangchenyan:html-text:+' //Hutool是一个小而全的Java工具类库 // 通过静态方法封装,降低相关API的学习成本 // 提高工作效率,使Java拥有函数式语言般的优雅 //https://github.com/looly/hutool implementation 'cn.hutool:hutool-all:5.7.14' //支付宝支付 //https://opendocs.alipay.com/open/204/105296 implementation 'com.alipay.sdk:alipaysdk-android:+@aar' //融云IM //https://docs.rongcloud.cn/v4/5X/views/im/ui/guide/quick/include/android.html implementation 'cn.rongcloud.sdk:im_lib:+' //微信支付 //官方sdk下载文档:https://developers.weixin.qq.com/doc/oplatform/Downloads/Android_Resource.html //官方集成文档:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5 implementation 'com.tencent.mm.opensdk:wechat-sdk-android:+' //腾讯bugly //https://bugly.qq.com/docs/user-guide/instruction-manual-android/?v=1.0.0#_3 //implementation 'com.tencent.bugly:crashreport:latest.release' implementation 'com.tencent.bugly:crashreport_upgrade:latest.release' implementation 'com.tencent.bugly:nativecrashreport:latest.release' //内存泄漏检测工具 //https://github.com/square/leakcanary //只有调试模式下才添加该依赖 debugImplementation 'com.squareup.leakcanary:leakcanary-android:+' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'8.项目效果
启动界面,广告界面,引导界面等就不再贴图了。
主界面/歌单详情/播放界面主界面是在原版项目上精简实现的,但并不简单,顶部是Banner轮播图,可以放活动,广告等信息,点击可以打开网页,打开应用内页面,第三方应用;接下来是可以左右滚动到按钮,采用水平ScrollView实现;然后就是九宫格歌单,点击进入歌单详情;然后是单曲,点击直接进入黑胶唱片播放界面;最后是底部布局,主要用来提供一些快捷功能。
API接口数据规范服务端采用Java Spring Boot框架。
9.详情API响应格式例如:用户详情,歌单详情。
{
"data": { //真实数据
"id": "152149019135997129",
"created_at": "2022-05-03T14:01:44.000Z",
"updated_at": "2022-05-08T15:42:22.000Z",
"nickname": "ixuea82",
"icon": "42238b32f7e44820acf50d2a18942084dev.jpg",
"gender": 0,
"email": "3469271680@qq.com",
"phone": "3469271680"
},
"status": 0, //正常为0,其他值表示具体的错误信息
"message": null //错误信息,正常不会有改字段
}
列表API响应格式
例如:用户列表,歌单列表;所有列表接口都是如下分页格式:
{
"data": {
"total": 37, //总数量
"pages": 4, //分多少页
"size": 10, //每页多少条
"page": 1, //当前页数
"next": 2, //下一页
"data": [ //真实数据,是一个列表
{
"id": "1521490191359971329",
"created_at": "2022-05-03T14:01:44.000Z",
"updated_at": "2022-05-08T15:42:22.000Z",
"nickname": "爱学啊",
"icon": "42238b32f7e44820acf50d2a18942084dev.jpg",
"gender": 0,
"email": "3469271680@qq.com",
"phone": "3469271680",
"followings_count": 1,
"followers_count": 2
}
]
},
"status": 0
}
加密API响应格式
{
"data": "这是加密数据",
...
}



