Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
GangJust committed Jan 30, 2024
1 parent c400bba commit 70e16f1
Show file tree
Hide file tree
Showing 21 changed files with 1,776 additions and 1,405 deletions.
4 changes: 4 additions & 0 deletions app/src/main/assets/update.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.2.7
增加视频下载自定义编码格式
恢复“分享->复制链接”,需手动开启功能

v1.2.6
增加下载弹窗文案复制选项
增加视频右侧控件自定义隐藏
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/io/github/fplus/activity/ErrorActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import io.github.fplus.FreedomTheme
import io.github.fplus.R
import io.github.fplus.Themes
import io.github.fplus.resource.StringRes
import com.freegang.ktutils.app.KAppCrashUtils
import com.freegang.ktutils.app.activeActivity
import com.freegang.ktutils.app.appVersionCode
import com.freegang.ktutils.app.appVersionName
import io.github.fplus.FreedomTheme
import io.github.fplus.R
import io.github.fplus.Themes
import io.github.fplus.core.ui.component.ScrollableContainer
import io.github.fplus.resource.StringRes
import kotlin.system.exitProcess

class ErrorActivity : ComponentActivity() {
private var errMessage: String? = null
private var crashMessage: String? = null

@OptIn(ExperimentalFoundationApi::class)
@Composable
Expand Down Expand Up @@ -71,10 +72,10 @@ class ErrorActivity : ComponentActivity() {
indication = null,
interactionSource = remember { MutableInteractionSource() },
onClick = {
shareErrorMessage(errMessage!!)
shareCrashMessage()
},
onLongClick = {
shareErrorMessage(errMessage!!)
shareCrashMessage()
}
)
)
Expand All @@ -83,25 +84,24 @@ class ErrorActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
errMessage = intent.getStringExtra("errMessage") ?: return finish()
errMessage = "模块版本: $appVersionName ($appVersionCode)\n$errMessage"
crashMessage = intent.getStringExtra(KAppCrashUtils.CRASH_MESSAGE) ?: return finish()

