Skip to content

Commit

Permalink
feat: add file size to epub list in open save epub dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Apr 13, 2022
1 parent c1ab241 commit 8cf4ce3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ open class BrowserActivity : ComponentActivity(), BrowserController, OnClickList
}
}


private fun listenKeyboardShowHide() {
binding.root.viewTreeObserver.addOnGlobalLayoutListener {
val heightDiff: Int = binding.root.rootView.height - binding.root.height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.webkit.URLUtil
import androidx.appcompat.app.AlertDialog
import androidx.core.net.toUri
import androidx.documentfile.provider.DocumentFile
import de.baumann.browser.Ninja.R
import de.baumann.browser.Ninja.databinding.DialogEditExtensionBinding
import de.baumann.browser.Ninja.databinding.DialogSavedEpubListBinding
Expand Down Expand Up @@ -101,7 +102,7 @@ class DialogManager(
config.savedEpubFileInfos.reversed().forEach { epubFileInfo ->
val itemBinding = ListItemEpubFileBinding.inflate(inflater)
with (itemBinding.epubTitle) {
text = epubFileInfo.title
text = "${epubFileInfo.title} (${getFileSizeString(epubFileInfo.uri)})"
setOnClickListener {
onNextAction(epubFileInfo.uri.toUri())
dialog.dismiss()
Expand All @@ -116,6 +117,13 @@ class DialogManager(
}
}

private fun getFileSizeString(uri: String): String {
val sizeInBytes = DocumentFile.fromSingleUri(activity, Uri.parse(uri))?.length() ?: 0
val sizeInKB = sizeInBytes / 1024
val sizeInMB = sizeInKB / 1024F
return if (sizeInMB > 1) "%.1fMB".format(sizeInMB) else "${sizeInKB}KB"
}

fun showSavePdfDialog(
url: String,
savePdf: (String, String) -> Unit,
Expand Down

0 comments on commit 8cf4ce3

Please sign in to comment.