From 35af445f00f83a65b90fae2890fefba64b06e203 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Tue, 10 Dec 2024 16:17:15 +0000 Subject: [PATCH] Uplift of #26940 (squashed) to beta --- .../chromium/chrome/browser/app/BraveActivity.java | 12 ++++++++++++ .../settings/QuickSearchEnginesFragment.java | 14 +++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index ae62eafbaada..d04654cf3587 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -173,6 +173,7 @@ import org.chromium.chrome.browser.rewards.adaptive_captcha.AdaptiveCaptchaHelper; import org.chromium.chrome.browser.safe_browsing.SafeBrowsingBridge; import org.chromium.chrome.browser.safe_browsing.SafeBrowsingState; +import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory; import org.chromium.chrome.browser.set_default_browser.BraveSetDefaultBrowserUtils; import org.chromium.chrome.browser.set_default_browser.OnBraveSetDefaultBrowserListener; import org.chromium.chrome.browser.settings.BraveNewsPreferencesV2; @@ -2582,6 +2583,17 @@ public void onClick(View v) { } }); + Runnable onQuickSearchEnginesReady = + () -> { + if (isActivityFinishingOrDestroyed()) return; + + quickSearchEnginesReady(recyclerView, keypadHeight); + }; + TemplateUrlServiceFactory.getForProfile(getCurrentProfile()) + .runWhenLoaded(onQuickSearchEnginesReady); + } + + private void quickSearchEnginesReady(RecyclerView recyclerView, int keypadHeight) { List searchEngines = QuickSearchEnginesUtil.getQuickSearchEnginesForView(getCurrentProfile()); QuickSearchEnginesModel leoQuickSearchEnginesModel = diff --git a/android/java/org/chromium/chrome/browser/quick_search_engines/settings/QuickSearchEnginesFragment.java b/android/java/org/chromium/chrome/browser/quick_search_engines/settings/QuickSearchEnginesFragment.java index 694f3ce18b33..2a440ad1470d 100644 --- a/android/java/org/chromium/chrome/browser/quick_search_engines/settings/QuickSearchEnginesFragment.java +++ b/android/java/org/chromium/chrome/browser/quick_search_engines/settings/QuickSearchEnginesFragment.java @@ -28,6 +28,7 @@ import org.chromium.chrome.R; import org.chromium.chrome.browser.quick_search_engines.ItemTouchHelperCallback; import org.chromium.chrome.browser.quick_search_engines.utils.QuickSearchEnginesUtil; +import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory; import org.chromium.chrome.browser.settings.BravePreferenceFragment; import org.chromium.chrome.browser.util.ImageUtils; @@ -137,9 +138,16 @@ public ObservableSupplier getPageTitle() { } private void refreshData() { - List quickSearchEngines = - QuickSearchEnginesUtil.getQuickSearchEnginesForSettings(getProfile()); - setRecyclerViewData(quickSearchEngines); + Runnable onQuickSearchEnginesReady = + () -> { + if (isRemoving() || isDetached()) return; + + List quickSearchEngines = + QuickSearchEnginesUtil.getQuickSearchEnginesForSettings(getProfile()); + setRecyclerViewData(quickSearchEngines); + }; + TemplateUrlServiceFactory.getForProfile(getProfile()) + .runWhenLoaded(onQuickSearchEnginesReady); } private void setRecyclerViewData(List searchEngines) {