Skip to content

Commit

Permalink
Merge pull request #275 from xyoye/dev_4.2.0
Browse files Browse the repository at this point in the history
Dev 4.2.0
  • Loading branch information
xyoye authored Jan 23, 2025
2 parents 7b357a6 + 9507177 commit 29fd9a7
Show file tree
Hide file tree
Showing 18 changed files with 511 additions and 1 deletion.
21 changes: 21 additions & 0 deletions app/src/main/java/com/xyoye/dandanplay/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.xyoye.dandanplay.ui.main

import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.MutableLiveData
Expand All @@ -22,6 +24,7 @@ import com.xyoye.dandanplay.BR
import com.xyoye.dandanplay.R
import com.xyoye.dandanplay.databinding.ActivityMainBinding
import com.xyoye.data_component.data.LoginData
import com.xyoye.user_component.ui.weight.DeveloperMenus
import kotlin.random.Random
import kotlin.system.exitProcess

Expand All @@ -47,6 +50,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),
private var fragmentTag = ""
private var touchTime = 0L

// 标题栏菜单管理器
private lateinit var mMenus: DeveloperMenus

override fun initViewModel() =
ViewModelInit(
BR.viewModel,
Expand Down Expand Up @@ -86,10 +92,12 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),
title = "弹弹play"
switchFragment(TAG_FRAGMENT_HOME)
}

R.id.navigation_media -> {
title = "媒体库"
switchFragment(TAG_FRAGMENT_MEDIA)
}

R.id.navigation_personal -> {
title = "个人中心"
switchFragment(TAG_FRAGMENT_PERSONAL)
Expand Down Expand Up @@ -123,6 +131,16 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),
return super.onKeyDown(keyCode, event)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
mMenus = DeveloperMenus.inflater(this, menu)
return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
mMenus.onOptionsItemSelected(item)
return super.onOptionsItemSelected(item)
}

override fun getLoginLiveData(): MutableLiveData<LoginData> {
return viewModel.reLoginLiveData
}
Expand Down Expand Up @@ -158,6 +176,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),
fragmentTag = tag
}
}

TAG_FRAGMENT_MEDIA -> {
val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT_MEDIA)
if (fragment == null) {
Expand All @@ -174,6 +193,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),
fragmentTag = tag
}
}

TAG_FRAGMENT_PERSONAL -> {
val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT_PERSONAL)
if (fragment == null) {
Expand All @@ -190,6 +210,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),
fragmentTag = tag
}
}

