Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 436d7503 authored by наб's avatar наб Committed by Bruno Martins
Browse files

health: Format notification's target time according to locale

Fixes: 8a7af5a9
Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/8317
Change-Id: I2c059da77c54c4fea11bdbabd1dde752f74ca6cf
parent 27727963
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -319,7 +319,7 @@ public class ChargingControlController extends LineageHealthFeature {
    private ChargeTime getChargeTime() {
        // Get duration to target full time
        final long currentTime = System.currentTimeMillis();
        Log.i(TAG, "Current time is " + msToString(currentTime));
        Log.i(TAG, "Current time is " + msToString(mContext, currentTime));
        long targetTime = 0, startTime = currentTime;
        int mode = getMode();

@@ -362,8 +362,9 @@ public class ChargingControlController extends LineageHealthFeature {
            return null;
        }

        Log.i(TAG, "Got target time " + msToString(targetTime) + ", start time " +
                msToString(startTime) + ", current time " + msToString(currentTime));
        Log.i(TAG, "Got target time " + msToString(mContext, targetTime)
                + ", start time " + msToString(mContext, startTime)
                + ", current time " + msToString(mContext, currentTime));
        Log.i(TAG, "Raw: " + targetTime + ", " + startTime + ", " + currentTime);

        return new ChargeTime(startTime, targetTime);
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ public class ChargingControlNotification {
        if (targetTime != null) {
            message = String.format(
                    mContext.getString(R.string.charging_control_notification_content_target),
                    msToString(targetTime));
                    msToString(mContext, targetTime));
        } else {
            message = String.format(
                    mContext.getString(R.string.charging_control_notification_content_limit),
+9 −9
Original line number Diff line number Diff line
@@ -5,33 +5,33 @@

package org.lineageos.platform.internal.health;

import static java.time.format.FormatStyle.SHORT;
import android.content.Context;
import android.text.format.DateFormat;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.TimeZone;

public class Util {
    private static final DateTimeFormatter mFormatter = DateTimeFormatter.ofLocalizedTime(SHORT);

    /**
     * Convert milliseconds to a string in the format "hh:mm:ss a".
     * Convert milliseconds to a string in the current locale's format.
     *
     * @param ms milliseconds from epoch
     * @return formatted time string in current time zone
     */
    static public String msToString(long ms) {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss a");
    static public String msToString(Context context, long ms) {
        return DateFormat.getTimeFormat(context).format(msToLocalTime(ms).getTime());
    }

    static private Calendar msToLocalTime(long ms) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(ms);
        return dateFormat.format(calendar.getTime());
        return calendar;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -243,7 +243,7 @@ public class Toggle extends ChargingControlProvider {
    public void dump(PrintWriter pw) {
        pw.println("Provider: " + getClass().getName());
        pw.println("  mIsLimitSet: " + mIsLimitSet);
        pw.println("  mSavedTargetTime: " + msToString(mSavedTargetTime));
        pw.println("  mSavedTargetTime: " + msToString(mContext, mSavedTargetTime));
        pw.println("  mEstimatedFullTime: " + msToUTCString(mEstimatedFullTime));
        pw.println("  mStage: " + mStage);
        pw.println("  mChargeLimitMargin: " + mChargingLimitMargin);