Skip to content

Commit 2fb19fa

Browse files
authored
Patch/250528 (#244)
1. Android打包仅保留中文简体繁体、英文 2. 登录页微调,自动滚动到协议选框 3. 修正下一节课小部件配置解析问题 4. 自定义皮肤取消选择不弹出报错
1 parent a27ff4e commit 2fb19fa

File tree

12 files changed

+94
-43
lines changed

12 files changed

+94
-43
lines changed

app/(guest)/academic-login.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Stack } from 'expo-router';
22
import { useCallback, useEffect, useRef, useState } from 'react';
3-
import { Alert, Image, Linking, Platform, StyleSheet, TouchableOpacity, View } from 'react-native';
3+
import { Alert, Image, Linking, Platform, ScrollView, StyleSheet, TouchableOpacity, View } from 'react-native';
44
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller';
55
import { SafeAreaView } from 'react-native-safe-area-context';
66
import { toast } from 'sonner-native';
@@ -26,6 +26,7 @@ const URL_RESET_PASSWORD_POSTGRADUATE = 'https://yjsglxt.fzu.edu.cn/ResetPasswor
2626

2727
const LoginPage: React.FC = () => {
2828
const loginRef = useRef<UserLogin | null>(null);
29+
const scrollViewRef = useRef<ScrollView>(null);
2930
const redirect = useRedirectWithoutHistory();
3031
if (!loginRef.current) {
3132
loginRef.current = new UserLogin();
@@ -89,6 +90,7 @@ const LoginPage: React.FC = () => {
8990
const handleLogin = useCallback(async () => {
9091
if (!isAgree) {
9192
toast.error('请先阅读并同意服务协议和隐私政策');
93+
scrollViewRef.current?.scrollToEnd();
9294
return;
9395
}
9496
// 研究生不需要输入验证码
@@ -158,6 +160,7 @@ const LoginPage: React.FC = () => {
158160
className="h-full"
159161
contentContainerStyle={styles.scrollViewContent}
160162
keyboardShouldPersistTaps="handled"
163+
ref={scrollViewRef}
161164
>
162165
<View className="flex-1 justify-between px-6 py-3">
163166
{/* 左上角标题 */}
@@ -221,14 +224,9 @@ const LoginPage: React.FC = () => {
221224

222225
{/* 其他操作 */}
223226
<View className="w-full flex-row justify-between px-2">
224-
<TouchableOpacity
225-
className="flex-row items-center"
226-
onPress={() => setIsPostGraduate(!isPostGraduate)}
227-
activeOpacity={0.5}
228-
>
229-
<Checkbox checked={isPostGraduate} onCheckedChange={setIsPostGraduate} />
230-
<Text className="text-center text-text-secondary">{' '}我是研究生</Text>
231-
</TouchableOpacity>
227+
<Text className="text-center text-text-secondary" onPress={() => setIsPostGraduate(!isPostGraduate)}>
228+
{isPostGraduate ? '本科生登录' : '研究生登录'}
229+
</Text>
232230
<Text className="text-primary" onPress={openResetPassword}>
233231
忘记密码
234232
</Text>

app/(guest)/sso-login.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AsyncStorage from '@react-native-async-storage/async-storage';
22
import { Stack, router, useFocusEffect } from 'expo-router';
33
import { useCallback, useRef, useState } from 'react';
4-
import { Alert, Linking, StyleSheet, TouchableOpacity, View } from 'react-native';
4+
import { Alert, Linking, ScrollView, StyleSheet, TouchableOpacity, View } from 'react-native';
55
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller';
66
import { SafeAreaView } from 'react-native-safe-area-context';
77
import { toast } from 'sonner-native';
@@ -41,6 +41,7 @@ const UnifiedLoginPage: React.FC = () => {
4141
const ymtLogin = useRef<YMTLogin | null>(null);
4242
const ssoLogin = useRef<SSOLogin | null>(null);
4343
const isStoredSSOUser = useRef(false);
44+
const scrollViewRef = useRef<ScrollView>(null);
4445

4546
if (!ymtLogin.current) {
4647
ymtLogin.current = new YMTLogin();
@@ -56,9 +57,8 @@ const UnifiedLoginPage: React.FC = () => {
5657
if (storedSSOUser) {
5758
const SSOUser = JSON.parse(storedSSOUser) as SSOUser;
5859
setAccount(SSOUser.account);
59-
setAccountPassword(SSOUser.password);
60+
// setAccountPassword(SSOUser.password);
6061
isStoredSSOUser.current = true;
61-
toast.success('检测到上次登录的账号,已自动填充');
6262
}
6363
};
6464
getSSOUser();
@@ -139,6 +139,7 @@ const UnifiedLoginPage: React.FC = () => {
139139
const handleLogin = useCallback(async () => {
140140
if (!isAgree) {
141141
toast.error('请先阅读并同意服务协议和隐私政策');
142+
scrollViewRef.current?.scrollToEnd();
142143
return;
143144
}
144145
if (!account) {
@@ -177,6 +178,7 @@ const UnifiedLoginPage: React.FC = () => {
177178
className="h-full"
178179
contentContainerStyle={styles.scrollViewContent}
179180
keyboardShouldPersistTaps="handled"
181+
ref={scrollViewRef}
180182
>
181183
<View className="flex-1 justify-between px-6 py-3">
182184
{/* 左上角标题 */}

app/settings/appearance.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export default function AppearancePage() {
7878
})
7979
.catch(err => {
8080
console.log('error', err);
81+
if (err.code === 'E_PICKER_CANCELLED') {
82+
return;
83+
}
8184
toast.error('设置失败:' + err);
8285
});
8386
}, [redirect]);

inject-android-config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ function withAndroidBuildConfig(config: ExpoConfig): ExpoConfig {
7070
'versionCode 700001',
7171
'versionCode ' + extractVersionNumber(contents) + getCommitCountString(),
7272
);
73+
// 保留指定语言,缩减包大小
74+
contents = insertAfter(
75+
contents,
76+
'defaultConfig {',
77+
`
78+
resourceConfigurations += ['zh', 'zh-rCN', 'zh-rTW', 'en']`,
79+
);
7380
config.modResults.contents = contents;
7481
return config;
7582
});

modules/native-widget/android/src/main/java/com/helper/west2ol/fzuhelper/CourseScheduleWidgetConfigurationActivity.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ class CourseScheduleWidgetConfigurationActivity : AppCompatActivity() {
4848
0 -> {
4949
binding.foregroundAlphaSeekbar.isEnabled = false
5050
binding.foregroundAlphaSeekbar.progress = 100
51-
saveWidgetConfig(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", binding.foregroundAlphaSeekbar.progress)
51+
putInt(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", binding.foregroundAlphaSeekbar.progress)
5252
}
5353
1 -> binding.foregroundAlphaSeekbar.isEnabled = true
5454
2 ->{
5555
binding.foregroundAlphaSeekbar.isEnabled = false
5656
binding.foregroundAlphaSeekbar.progress = binding.backgroundAlphaSeekbar.progress
57-
saveWidgetConfig(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", binding.backgroundAlphaSeekbar.progress)
57+
putInt(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", binding.backgroundAlphaSeekbar.progress)
5858
}
5959
}
60-
saveWidgetConfig(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha_mode", position)
60+
putInt(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha_mode", position)
6161
val appWidgetManager = AppWidgetManager.getInstance(this@CourseScheduleWidgetConfigurationActivity)
6262
updateCourseScheduleWidget(this@CourseScheduleWidgetConfigurationActivity, appWidgetManager, appWidgetId)
6363
}
@@ -70,7 +70,7 @@ class CourseScheduleWidgetConfigurationActivity : AppCompatActivity() {
7070
}
7171
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
7272
override fun onStopTrackingTouch(seekBar: SeekBar?) {
73-
saveWidgetConfig(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", seekBar!!.progress)
73+
putInt(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", seekBar!!.progress)
7474
val appWidgetManager = AppWidgetManager.getInstance(this@CourseScheduleWidgetConfigurationActivity)
7575
updateCourseScheduleWidget(this@CourseScheduleWidgetConfigurationActivity, appWidgetManager, appWidgetId)
7676
}
@@ -86,17 +86,17 @@ class CourseScheduleWidgetConfigurationActivity : AppCompatActivity() {
8686
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
8787
override fun onStopTrackingTouch(seekBar: SeekBar?) {
8888
if (binding.foregroundAlphaSpinner.selectedItemPosition == 2) {
89-
saveWidgetConfig(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", seekBar!!.progress)
89+
putInt(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "foreground_alpha", seekBar!!.progress)
9090
}
91-
saveWidgetConfig(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "background_alpha", seekBar!!.progress)
91+
putInt(this@CourseScheduleWidgetConfigurationActivity, appWidgetId, "background_alpha", seekBar!!.progress)
9292
val appWidgetManager = AppWidgetManager.getInstance(this@CourseScheduleWidgetConfigurationActivity)
9393
updateCourseScheduleWidget(this@CourseScheduleWidgetConfigurationActivity, appWidgetManager, appWidgetId)
9494
}
9595
})
9696

97-
binding.foregroundAlphaSpinner.setSelection(loadWidgetConfig(this, appWidgetId, "foreground_alpha_mode", 0))
98-
binding.backgroundAlphaSeekbar.progress = loadWidgetConfig(this, appWidgetId, "background_alpha", 80)
99-
binding.foregroundAlphaSeekbar.progress = loadWidgetConfig(this, appWidgetId, "foreground_alpha", 100)
97+
binding.foregroundAlphaSpinner.setSelection(getInt(this, appWidgetId, "foreground_alpha_mode", 0))
98+
binding.backgroundAlphaSeekbar.progress = getInt(this, appWidgetId, "background_alpha", 80)
99+
binding.foregroundAlphaSeekbar.progress = getInt(this, appWidgetId, "foreground_alpha", 100)
100100
binding.backgroundAlphaText.text = "${binding.backgroundAlphaSeekbar.progress}%"
101101
binding.foregroundAlphaText.text = "${binding.foregroundAlphaSeekbar.progress}%"
102102

modules/native-widget/android/src/main/java/com/helper/west2ol/fzuhelper/CourseScheduleWidgetProvider.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import com.west2online.nativewidget.BuildConfig
1313
import com.west2online.nativewidget.R
1414

1515
open class CourseScheduleWidgetProvider : AppWidgetProvider() {
16-
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
16+
override fun onUpdate(
17+
context: Context,
18+
appWidgetManager: AppWidgetManager,
19+
appWidgetIds: IntArray
20+
) {
1721
appWidgetIds.filter {
1822
appWidgetManager.getAppWidgetIds(ComponentName(context, this::class.java)).contains(it)
1923
}.forEach {
@@ -56,8 +60,16 @@ internal fun updateCourseScheduleWidget(
5660
setRemoteAdapter(R.id.list_view, intent2)
5761
setOnClickPendingIntent(R.id.container, pendingIntent)
5862
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
59-
setFloat(R.id.top_shadow, "setAlpha", loadWidgetConfig(context, appWidgetId, "background_alpha",80)/100.0f)
60-
setFloat(R.id.container, "setAlpha", loadWidgetConfig(context, appWidgetId, "foreground_alpha",100)/100.0f)
63+
setFloat(
64+
R.id.top_shadow,
65+
"setAlpha",
66+
getInt(context, appWidgetId, "background_alpha", 80) / 100.0f
67+
)
68+
setFloat(
69+
R.id.container,
70+
"setAlpha",
71+
getInt(context, appWidgetId, "foreground_alpha", 100) / 100.0f
72+
)
6173
}
6274
}
6375
appWidgetManager.updateAppWidget(appWidgetId, views)

modules/native-widget/android/src/main/java/com/helper/west2ol/fzuhelper/NextClassWidgetConfigurationActivity.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ class NextClassWidgetConfigurationActivity : AppCompatActivity() {
3131
return
3232
}
3333

34+
doConfigMigration(this, appWidgetId)
35+
3436
binding.showLastUpdateTimeSwitch.setOnClickListener {
35-
saveWidgetConfig(
37+
putBoolean(
3638
this,
3739
appWidgetId,
3840
"showLastUpdateTime",
39-
if(binding.showLastUpdateTimeSwitch.isChecked) 1 else 0
41+
binding.showLastUpdateTimeSwitch.isChecked
4042
)
4143

4244
val appWidgetManager = AppWidgetManager.getInstance(this)
@@ -54,20 +56,20 @@ class NextClassWidgetConfigurationActivity : AppCompatActivity() {
5456
.show()
5557
return@setOnClickListener
5658
}
57-
saveWidgetConfig(
59+
putBoolean(
5860
this,
5961
appWidgetId,
6062
"showAsSquare",
61-
if(binding.showAsSquareSwitch.isChecked)1 else 0
63+
binding.showAsSquareSwitch.isChecked
6264
)
6365

6466
val appWidgetManager = AppWidgetManager.getInstance(this)
6567
updateNextClassWidget(this, appWidgetManager, appWidgetId)
6668
}
6769

6870
binding.showLastUpdateTimeSwitch.isChecked =
69-
loadWidgetConfig(this, appWidgetId, "showLastUpdateTime",0) == 1
70-
binding.showAsSquareSwitch.isChecked = loadWidgetConfig(this, appWidgetId, "showAsSquare",0) == 1
71+
getBoolean(this, appWidgetId, "showLastUpdateTime", false)
72+
binding.showAsSquareSwitch.isChecked = getBoolean(this, appWidgetId, "showAsSquare", false)
7173

7274
binding.refreshData.setOnClickListener {
7375
val appWidgetManager = AppWidgetManager.getInstance(this)

modules/native-widget/android/src/main/java/com/helper/west2ol/fzuhelper/NextClassWidgetProvider.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ internal fun updateNextClassWidget(
5656
appWidgetManager: AppWidgetManager,
5757
appWidgetId: Int
5858
) {
59+
doConfigMigration(context, appWidgetId)
60+
5961
val views = RemoteViews(context.packageName, R.layout.next_class_widget_provider)
6062

6163
val refreshIntent = Intent(context, NextClassWidgetProvider::class.java).apply {
@@ -135,7 +137,7 @@ internal fun updateNextClassWidget(
135137
setTextViewText(R.id.course_week, null)
136138
}
137139

138-
if (loadWidgetConfig(context, appWidgetId, "showLastUpdateTime",0)==1) {
140+
if (getBoolean(context, appWidgetId, "showLastUpdateTime", false)) {
139141
val currentDateTime = Calendar.getInstance()
140142
val sdf = SimpleDateFormat("MM-dd HH:mm", Locale.PRC)
141143
val formattedDate = sdf.format(currentDateTime.time)
@@ -145,12 +147,12 @@ internal fun updateNextClassWidget(
145147
}
146148

147149
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
148-
if (loadWidgetConfig(
150+
if (getBoolean(
149151
context,
150152
appWidgetId,
151153
"showAsSquare",
152-
0
153-
)==1
154+
false
155+
)
154156
) {
155157
val options = appWidgetManager.getAppWidgetOptions(appWidgetId)
156158
val minWidth =

modules/native-widget/android/src/main/java/com/helper/west2ol/fzuhelper/WidgetUtils.kt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,22 @@ fun getSharedPreference(context: Context): SharedPreferences {
6060
return context.getSharedPreferences("${context.packageName}.widgetdata", Context.MODE_PRIVATE)
6161
}
6262

63-
fun saveWidgetConfig(context: Context, appWidgetId: Int, key: String, value: Int) {
64-
getSharedPreference(context).edit().putInt("$appWidgetId$key", value).commit()
63+
fun getBoolean(context: Context, appWidgetId: Int, key: String, defaultValue: Boolean): Boolean {
64+
return getSharedPreference(context).getBoolean("$appWidgetId$key", defaultValue)
65+
}
66+
67+
fun putBoolean(context: Context, appWidgetId: Int, key: String, value: Boolean) {
68+
getSharedPreference(context).edit().putBoolean("$appWidgetId$key", value).commit()
6569
}
6670

67-
fun loadWidgetConfig(context: Context, appWidgetId: Int, key: String, defaultValue: Int): Int {
71+
fun getInt(context: Context, appWidgetId: Int, key: String, defaultValue: Int): Int {
6872
return getSharedPreference(context).getInt("$appWidgetId$key", defaultValue)
6973
}
7074

75+
fun putInt(context: Context, appWidgetId: Int, key: String, value: Int) {
76+
getSharedPreference(context).edit().putInt("$appWidgetId$key", value).commit()
77+
}
78+
7179
fun deleteWidgetConfig(context: Context, appWidgetId: Int, key: String) {
7280
getSharedPreference(context).edit().remove("$appWidgetId$key").commit()
7381
}
@@ -85,3 +93,20 @@ fun getCourseBeans(cacheCourseData: CacheCourseData): List<ExtendCourse> = try {
8593
Log.e("NextClassWidgetProvider", "Failed to load widget data", e)
8694
emptyList()
8795
}
96+
97+
/**
98+
* 将部分Int值迁移到Boolean,修正由于数据类型变化导致的解析问题
99+
*/
100+
fun doConfigMigration(context: Context, widgetId: Int) {
101+
arrayOf("showLastUpdateTime", "showAsSquare").forEach { key ->
102+
try {
103+
getInt(context, widgetId, key, -1).let { value ->
104+
// -1 代表未曾写入
105+
if (value != -1) {
106+
putBoolean(context, widgetId, key, value == 1)
107+
}
108+
}
109+
} catch (_: Exception) {
110+
}
111+
}
112+
}

modules/native-widget/android/src/main/res/layout/next_class_widget_configuration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
android:layout_height="wrap_content"
1818
android:layout_marginHorizontal="20dp"
1919
android:height="50dp"
20-
android:text="显示刷新与更新时间"
20+
android:text="显示更新时间与刷新"
2121
android:textSize="16sp" />
2222

2323
<androidx.appcompat.widget.SwitchCompat

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"react-native-gesture-handler": "~2.22.0",
9191
"react-native-image-crop-picker": "^0.42.0",
9292
"react-native-image-zoom-viewer": "^3.0.1",
93-
"react-native-keyboard-controller": "^1.15.2",
93+
"react-native-keyboard-controller": "^1.17.3",
9494
"react-native-mime-types": "^2.5.0",
9595
"react-native-pager-view": "^6.7.0",
9696
"react-native-permissions": "^5.3.0",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9214,10 +9214,10 @@ react-native-is-edge-to-edge@^1.1.6:
92149214
resolved "https://registry.yarnpkg.com/react-native-is-edge-to-edge/-/react-native-is-edge-to-edge-1.1.6.tgz#69ec13f70d76e9245e275eed4140d0873a78f902"
92159215
integrity sha512-1pHnFTlBahins6UAajXUqeCOHew9l9C2C8tErnpGC3IyLJzvxD+TpYAixnCbrVS52f7+NvMttbiSI290XfwN0w==
92169216

9217-
react-native-keyboard-controller@^1.15.2:
9218-
version "1.16.1"
9219-
resolved "https://registry.yarnpkg.com/react-native-keyboard-controller/-/react-native-keyboard-controller-1.16.1.tgz#d0a830a2dfba95622fc52c72c89cc3afd88fdfa9"
9220-
integrity sha512-6Yynx9P+/bzpbYvi5eNZ7FQadm5ZyXpUiXHjaUGQP0KQQGSPpS4CohpLhDZ5z5mqkU2QeJmUzMzGPF+q6MjNfw==
9217+
react-native-keyboard-controller@^1.17.3:
9218+
version "1.17.3"
9219+
resolved "https://registry.npmjs.org/react-native-keyboard-controller/-/react-native-keyboard-controller-1.17.3.tgz#db3d8dd43acb355b3d1d5fa88c0166d95b0912e5"
9220+
integrity sha512-e17P/+Wu1rcVN+F5fkqWyq7oX7pf0LT+tZPwWJQyF3CN9X0EOtbSfoGazsjagt0BnIXDCGYFqQG8Xf39y8+szg==
92219221
dependencies:
92229222
react-native-is-edge-to-edge "^1.1.6"
92239223

0 commit comments

Comments
 (0)