Skip to content

Commit

Permalink
修复插件化产生的一个错误
Browse files Browse the repository at this point in the history
  • Loading branch information
GangJust committed Jul 12, 2023
1 parent 4b537eb commit dfee82f
Show file tree
Hide file tree
Showing 26 changed files with 258 additions and 149 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.freegang.fplus"
minSdk 24
targetSdk 33
versionCode 35
versionName "1.1.5"
versionCode 37
versionName "1.1.6-beta-1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</provider>

<activity
android:name=".activity.DoHomeActivity"
android:name=".activity.HomeActivity"
android:exported="false" />

<activity
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/assets/update.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v1.1.6
增加抖音设置页模块入口
增加长按视频唤起模块菜单
移除抖音内置模块更新提示
修复插件化产生的一个错误
修复部分其它已知问题

v1.1.5
修复下载对话框不关闭
修复下载通知栏在UI线程下造成视频卡顿
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5-35
1.1.6-36
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.random.Random

class DoHomeActivity : ComponentActivity() {
class HomeActivity : ComponentActivity() {
private val model by viewModels<HomeVM>()

@OptIn(ExperimentalFoundationApi::class)
Expand Down Expand Up @@ -208,6 +208,7 @@ class DoHomeActivity : ComponentActivity() {
var showNewVersionDialog by remember { mutableStateOf(true) }
val version by model.versionConfig.observeAsState()
if (version != null) {
model.isSupportHint(true)
val version = version!!
if (version.name.compareTo("v${application.appVersionName}") >= 1 && showNewVersionDialog) {
FMessageDialog(
Expand Down Expand Up @@ -272,7 +273,7 @@ class DoHomeActivity : ComponentActivity() {
text = "${lspatchActive[0]} ${lspatchActive[1]} - ${lspatchActive[2]}",
style = Themes.nowTypography.body2,
)
} else if (HookStatus.isExpModuleActive(this@DoHomeActivity)) {
} else if (HookStatus.isExpModuleActive(this@HomeActivity)) {
Text(
text = "太极加载成功!",
style = Themes.nowTypography.body1,
Expand Down Expand Up @@ -334,7 +335,7 @@ class DoHomeActivity : ComponentActivity() {
style = Themes.nowTypography.body1,
)
Text(
text = "模块设置已迁移至抖音内部,点击抖音左上角侧滑栏,滑动至底部唤起模块设置",
text = "模块设置已迁移至抖音内部,抖音左上角侧滑栏/设置页,滑动至底部唤起模块设置",
style = Themes.nowTypography.overline,
)
}
Expand Down Expand Up @@ -553,6 +554,11 @@ class DoHomeActivity : ComponentActivity() {
model.checkVersion()
}

override fun onPause() {
super.onPause()
model.setVersionConfig(assets)
}

private fun toBrowse() {
try {
startActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MainActivity : ComponentActivity() {
}

ConfigV1.initialize(application)
startActivity(Intent(application, DoHomeActivity::class.java))
startActivity(Intent(application, HomeActivity::class.java))
finish()
}

Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/freegang/fplus/viewmodel/HomeVM.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package com.freegang.fplus.viewmodel

import android.app.Application
import android.content.res.AssetManager
import android.os.Environment
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.freegang.config.ConfigV1
import com.freegang.config.Version
import com.freegang.config.VersionConfig
import com.freegang.ktutils.app.appVersionCode
import com.freegang.ktutils.app.appVersionName
import com.freegang.ktutils.app.readAssetsAsText
import com.freegang.ktutils.io.child
import com.freegang.ktutils.io.storageRootFile
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class HomeVM(application: Application) : AndroidViewModel(application) {
val app: Application get() = getApplication()

private var _versionConfig = MutableLiveData<VersionConfig>()
val versionConfig: LiveData<VersionConfig> = _versionConfig

// module config
private val config: ConfigV1 get() = ConfigV1.get()

// 检查版本更新
fun checkVersion() {
viewModelScope.launch {
Expand All @@ -37,4 +47,21 @@ class HomeVM(application: Application) : AndroidViewModel(application) {
get() = getApplication<Application>().storageRootFile
.child(Environment.DIRECTORY_DCIM)
.child("Freedom")

// 是否显示兼容提示
fun isSupportHint(value: Boolean) {
config.isSupportHint = value
}

// 保存版本信息
fun setVersionConfig(asset: AssetManager) {
val version = asset.readAssetsAsText("version").split("-")
config.isSupportHint = version[1].toLong() != config.versionConfig.versionCode
config.versionConfig = ConfigV1.Version(
version[0],
version[1].toLong(),
app.appVersionName,
app.appVersionCode
)
}
}
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ dependencies {
implementation project(":ktutils")
implementation 'org.luckypray:DexKit:1.1.8'
implementation 'com.tencent:mmkv:1.3.0'
implementation 'xyz.junerver.ssktx:ss-ktx:0.0.1'
//implementation 'com.squareup.okhttp3:okhttp:4.8.0'
}
6 changes: 3 additions & 3 deletions core/src/main/java/com/freegang/base/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import com.freegang.plugin.XplerActivity
import com.freegang.ui.ModuleTheme

open class BaseActivity : XplerActivity() {
private var isLight = false
private var isDark = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initExtraData()
}

private fun initExtraData() {
isLight = intent.getBooleanExtra("isLight", false)
isDark = intent.getBooleanExtra("isDark", false)
}

@Composable
protected fun AutoTheme(
content: @Composable () -> Unit,
) {
ModuleTheme(
isDark = isLight,
isDark = isDark,
followSystem = false,
) {
content()
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/java/com/freegang/base/BaseHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package com.freegang.base
import android.content.Context
import android.content.Context.VIBRATOR_SERVICE
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.NinePatchDrawable
import android.os.Build
import android.os.Handler
import android.os.Looper
Expand All @@ -17,6 +20,7 @@ import android.widget.Toast
import androidx.core.view.isVisible
import com.freegang.ktutils.app.IProgressNotification
import com.freegang.ktutils.app.KNotifiUtils
import com.freegang.ktutils.app.isDarkMode
import com.freegang.ktutils.log.KLogCat
import com.freegang.view.KDialog
import com.freegang.view.adapter.DialogChoiceAdapter
Expand Down Expand Up @@ -83,6 +87,34 @@ abstract class BaseHook<T>(lpparam: XC_LoadPackage.LoadPackageParam) : KtOnHook<
toast?.cancel()
Toast.makeText(context.applicationContext, null, Toast.LENGTH_LONG)
}

runCatching {
//val view = toast?.findFieldAndGet("mNextView")

toast?.view?.isClickable = false
toast?.view?.isLongClickable = false

val modeNight = context.isDarkMode

//背景色
val drawable = toast?.view?.background as NinePatchDrawable?
drawable?.colorFilter = if (modeNight) {
PorterDuffColorFilter(Color.parseColor("#FF161823"), PorterDuff.Mode.SRC_IN)
} else {
PorterDuffColorFilter(Color.parseColor("#FFFFFFFF"), PorterDuff.Mode.SRC_IN)
}

//文字颜色
val textView: TextView? = toast?.view?.findViewById(android.R.id.message)
textView?.setTextColor(
if (modeNight) {
Color.parseColor("#FFFFFFFF")
} else {
Color.parseColor("#FF161823")
}
)
}

toast?.setText(message)
toast?.show()
}
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/com/freegang/config/ConfigV1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class ConfigV1 private constructor() {
}

/// 是否显示兼容提示
var isSupportHint: Boolean = false
var isSupportHint: Boolean = true
get() {
field = mmkv.getBoolean("isSupportHint", false)
field = mmkv.getBoolean("isSupportHint", true)
return field
}
set(value) {
Expand Down Expand Up @@ -187,7 +187,7 @@ class ConfigV1 private constructor() {
mmkv.putString("webDavPassword", field.password)
}

//是否开启隐藏顶部tab
/// 是否开启隐藏顶部tab
var isHideTab: Boolean = false
get() {
field = mmkv.getBoolean("isHideTab", false)
Expand All @@ -198,7 +198,7 @@ class ConfigV1 private constructor() {
field = value
}

//隐藏顶部tab包含的关键字, 逗号隔开
/// 隐藏顶部tab包含的关键字, 逗号隔开
var hideTabKeywords: String = "经验, 探索, 商城"
get() {
field = mmkv.getString("hideTabKeywords", "经验, 探索, 商城")!!
Expand All @@ -209,6 +209,7 @@ class ConfigV1 private constructor() {
field = value
}

/// 版本信息
var versionConfig: ConfigV1.Version = ConfigV1.Version()
get() {
return Version(
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/freegang/config/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Version {

// 获取Github最后一次 releases
fun getRemoteReleasesLatest(): VersionConfig? {
//if (null == null) return null //一般用作逻辑阻断
if (null == null) return null //一般用作逻辑阻断

val get = KHttpUtils.get(githubReleasesApi)
if (get.isEmpty()) return null
Expand Down
23 changes: 16 additions & 7 deletions core/src/main/java/com/freegang/douyin/DouYinMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import java.lang.reflect.Method
class DouYinMain(private val app: Application) {
companion object {
val awemeHostApplication get() = "com.ss.android.ugc.aweme.app.host.AwemeHostApplication".toClass(lpparam.classLoader)!!
var commonPageClazz: Class<*>? = null
var detailPageFragmentClazz: Class<*>? = null
var emojiMethods: List<Method> = emptyList()
}

init {
run {
runCatching {
//日志工具
KLogCat.init(app)
//KLogCat.openStorage()
Expand All @@ -32,7 +32,7 @@ class DouYinMain(private val app: Application) {
//文件读写权限检查
if (!app.hasOperationStorage) {
Toast.makeText(app, "抖音没有文件读写权限!", Toast.LENGTH_LONG).show()
return@run
return@runCatching
}

//插件化注入
Expand All @@ -51,23 +51,32 @@ class DouYinMain(private val app: Application) {
HDetailActivity(lpparam)
HFlippableViewPager(lpparam)
HVerticalViewPager(lpparam)
HCommonPageFragment(lpparam)
HDetailPageFragment(lpparam)
HGifEmojiDetailActivity(lpparam)
HEmojiDetailDialog(lpparam)
HEmojiDetailDialogNew(lpparam)
HHomeSideBarEntranceManagerV1(lpparam)
HDouYinSettingNewVersionActivity(lpparam)
}
}

private fun initDexKit() {
System.loadLibrary("dexkit")
DexKitBridge.create(lpparam.appInfo.sourceDir)?.use { bridge ->
if (commonPageClazz == null) {
if (detailPageFragmentClazz == null) {
val findMaps = bridge.batchFindClassesUsingStrings {
addQuery("CommonPage", setOf("a1128.b7947", "DetailActOtherNitaView"))
addQuery(
"DetailPageFragment",
setOf(
"a1128.b7947",
"com/ss/android/ugc/aweme/detail/ui/DetailPageFragment",
"DetailActOtherNitaView",
),
)
}
commonPageClazz = findMaps["CommonPage"]?.firstOrNull()?.getClassInstance(lpparam.classLoader)
detailPageFragmentClazz = findMaps["DetailPageFragment"]?.firstOrNull()?.getClassInstance(lpparam.classLoader)
}

if (emojiMethods.isEmpty()) {
emojiMethods = bridge.findMethod {
methodReturnType = "V"
Expand Down
Loading

0 comments on commit dfee82f

Please sign in to comment.