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
  • Loading branch information
criticalAY committed Sep 6, 2024
1 parent eaa0463 commit 82d33e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,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 @@ -467,11 +484,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
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,6 @@ 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>
</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 82d33e7

Please sign in to comment.