Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Refresh the UA hamburger icon when addons are updated. (#3785)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored Aug 12, 2020
1 parent 46b186b commit 06c02fa
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public interface MenuDelegate {
boolean mSendTabEnabled = false;
private ArrayList<HamburgerMenuAdapter.MenuItem> mItems;
private MenuDelegate mDelegate;
private int mCurrentUAMode;

public HamburgerMenuWidget(@NonNull Context aContext) {
super(aContext);

mItems = new ArrayList<>();
mCurrentUAMode = SettingsStore.getInstance(aContext).getUaMode();

updateUI();
}
Expand Down Expand Up @@ -135,6 +137,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
}

public void setUAMode(int uaMode) {
mCurrentUAMode = uaMode;
HamburgerMenuAdapter.MenuItem item = getSwitchModeIndex();
if (item != null) {
switch (uaMode) {
Expand Down Expand Up @@ -224,7 +227,7 @@ private void updateItems() {
.build());
}

mItems.add(new HamburgerMenuAdapter.MenuItem.Builder(
HamburgerMenuAdapter.MenuItem item = new HamburgerMenuAdapter.MenuItem.Builder(
HamburgerMenuAdapter.MenuItem.TYPE_DEFAULT,
(menuItem) -> {
if (mDelegate != null) {
Expand All @@ -234,8 +237,20 @@ private void updateItems() {
})
.withId(SWITCH_ITEM_ID)
.withTitle(getContext().getString(R.string.hamburger_menu_switch_to_desktop))
.withIcon(R.drawable.ic_icon_ua_default)
.build());
.build();
switch (mCurrentUAMode) {
case GeckoSessionSettings.USER_AGENT_MODE_DESKTOP: {
item.setIcon(R.drawable.ic_icon_ua_desktop);
}
break;

case GeckoSessionSettings.USER_AGENT_MODE_MOBILE:
case GeckoSessionSettings.USER_AGENT_MODE_VR: {
item.setIcon(R.drawable.ic_icon_ua_default);
}
break;
}
mItems.add(item);

mAdapter.setItems(mItems);
mAdapter.notifyDataSetChanged();
Expand Down

0 comments on commit 06c02fa

Please sign in to comment.