Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/src/main/java/com/swallow/gyps/main/MainRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ class MainRepository @Inject constructor() : BaseRepository() {
handleError(it)
}
}

/**
* 获取设备 待维修/正在维修列表
*/
fun reportHealthyStatus2(model: HealthModel): Flow<HttpResult<BaseResponse<Any>>> {
return flow {
val response = obtainService(HealthyService::class.java).reportHealthyStatus2(model)
emit(HttpResult.Success(response))
}.retry(1)
.flowOn(Dispatchers.IO)
.catch {
handleError(it)
}
}
}
9 changes: 7 additions & 2 deletions app/src/main/java/com/swallow/gyps/service/HealthyService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.swallow.gyps.service

import com.swallow.fly.http.di.DynamicTimeout
import com.swallow.fly.http.result.BaseResponse
import com.swallow.gyps.main.models.HealthModel
import retrofit2.http.Body
Expand All @@ -15,6 +16,10 @@ import retrofit2.http.POST
interface HealthyService {
@POST("add")
suspend fun reportHealthyStatus(@Body model: HealthModel): BaseResponse<Any>




@POST("tuzai/mobile/killpass/test")
@DynamicTimeout(timeout =20 )
suspend fun reportHealthyStatus2(@Body model: HealthModel): BaseResponse<Any>

}
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ext {
buildToolsVersion: "30.0.2",
minSdkVersion : 21,
targetSdkVersion : 30,
versionCode : 27,
versionName : "1.4.3"
versionCode : 28,
versionName : "1.4.4"
]
version = [
androidSupportSdkVersion: "28.0.0",
Expand Down
3 changes: 3 additions & 0 deletions swallow/src/main/java/com/swallow/fly/http/di/ClientModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.swallow.fly.base.app.AppModule
import com.swallow.fly.http.CoroutineCallAdapterFactory
import com.swallow.fly.http.TimeoutCallAdapterFactory
import com.swallow.fly.http.interceptor.GlobalHttpHandler
import com.swallow.fly.http.interceptor.TimeoutInterceptor
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -81,6 +82,8 @@ object ClientModule {
}
})
builder.addInterceptor(intercept)
builder.addInterceptor(TimeoutInterceptor())

//如果外部提供了 Interceptor 的集合则遍历添加
// if (!interceptors.isNullOrEmpty()) {
// for (item in interceptors) {
Expand Down
13 changes: 13 additions & 0 deletions swallow/src/main/java/com/swallow/fly/http/di/DynamicTimeout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.swallow.fly.http.di;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface DynamicTimeout {
int timeout();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.swallow.fly.http.interceptor

import com.swallow.fly.http.di.ClientModule
import com.swallow.fly.http.di.DynamicTimeout
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import retrofit2.Invocation
import java.util.concurrent.TimeUnit


/**
* @Description: 超时配置拦截器
* @Author: lfc
* @Email: iamlifuchang@163.com
* @CreateTime: 2023/2/21 10:45
* @UpdateRemark: 超时配置拦截器
*/
class TimeoutInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
try {
val reequest: Request = chain.request()

//核心代码!!!
//核心代码!!!
val tag = request.tag(Invocation::class.java)
val timeout: DynamicTimeout? =
tag?.method()?.getAnnotation(DynamicTimeout::class.java)


return chain.withConnectTimeout(timeout?.timeout ?: 10, TimeUnit.SECONDS)
.withReadTimeout(timeout?.timeout ?: 10, TimeUnit.SECONDS)
.proceed(reequest)
// return chain.proceed(reequest)
} catch (e: Exception) {
e.printStackTrace()
return chain.proceed(request);

}


}
}