From 5d8da4bff7acac61e92cc3a2aca8e2c4a6cbc12f Mon Sep 17 00:00:00 2001 From: yimiao Date: Mon, 19 Jul 2021 15:42:41 +0800 Subject: [PATCH] =?UTF-8?q?author:wangyimiao=20desc:=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=A0=B7=E4=BE=8BDEMO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 16 ++++++- app/src/main/AndroidManifest.xml | 1 + .../com/yinuo/commonlibtest/MainActivity.java | 33 +++++++++++++- .../com/yinuo/commonlibtest/MyApplication.kt | 12 ++++++ .../com/yinuo/commonlibtest/bean/Article.kt | 43 +++++++++++++++++++ .../yinuo/commonlibtest/bean/ArticleTag.kt | 10 +++++ .../com/yinuo/commonlibtest/bean/Articles.kt | 15 +++++++ .../commonlibtest/bean/ArticlesResponse.kt | 8 ++++ .../commonlibtest/manager/InternetLoader.kt | 27 ++++++++++++ app/src/main/res/layout/activity_main.xml | 1 + commonLib/src/main/AndroidManifest.xml | 1 + .../com/yinuo/commonlib/CommonApplication.kt | 3 +- .../com/yinuo/commonlib/net/BaseObserve.kt | 4 +- 13 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/yinuo/commonlibtest/MyApplication.kt create mode 100644 app/src/main/java/com/yinuo/commonlibtest/bean/Article.kt create mode 100644 app/src/main/java/com/yinuo/commonlibtest/bean/ArticleTag.kt create mode 100644 app/src/main/java/com/yinuo/commonlibtest/bean/Articles.kt create mode 100644 app/src/main/java/com/yinuo/commonlibtest/bean/ArticlesResponse.kt create mode 100644 app/src/main/java/com/yinuo/commonlibtest/manager/InternetLoader.kt diff --git a/app/build.gradle b/app/build.gradle index 667fb79..e507a86 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,9 +39,23 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation project(path: ':commonLib') + + // 添加kotlin依赖 + implementation rootProject.ext.dependencies.kotlin + // 添加okhttp依赖 + implementation rootProject.ext.dependencies.okhttp + // 添加retrofit依赖 + implementation rootProject.ext.dependencies.retrofit + // 添加retrofit转化gson能力依赖 + implementation rootProject.ext.dependencies.converter_gson + // 添加rxjava依赖 + implementation rootProject.ext.dependencies.rxjava + // 添加rxAndroid依赖 + implementation rootProject.ext.dependencies.rxandroid + // 添加retrofit和rxjava适配器 + implementation rootProject.ext.dependencies.retrofit_rxjava } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 321a4ca..fb215d2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ package="com.yinuo.commonlibtest"> { + InternetLoader loader = new InternetLoader(); + loader.getHomeArticles(0, new RequestCallBack() { + @Override + public void onResult(ArticlesResponse result) { + Log.d(TAG, result.getData().toString()); + } + + @Override + public void onError(@Nullable String error) { + Log.d(TAG, "onError"); + } + + @Override + public void onComplete() { + Log.d(TAG, "onComplete"); + } + }); + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/yinuo/commonlibtest/MyApplication.kt b/app/src/main/java/com/yinuo/commonlibtest/MyApplication.kt new file mode 100644 index 0000000..5a51a42 --- /dev/null +++ b/app/src/main/java/com/yinuo/commonlibtest/MyApplication.kt @@ -0,0 +1,12 @@ +package com.yinuo.commonlibtest + +import android.app.Application +import com.yinuo.commonlib.CommonApplication + +class MyApplication : Application() { + override fun onCreate() { + super.onCreate() + + CommonApplication.intLibs(this) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yinuo/commonlibtest/bean/Article.kt b/app/src/main/java/com/yinuo/commonlibtest/bean/Article.kt new file mode 100644 index 0000000..42f65c8 --- /dev/null +++ b/app/src/main/java/com/yinuo/commonlibtest/bean/Article.kt @@ -0,0 +1,43 @@ +package com.yinuo.commonlibtest.bean + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + +/** + * 文章数据类 + */ +@Parcelize +data class Article(var apkLink: String = ""): Parcelable { + var audit: Int = 0 + var author: String = "" + var canEdit: Boolean = false + var chapterId: Int = 0 + var chapterName: String = "" + var collect: Boolean = false + var courseId: Int = 0 + var desc: String = "" + var descMd: String = "" + var envelopePic: String = "" + var fresh: Boolean = false + var host: String = "" + var id: Long = 0 + var link: String = "" + var niceDate: String = "" + var niceShareDate: String = "" + var origin: String = "" + var prefix: String = "" + var projectLink: String = "" + var publishTime: Long = 0 + var realSuperChapterId: Long = 0 + var selfVisible: Int = 0 + var shareDate: Long = 0 + var shareUser: String = "" + var superChapterId: Long = 0 + var superChapterName: String = "" + var tags: List? = null + var title: String = "" + var type: Int = 0 + var userId: Long = 0 + var visible: Int = 0 + var zan: Int = 0 +} diff --git a/app/src/main/java/com/yinuo/commonlibtest/bean/ArticleTag.kt b/app/src/main/java/com/yinuo/commonlibtest/bean/ArticleTag.kt new file mode 100644 index 0000000..9c9d091 --- /dev/null +++ b/app/src/main/java/com/yinuo/commonlibtest/bean/ArticleTag.kt @@ -0,0 +1,10 @@ +package com.yinuo.commonlibtest.bean + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + +@Parcelize +data class ArticleTag( + var name: String? = "", + var url: String? = "" +) : Parcelable diff --git a/app/src/main/java/com/yinuo/commonlibtest/bean/Articles.kt b/app/src/main/java/com/yinuo/commonlibtest/bean/Articles.kt new file mode 100644 index 0000000..feb4845 --- /dev/null +++ b/app/src/main/java/com/yinuo/commonlibtest/bean/Articles.kt @@ -0,0 +1,15 @@ +package com.yinuo.commonlibtest.bean + +import android.os.Parcelable +import com.yinuo.commonlibtest.bean.Article +import kotlinx.android.parcel.Parcelize + +@Parcelize +data class Articles(var curPage: Int) : Parcelable { + var datas: List
? = null + var offset: Int = 0 + var over: Boolean = false + var pageCount: Long = 0 + var size: Int = 0 + var total: Long = 0 +} diff --git a/app/src/main/java/com/yinuo/commonlibtest/bean/ArticlesResponse.kt b/app/src/main/java/com/yinuo/commonlibtest/bean/ArticlesResponse.kt new file mode 100644 index 0000000..c23590d --- /dev/null +++ b/app/src/main/java/com/yinuo/commonlibtest/bean/ArticlesResponse.kt @@ -0,0 +1,8 @@ +package com.yinuo.commonlibtest.bean + +import android.os.Parcelable +import com.yinuo.commonlib.net.bean.BaseResponse +import kotlinx.android.parcel.Parcelize + +@Parcelize +data class ArticlesResponse(var data: Articles? = null): Parcelable, BaseResponse() diff --git a/app/src/main/java/com/yinuo/commonlibtest/manager/InternetLoader.kt b/app/src/main/java/com/yinuo/commonlibtest/manager/InternetLoader.kt new file mode 100644 index 0000000..1152059 --- /dev/null +++ b/app/src/main/java/com/yinuo/commonlibtest/manager/InternetLoader.kt @@ -0,0 +1,27 @@ +package com.yinuo.commonlibtest.manager + +import com.common.commonlib.net.RequestCallBack +import com.yinuo.commonlib.net.BaseObserve +import com.yinuo.commonlibtest.bean.ArticlesResponse +import io.reactivex.Observable +import retrofit2.http.GET +import retrofit2.http.Headers +import retrofit2.http.Path + +class InternetLoader : BaseObserve() { + var homeApi: HomeApi + + init { + homeApi = initService(HomeApi::class.java) + } + + fun getHomeArticles(pageName: Int, callBack: RequestCallBack) { + observe(homeApi.getHomeArticles(pageName), callBack) + } + + interface HomeApi { + @Headers("baseurl:debug1") + @GET("/article/list/{pageNum}/json") + fun getHomeArticles(@Path("pageNum") pageNum: Int): Observable + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4fc2444..7b64f39 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,6 +7,7 @@ tools:context=".MainActivity"> + \ No newline at end of file diff --git a/commonLib/src/main/java/com/yinuo/commonlib/CommonApplication.kt b/commonLib/src/main/java/com/yinuo/commonlib/CommonApplication.kt index 7fc9f2e..cb598d0 100644 --- a/commonLib/src/main/java/com/yinuo/commonlib/CommonApplication.kt +++ b/commonLib/src/main/java/com/yinuo/commonlib/CommonApplication.kt @@ -1,10 +1,11 @@ package com.yinuo.commonlib import android.annotation.SuppressLint +import android.app.Application import android.content.Context @SuppressLint("StaticFieldLeak") -object CommonApplication { +object CommonApplication : Application() { private var commonContext: Context? = null fun intLibs(context: Context) { diff --git a/commonLib/src/main/java/com/yinuo/commonlib/net/BaseObserve.kt b/commonLib/src/main/java/com/yinuo/commonlib/net/BaseObserve.kt index 1eda43a..ba53285 100644 --- a/commonLib/src/main/java/com/yinuo/commonlib/net/BaseObserve.kt +++ b/commonLib/src/main/java/com/yinuo/commonlib/net/BaseObserve.kt @@ -1,7 +1,9 @@ -package com.common.commonlib.net +package com.yinuo.commonlib.net import android.net.ParseException import android.util.Log +import com.common.commonlib.net.RequestCallBack +import com.common.commonlib.net.RequestManager import com.google.gson.JsonParseException import io.reactivex.Observable import io.reactivex.Observer