Android OkHttp Retrofit RxJava Glide仿網易雲音樂

簡介

這是一個使用Java(以後還會推出Kotlin版本)語言,從0開發一個Android平臺,接近企業級的項目(我的雲音樂),包含了基礎內容,高級內容,項目封裝,項目重構等知識;主要是使用系統功能,流行的第三方框架,第三方服務,完成接近企業級商業級項目,目的是讓大家,學到真正的企業級項目開發技術。

功能點

隱私協議對話框
啓動界面和動態處理權限
引導界面和廣告
輪播圖和側滑菜單
首頁複雜列表和列表排序
音樂播放和音樂列表管理
全局音樂控制條
桌面歌詞和自定義樣式
全局媒體控制中心
評論和回覆評論
評論富文本點擊
評論提醒人和話題
朋友圈動態列表和發佈
高德地圖定位和路徑規劃
阿里雲OSS上傳
視頻播放和控制
自動和手動檢查更新
內存泄漏和優化
...

開發環境概述

2022年5月開發完成的,所以全部都是最新的,平均每3年會重新制作,現在已經是第三版了。

JDK17
Android 12/13
最低兼容版本:Android 6.0
Android Studio 2021.1

編譯和運行

用最新AS打開MyCloudMusicAndroidJava目錄,然後等待完全編譯成功,因爲是企業級項目,所以第三方依賴很多,同時代碼量也很多,所以必須要確認完全編譯成功,才能運行。

項目目錄結構

├── 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 //百度語音識別

依賴框架

內容太多,只列出部分。

//分頁組件版本
//這裏可以查看最新版本: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'

//自動釋放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'

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'

//阿里雲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:+'

//百度語音相關技術,目前主要用在收貨地址編輯界面,語音輸入收貨地址
//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:+'

//內存泄漏檢測工具
//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'

用戶協議對話框

使用自定義DialogFragment實現,內容是放到字符串文件中的,其中的鏈接是HTML標籤,設置後就可以點擊了,然後修改默認對話框寬度,因爲默認的有點窄。

public class TermServiceDialogFragment extends BaseViewModelDialogFragment<FragmentDialogTermServiceBinding> {

    ...

    @Override
    protected void initViews() {
        super.initViews();
        //點擊彈窗外邊不能關閉
        setCancelable(false);

        SuperTextUtil.setLinkColor(binding.content, getActivity().getColor(R.color.link));
    }

    @Override
    protected void initListeners() {
        super.initListeners();
        binding.primary.setOnClickListener(view -> {
            dismiss();
            onAgreementClickListener.onClick(view);
        });

        binding.disagree.setOnClickListener(view -> {
            dismiss();
            SuperProcessUtil.killApp();
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        //修改寬度,默認比AlertDialog.Builder顯示對話框寬度窄,看着不好看
        //參考:https://stackoverflow.com/questions/12478520/how-to-set-dialogfragments-width-and-height
        ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();

        params.width = (int) (ScreenUtil.getScreenWith(getContext()) * 0.9);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章