fix file size parsing issue causing crash
Opening a PDF using Storage Access Framework (SAF) causes the app to crash in some cases, when the file is not present on the device's internal storage (for example, on Proton Drive).
This commit is contained in:
parent
145fd9896c
commit
bfb5e4a538
@ -9,6 +9,7 @@ import android.text.Spanned
|
|||||||
import android.text.format.Formatter
|
import android.text.format.Formatter
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.core.database.getLongOrNull
|
||||||
import app.grapheneos.pdfviewer.R
|
import app.grapheneos.pdfviewer.R
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
|
|
||||||
@ -102,8 +103,9 @@ 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 = cursor.getLongOrNull(indexSize)
|
||||||
collections[DocumentProperty.FileSize] = Formatter.formatShortFileSize(context, fileSize)
|
collections[DocumentProperty.FileSize] =
|
||||||
|
fileSize?.let { Formatter.formatFileSize(context, it) } ?: context.getString(R.string.unknown_file_size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return collections
|
return collections
|
||||||
|
@ -44,4 +44,6 @@
|
|||||||
<string name="creator">Creator</string>
|
<string name="creator">Creator</string>
|
||||||
<string name="pdf_version">PDF version</string>
|
<string name="pdf_version">PDF version</string>
|
||||||
<string name="pages">Pages</string>
|
<string name="pages">Pages</string>
|
||||||
|
|
||||||
|
<string name="unknown_file_size">Unknown</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user