Skip to content

Commit 810fa80

Browse files
committed
fix list summary updating after refactor
1 parent e193672 commit 810fa80

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/CustomDialogListPreference.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.widget.*;
1313

1414
import androidx.annotation.NonNull;
15+
import androidx.annotation.Nullable;
1516

1617
import app.revanced.extension.shared.Utils;
1718
import app.revanced.extension.shared.ui.CustomDialog;
@@ -43,6 +44,14 @@ public void setStaticSummary(String summary) {
4344
this.staticSummary = summary;
4445
}
4546

47+
/**
48+
* Returns the static summary if set, otherwise null.
49+
*/
50+
@Nullable
51+
public String getStaticSummary() {
52+
return staticSummary;
53+
}
54+
4655
/**
4756
* Always return static summary if set.
4857
*/

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/search/SearchResultItem.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ public CharSequence getCurrentEffectiveSummary() {
239239
originalSummary != null ? originalSummary : "")
240240
: (originalSummaryOff != null ? originalSummaryOff :
241241
originalSummary != null ? originalSummary : "");
242+
} else if (preference instanceof ListPreference listPref) {
243+
String value = listPref.getValue();
244+
CharSequence[] entries = listPref.getEntries();
245+
CharSequence[] entryValues = listPref.getEntryValues();
246+
if (value != null && entries != null && entryValues != null) {
247+
for (int i = 0; i < entryValues.length; i++) {
248+
if (value.equals(entryValues[i].toString())) {
249+
return entries[i] != null ? entries[i] : originalSummary != null ? originalSummary : "";
250+
}
251+
}
252+
}
253+
return originalSummary != null ? originalSummary : "";
242254
}
243255
return originalSummary != null ? originalSummary : "";
244256
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/search/SearchResultsAdapter.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import android.content.Context;
88
import android.os.Handler;
99
import android.os.Looper;
10-
import android.preference.Preference;
11-
import android.preference.PreferenceGroup;
12-
import android.preference.PreferenceScreen;
13-
import android.preference.SwitchPreference;
10+
import android.preference.*;
1411
import android.text.TextUtils;
1512
import android.view.LayoutInflater;
1613
import android.view.View;
@@ -177,11 +174,20 @@ private View createPreferenceView(SearchResultItem item, View convertView,
177174
case REGULAR, URL_LINK, LIST -> {
178175
RegularViewHolder regularHolder = (RegularViewHolder) holder;
179176
SearchResultItem.PreferenceSearchItem prefItem = (SearchResultItem.PreferenceSearchItem) item;
177+
prefItem.refreshHighlighting();
180178
regularHolder.titleView.setText(item.highlightedTitle);
181179
regularHolder.summaryView.setText(item.highlightedSummary);
182180
regularHolder.summaryView.setVisibility(TextUtils.isEmpty(item.highlightedSummary) ? View.GONE : View.VISIBLE);
183181
setupPreferenceView(view, regularHolder.titleView, regularHolder.summaryView, prefItem.preference,
184-
() -> handlePreferenceClick(prefItem.preference),
182+
() -> {
183+
handlePreferenceClick(prefItem.preference);
184+
if (prefItem.preference instanceof ListPreference) {
185+
prefItem.refreshHighlighting();
186+
regularHolder.summaryView.setText(prefItem.getCurrentEffectiveSummary());
187+
regularHolder.summaryView.setVisibility(TextUtils.isEmpty(prefItem.highlightedSummary) ? View.GONE : View.VISIBLE);
188+
notifyDataSetChanged();
189+
}
190+
},
185191
() -> navigateAndScrollToPreference(item));
186192
}
187193
case SWITCH -> {

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/search/SearchViewController.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import android.app.Activity;
77
import android.content.Context;
88
import android.graphics.drawable.GradientDrawable;
9-
import android.preference.Preference;
10-
import android.preference.PreferenceCategory;
11-
import android.preference.PreferenceGroup;
12-
import android.preference.PreferenceScreen;
9+
import android.preference.*;
1310
import android.text.TextUtils;
1411
import android.view.*;
1512
import android.view.inputmethod.EditorInfo;
@@ -27,6 +24,7 @@
2724
import app.revanced.extension.shared.settings.BaseSettings;
2825
import app.revanced.extension.shared.settings.Setting;
2926
import app.revanced.extension.shared.settings.preference.ColorPickerPreference;
27+
import app.revanced.extension.shared.settings.preference.CustomDialogListPreference;
3028
import app.revanced.extension.shared.settings.preference.NoTitlePreferenceCategory;
3129
import app.revanced.extension.youtube.settings.LicenseActivityHook;
3230
import app.revanced.extension.youtube.sponsorblock.objects.SegmentCategoryListPreference;
@@ -331,6 +329,28 @@ private void setupPreferenceListeners() {
331329
}
332330
return true;
333331
});
332+
} else if (pref instanceof CustomDialogListPreference listPref) {
333+
listPref.setOnPreferenceChangeListener((preference, newValue) -> {
334+
SearchResultItem.PreferenceSearchItem searchItem =
335+
(SearchResultItem.PreferenceSearchItem) keyToSearchItem.get(preference.getKey());
336+
if (searchItem == null) return true;
337+
338+
int index = listPref.findIndexOfValue(newValue.toString());
339+
if (index >= 0) {
340+
// Check if a static summary is set.
341+
boolean isStaticSummary = listPref.getStaticSummary() != null;
342+
343+
if (!isStaticSummary) {
344+
// Only update summary if it is not static.
345+
CharSequence newSummary = listPref.getEntries()[index];
346+
searchItem.refreshHighlighting();
347+
listPref.setSummary(newSummary);
348+
}
349+
}
350+
351+
refreshSearchResults();
352+
return true;
353+
});
334354
}
335355
}
336356
}
@@ -448,6 +468,9 @@ private void filterAndShowResults(String query) {
448468
SearchResultItem parentItem = keyToSearchItem.get(parentSetting.key);
449469
if (parentItem != null && !addedParentKeys.contains(parentSetting.key)) {
450470
if (!parentItem.matchesQuery(queryLower)) {
471+
// Apply highlighting to parent items even if they don't match the query.
472+
// This ensures they get their current effective summary calculated.
473+
parentItem.applyHighlighting(queryPattern);
451474
filteredSearchItems.add(parentItem);
452475
}
453476
addedParentKeys.add(parentSetting.key);

0 commit comments

Comments
 (0)