Warn user when adding media files exceeding the AnkiWeb size limit #20193
Warn user when adding media files exceeding the AnkiWeb size limit #20193ujjol1234 wants to merge 8 commits intoankidroid:mainfrom
Conversation
|
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
|
Important Maintainers: This PR contains Strings changes
|
| android.text.format.Formatter | ||
| .formatShortFileSize(requireContext(), fileSize) | ||
|
|
||
| MaterialAlertDialogBuilder(requireContext()) |
|
Hi @david-allison, I have implemented your suggested changes. Could you please check them out? |
david-allison
left a comment
There was a problem hiding this comment.
Quick review on my phone, I think this is almost there. Thanks!!
libanki/src/main/java/com/ichi2/anki/libanki/exception/MediaSizeLimitExceededException.kt
Outdated
Show resolved
Hide resolved
|
Hi @david-allison, hope you are doing well! |
AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt
Outdated
Show resolved
Hide resolved
| } | ||
| changed = true | ||
| } catch (e: Exception) { | ||
| Timber.e(e, "Failed to add large media file after warning") |
There was a problem hiding this comment.
| Timber.e(e, "Failed to add large media file after warning") | |
| Timber.w(e, "Failed to add large media file after warning") |
# Conflicts: # libanki/src/main/java/com/ichi2/anki/libanki/Media.kt
850d129 to
909effe
Compare
|
Hi @david-allison I have made the required changed, could you please review them? |
| index: Int, | ||
| field: IField, | ||
| ) { | ||
| // Initial call checks size (skipSizeCheck = false) |
There was a problem hiding this comment.
| // Initial call checks size (skipSizeCheck = false) |
| field: IField, | ||
| skipSizeCheck: Boolean = false, | ||
| ) { | ||
| val file = field.mediaFile |
There was a problem hiding this comment.
It doesn't make sense to me that we continue execution if the file is null.
I may have missed something
| index: Int, | ||
| field: IField, | ||
| ) { | ||
| // Initial call checks size (skipSizeCheck = false) |
There was a problem hiding this comment.
| // Initial call checks size (skipSizeCheck = false) |
There was a problem hiding this comment.
This is great!
I think removing the null check will massively improve typing throughout the change
Optional extension: define a value class for something like fileSize to produce a nicer looking string format
Here's something similar I wrote last night which might be of use
@JvmInline
value class Bytes(val bytes: Long) {
fun toShortString(context: Context): String = Formatter.formatShortFileSize(context, this.bytes)
}
val Int.bytes get() = Bytes(this.toLong())|
You are absolutely right @david-allison. I see now how removing the null check significantly cleaned up the types in both the exception class and the fragment. Also, that Bytes value class is super helpful. I have implemented it as you shared. |
Purpose / Description
This PR implements a warning dialog when a user attempts to add a media file that exceeds the AnkiWeb synchronization limit (100MB).
Fixes