Skip to content

Commit e716f4e

Browse files
authored
Merge pull request #24 from gx-bangsong/fix-preference-and-resource-crashes-14528928520064845018
Fix Runtime Crashes: Preference NPEs and Resource Mismatches
2 parents 0729398 + f18583b commit e716f4e

18 files changed

Lines changed: 34153 additions & 27 deletions

‎app/build.gradle‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ android {
66
compileSdk = 35
77

88
defaultConfig {
9+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
910
applicationId = "com.best.deskclock"
1011
minSdk = 23
1112
targetSdk = 35
@@ -71,7 +72,9 @@ android {
7172
}
7273

7374
lintOptions {
74-
abortOnError = false
75+
baseline file("lint-baseline.xml")
76+
abortOnError true
77+
fatal "InconsistentArrays"
7578
}
7679

7780
compileOptions {
@@ -94,6 +97,11 @@ android {
9497
}
9598

9699
dependencies {
100+
androidTestImplementation "androidx.test.ext:junit:1.2.1"
101+
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
102+
androidTestImplementation "androidx.test:runner:1.6.1"
103+
androidTestImplementation "androidx.test:rules:1.6.1"
104+
androidTestImplementation "androidx.test.espresso:espresso-intents:3.6.1"
97105
// Room components
98106
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
99107
annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"

‎app/lint-baseline.xml‎

Lines changed: 32794 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.best.deskclock.settings;
2+
3+
import static androidx.test.espresso.Espresso.onView;
4+
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
5+
import static androidx.test.espresso.matcher.ViewMatchers.withText;
6+
import static androidx.test.espresso.assertion.ViewAssertions.matches;
7+
8+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
9+
import androidx.test.ext.junit.runners.AndroidJUnit4;
10+
import androidx.test.filters.LargeTest;
11+
12+
import com.best.deskclock.DeskClock;
13+
import com.best.deskclock.R;
14+
15+
import org.junit.Rule;
16+
import org.junit.Test;
17+
import org.junit.runner.RunWith;
18+
19+
@LargeTest
20+
@RunWith(AndroidJUnit4.class)
21+
public class SettingsSmokeTest {
22+
23+
@Rule
24+
public ActivityScenarioRule<DeskClock> mActivityScenarioRule =
25+
new ActivityScenarioRule<>(DeskClock.class);
26+
27+
@Test
28+
public void testAppLaunches() {
29+
// Just verify DeskClock launches and displays the "Clock" tab or similar
30+
onView(withText(R.string.menu_clock)).check(matches(isDisplayed()));
31+
}
32+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
3+
package com.best.deskclock.settings.custompreference;
4+
5+
import android.content.Context;
6+
import android.util.AttributeSet;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.annotation.Nullable;
10+
import androidx.preference.ListPreference;
11+
import androidx.preference.PreferenceViewHolder;
12+
13+
import com.best.deskclock.R;
14+
15+
/**
16+
* A {@link ListPreference} with a custom Material-style layout.
17+
*
18+
* <p>This class applies a custom card-based appearance to the preference row
19+
* and updates its typography and visual styling based on the user's settings
20+
* (font, card background, card border, etc.).</p>
21+
*
22+
* <p>The preference behavior remains identical to a standard {@link ListPreference};
23+
* only its visual presentation is customized.</p>
24+
*/
25+
public class CustomListPreference extends ListPreference {
26+
27+
public CustomListPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
28+
super(context, attrs);
29+
setLayoutResource(R.layout.settings_preference_layout);
30+
}
31+
32+
@Override
33+
public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
34+
PreferenceStyler.apply(holder);
35+
super.onBindViewHolder(holder);
36+
}
37+
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
3+
package com.best.deskclock.settings.custompreference;
4+
5+
import android.content.Context;
6+
import android.util.AttributeSet;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.annotation.Nullable;
10+
import androidx.preference.Preference;
11+
import androidx.preference.PreferenceViewHolder;
12+
13+
import com.best.deskclock.R;
14+
15+
/**
16+
* A {@link Preference} with a custom Material-style layout.
17+
*
18+
* <p>This class applies a custom card-based appearance to the preference row
19+
* and updates its typography and visual styling based on the user's settings
20+
* (font, card background, card border, etc.).</p>
21+
*
22+
* <p>The preference behavior remains identical to a standard {@link Preference};
23+
* only its visual presentation is customized.</p>
24+
*/
25+
public class CustomPreference extends Preference {
26+
27+
public CustomPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
28+
super(context, attrs);
29+
setLayoutResource(R.layout.settings_preference_layout);
30+
}
31+
32+
@Override
33+
public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
34+
PreferenceStyler.apply(holder);
35+
super.onBindViewHolder(holder);
36+
}
37+
38+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.best.deskclock.settings.custompreference;
2+
3+
import static com.best.deskclock.DeskClockApplication.getDefaultSharedPreferences;
4+
5+
import android.content.Context;
6+
import android.content.SharedPreferences;
7+
import android.util.AttributeSet;
8+
import android.widget.TextView;
9+
10+
import androidx.annotation.NonNull;
11+
import androidx.annotation.Nullable;
12+
import androidx.preference.PreferenceCategory;
13+
import androidx.preference.PreferenceViewHolder;
14+
15+
import com.best.deskclock.R;
16+
import com.best.deskclock.data.SettingsDAO;
17+
import com.best.deskclock.utils.ThemeUtils;
18+
19+
/**
20+
* A {@link PreferenceCategory} with a custom layout.
21+
*
22+
* <p>This class updates its typography and visual styling based on the user's settings
23+
* (font, accent color, etc.).</p>
24+
*
25+
* <p>The preference behavior remains identical to a standard {@link PreferenceCategory};
26+
* only its visual presentation is customized.</p>
27+
*/
28+
public class CustomPreferenceCategory extends PreferenceCategory {
29+
30+
public CustomPreferenceCategory(@NonNull Context context, @Nullable AttributeSet attrs) {
31+
super(context, attrs);
32+
setLayoutResource(R.layout.settings_preference_category_layout);
33+
}
34+
35+
@Override
36+
public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
37+
if (holder.itemView.isInEditMode()) {
38+
// Skip logic during Android Studio preview
39+
return;
40+
}
41+
42+
super.onBindViewHolder(holder);
43+
44+
SharedPreferences prefs = getDefaultSharedPreferences(getContext());
45+
46+
TextView prefTitle = (TextView) holder.findViewById(android.R.id.title);
47+
prefTitle.setTypeface(ThemeUtils.boldTypeface(SettingsDAO.getGeneralFont(prefs)));
48+
}
49+
}

0 commit comments

Comments
 (0)