Skip to content

Commit 7373ac0

Browse files
committed
fix: address PR review comments
- Refactor FontSizeUtil to reduce code duplication by extracting common helper method - Change layout margin from 8dp to 2dp as requested - Adjust line spacing multiplier from 1.3 to 1.1 for better readability Addresses feedback from Copilot and @graycreate in PR #131
1 parent 92684fa commit 7373ac0

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

app/src/main/java/me/ghui/v2er/util/FontSizeUtil.java

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,60 @@
66

77
public class FontSizeUtil {
88

9-
public static float getContentSize() {
9+
/**
10+
* Common helper method to get font dimension based on size preference
11+
* @param smallDimen dimension resource for "小" size
12+
* @param mediumDimen dimension resource for "中" size (default)
13+
* @param largeDimen dimension resource for "大" size
14+
* @param extraLargeDimen dimension resource for "特大" size
15+
* @return font size in pixels
16+
*/
17+
private static float getFontSizeForPreference(int smallDimen, int mediumDimen,
18+
int largeDimen, int extraLargeDimen) {
1019
String size = Pref.read(R.string.pref_key_fontsize);
1120
int id;
1221
switch (size) {
1322
case "小":
14-
id = R.dimen.smallTextSize;
23+
id = smallDimen;
1524
break;
1625
case "大":
17-
id = R.dimen.largeTextSize;
26+
id = largeDimen;
1827
break;
1928
case "特大":
20-
id = R.dimen.extralargeTextSize;
29+
id = extraLargeDimen;
2130
break;
2231
case "中":
2332
default:
24-
id = R.dimen.mediumTextSize;
33+
id = mediumDimen;
2534
}
2635
return App.get().getResources().getDimension(id);
2736
}
2837

38+
public static float getContentSize() {
39+
return getFontSizeForPreference(
40+
R.dimen.smallTextSize,
41+
R.dimen.mediumTextSize,
42+
R.dimen.largeTextSize,
43+
R.dimen.extralargeTextSize
44+
);
45+
}
46+
2947
public static float getTitleSize() {
30-
String size = Pref.read(R.string.pref_key_fontsize);
31-
int id;
32-
switch (size) {
33-
case "小":
34-
id = R.dimen.smallTextSize;
35-
break;
36-
case "大":
37-
id = R.dimen.largeTextSize;
38-
break;
39-
case "特大":
40-
id = R.dimen.extralargeTextSize;
41-
break;
42-
case "中":
43-
default:
44-
id = R.dimen.mediumTextSize;
45-
}
46-
return App.get().getResources().getDimension(id);
48+
return getFontSizeForPreference(
49+
R.dimen.smallTextSize,
50+
R.dimen.mediumTextSize,
51+
R.dimen.largeTextSize,
52+
R.dimen.extralargeTextSize
53+
);
4754
}
4855

4956
public static float getSubTextSize() {
50-
String size = Pref.read(R.string.pref_key_fontsize);
51-
int id;
52-
switch (size) {
53-
case "小":
54-
id = R.dimen.microTextSize;
55-
break;
56-
case "大":
57-
id = R.dimen.mediumTextSize;
58-
break;
59-
case "特大":
60-
id = R.dimen.largeTextSize;
61-
break;
62-
case "中":
63-
default:
64-
id = R.dimen.smallTextSize;
65-
}
66-
return App.get().getResources().getDimension(id);
57+
return getFontSizeForPreference(
58+
R.dimen.microTextSize,
59+
R.dimen.smallTextSize,
60+
R.dimen.mediumTextSize,
61+
R.dimen.largeTextSize
62+
);
6763
}
6864

6965
public static float getHtmlFontSize() {

app/src/main/res/layout/common_list_item.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
android:id="@+id/title_tv"
1414
style="@style/TopicTitle"
1515
android:layout_below="@id/time_tv"
16-
android:layout_marginTop="8dp"
16+
android:layout_marginTop="2dp"
1717
tools:text="[macOS]有人用 magnet 分屏的吗?好像有会导致系统卡顿的奇怪是的呵呵,里" />
1818

1919
<de.hdodenhof.circleimageview.CircleImageView

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<item name="android:textSize">@dimen/mediumTextSize</item>
135135
<item name="android:textStyle">normal</item>
136136
<item name="android:paddingTop">6dp</item>
137-
<item name="android:lineSpacingMultiplier">1.3</item>
137+
<item name="android:lineSpacingMultiplier">1.1</item>
138138
<!--<item name="android:transitionName">@string/share_element_topic_title</item>-->
139139
</style>
140140

0 commit comments

Comments
 (0)