Skip to content

Commit

Permalink
Update time based on current display language (#3856)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Aug 21, 2020
1 parent e24b726 commit f6e0604
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ public MutableLiveData<ObservableInt> getDownloadsNumber() {
}

public void setTime(String time) {
this.time.postValue(time);
this.time.setValue(time);
}

public MutableLiveData<String> getTime() {
return time;
}

public void setPm(String pm) {
this.pm.postValue(pm);
this.pm.setValue(pm);
}

public MutableLiveData<String> getPm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.LocaleUtils;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.text.SimpleDateFormat;
Expand All @@ -56,7 +57,6 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class TrayWidget extends UIWidget implements WidgetManagerDelegate.UpdateListener, DownloadsManager.DownloadsListener, ConnectivityReceiver.Delegate {

Expand Down Expand Up @@ -245,7 +245,7 @@ public void updateUI() {
.withView(mBinding.leftController)
.withDensity(R.dimen.tray_tooltip_density)
.withLayout(R.layout.tooltip)
.withString(String.format(Locale.getDefault(), "%d%%", mLeftControllerBatteryLevel))
.withString(String.format(LocaleUtils.getDisplayLanguage(getContext()).getLocale(), "%d%%", mLeftControllerBatteryLevel))
.withAutoHide(false)
.withMargin(-15.0f)
.withPosition(NotificationManager.Notification.TOP).build();
Expand All @@ -264,7 +264,7 @@ public void updateUI() {
.withView(mBinding.rightController)
.withDensity(R.dimen.tray_tooltip_density)
.withLayout(R.layout.tooltip)
.withString(String.format(Locale.getDefault(), "%d%%", mRightControllerBatteryLevel))
.withString(String.format(LocaleUtils.getDisplayLanguage(getContext()).getLocale(), "%d%%", mRightControllerBatteryLevel))
.withAutoHide(false)
.withMargin(-15.0f)
.withPosition(NotificationManager.Notification.TOP).build();
Expand All @@ -283,7 +283,7 @@ public void updateUI() {
.withView(mBinding.headset)
.withDensity(R.dimen.tray_tooltip_density)
.withLayout(R.layout.tooltip)
.withString(String.format(Locale.getDefault(), "%d%%", mHeadsetBatteryLevel))
.withString(String.format(LocaleUtils.getDisplayLanguage(getContext()).getLocale(), "%d%%", mHeadsetBatteryLevel))
.withAutoHide(false)
.withMargin(-15.0f)
.withPosition(NotificationManager.Notification.TOP).build();
Expand Down Expand Up @@ -732,7 +732,7 @@ private void updateTime() {
Date currentTime = Calendar.getInstance().getTime();
String androidDateTime = DateFormat.getTimeFormat(getContext()).format(currentTime);
String AmPm = "";
SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
SimpleDateFormat format = new SimpleDateFormat("HH:mm", LocaleUtils.getDisplayLanguage(getContext()).getLocale());
if (!Character.isDigit(androidDateTime.charAt(androidDateTime.length() - 1))) {
if (androidDateTime.contains(format.getDateFormatSymbols().getAmPmStrings()[Calendar.AM])) {
AmPm = " " + format.getDateFormatSymbols().getAmPmStrings()[Calendar.AM];
Expand Down Expand Up @@ -852,7 +852,7 @@ public void setBatteryLevels(final int headset, final boolean isCharging, final

@NonNull
private String getFormattedDate() {
SimpleDateFormat format = new SimpleDateFormat("EEEE, dd MMMM yyyy", Locale.getDefault());
SimpleDateFormat format = new SimpleDateFormat("EEEE, dd MMMM yyyy", LocaleUtils.getDisplayLanguage(getContext()).getLocale());
return format.format(new Date());
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="12dp"
android:layout_marginEnd="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/time_text"
Expand All @@ -50,6 +50,7 @@
android:gravity="bottom"
android:textColor="@color/concrete"
android:text="@{traymodel.pm}"
app:visibleGone="@{!traymodel.pm.isEmpty}"
tool:text="pm"/>
</LinearLayout>
<FrameLayout
Expand Down

0 comments on commit f6e0604

Please sign in to comment.