Skip to content

Commit

Permalink
fix: handle gif import and retain original properties of gif
Browse files Browse the repository at this point in the history
fix: remove the 1MB limit for the images in AnkiDroid

Follow the Anki convetions for image size see https://faqs.ankiweb.net/are-there-limits-on-file-sizes-on-ankiweb.html
  • Loading branch information
criticalAY authored and mikehardy committed Oct 2, 2024
1 parent c8b5c36 commit 56ae53d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,6 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_

updateAndDisplayImageSize(imagePath)

if (!rotateAndCompress(imagePath)) {
Timber.d("Unable to compress the clicked image")
showErrorDialog(errorMessage = resources.getString(R.string.multimedia_editor_image_compression_failed))
return
}

showCropDialog(getString(R.string.crop_image))
}

Expand All @@ -412,7 +406,24 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_
val decimalFormat = DecimalFormat(".00")
val size = decimalFormat.format(length.toDouble())
val message = getString(R.string.save_dialog_content, size)
showCropDialog(message)
showCompressImageDialog(message)
}

private fun showCompressImageDialog(message: String) {
AlertDialog.Builder(requireActivity()).show {
message(text = message)
positiveButton(R.string.compress) {
viewModel.currentMultimediaPath.value.let {
if (it == null) return@positiveButton
if (!rotateAndCompress(it)) {
Timber.d("Unable to compress the clicked image")
showErrorDialog(errorMessage = resources.getString(R.string.multimedia_editor_image_compression_failed))
return@positiveButton
}
}
}
negativeButton(R.string.dialog_no)
}
}

private fun showCropDialog(message: String) {
Expand Down Expand Up @@ -464,11 +475,11 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_

val imagePath = internalizedPick.absolutePath

if (!rotateAndCompress(imagePath)) {
Timber.d("Unable to compress the clicked image")
showErrorDialog(errorMessage = resources.getString(R.string.multimedia_editor_image_compression_failed))
return
}
viewModel.updateCurrentMultimediaUri(imageUri)
viewModel.updateCurrentMultimediaPath(imagePath)
imagePreview.setImageURI(imageUri)
viewModel.selectedMediaFileSize = internalizedPick.length()
updateAndDisplayImageSize(imagePath)
}

private fun requestCrop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ object MultimediaUtils {
*/
private const val RAW_DOCUMENTS_FILE_PREFIX = "raw:"

const val IMAGE_LIMIT = 1024 * 1024 // 1MB in bytes
/** 100MB in bytes upstream limit https://faqs.ankiweb.net/are-there-limits-on-file-sizes-on-ankiweb.html **/
const val IMAGE_LIMIT = 1024 * 1024 * 100

/**
* Get image name based on uri and selection args
Expand Down
3 changes: 2 additions & 1 deletion AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,11 @@ also changes the interval of the card"
<!-- Outdated WebView dialog -->
<string name="webview_update_message">The system WebView is outdated. Some features won’t work correctly. Please update it.\n\nInstalled version: %1$d\nMinimum required version: %2$d</string>

<string name="compress">Compress</string>

<!-- Tts playback error dialog -->
<string name="tts_error_dialog_title">Language not supported</string>
<string name="tts_error_dialog_reason_text">The text to speech engine <b>%1$s</b> does not support the following language: <b>%2$s</b></string>
<string name="tts_error_dialog_change_button_text">Change engine</string>
<string name="tts_error_dialog_supported_voices_button_text">Voice options</string>

</resources>
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/values/16-multimedia-editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<!-- Crop function-->
<string name="crop_image">Do you want to crop this image?</string>
<string name="crop_button">Crop image</string>
<string name="save_dialog_content">Current image size is %sMB. Default image size limit is 1MB. Do you want to crop it?</string>
<string name="save_dialog_content">Current image size is %sMB. Default image size limit is 1MB. Do you want to compress it?</string>
<string name="select_image_failed">"Select image failed, Please retry"</string>
<string name="activity_result_unexpected">App returned an unexpected value. You may need to use a different app</string>
<string name="audio_recording_field_list" comment="Displays a list of the field data in the note editor while audio recording is taking place">Field Contents</string>
Expand Down

0 comments on commit 56ae53d

Please sign in to comment.