Skip to content

Commit

Permalink
[Android] Fix update se text brave widget android (uplift to 1.47.x) (#…
Browse files Browse the repository at this point in the history
…16763)

Co-authored-by: tapanmodh <modhtapan@gmail.com>
  • Loading branch information
deeppandya and tapanmodh authored Jan 20, 2023
1 parent 00f36f5 commit 148a432
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static private void doInitializeBraveSearchEngineStates(Profile profile) {

initializeDSEPrefs(profile);
updateActiveDSE(profile);
QuickActionSearchAndBookmarkWidgetProvider.initializeDelegate();
}

static public void setDSEPrefs(TemplateUrl templateUrl, Profile profile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -60,6 +63,17 @@
import java.util.Objects;

public class QuickActionSearchAndBookmarkWidgetProvider extends AppWidgetProvider {
static class QuickActionSearchAndBookmarkWidgetProviderDelegate
implements Consumer<SearchActivityPreferences> {
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 148a432

Please sign in to comment.