正在迁移至Retrofit,废弃部分代码
This commit is contained in:
parent
0eb306d499
commit
204d9a7ab9
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -69,12 +69,10 @@ android {
|
|||
|
||||
dependencies {
|
||||
|
||||
//视频播放器
|
||||
implementation 'com.github.CarGuo.GSYVideoPlayer:GSYVideoPlayer:v8.2.0-release-jitpack'
|
||||
|
||||
|
||||
//权限申请
|
||||
implementation 'com.guolindev.permissionx:permissionx:1.6.1'
|
||||
|
||||
implementation "androidx.room:room-runtime:2.4.0"
|
||||
//注释处理器加上Room
|
||||
annotationProcessor "androidx.room:room-compiler:2.4.0"
|
||||
|
@ -89,11 +87,6 @@ dependencies {
|
|||
// TinyPinyin核心包,约80KB
|
||||
implementation 'com.github.promeg:tinypinyin:2.0.3'
|
||||
implementation 'io.github.youth5201314:banner:2.2.2'
|
||||
// 友盟统计SDK
|
||||
// implementation 'com.umeng.umsdk:common:9.4.4'
|
||||
// implementation 'com.umeng.umsdk:asms:1.4.1'
|
||||
// implementation 'com.umeng.umsdk:apm:1.5.2'
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.7.0'
|
||||
implementation 'com.github.deano2390:MaterialShowcaseView:1.3.4'
|
||||
implementation 'com.google.code.gson:gson:2.8.8'
|
||||
|
@ -101,6 +94,7 @@ dependencies {
|
|||
implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9'
|
||||
implementation files('libs/editor_0.8.aar')
|
||||
implementation project(path: ':assistantCoreLibrary')
|
||||
implementation project(path: ':networkApi')
|
||||
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'
|
||||
implementation 'com.afollestad.material-dialogs:input:3.3.0'
|
||||
|
||||
|
|
|
@ -37,21 +37,13 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'com.google.code.gson:gson:2.8.8'
|
||||
implementation "com.squareup.okhttp3:mockwebserver:4.9.1"
|
||||
implementation "androidx.room:room-runtime:2.4.0"
|
||||
//注释处理器加上Room
|
||||
annotationProcessor "androidx.room:room-compiler:2.4.0"
|
||||
kapt "androidx.room:room-compiler:2.4.0"
|
||||
|
||||
//使用Kotlin注释处理工具(kapt)
|
||||
// kapt("androidx.room:room-compiler:2.4.0")
|
||||
//使用Kotlin符号处理(KSP)
|
||||
// ksp("androidx.room:room-compiler:2.4.0")
|
||||
|
||||
//可选- Kotlin扩展和协程支持的房间
|
||||
//implementation("androidx.room:room-ktx:2.4.0")
|
||||
implementation 'com.google.code.gson:gson:2.8.8'
|
||||
implementation "com.squareup.okhttp3:mockwebserver:4.9.1"
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.coldmint.rust.core">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
</manifest>
|
|
@ -16,6 +16,7 @@ import java.io.IOException
|
|||
* @author Cold Mint
|
||||
* @date 2021/12/22 20:12
|
||||
*/
|
||||
@Deprecated("已废弃")
|
||||
class ActivationApp private constructor() {
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.google.gson.Gson
|
|||
import okhttp3.*
|
||||
import java.io.IOException
|
||||
|
||||
@Deprecated("已废弃")
|
||||
class AppUpdate {
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.io.IOException
|
|||
/**
|
||||
* 轮播图管理器
|
||||
*/
|
||||
@Deprecated("已废弃")
|
||||
class BannerManager private constructor() {
|
||||
companion object {
|
||||
val instance: BannerManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.google.gson.Gson
|
|||
import okhttp3.*
|
||||
import java.io.IOException
|
||||
|
||||
@Deprecated("已废弃")
|
||||
object Community {
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.io.IOException
|
|||
* @author Cold Mint
|
||||
* @date 2022/1/10 20:17
|
||||
*/
|
||||
@Deprecated("已废弃")
|
||||
class Coupon {
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.io.IOException
|
|||
/**
|
||||
* 动态
|
||||
*/
|
||||
@Deprecated("已废弃")
|
||||
class Dynamic private constructor() {
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.io.IOException
|
|||
* @author Cold Mint
|
||||
* @date 2022/1/6 19:45
|
||||
*/
|
||||
@Deprecated("已废弃")
|
||||
class Report private constructor() {
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.google.gson.Gson
|
|||
import okhttp3.*
|
||||
import java.io.IOException
|
||||
|
||||
@Deprecated("已过时")
|
||||
class Search private constructor() {
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.lang.NullPointerException
|
|||
/**
|
||||
* 用户类
|
||||
*/
|
||||
@Deprecated("已废弃")
|
||||
object User {
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,7 @@ import okhttp3.RequestBody.Companion.asRequestBody
|
|||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@Deprecated("已废弃")
|
||||
class WebMod private constructor() {
|
||||
|
||||
enum class SortMode(private val value: String) {
|
||||
|
|
|
@ -9,7 +9,7 @@ buildscript {
|
|||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.2.0'
|
||||
// classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
|
1
networkApi/.gitignore
vendored
Normal file
1
networkApi/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
43
networkApi/build.gradle
Normal file
43
networkApi/build.gradle
Normal file
|
@ -0,0 +1,43 @@
|
|||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk 32
|
||||
|
||||
defaultConfig {
|
||||
minSdk 21
|
||||
targetSdk 32
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation project(path: ':assistantCoreLibrary')
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
|
||||
implementation 'androidx.core:core-ktx:1.7.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||
implementation 'com.google.android.material:material:1.4.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
}
|
0
networkApi/consumer-rules.pro
Normal file
0
networkApi/consumer-rules.pro
Normal file
21
networkApi/proguard-rules.pro
vendored
Normal file
21
networkApi/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,24 @@
|
|||
package com.coldmint.rust.networkapi
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.coldmint.rust.networkapi.test", appContext.packageName)
|
||||
}
|
||||
}
|
5
networkApi/src/main/AndroidManifest.xml
Normal file
5
networkApi/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.coldmint.rust.networkapi">
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,14 @@
|
|||
package com.coldmint.rust.networkapi
|
||||
|
||||
/**
|
||||
* 网络回调
|
||||
* @param T
|
||||
*/
|
||||
interface NetworkCallback<T> {
|
||||
|
||||
fun onSuccess(response: T)
|
||||
|
||||
|
||||
fun onFail(throwable: Throwable? = null)
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package com.coldmint.rust.networkapi
|
||||
|
||||
import com.coldmint.rust.core.tool.DebugHelper
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
/**
|
||||
* 网络管理器
|
||||
*/
|
||||
object NetworkManager {
|
||||
|
||||
private var baseUrl: String? = null
|
||||
|
||||
private var retrofit: Retrofit? = null
|
||||
|
||||
const val debugKey = "网络管理器"
|
||||
|
||||
/**
|
||||
* 设置BaseUrl
|
||||
* @param url String
|
||||
*/
|
||||
fun setBaseUrl(url: String) {
|
||||
if (retrofit == null) {
|
||||
baseUrl = url
|
||||
} else {
|
||||
retrofit = createRetrofit(url)
|
||||
}
|
||||
DebugHelper.printLog(debugKey, "已设置Url:${url}", "设置Url")
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建接口实例
|
||||
* @param service Class<T> 类名
|
||||
* @return T
|
||||
*/
|
||||
fun <T> create(service: Class<T>): T {
|
||||
if (retrofit == null) {
|
||||
retrofit = createRetrofit(baseUrl!!)
|
||||
}
|
||||
DebugHelper.printLog(debugKey, "已创建${service.name}接口实例。", "创建")
|
||||
return retrofit!!.create(service)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行异步请求
|
||||
* @receiver Call<T>
|
||||
*/
|
||||
fun <T> Call<T>.doEnqueue(networkCallback: NetworkCallback<T>) {
|
||||
val key = "异步请求"
|
||||
this.enqueue(object : Callback<T> {
|
||||
override fun onResponse(call: Call<T>, response: Response<T>) {
|
||||
if (response.isSuccessful) {
|
||||
val responseBody = response.body()
|
||||
if (responseBody == null) {
|
||||
DebugHelper.printLog(
|
||||
debugKey,
|
||||
"${call.request().url.toString()},响应体为空。",
|
||||
key,
|
||||
true
|
||||
)
|
||||
networkCallback.onFail(null)
|
||||
} else {
|
||||
DebugHelper.printLog(
|
||||
debugKey,
|
||||
"${call.request().url.toString()},响应成功。",
|
||||
key
|
||||
)
|
||||
networkCallback.onSuccess(responseBody)
|
||||
}
|
||||
} else {
|
||||
DebugHelper.printLog(
|
||||
debugKey,
|
||||
"${call.request().url.toString()},错误的响应码:${response.code()}",
|
||||
key,
|
||||
true
|
||||
)
|
||||
networkCallback.onFail(null)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<T>, t: Throwable) {
|
||||
DebugHelper.printLog(debugKey, "${call.request().url.toString()},请求失败。", key, true)
|
||||
networkCallback.onFail(t)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Retrofit对象
|
||||
* @param url String baseUrl
|
||||
* @return Retrofit
|
||||
*/
|
||||
private fun createRetrofit(url: String): Retrofit {
|
||||
return Retrofit.Builder().baseUrl(url)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.coldmint.rust.networkapi
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
include ':app'
|
||||
rootProject.name = "铁锈助手"
|
||||
include ':assistantCoreLibrary'
|
||||
include ':networkApi'
|
||||
|
|
Reference in New Issue
Block a user