mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Add low on storage info; Closes #56
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
0ebbf86450
commit
a6856476ce
@ -7,12 +7,15 @@ import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.storage.StorageManager
|
||||
import android.provider.MediaStore
|
||||
import android.provider.MediaStore.Video.Media
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.net.toFile
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import app.myzel394.alibi.db.AppSettings
|
||||
import app.myzel394.alibi.ui.MEDIA_RECORDINGS_PREFIX
|
||||
import app.myzel394.alibi.ui.RECORDER_INTERNAL_SELECTED_VALUE
|
||||
import app.myzel394.alibi.ui.RECORDER_MEDIA_SELECTED_VALUE
|
||||
@ -519,10 +522,32 @@ abstract class BatchesFolder(
|
||||
return uri!!
|
||||
}
|
||||
|
||||
fun getAvailableBytes(): Long {
|
||||
val storageManager = context.getSystemService(StorageManager::class.java) ?: return -1
|
||||
val file = when (type) {
|
||||
BatchType.INTERNAL -> context.filesDir
|
||||
BatchType.CUSTOM -> customFolder!!.uri.toFile()
|
||||
BatchType.MEDIA -> scopedMediaContentUri.toFile()
|
||||
}
|
||||
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
storageManager.getAllocatableBytes(storageManager.getUuidForPath(file))
|
||||
} else {
|
||||
file.usableSpace;
|
||||
}
|
||||
}
|
||||
|
||||
enum class BatchType {
|
||||
INTERNAL,
|
||||
CUSTOM,
|
||||
MEDIA,
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun requiredBytesForOneMinuteOfRecording(appSettings: AppSettings): Long {
|
||||
// 300 MiB sounds like a good default
|
||||
return 300 * 1024 * 1024
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,8 @@ class VideoBatchesFolder(
|
||||
|
||||
fun viaMediaFolder(context: Context) = VideoBatchesFolder(context, BatchType.MEDIA)
|
||||
|
||||
fun importFromFolder(folder: String, context: Context) = when (folder) {
|
||||
fun importFromFolder(folder: String?, context: Context) = when (folder) {
|
||||
null -> viaInternalFolder(context)
|
||||
RECORDER_INTERNAL_SELECTED_VALUE -> viaInternalFolder(context)
|
||||
RECORDER_MEDIA_SELECTED_VALUE -> viaMediaFolder(context)
|
||||
else -> viaCustomFolder(
|
||||
|
@ -0,0 +1,41 @@
|
||||
package app.myzel394.alibi.ui.components.RecorderScreen.atoms
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.myzel394.alibi.R
|
||||
import app.myzel394.alibi.db.AppSettings
|
||||
import app.myzel394.alibi.helpers.BatchesFolder
|
||||
import app.myzel394.alibi.helpers.VideoBatchesFolder
|
||||
import app.myzel394.alibi.ui.components.atoms.MessageBox
|
||||
import app.myzel394.alibi.ui.components.atoms.MessageType
|
||||
|
||||
@Composable
|
||||
fun LowStorageInfo(
|
||||
appSettings: AppSettings,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val availableBytes =
|
||||
VideoBatchesFolder.importFromFolder(appSettings.saveFolder, context).getAvailableBytes()
|
||||
|
||||
val bytesPerMinute = BatchesFolder.requiredBytesForOneMinuteOfRecording(appSettings)
|
||||
val requiredBytes = appSettings.maxDuration / 1000 / 60 * bytesPerMinute
|
||||
|
||||
// Allow for a 10% margin of error
|
||||
val isLowOnStorage = availableBytes < requiredBytes * 1.1
|
||||
println("LowStorageInfo: availableBytes: $availableBytes, requiredBytes: $requiredBytes, isLowOnStorage: $isLowOnStorage")
|
||||
|
||||
if (isLowOnStorage)
|
||||
Box(
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
) {
|
||||
MessageBox(
|
||||
type = MessageType.WARNING,
|
||||
message = stringResource(R.string.ui_recorder_lowOnStorage_hint),
|
||||
)
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@ import app.myzel394.alibi.R
|
||||
import app.myzel394.alibi.db.AppSettings
|
||||
import app.myzel394.alibi.ui.BIG_PRIMARY_BUTTON_MAX_WIDTH
|
||||
import app.myzel394.alibi.ui.BIG_PRIMARY_BUTTON_SIZE
|
||||
import app.myzel394.alibi.ui.components.RecorderScreen.atoms.LowStorageInfo
|
||||
import app.myzel394.alibi.ui.components.RecorderScreen.molecules.AudioRecordingStart
|
||||
import app.myzel394.alibi.ui.components.RecorderScreen.molecules.QuickMaxDurationSelector
|
||||
import app.myzel394.alibi.ui.components.RecorderScreen.molecules.VideoRecordingStart
|
||||
@ -212,5 +213,7 @@ fun StartRecording(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LowStorageInfo(appSettings = appSettings)
|
||||
}
|
||||
}
|
@ -193,4 +193,5 @@
|
||||
<string name="goBack">Back</string>
|
||||
<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>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user