From eb8c8f3201dbad2c916d41595696377c4763e847 Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Tue, 4 Jul 2023 19:49:03 +0300 Subject: [PATCH] replace outdated image cropper library with an up to date fork --- app/build.gradle | 2 +- .../gallery/pro/activities/EditActivity.kt | 14 ++++++------- .../pro/activities/SetWallpaperActivity.kt | 20 ++++++++++--------- app/src/main/res/layout/activity_edit.xml | 2 +- .../res/layout/activity_set_wallpaper.xml | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7e824f210..854b0e922 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -79,7 +79,7 @@ android { dependencies { implementation 'com.github.SimpleMobileTools:Simple-Commons:30e6321592' - implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' + implementation 'com.vanniktech:android-image-cropper:4.5.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index ccc0ad02a..46cee5feb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -24,6 +24,7 @@ import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target +import com.canhub.cropper.CropImageView import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.* @@ -44,7 +45,6 @@ import com.simplemobiletools.gallery.pro.extensions.fixDateTaken import com.simplemobiletools.gallery.pro.extensions.openEditor import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.models.FilterItem -import com.theartofdev.edmodo.cropper.CropImageView import com.zomato.photofilters.FilterPack import com.zomato.photofilters.imageprocessors.Filter import kotlinx.android.synthetic.main.activity_edit.* @@ -318,7 +318,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener setOldExif() if (crop_image_view.isVisible()) { - crop_image_view.getCroppedImageAsync() + crop_image_view.croppedImageAsync() } else if (editor_draw_canvas.isVisible()) { val bitmap = editor_draw_canvas.getBitmap() if (saveUri.scheme == "file") { @@ -387,7 +387,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener crop_image_view.isVisible() -> { isSharingBitmap = true runOnUiThread { - crop_image_view.getCroppedImageAsync() + crop_image_view.croppedImageAsync() } } editor_draw_canvas.isVisible() -> shareBitmap(editor_draw_canvas.getBitmap()) @@ -752,7 +752,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener ResizeDialog(this, point) { resizeWidth = it.x resizeHeight = it.y - crop_image_view.getCroppedImageAsync() + crop_image_view.croppedImageAsync() } } @@ -776,10 +776,10 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) { - if (result.error == null) { + if (result.error == null && result.bitmap != null) { setOldExif() - val bitmap = result.bitmap + val bitmap = result.bitmap!! if (isSharingBitmap) { isSharingBitmap = false shareBitmap(bitmap) @@ -826,7 +826,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener toast(R.string.unknown_file_location) } } else { - toast("${getString(R.string.image_editing_failed)}: ${result.error.message}") + toast("${getString(R.string.image_editing_failed)}: ${result.error?.message}") } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SetWallpaperActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SetWallpaperActivity.kt index 9a36ee237..5de0ae738 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SetWallpaperActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SetWallpaperActivity.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.graphics.Bitmap import android.net.Uri import android.os.Bundle +import com.canhub.cropper.CropImageView import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.checkAppSideloading import com.simplemobiletools.commons.extensions.toast @@ -14,9 +15,10 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.gallery.pro.R -import com.theartofdev.edmodo.cropper.CropImageView -import kotlinx.android.synthetic.main.activity_set_wallpaper.* -import kotlinx.android.synthetic.main.bottom_set_wallpaper_actions.* +import kotlinx.android.synthetic.main.activity_set_wallpaper.crop_image_view +import kotlinx.android.synthetic.main.activity_set_wallpaper.set_wallpaper_toolbar +import kotlinx.android.synthetic.main.bottom_set_wallpaper_actions.bottom_set_wallpaper_aspect_ratio +import kotlinx.android.synthetic.main.bottom_set_wallpaper_actions.bottom_set_wallpaper_rotate class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener { private val RATIO_PORTRAIT = 0 @@ -134,21 +136,21 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete RadioGroupDialog(this, items) { wallpaperFlag = it as Int - crop_image_view.getCroppedImageAsync() + crop_image_view.croppedImageAsync() } } else { - crop_image_view.getCroppedImageAsync() + crop_image_view.croppedImageAsync() } } - override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) { + override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) { if (isDestroyed) return - if (result.error == null) { + if (result.error == null && result.bitmap != null) { toast(R.string.setting_wallpaper) ensureBackgroundThread { - val bitmap = result.bitmap + val bitmap = result.bitmap!! val wantedHeight = wallpaperManager.desiredMinimumHeight val ratio = wantedHeight / bitmap.height.toFloat() val wantedWidth = (bitmap.width * ratio).toInt() @@ -167,7 +169,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete finish() } } else { - toast("${getString(R.string.image_editing_failed)}: ${result.error.message}") + toast("${getString(R.string.image_editing_failed)}: ${result.error?.message}") } } } diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml index 6a1f538de..e3ba641dd 100644 --- a/app/src/main/res/layout/activity_edit.xml +++ b/app/src/main/res/layout/activity_edit.xml @@ -34,7 +34,7 @@ android:layout_above="@+id/bottom_editor_crop_rotate_actions" android:layout_marginBottom="@dimen/bottom_filters_height_with_margin" /> - -