setContent {
FreedomTheme(
window = window,
isImmersive = true,
isDark = false,
followSystem = false,
){
) {
Scaffold(
topBar = { TopBarView() },
){
) {
BoxWithConstraints(
modifier = Modifier.padding(it),
){
) {
ScrollableContainer {
BasicTextField(
value = errMessage!!,
value = crashMessage!!,
textStyle = Themes.nowTypography.body2,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
readOnly = true,
Expand All @@ -122,10 +122,10 @@ class ErrorActivity : ComponentActivity() {
exitProcess(1)
}

private fun shareErrorMessage(text: String) {
private fun shareCrashMessage() {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, text)
intent.putExtra(Intent.EXTRA_TEXT, "模块版本: $appVersionName ($appVersionCode)\n$crashMessage")
startActivity(Intent.createChooser(intent, "日志分享"))
}
}
5 changes: 4 additions & 1 deletion core/src/main/java/io/github/fplus/core/base/BaseHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.github.fplus.core.databinding.DialogChoiceLayoutBinding
import io.github.fplus.core.databinding.DialogInputChoiceLayoutBinding
import io.github.fplus.core.databinding.DialogMessageLayoutBinding
import io.github.fplus.core.databinding.DialogProgressLayoutBinding
import io.github.fplus.core.ui.ModuleTheme
import io.github.fplus.core.ui.dialog.XplerDialogWrapper
import io.github.fplus.core.view.KDialog
import io.github.fplus.core.view.adapter.DialogChoiceAdapter
Expand Down Expand Up @@ -110,7 +111,9 @@ abstract class BaseHook<T>() : HookEntity<T>() {
) {
XplerDialogWrapper(context).apply {
setWrapperContent {
content.invoke(this::dismiss)
ModuleTheme {
content.invoke(this::dismiss)
}
}
}.show()
}
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/java/io/github/fplus/core/config/ConfigV1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ class ConfigV1 private constructor() {
field = value
}

/// 复制链接时弹出下载
var isCopyDownload: Boolean = false
get() {
field = mmkv.getBoolean("isCopyDownload", false)
return field
}
set(value) {
mmkv.putBoolean("isCopyDownload", value)
field = value
}

/// 视频编码 [Auto, H265, H264]
var videoCoding: String = "H265"
get() {
field = mmkv.getString("videoCoding", "H265")!!
return field
}
set(value) {
mmkv.putString("videoCoding", value)
field = value
}

/// 表情包/评论区视频、图片保存
var isEmoji: Boolean = false
get() {
Expand Down Expand Up @@ -490,6 +512,16 @@ class ConfigV1 private constructor() {
mmkv.putLong("dyVersionCode", value.dyVersionCode)
}

var is32BitTips: Boolean = true
get() {
field = mmkv.getBoolean("is32BitTips", true)
return field
}
set(value) {
field = value
mmkv.putBoolean("is32BitTips", value)
}

var dexkitCache: JSONObject = JSONObject()
get() {
return mmkv.getString("dexkitCache", "")!!.parseJSON()
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/io/github/fplus/core/hook/DouYinMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DouYinMain(private val app: Application) {
val intent = Intent()
val className = "${Constant.modulePackage}.activity.ErrorActivity"
intent.setClassName(Constant.modulePackage, className)
KAppCrashUtils.init(app, "抖音异常退出!", intent) {
KAppCrashUtils.init(app, "抖音异常退出!", intent) { e, m ->
KActivityUtils.unregister(app)
true
}
Expand All @@ -56,10 +56,11 @@ class DouYinMain(private val app: Application) {
// search and hook
DexkitBuilder.running(
app = app,
version = 8,
version = 10,
searchBefore = {
HActivity()
HMainActivity()
HDetailActivity()
HLivePlayActivity()
HDisallowInterceptRelativeLayout()
HMainTabStripScrollView()
Expand All @@ -76,6 +77,8 @@ class DouYinMain(private val app: Application) {
HDialog()
// HDialogFragment()
// HPopupWindow()

HFragment()
},
searchAfter = {
HSideBarNestedScrollView()
Expand Down
15 changes: 10 additions & 5 deletions core/src/main/java/io/github/fplus/core/hook/HActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import com.freegang.ktutils.app.navBarInteractionMode
import com.freegang.ktutils.app.navigationBarHeight
import com.freegang.ktutils.log.KLogCat
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.callbacks.XC_LoadPackage
import io.github.fplus.core.base.BaseHook
import io.github.fplus.core.config.ConfigV1
import io.github.fplus.core.helper.ImmersiveHelper
import io.github.fplus.core.ui.activity.FreedomSettingActivity
import io.github.xpler.core.entity.OnBefore
import io.github.xpler.core.hookBlockRunning
import io.github.xpler.core.thisActivity
Expand All @@ -24,9 +24,12 @@ class HActivity : BaseHook<Activity>() {
private val config get() = ConfigV1.get()

@OnBefore("dispatchTouchEvent")
fun dispatchTouchEventBefore(param: XC_MethodHook.MethodHookParam, event: MotionEvent) {
hookBlockRunning(param) {
fun dispatchTouchEventBefore(params: XC_MethodHook.MethodHookParam, event: MotionEvent) {
hookBlockRunning(params) {
DouYinMain.freeExitCountDown?.restart()

if (thisActivity is FreedomSettingActivity) return

if (config.isImmersive) {
// 底部三键导航
val activity = thisObject as Activity
Expand All @@ -42,10 +45,12 @@ class HActivity : BaseHook<Activity>() {
}

@OnBefore("onResume")
fun onResumeBefore(param: XC_MethodHook.MethodHookParam) {
hookBlockRunning(param) {
fun onResumeBefore(params: XC_MethodHook.MethodHookParam) {
hookBlockRunning(params) {
DouYinMain.freeExitCountDown?.restart()

if (thisActivity is FreedomSettingActivity) return

if (config.isImmersive) {
ImmersiveHelper.immersive(
activity = thisActivity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.github.xpler.core.hookBlockRunning
import io.github.xpler.core.thisView
import io.github.xpler.core.wrapper.CallMethods

@Deprecated("暂存区, 评论区语音保存")
class HCommentAudioView : BaseHook<Any>(), CallMethods {
companion object {
const val TAG = "HCommentAudioView"
Expand All @@ -40,7 +41,7 @@ class HCommentAudioView : BaseHook<Any>(), CallMethods {
if (argsOrEmpty.size != 4) {
return
}

val value = args[1].fieldGets().filterNotNull().firstOrNull() ?: return
val gets = value.fieldGets().filter { it?.javaClass?.`package`?.name == "X" }

Expand Down
59 changes: 59 additions & 0 deletions core/src/main/java/io/github/fplus/core/hook/HDetailActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.fplus.core.hook

import android.app.Activity
import com.freegang.ktutils.log.KLogCat
import com.ss.android.ugc.aweme.detail.ui.DetailActivity
import de.robv.android.xposed.XC_MethodHook
import io.github.fplus.core.base.BaseHook
import io.github.fplus.core.config.ConfigV1
import io.github.fplus.core.hook.logic.ClipboardLogic
import io.github.fplus.core.hook.logic.DownloadLogic
import io.github.xpler.core.entity.OnAfter
import io.github.xpler.core.entity.OnBefore
import io.github.xpler.core.hookBlockRunning
import io.github.xpler.core.thisActivity

class HDetailActivity : BaseHook<DetailActivity>() {
companion object {
const val TAG = "HDetailActivity"
}

private val config get() = ConfigV1.get()

private val clipboardLogic = ClipboardLogic(this)

@OnAfter("onResume")
fun onResumeAfter(params: XC_MethodHook.MethodHookParam) {
hookBlockRunning(params) {
addClipboardListener(thisActivity as DetailActivity)
}.onFailure {
KLogCat.tagE(TAG, it)
}
}

@OnBefore("onPause")
fun onPauseBefore(params: XC_MethodHook.MethodHookParam) {
hookBlockRunning(params) {
removeClipboardListener(thisActivity)
}.onFailure {
KLogCat.tagE(TAG, it)
}
}

private fun addClipboardListener(activity: Activity) {
if (!config.isDownload) return
if (!config.isCopyDownload) return

clipboardLogic.addClipboardListener(activity) { clipData, firstText ->
DownloadLogic(
this@HDetailActivity,
activity,
HVideoViewHolder.aweme,
)
}
}

private fun removeClipboardListener(activity: Activity) {
clipboardLogic.removeClipboardListener(activity)
}
}
Loading

0 comments on commit 70e16f1

Please sign in to comment.