replace custom file size parser with AOSP implementation

This commit is contained in:
Pratyush 2023-04-20 15:34:04 +05:30 committed by Daniel Micay
parent 17c7c84296
commit 195bba7891
2 changed files with 2 additions and 17 deletions

View File

@ -9,21 +9,6 @@ import java.text.ParseException;
import java.util.Calendar; import java.util.Calendar;
public class Utils { public class Utils {
public static String parseFileSize(long fileSize) {
final double kb = fileSize / 1000d;
if (kb == 0d) {
return fileSize + " Bytes";
}
final DecimalFormat format = new DecimalFormat("#.##");
format.setRoundingMode(RoundingMode.CEILING);
if (kb < 1000) {
return format.format(kb) + " kB (" + fileSize + " Bytes)";
}
return format.format(kb / 1000) + " MB (" + fileSize + " Bytes)";
}
private static int parseIntSafely(String field) throws ParseException { private static int parseIntSafely(String field) throws ParseException {
try { try {

View File

@ -6,10 +6,10 @@ import android.net.Uri
import android.provider.OpenableColumns import android.provider.OpenableColumns
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.text.Spanned import android.text.Spanned
import android.text.format.Formatter
import android.text.style.StyleSpan import android.text.style.StyleSpan
import android.util.Log import android.util.Log
import app.grapheneos.pdfviewer.R import app.grapheneos.pdfviewer.R
import app.grapheneos.pdfviewer.Utils
import org.json.JSONException import org.json.JSONException
class DocumentPropertiesLoader( class DocumentPropertiesLoader(
@ -103,7 +103,7 @@ class DocumentPropertiesLoader(
val indexSize: Int = cursor.getColumnIndex(OpenableColumns.SIZE) val indexSize: Int = cursor.getColumnIndex(OpenableColumns.SIZE)
if (indexSize >= 0) { if (indexSize >= 0) {
val fileSize: Long = cursor.getString(indexSize).toLong() val fileSize: Long = cursor.getString(indexSize).toLong()
collections[DocumentProperty.FileSize] = Utils.parseFileSize(fileSize) collections[DocumentProperty.FileSize] = Formatter.formatShortFileSize(context, fileSize)
} }
} }
return collections return collections