Skip to content

Commit

Permalink
时长提示开关
Browse files Browse the repository at this point in the history
时长提示开关
  • Loading branch information
GangJust committed Oct 5, 2023
1 parent 06a1e5f commit a6b1c3f
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 33 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 34
versionCode 70
versionName "1.2.1"
versionCode 72
versionName "1.2.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
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.2
增加视频时长超过10分钟提示开关
调整视频时长提示为超过10分钟

v1.2.1
增加底部加号按钮隐藏
增加底部加号按钮禁止拍摄
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.2.1-70
1.2.2-72
11 changes: 11 additions & 0 deletions core/src/main/java/com/freegang/config/ConfigV1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ class ConfigV1 private constructor() {
field = value
}

/// 视频时长超过10分钟提示
var isLongtimeVideoToast: Boolean = false
get() {
field = mmkv.getBoolean("isLongtimeVideoToast", false)
return field
}
set(value) {
mmkv.putBoolean("isLongtimeVideoToast", value)
field = value
}

/// 隐藏底部加号按钮
var isHidePhotoButton: Boolean = false
get() {
Expand Down
12 changes: 11 additions & 1 deletion core/src/main/java/com/freegang/hook/DouYinMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DouYinMain(private val app: Application) {
val awemeHostApplication
get() = "com.ss.android.ugc.aweme.app.host.AwemeHostApplication".findClass(lpparam.classLoader)!!

var classCacheVersion: Int = 2
var classCacheVersion: Int = 3
var mainBottomTabItemClazz: Class<*>? = null
var detailPageFragmentClazz: Class<*>? = null
var videoPinchClazz: Class<*>? = null
Expand Down Expand Up @@ -227,13 +227,18 @@ class DouYinMain(private val app: Application) {

private fun readClassCache(): Boolean {
val cache = ConfigV1.get().classCache

// version
val version = cache.getIntOrDefault("version")
val appVersion = cache.getStringOrDefault("appVersion")

// class
val mainBottomTabItem = cache.getStringOrDefault("mainBottomTabItem")
val videoPinch = cache.getStringOrDefault("videoPinch")
val videoPagerAdapter = cache.getStringOrDefault("videoPagerAdapter")
val emojiPopupWindow = cache.getStringOrDefault("emojiPopupWindow")
val detailPageFragment = cache.getStringOrDefault("detailPageFragment")
val emojiApiProxy = cache.getStringOrDefault("emojiApiProxy")
val ripsChatRoomFragment = cache.getStringOrDefault("ripsChatRoomFragment")

if (appVersion.compareTo("${app.appVersionName}_${app.appVersionCode}") != 0) {
Expand All @@ -249,20 +254,25 @@ class DouYinMain(private val app: Application) {
videoPagerAdapterClazz = videoPagerAdapter.ifNotEmpty { lpparam.findClass(it) }
emojiPopupWindowClazz = emojiPopupWindow.ifNotEmpty { lpparam.findClass(it) }
detailPageFragmentClazz = detailPageFragment.ifNotEmpty { lpparam.findClass(it) }
emojiApiProxyClazz = emojiApiProxy.ifNotEmpty { lpparam.findClass(it) }
ripsChatRoomFragmentClazz = ripsChatRoomFragment.ifNotEmpty { lpparam.findClass(it) }

return true
}

private fun saveClassCache() {
val json = JSONObject().apply {
// version
put("version", "$classCacheVersion")
put("appVersion", "${app.appVersionName}_${app.appVersionCode}")

// class
put("mainBottomTabItem", mainBottomTabItemClazz?.name)
put("videoPinch", videoPinchClazz?.name)
put("videoPagerAdapter", videoPagerAdapterClazz?.name)
put("emojiPopupWindow", emojiPopupWindowClazz?.name)
put("detailPageFragment", detailPageFragmentClazz?.name)
put("emojiApiProxy", emojiApiProxyClazz?.name)
put("ripsChatRoomFragment", ripsChatRoomFragmentClazz?.name)
}
ConfigV1.get().classCache = json
Expand Down
44 changes: 23 additions & 21 deletions core/src/main/java/com/freegang/hook/HVerticalViewPager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,32 @@ class HVerticalViewPager(lpparam: XC_LoadPackage.LoadPackageParam) : BaseHook<Ve
) as? Aweme

//
durationRunnable?.run {
handler.removeCallbacks(this)
durationRunnable = null
}
durationRunnable = Runnable {
//
val delayItem = thisObject.methodInvokeFirst("getCurrentItem") as? Int ?: return@Runnable
if (delayItem == currentItem) {
return@Runnable
if (config.isLongtimeVideoToast) {
durationRunnable?.run {
handler.removeCallbacks(this)
durationRunnable = null
}

//
val delayAweme = adapter.methodInvokeFirst(
returnType = Aweme::class.java,
args = arrayOf(delayItem),
) as? Aweme
val duration = delayAweme?.duration ?: 0
if (duration >= 1000 * 60 * 3) {
val minute = duration / 1000 / 60
val second = duration / 1000 % 60
KToastUtils.show(thisView.context, "请注意, 本条视频时长${minute}${second}秒!")
durationRunnable = Runnable {
//
val delayItem = thisObject.methodInvokeFirst("getCurrentItem") as? Int ?: return@Runnable
if (delayItem == currentItem) {
return@Runnable
}

//
val delayAweme = adapter.methodInvokeFirst(
returnType = Aweme::class.java,
args = arrayOf(delayItem),
) as? Aweme
val duration = delayAweme?.duration ?: 0
if (duration >= 1000 * 60 * 10) {
val minute = duration / 1000 / 60
val second = duration / 1000 % 60
KToastUtils.show(thisView.context, "请注意, 本条视频时长${minute}${second}秒!")
}
}
handler.postDelayed(durationRunnable!!, 3000L)
}
handler.postDelayed(durationRunnable!!, 1000L)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import com.freegang.ui.asDp
import com.freegang.ui.component.FCard
import com.freegang.ui.component.FCardBorder
import com.freegang.ui.component.FMessageDialog
import com.freegang.ui.component.NeverOverScrollMode
import com.freegang.ui.viewmodel.FreedomSettingVM
import com.freegang.webdav.WebDav
import com.freegang.xpler.HookPackages
Expand Down Expand Up @@ -254,7 +255,9 @@ class FreedomSettingActivity : BaseActivity() {

@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class)
@Composable
private fun BodyView() {
private fun BodyView(
modifier: Modifier,
) {
// 版本更新弹窗
var showNewVersionDialog by remember { mutableStateOf(true) }
val version by model.versionConfig.observeAsState()
Expand Down Expand Up @@ -320,12 +323,9 @@ class FreedomSettingActivity : BaseActivity() {
}
}

Scaffold(
modifier = Modifier.padding(horizontal = 24.dp),
topBar = { TopBarView() }
) {
NeverOverScrollMode {
LazyColumn(
modifier = Modifier.padding(it),
modifier = modifier,
content = {
item {
// 选项
Expand Down Expand Up @@ -407,6 +407,14 @@ class FreedomSettingActivity : BaseActivity() {
model.changeIsDisableDoubleLike(it)
}
)
SwitchItem(
text = "视频时长超过10分钟提示",
subtext = "避免你die在厕所",
checked = model.isLongtimeVideoToast.observeAsState(false),
onCheckedChange = {
model.changeIsLongtimeVideoToast(it)
}
)
BoxWithConstraints {
// 加号按钮响应状态
var showIsDisablePhotoDialog by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -1172,7 +1180,14 @@ class FreedomSettingActivity : BaseActivity() {
super.onCreate(savedInstanceState)
setContent {
AutoTheme {
BodyView()
Scaffold(
modifier = Modifier.padding(horizontal = 24.dp),
topBar = { TopBarView() }
) {
BodyView(
modifier = Modifier.padding(it),
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.freegang.ui.component

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Indication
import androidx.compose.foundation.IndicationInstance
import androidx.compose.foundation.LocalOverscrollConfiguration
import androidx.compose.foundation.interaction.InteractionSource
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.drawscope.ContentDrawScope

// see at: https://blog.csdn.net/ly_xiamu/article/details/125830327
// see at: https://www.saoniuhuo.com/question/detail-2624369.html
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun NeverOverScrollMode(
content: @Composable () -> Unit,
) {
CompositionLocalProvider(
LocalOverscrollConfiguration provides null
) {
content()
}
}

object NoIndication : Indication {
private object NoIndicationInstance : IndicationInstance {
override fun ContentDrawScope.drawIndication() {
drawContent()
}
}

@Composable
override fun rememberUpdatedInstance(interactionSource: InteractionSource): IndicationInstance {
return NoIndicationInstance
}
}
10 changes: 10 additions & 0 deletions core/src/main/java/com/freegang/ui/viewmodel/FreedomSettingVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class FreedomSettingVM(application: Application) : AndroidViewModel(application)
private var _isDisableDoubleLike = MutableLiveData(false)
val isDisableDoubleLike: LiveData<Boolean> = _isDisableDoubleLike

private var _isLongtimeVideoToast = MutableLiveData(false)
val isLongtimeVideoToast: LiveData<Boolean> = _isLongtimeVideoToast

private var _isHidePhotoButton = MutableLiveData(false)
val isDHidePhotoButton: LiveData<Boolean> = _isHidePhotoButton

Expand Down Expand Up @@ -123,6 +126,7 @@ class FreedomSettingVM(application: Application) : AndroidViewModel(application)
changeIsTranslucent(config.isTranslucent)
changeIsNeatMode(config.isNeatMode)
changeIsDisableDoubleLike(config.isDisableDoubleLike)
changeIsLongtimeVideoToast(config.isLongtimeVideoToast)
changeIsHidePhotoButton(config.isHidePhotoButton)
changeIsDisablePhotoButton(config.isDisablePhotoButton)
changeIsVideoFilter(config.isVideoFilter)
Expand Down Expand Up @@ -181,6 +185,12 @@ class FreedomSettingVM(application: Application) : AndroidViewModel(application)
config.isDisableDoubleLike = value
}

// 视频时长超过5分钟提示
fun changeIsLongtimeVideoToast(value: Boolean) {
_isLongtimeVideoToast.value = value
config.isLongtimeVideoToast = value
}

// 隐藏底部加号按钮
fun changeIsHidePhotoButton(value: Boolean) {
_isHidePhotoButton.value = value
Expand Down

0 comments on commit a6b1c3f

Please sign in to comment.