else -> {
throw RuntimeException("no match fragment")
}
Expand Down
Binary file modified common_component/libs/arm64-v8a/libsecurity.so
Binary file not shown.
Binary file modified common_component/libs/armeabi-v7a/libsecurity.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ class BaseAdapter : AnimatedAdapter<RecyclerView.ViewHolder>() {
super.setData(data)

if (diffCreator != null) {
setDiffData(data, diffCreator!!)
// [Bugly] #2529539
// TODO: 临时的解决方案,需要复现与排查
try {
setDiffData(data, diffCreator!!)
} catch (e: Exception) {
setNotifyData(data)
}
} else {
setNotifyData(data)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.xyoye.common_component.config

import com.xyoye.mmkv_annotation.MMKVFiled
import com.xyoye.mmkv_annotation.MMKVKotlinClass

/**
* author: [email protected]
* time : 2025/1/22
* desc : 开发者配置表
*/

@MMKVKotlinClass(className = "DevelopConfig")
object DevelopConfigTable {

// AppId
@MMKVFiled
const val appId = ""

// App Secret
@MMKVFiled
const val appSecret = ""

// 是否已自动显示认证弹窗
@MMKVFiled
const val isAutoShowAuthDialog = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import com.xyoye.common_component.network.helper.AgentInterceptor
import com.xyoye.common_component.network.helper.AuthInterceptor
import com.xyoye.common_component.network.helper.BackupDomainInterceptor
import com.xyoye.common_component.network.helper.DecompressInterceptor
import com.xyoye.common_component.network.helper.DeveloperCertificateInterceptor
import com.xyoye.common_component.network.helper.DynamicBaseUrlInterceptor
import com.xyoye.common_component.network.helper.LoggerInterceptor
import com.xyoye.common_component.network.helper.SignatureInterceptor
import com.xyoye.common_component.network.service.AlistService
import com.xyoye.common_component.network.service.DanDanService
import com.xyoye.common_component.network.service.ExtendedService
Expand Down Expand Up @@ -43,6 +45,8 @@ class Retrofit private constructor() {
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(4, TimeUnit.SECONDS)
.hostnameVerifier { _, _ -> true }
.addInterceptor(SignatureInterceptor())
.addInterceptor(DeveloperCertificateInterceptor())
.addInterceptor(AgentInterceptor())
.addInterceptor(AuthInterceptor())
.addInterceptor(DecompressInterceptor())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.xyoye.common_component.network.helper

import com.xyoye.common_component.config.DevelopConfig
import com.xyoye.common_component.utils.SecurityHelper
import okhttp3.Interceptor
import okhttp3.Response

/**
* author: [email protected]
* time : 2025/1/22
* desc : 开发者凭证拦截器
*/
class DeveloperCertificateInterceptor : Interceptor {
companion object {
const val HEADER_APP_ID = "X-AppId"
const val HEADER_APP_SECRET = "X-AppSecret"
}


override fun intercept(chain: Interceptor.Chain): Response {
val oldRequest = chain.request()

// 官方应用,不做处理
if (SecurityHelper.getInstance().isOfficialApplication) {
return chain.proceed(oldRequest)
}

// 请求自带凭证,不做处理
val requestAppId = oldRequest.header(HEADER_APP_ID)
val requestAppSecret = oldRequest.header(HEADER_APP_SECRET)
if (requestAppId?.isNotEmpty() == true && requestAppSecret?.isNotEmpty() == true) {
return chain.proceed(oldRequest)
}

// 未配置凭证,不做处理
val appId = DevelopConfig.getAppId()
val appSecret = DevelopConfig.getAppSecret()
if (appId.isNullOrEmpty() || appSecret.isNullOrEmpty()) {
return chain.proceed(oldRequest)
}

// 添加凭证
return chain.proceed(
oldRequest.newBuilder()
.header(HEADER_APP_ID, appId)
.header(HEADER_APP_SECRET, appSecret).build()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.xyoye.common_component.network.helper

import com.xyoye.common_component.base.app.BaseApplication
import com.xyoye.common_component.utils.SecurityHelper
import okhttp3.Interceptor
import okhttp3.Response


/**
* author: [email protected]
* time : 2025/1/21
* desc : 签名验证拦截器
*/
class SignatureInterceptor : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val oldRequest = chain.request()
val newRequest = oldRequest.newBuilder()

SecurityHelper.getInstance().getSignatureMap(
oldRequest.url.encodedPath,
BaseApplication.getAppContext()
).forEach {
newRequest.addHeader(it.key, it.value ?: "")
}

return chain.proceed(newRequest.build())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,12 @@ object UserRepository : BaseRepository() {
.doPost {
Retrofit.danDanService.updatePassword(it)
}

/**
* 校验凭证
*/
suspend fun checkAuthenticate(appId: String, appSecret: String) = request()
.doGet {
Retrofit.danDanService.checkAuthenticate(appId, appSecret, 1)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xyoye.common_component.network.service

import com.xyoye.common_component.network.helper.DeveloperCertificateInterceptor
import com.xyoye.common_component.network.request.RequestParams
import com.xyoye.data_component.data.AnimeDetailData
import com.xyoye.data_component.data.AnimeTagData
Expand All @@ -17,9 +18,11 @@ import com.xyoye.data_component.data.SearchAnimeData
import com.xyoye.data_component.data.SendDanmuData
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Headers
import retrofit2.http.POST
import retrofit2.http.Path
Expand Down Expand Up @@ -116,4 +119,11 @@ interface DanDanService {

@POST("/api/v2/playhistory")
suspend fun addPlayHistory(@Body body: RequestBody): CommonJsonData

@GET("api/v2/login/renew")
suspend fun checkAuthenticate(
@Header(DeveloperCertificateInterceptor.HEADER_APP_ID) appId: String,
@Header(DeveloperCertificateInterceptor.HEADER_APP_SECRET) appSecret: String,
@Header("X-Auth") authMode: Int
): Response<ResponseBody>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import com.xyoye.common_component.base.app.BaseApplication;

import java.util.HashMap;
import java.util.Map;

/**
* Created by xyoye on 2021/1/6.
*/
Expand Down Expand Up @@ -52,7 +55,32 @@ public Boolean isOfficialApplication() {
return !ERROR_RESULT.equals(getAppId());
}

public Map<String, String> getSignatureMap(String path, Context context) {
Object signature = getSignature(path, context);
if (signature == null) {
return null;
}

if (signature instanceof Map) {
HashMap<String, String> map = new HashMap<>();
for (Map.Entry<?, ?> entry : ((Map<?, ?>) signature).entrySet()) {
Object key = entry.getKey();
if (key instanceof String) {
Object value = entry.getValue();
if (value instanceof String) {
map.put((String) key, (String) value);
}
}
}
return map;
}

return null;
}

private static native String getKey(int position, Context context);

private static native String buildHash(String hashInfo, Context context);

private static native Object getSignature(String path, Context context);
}
Loading

0 comments on commit 29fd9a7

Please sign in to comment.