Skip to content

Commit 0faaf07

Browse files
committed
fix(net): Fix time formatting anomalies
1 parent f53a0e1 commit 0faaf07

File tree

10 files changed

+116
-34
lines changed

10 files changed

+116
-34
lines changed

.github/workflows/android-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
# KEY_PASSWORD: ${{ secrets.SIGN_KEY_PASSWORD }}
4444

4545
- name: Upload APK
46-
uses: actions/upload-artifact@v4.6.2
46+
uses: actions/upload-artifact@v5
4747
with:
4848
name: TimTool-unsign.apk
4949
path: ./app/build/outputs/apk/release/*.apk

app/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
2-
3-
import top.sacz.buildplugin.BuildVersionConfig
41
import com.google.protobuf.gradle.proto
2+
import top.sacz.buildplugin.BuildVersionConfig
53

64
plugins {
75
alias(libs.plugins.android.application)
@@ -67,7 +65,7 @@ android {
6765
"--package-id", "0x42"
6866
)
6967
}
70-
68+
7169
buildFeatures {
7270
viewBinding = true
7371
}
@@ -114,10 +112,12 @@ dependencies {
114112
//常用
115113
implementation(libs.okhttp3)
116114
implementation(libs.retrofit2)
117-
implementation(libs.squareup.retrofit.converter.gson)
118115
implementation(libs.glide)
119116
implementation(libs.fastkv)
120117
implementation(libs.fastjson2)
118+
implementation(libs.fastjson2.kotlin)
119+
implementation(libs.kotlin.stdlib)
120+
implementation(libs.kotlin.reflect)
121121
implementation(libs.base.recyclerview.helper)
122122

123123
//dialogx

app/src/main/java/top/sacz/timtool/net/HttpClient.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package top.sacz.timtool.net;
22

3-
import com.google.gson.Gson;
4-
import com.google.gson.GsonBuilder;
3+
54

65
import okhttp3.OkHttpClient;
76
import retrofit2.Retrofit;
8-
import retrofit2.converter.gson.GsonConverterFactory;
97
import top.sacz.timtool.net.api.PayApi;
108
import top.sacz.timtool.net.api.UpdateApi;
119
import top.sacz.timtool.net.api.UserApi;
@@ -21,7 +19,7 @@
2119
*/
2220
public class HttpClient {
2321

24-
public static final String BASE_URL = "https://timtool.sacz.top";
22+
public static final String BASE_URL = "https://timtool.suzhelan.top";
2523

2624

2725
public static String createKey() {
@@ -68,11 +66,10 @@ public static PayApi getPayApi() {
6866
}
6967

7068
public static UpdateApi getUpdateApi() {
71-
Gson gson = new GsonBuilder().setLenient().create();
7269
return new Retrofit.Builder()
7370
.baseUrl(BASE_URL)
7471
.client(buildClient(false))
75-
.addConverterFactory(GsonConverterFactory.create(gson))
72+
.addConverterFactory(new FastJsonConverterFactory())
7673
.build()
7774
.create(UpdateApi.class);
7875
}

app/src/main/java/top/sacz/timtool/net/UpdateService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ class UpdateService {
174174
}
175175

176176

177-
}
177+
}

app/src/main/java/top/sacz/timtool/net/entity/Update.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package top.sacz.timtool.net.entity
22

3-
import java.util.Date
3+
import java.time.LocalDateTime
44

55
data class HasUpdate(
66
val hasUpdate: Boolean,
@@ -12,8 +12,8 @@ data class UpdateInfo(
1212
val fileName: String,
1313
val forceUpdate: Boolean,
1414
val id: Int,
15-
val time: Date,
15+
val time: LocalDateTime,
1616
val updateLog: String,
1717
val versionCode: Int,
1818
val versionName: String
19-
)
19+
)

app/src/main/java/top/sacz/timtool/net/entity/User.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.alibaba.fastjson2.JSON;
66

77
import java.io.Serializable;
8-
import java.util.Date;
8+
import java.time.LocalDateTime;
99

