Skip to content

Commit

Permalink
[mod] 优化时间旅行功能,避免列表多次加载导致时间一直后退
Browse files Browse the repository at this point in the history
  • Loading branch information
vitvm committed Nov 4, 2024
1 parent 061ef3f commit dc5409c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lu.wxmask.plugin.part

import android.content.Context
import android.graphics.Bitmap.Config
import android.util.TimeUtils
import android.view.View
import android.view.ViewGroup
import android.widget.ListAdapter
Expand All @@ -22,6 +23,7 @@ import com.lu.wxmask.plugin.WXMaskPlugin
import com.lu.wxmask.plugin.ui.MaskUtil
import com.lu.wxmask.util.AppVersionUtil
import com.lu.wxmask.util.ConfigUtil
import com.lu.wxmask.util.ext.format2DateText
import com.lu.wxmask.util.ext.getViewId
import de.robv.android.xposed.callbacks.XC_LoadPackage
import java.lang.reflect.Method
Expand All @@ -41,6 +43,8 @@ class HideMainUIListPluginPart : IPlugin {
else -> "m"
}

private val mUserTravelTimeTemp: MutableMap<String, Long> = mutableMapOf()

override fun handleHook(context: Context, lpparam: XC_LoadPackage.LoadPackageParam) {
runCatching {
handleMainUIChattingListView2(context, lpparam)
Expand Down Expand Up @@ -357,7 +361,12 @@ class HideMainUIListPluginPart : IPlugin {
if (option.enableTravelTime && option.travelTime != 0L) {
val cTime = XposedHelpers2.getObjectField<Any>(itemData, "field_conversationTime")
if (cTime is Long) {
XposedHelpers2.setObjectField(itemData, "field_conversationTime", cTime - option.travelTime)
if (mUserTravelTimeTemp[chatUser] != cTime) {//时间有变更,进行处理,没变更不用处理,避免列表多次加载导致时间不停后退
LogUtil.d("travel time change", chatUser, cTime.format2DateText(),"-->", mUserTravelTimeTemp[chatUser].format2DateText())
val nexTime = cTime - option.travelTime
XposedHelpers2.setObjectField(itemData, "field_conversationTime", nexTime)
mUserTravelTimeTemp[chatUser] = nexTime
}
}
}
// 恢复被置底的好友
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/lu/wxmask/util/ext/AnyX.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lu.wxmask.util.ext

import android.graphics.Color
import android.text.format.DateFormat
import android.widget.TextView
import com.google.gson.JsonObject
import com.lu.magic.util.AppUtil
Expand Down Expand Up @@ -109,4 +110,17 @@ fun TextView?.dayText2Mills(fallback : Long=0): Long {
} catch (e: Exception) {
}
return fallback
}

fun Long?.format2DateText(pattern:String="yyyy-MM-dd HH:mm:ss"): CharSequence {
return try {
if (this == null) {
""
} else {
DateFormat.format(pattern, this)
// java.text.SimpleDateFormat(pattern).format(this)
}
} catch (e: Exception) {
""
}
}
29 changes: 29 additions & 0 deletions loop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# 一些循环执行的命令定义,避免代码推拉不了。例如,你可以这样推送代码直到成功:
# ./loop.sh "git push"

#command="git push --set-upstream origin feature/dev_download"
#command="git push"
#输入的参数
command=$1
if [ -z "$command" ]; then
echo "Command is empty, please enter a command:"
read command
fi

# 开始循环执行命令
while true; do
# 执行命令并获取返回状态
eval $command
retval=$?

# 检查命令是否成功
if [ $retval -eq 0 ]; then
echo "Command executed successfully."
break
else
echo "Command failed with return code: $retval. Retrying..."
sleep 2 # 等待2秒后重试
fi
done

0 comments on commit dc5409c

Please sign in to comment.