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

Commit 355bb4d7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Improve Settings launch performance"

parents fae67996 0c37f019
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -20,10 +20,13 @@ import android.content.Context;
import android.os.storage.StorageManager;
import android.text.format.Formatter;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import com.android.settingslib.utils.ThreadUtils;

import java.text.NumberFormat;

@@ -44,14 +47,22 @@ public class TopLevelStoragePreferenceController extends BasePreferenceControlle
    }

    @Override
    public CharSequence getSummary() {
        // TODO: Register listener.
    protected void refreshSummary(Preference preference) {
        if (preference == null) {
            return;
        }

        ThreadUtils.postOnBackgroundThread(() -> {
            final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
            final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
                    mStorageManagerVolumeProvider);
        double privateUsedBytes = info.totalBytes - info.freeBytes;
        return mContext.getString(R.string.storage_summary,
            final double privateUsedBytes = info.totalBytes - info.freeBytes;

            ThreadUtils.postOnMainThread(() -> {
                preference.setSummary(mContext.getString(R.string.storage_summary,
                        percentageFormat.format(privateUsedBytes / info.totalBytes),
                Formatter.formatFileSize(mContext, info.freeBytes));
                        Formatter.formatFileSize(mContext, info.freeBytes)));
            });
        });
    }
}