1010
public class User implements Serializable {
1111

@@ -19,9 +19,11 @@ public class User implements Serializable {
1919

2020
private String label;
2121

22-
private Date createTime;
22+
private LocalDateTime createTime;
2323

24-
private Date updateTime;
24+
private LocalDateTime updateTime;
25+
26+
public LocalDateTime sponsorEndDate;
2527

2628
/**
2729
* QQ
@@ -96,34 +98,42 @@ public void setLabel(String label) {
9698
/**
9799
* 创建时间
98100
*/
99-
public Date getCreateTime() {
101+
public LocalDateTime getCreateTime() {
100102
return createTime;
101103
}
102104

103105
/**
104106
* 创建时间
105107
*/
106-
public void setCreateTime(Date createTime) {
108+
public void setCreateTime(LocalDateTime createTime) {
107109
this.createTime = createTime;
108110
}
109111

110112
/**
111113
* 更新时间
112114
*/
113-
public Date getUpdateTime() {
115+
public LocalDateTime getUpdateTime() {
114116
return updateTime;
115117
}
116118

117119
/**
118120
* 更新时间
119121
*/
120-
public void setUpdateTime(Date updateTime) {
122+
public void setUpdateTime(LocalDateTime updateTime) {
121123
this.updateTime = updateTime;
122124
}
123125

126+
public LocalDateTime getSponsorEndDate() {
127+
return sponsorEndDate;
128+
}
129+
130+
public void setSponsorEndDate(LocalDateTime sponsorEndDate) {
131+
this.sponsorEndDate = sponsorEndDate;
132+
}
133+
124134
@NonNull
125135
@Override
126136
public String toString() {
127137
return JSON.toJSONString(this);
128138
}
129-
}
139+
}

app/src/main/java/top/sacz/timtool/ui/dialog/UpdateLogDialog.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import retrofit2.Call
55
import retrofit2.Callback
66
import retrofit2.Response
77
import top.sacz.timtool.R
8+
import top.sacz.timtool.hook.util.LogUtils
89
import top.sacz.timtool.hook.util.ToastTool
910
import top.sacz.timtool.net.HttpClient
1011
import top.sacz.timtool.net.entity.QSResult
1112
import top.sacz.timtool.net.entity.UpdateInfo
13+
import top.sacz.timtool.util.Log
1214
import top.sacz.timtool.util.TimeUtils
1315
import top.sacz.xphelper.util.ActivityTools
1416

@@ -54,8 +56,9 @@ class UpdateLogDialog {
5456
p0: Call<QSResult<List<UpdateInfo>>?>,
5557
p1: Throwable
5658
) {
59+
Log.e("update-log-dialog", p1)
5760
ToastTool.show(p1.message!!)
5861
}
5962
})
6063
}
61-
}
64+
}

app/src/main/java/top/sacz/timtool/util/TimeUtils.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package top.sacz.timtool.util;
22

33
import java.text.SimpleDateFormat;
4+
import java.time.LocalDateTime;
5+
import java.time.ZoneId;
6+
import java.time.format.DateTimeFormatter;
47
import java.util.Date;
58
import java.util.Locale;
69

@@ -29,4 +32,27 @@ public static String formatTime(long time, String pattern) {
2932
SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault());
3033
return format.format(time);
3134
}
32-
}
35+
36+
/**
37+
* 格式化LocalDateTime时间
38+
*/
39+
public static String formatTime(LocalDateTime dateTime) {
40+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
41+
return dateTime.format(formatter);
42+
}
43+
44+
/**
45+
* 格式化LocalDateTime时间
46+
*/
47+
public static String formatTime(LocalDateTime dateTime, String pattern) {
48+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
49+
return dateTime.format(formatter);
50+
}
51+
52+
/**
53+
* 将LocalDateTime转换为时间戳
54+
*/
55+
public static long toTimestamp(LocalDateTime dateTime) {
56+
return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
57+
}
58+
}

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ xphelper = "2.8"
3535

