fix: Show low storage message dependent on whether user uses internal or external storage

Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
Myzel394 2024-03-21 21:54:21 +01:00
parent a6856476ce
commit 5cdbb605f2
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
3 changed files with 12 additions and 5 deletions

View File

@ -522,8 +522,8 @@ abstract class BatchesFolder(
return uri!!
}
fun getAvailableBytes(): Long {
val storageManager = context.getSystemService(StorageManager::class.java) ?: return -1
fun getAvailableBytes(): Long? {
val storageManager = context.getSystemService(StorageManager::class.java) ?: return null
val file = when (type) {
BatchType.INTERNAL -> context.filesDir
BatchType.CUSTOM -> customFolder!!.uri.toFile()
@ -545,8 +545,8 @@ abstract class BatchesFolder(
companion object {
fun requiredBytesForOneMinuteOfRecording(appSettings: AppSettings): Long {
// 300 MiB sounds like a good default
return 300 * 1024 * 1024
// 250 MiB sounds like a good default
return 250 * 1024 * 1024
}
}
}

View File

@ -22,6 +22,10 @@ fun LowStorageInfo(
val availableBytes =
VideoBatchesFolder.importFromFolder(appSettings.saveFolder, context).getAvailableBytes()
if (availableBytes == null) {
return
}
val bytesPerMinute = BatchesFolder.requiredBytesForOneMinuteOfRecording(appSettings)
val requiredBytes = appSettings.maxDuration / 1000 / 60 * bytesPerMinute
@ -35,7 +39,9 @@ fun LowStorageInfo(
) {
MessageBox(
type = MessageType.WARNING,
message = stringResource(R.string.ui_recorder_lowOnStorage_hint),
message = if (appSettings.saveFolder == null)
stringResource(R.string.ui_recorder_lowOnStorage_hintANDswitchSaveFolder)
else stringResource(R.string.ui_recorder_lowOnStorage_hint)
)
}
}

View File

@ -194,4 +194,5 @@
<string name="ui_recorder_action_saveCurrent">Save now?</string>
<string name="ui_recorder_action_saveCurrent_explanation">You can save the current ongoing recording by pressing and holding down on the save button. The recording will continue in the background.</string>
<string name="ui_recorder_lowOnStorage_hint">You are low on storage. Alibi may not function properly. Please free up some space.</string>
<string name="ui_recorder_lowOnStorage_hintANDswitchSaveFolder">You are low on storage. Alibi may not function properly. Please free up some space. Alternatively, change the batches folder to a different location in the settings.</string>
</resources>