更新消息功能
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.aiosman.riderpro.data.api
|
||||
|
||||
import android.icu.text.SimpleDateFormat
|
||||
import com.aiosman.riderpro.AppStore
|
||||
import com.aiosman.riderpro.ConstVars
|
||||
import okhttp3.Interceptor
|
||||
@@ -8,6 +9,8 @@ import okhttp3.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.security.cert.CertificateException
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.TrustManager
|
||||
import javax.net.ssl.X509TrustManager
|
||||
@@ -17,10 +20,18 @@ fun getUnsafeOkHttpClient(): OkHttpClient {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkClientTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) {}
|
||||
override fun checkClientTrusted(
|
||||
chain: Array<java.security.cert.X509Certificate>,
|
||||
authType: String
|
||||
) {
|
||||
}
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkServerTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) {}
|
||||
override fun checkServerTrusted(
|
||||
chain: Array<java.security.cert.X509Certificate>,
|
||||
authType: String
|
||||
) {
|
||||
}
|
||||
|
||||
override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> = arrayOf()
|
||||
})
|
||||
@@ -40,6 +51,7 @@ fun getUnsafeOkHttpClient(): OkHttpClient {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
|
||||
class AuthInterceptor() : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val requestBuilder = chain.request().newBuilder()
|
||||
@@ -52,6 +64,7 @@ object ApiClient {
|
||||
const val BASE_SERVER = ConstVars.BASE_SERVER
|
||||
const val BASE_API_URL = "${BASE_SERVER}/api/v1"
|
||||
const val RETROFIT_URL = "${BASE_API_URL}/"
|
||||
const val TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"
|
||||
private val okHttpClient: OkHttpClient by lazy {
|
||||
getUnsafeOkHttpClient()
|
||||
}
|
||||
@@ -62,9 +75,19 @@ object ApiClient {
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
}
|
||||
|
||||
val api: RiderProAPI by lazy {
|
||||
retrofit.create(RiderProAPI::class.java)
|
||||
}
|
||||
|
||||
fun formatTime(date: Date): String {
|
||||
val dateFormat = SimpleDateFormat(TIME_FORMAT, Locale.getDefault())
|
||||
return dateFormat.format(date)
|
||||
}
|
||||
|
||||
fun dateFromApiString(apiString: String): Date {
|
||||
val timeFormat = ApiClient.TIME_FORMAT
|
||||
val simpleDateFormat = SimpleDateFormat(timeFormat, Locale.getDefault())
|
||||
val date = simpleDateFormat.parse(apiString)
|
||||
return date
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.aiosman.riderpro.data.api
|
||||
|
||||
import com.aiosman.riderpro.data.AccountFavourite
|
||||
import com.aiosman.riderpro.data.AccountFollow
|
||||
import com.aiosman.riderpro.data.AccountLike
|
||||
import com.aiosman.riderpro.data.AccountNotice
|
||||
import com.aiosman.riderpro.data.AccountProfile
|
||||
import com.aiosman.riderpro.data.AccountProfileEntity
|
||||
import com.aiosman.riderpro.data.Comment
|
||||
@@ -59,6 +63,15 @@ data class ChangePasswordRequestBody(
|
||||
val newPassword: String = ""
|
||||
)
|
||||
|
||||
data class UpdateNoticeRequestBody(
|
||||
@SerializedName("lastLookLikeTime")
|
||||
val lastLookLikeTime: String? = null,
|
||||
@SerializedName("lastLookFollowTime")
|
||||
val lastLookFollowTime: String? = null,
|
||||
@SerializedName("lastLookFavoriteTime")
|
||||
val lastLookFavouriteTime: String? = null
|
||||
)
|
||||
|
||||
interface RiderProAPI {
|
||||
@POST("register")
|
||||
suspend fun register(@Body body: RegisterRequestBody): Response<Unit>
|
||||
@@ -76,6 +89,7 @@ interface RiderProAPI {
|
||||
@Query("timelineId") timelineId: Int? = null,
|
||||
@Query("authorId") authorId: Int? = null,
|
||||
@Query("contentSearch") contentSearch: String? = null,
|
||||
@Query("postUser") postUser: Int? = null,
|
||||
): Response<ListContainer<Moment>>
|
||||
|
||||
@Multipart
|
||||
@@ -126,12 +140,19 @@ interface RiderProAPI {
|
||||
@Path("id") id: Int
|
||||
): Response<Unit>
|
||||
|
||||
@POST("comment/{id}/read")
|
||||
suspend fun updateReadStatus(
|
||||
@Path("id") id: Int
|
||||
): Response<Unit>
|
||||
|
||||
|
||||
@GET("comments")
|
||||
suspend fun getComments(
|
||||
@Query("page") page: Int = 1,
|
||||
@Query("postId") postId: Int? = null,
|
||||
@Query("pageSize") pageSize: Int = 20,
|
||||
@Query("postUser") postUser: Int? = null,
|
||||
@Query("selfNotice") selfNotice: Int? = 0,
|
||||
): Response<ListContainer<Comment>>
|
||||
|
||||
@GET("account/my")
|
||||
@@ -149,6 +170,33 @@ interface RiderProAPI {
|
||||
@Body body: ChangePasswordRequestBody
|
||||
): Response<Unit>
|
||||
|
||||
@GET("account/my/notice/like")
|
||||
suspend fun getMyLikeNotices(
|
||||
@Query("page") page: Int = 1,
|
||||
@Query("pageSize") pageSize: Int = 20,
|
||||
): Response<ListContainer<AccountLike>>
|
||||
|
||||
@GET("account/my/notice/follow")
|
||||
suspend fun getMyFollowNotices(
|
||||
@Query("page") page: Int = 1,
|
||||
@Query("pageSize") pageSize: Int = 20,
|
||||
): Response<ListContainer<AccountFollow>>
|
||||
|
||||
@GET("account/my/notice/favourite")
|
||||
suspend fun getMyFavouriteNotices(
|
||||
@Query("page") page: Int = 1,
|
||||
@Query("pageSize") pageSize: Int = 20,
|
||||
): Response<ListContainer<AccountFavourite>>
|
||||
|
||||
@GET("account/my/notice")
|
||||
suspend fun getMyNoticeInfo(): Response<DataContainer<AccountNotice>>
|
||||
|
||||
@POST("account/my/notice")
|
||||
suspend fun updateNoticeInfo(
|
||||
@Body body: UpdateNoticeRequestBody
|
||||
): Response<Unit>
|
||||
|
||||
|
||||
@GET("profile/{id}")
|
||||
suspend fun getAccountProfileById(
|
||||
@Path("id") id: Int
|
||||
|
||||
Reference in New Issue
Block a user