3636
# kotlin
3737
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
38+
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
39+
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
40+
3841
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutine" }
3942
androidx-lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
4043
androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "lifecycleLivedataKtx" }
@@ -47,6 +50,7 @@ material = { group = "com.google.android.material", name = "material", version.r
4750
#常用库
4851
fastkv = { group = 'io.github.billywei01', name = 'fastkv', version.ref = "fastkv" }
4952
fastjson2 = { module = "com.alibaba.fastjson2:fastjson2", version.ref = "fastjson2" }
53+
fastjson2-kotlin = { module = "com.alibaba.fastjson2:fastjson2-kotlin", version.ref = "fastjson2" }
5054
okhttp3 = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
5155
squareup-retrofit-converter-gson = { group = "com.squareup.retrofit2", name = "converter-gson", version.ref = "retrofit2" }
5256

libs/annotation-scanner/src/main/java/top/sacz/timtool/scanner/HookItemScanner.kt

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,67 @@ class HookItemScanner(
3535
val logger: KSPLogger
3636
) : SymbolProcessor {
3737

38+
companion object {
39+
/**
40+
* 不动
41+
*/
42+
private const val RETURN_TYPE_PACKAGE = "kotlin.collections"
43+
44+
/**
45+
* 不动
46+
*/
47+
private const val RETURN_TYPE_NAME = "List"
48+
49+
/**
50+
* Base类包名
51+
*/
52+
private const val BASE_CLASS_PACKAGE = "top.sacz.timtool.hook.base"
53+
54+
/**
55+
* Base类名
56+
*/
57+
private const val BASE_CLASS_NAME = "BaseHookItem"
58+
59+
/**
60+
* 生成的包名
61+
*/
62+
private const val GENERATED_PACKAGE = "top.sacz.timtool.hook.gen"
63+
64+
/**
65+
* 要扫描的字段
66+
*/
67+
private const val TARGET_ANNOTATION = "top.sacz.timtool.hook.core.annotation.HookItem"
68+
69+
/**
70+
* 生成的类名称
71+
* */
72+
private const val GENERATED_CLASS_NAME = "HookItemEntryList"
73+
74+
/**
75+
* 生成的方法名称
76+
*/
77+
private const val GENERATED_FUNCTION_NAME = "getAllHookItems"
78+
}
79+
3880
@OptIn(KspExperimental::class)
3981
override fun process(resolver: Resolver): List<KSAnnotated> {
4082
//获取被注解标记的类列表
4183
val symbols =
42-
resolver.getSymbolsWithAnnotation("top.sacz.timtool.hook.core.annotation.HookItem")
84+
resolver.getSymbolsWithAnnotation(TARGET_ANNOTATION)
4385
.filterIsInstance<KSClassDeclaration>()
4486
.toList()
4587
if (symbols.isEmpty()) return emptyList()
4688
//返回类型
47-
val returnType = ClassName("kotlin.collections", "List")
48-
//基😮类
49-
val genericsType = ClassName("top.sacz.timtool.hook.base", "BaseHookItem")
89+
val returnType = ClassName(RETURN_TYPE_PACKAGE, RETURN_TYPE_NAME)
90+
//基类
91+
val genericsType = ClassName(BASE_CLASS_PACKAGE, BASE_CLASS_NAME)
5092
//方法构建
51-
val methodBuilder = FunSpec.builder("getAllHookItems")
93+
val methodBuilder = FunSpec.builder(GENERATED_FUNCTION_NAME)
5294
methodBuilder.returns(returnType.parameterizedBy(genericsType))//泛型返回
5395
methodBuilder.addAnnotation(JvmStatic::class)//jvm静态方法
5496
methodBuilder.addCode(
5597
CodeBlock.Builder().apply {
56-
addStatement("val list = mutableListOf<BaseHookItem>()")
98+
addStatement("val list = mutableListOf<%T>()", genericsType)
5799
for (symbol in symbols) {
58100
val typeName = symbol.toClassName()
59101
//获取 hook item 注解
@@ -72,14 +114,14 @@ class HookItemScanner(
72114
)
73115

74116
//class
75-
val classSpec = TypeSpec.objectBuilder("HookItemEntryList")
117+
val classSpec = TypeSpec.objectBuilder(GENERATED_CLASS_NAME)
76118
.addFunction(methodBuilder.build())
77119
.build()
78120
val dependencies = Dependencies(true, *Array(symbols.size) {
79121
symbols[it].containingFile!!
80122
})
81123
//文件
82-
FileSpec.builder("top.sacz.timtool.hook.gen", "HookItemEntryList")
124+
FileSpec.builder(GENERATED_PACKAGE, GENERATED_CLASS_NAME)
83125
.addType(classSpec)
84126
.build()
85127
.writeTo(codeGenerator, dependencies)

0 commit comments

Comments
 (0)