feat: low nvram alert #62

Merged
PeterCxy merged 10 commits from septs/OpenEUICC:low-nvram-alert into master 2024-11-14 14:02:28 +01:00
2 changed files with 21 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package im.angry.openeuicc.ui
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.Dialog
import android.content.DialogInterface
import android.graphics.BitmapFactory
@ -25,13 +26,14 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.Exception
class ProfileDownloadFragment : BaseMaterialDialogFragment(),
Toolbar.OnMenuItemClickListener, EuiccChannelFragmentMarker {
companion object {
const val TAG = "ProfileDownloadFragment"
const val LOW_NVRAM_THRESHOLD = 30 * 1024 // < 30 KiB, the alert may fail
fun newInstance(slotId: Int, portId: Int, finishWhenDone: Boolean = false): ProfileDownloadFragment =
newInstanceEuicc(ProfileDownloadFragment::class.java, slotId, portId) {
putBoolean("finishWhenDone", finishWhenDone)
@ -135,7 +137,21 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
true
}
R.id.ok -> {
startDownloadProfile()
if (freeNvram > LOW_NVRAM_THRESHOLD) {
startDownloadProfile()
} else {
AlertDialog.Builder(requireContext()).apply {
setTitle(R.string.profile_download_low_nvram_title)
setMessage(R.string.profile_download_low_nvram_message)
setIcon(android.R.drawable.ic_dialog_alert)
setCancelable(true)
setPositiveButton(android.R.string.ok) { _, _ ->
startDownloadProfile()
}
setNegativeButton(android.R.string.cancel, null)
show()
}
}
true
}
else -> false

View file

@ -55,6 +55,9 @@
<string name="profile_download_ok">Download</string>
<string name="profile_download_failed">Failed to download eSIM. Check your activation / QR code.</string>
<string name="profile_download_low_nvram_title">This download may fail</string>
<string name="profile_download_low_nvram_message">This download may fail due to low remaining capacity.</string>
<string name="profile_rename_new_name">New nickname</string>
<string name="profile_delete_confirm">Are you sure you want to delete the profile %s? This operation is irreversible.</string>