From 148a432de8437336b5041a88aa17b1305202381d Mon Sep 17 00:00:00 2001 From: Deep Pandya <5146988+deeppandya@users.noreply.github.com> Date: Fri, 20 Jan 2023 03:27:39 -0500 Subject: [PATCH] [Android] Fix update se text brave widget android (uplift to 1.47.x) (#16763) Co-authored-by: tapanmodh --- .../settings/BraveSearchEngineUtils.java | 1 + ...ActionSearchAndBookmarkWidgetProvider.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/android/java/org/chromium/chrome/browser/settings/BraveSearchEngineUtils.java b/android/java/org/chromium/chrome/browser/settings/BraveSearchEngineUtils.java index 4624b8a42323..9584582104fa 100644 --- a/android/java/org/chromium/chrome/browser/settings/BraveSearchEngineUtils.java +++ b/android/java/org/chromium/chrome/browser/settings/BraveSearchEngineUtils.java @@ -73,6 +73,7 @@ static private void doInitializeBraveSearchEngineStates(Profile profile) { initializeDSEPrefs(profile); updateActiveDSE(profile); + QuickActionSearchAndBookmarkWidgetProvider.initializeDelegate(); } static public void setDSEPrefs(TemplateUrl templateUrl, Profile profile) { diff --git a/android/java/org/chromium/chrome/browser/widget/quickactionsearchandbookmark/QuickActionSearchAndBookmarkWidgetProvider.java b/android/java/org/chromium/chrome/browser/widget/quickactionsearchandbookmark/QuickActionSearchAndBookmarkWidgetProvider.java index be13b2380bd9..29bca0f02eaf 100644 --- a/android/java/org/chromium/chrome/browser/widget/quickactionsearchandbookmark/QuickActionSearchAndBookmarkWidgetProvider.java +++ b/android/java/org/chromium/chrome/browser/widget/quickactionsearchandbookmark/QuickActionSearchAndBookmarkWidgetProvider.java @@ -29,6 +29,7 @@ import org.json.JSONException; import org.json.JSONObject; +import org.chromium.base.Consumer; import org.chromium.base.ContextUtils; import org.chromium.base.IntentUtils; import org.chromium.chrome.R; @@ -43,6 +44,8 @@ import org.chromium.chrome.browser.suggestions.tile.Tile; import org.chromium.chrome.browser.ui.favicon.FaviconUtils; import org.chromium.chrome.browser.ui.searchactivityutils.SearchActivityConstants; +import org.chromium.chrome.browser.ui.searchactivityutils.SearchActivityPreferencesManager; +import org.chromium.chrome.browser.ui.searchactivityutils.SearchActivityPreferencesManager.SearchActivityPreferences; import org.chromium.chrome.browser.widget.quickactionsearchandbookmark.utils.BraveSearchWidgetUtils; import org.chromium.components.browser_ui.widget.RoundedIconGenerator; import org.chromium.components.favicon.IconType; @@ -60,6 +63,17 @@ import java.util.Objects; public class QuickActionSearchAndBookmarkWidgetProvider extends AppWidgetProvider { + static class QuickActionSearchAndBookmarkWidgetProviderDelegate + implements Consumer { + public QuickActionSearchAndBookmarkWidgetProviderDelegate() {} + + @Override + public void accept(SearchActivityPreferences prefs) { + if (prefs == null) prefs = SearchActivityPreferencesManager.getCurrent(); + updateSearchEngine(prefs.searchEngineName); + } + } + public static String FROM_SETTINGS = "FROM_SETTINGS"; private static final int TOTAL_TILES = 16; @@ -98,10 +112,23 @@ public class QuickActionSearchAndBookmarkWidgetProvider extends AppWidgetProvide }, }; + private static QuickActionSearchAndBookmarkWidgetProviderDelegate mDelegate; + public QuickActionSearchAndBookmarkWidgetProvider() { ChromeBrowserInitializer.getInstance().handleSynchronousStartup(); } + public static void initializeDelegate() { + SearchActivityPreferencesManager.addObserver(getDelegate()); + } + + private static QuickActionSearchAndBookmarkWidgetProviderDelegate getDelegate() { + if (mDelegate == null) { + mDelegate = new QuickActionSearchAndBookmarkWidgetProviderDelegate(); + } + return mDelegate; + } + @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); @@ -134,6 +161,7 @@ public static void updateTileIcon(Tile tile) { } public static void updateSearchEngine(String searchEngine) { + if (searchEngine == null) return; Context context = ContextUtils.getApplicationContext(); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = getAppWidgetIds(context, appWidgetManager);