adding some old editor improvements, do not request storage permission
This commit is contained in:
parent
1a05ea8db4
commit
53d48cce6d
|
@ -78,7 +78,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.23.7'
|
implementation 'com.simplemobiletools:commons:5.23.8'
|
||||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.media.ExifInterface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
@ -27,7 +28,6 @@ import com.bumptech.glide.request.target.Target
|
||||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
|
||||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||||
|
@ -75,8 +75,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
private val CROP_ROTATE_NONE = 0
|
private val CROP_ROTATE_NONE = 0
|
||||||
private val CROP_ROTATE_ASPECT_RATIO = 1
|
private val CROP_ROTATE_ASPECT_RATIO = 1
|
||||||
|
|
||||||
private lateinit var uri: Uri
|
|
||||||
private lateinit var saveUri: Uri
|
private lateinit var saveUri: Uri
|
||||||
|
private var uri: Uri? = null
|
||||||
private var resizeWidth = 0
|
private var resizeWidth = 0
|
||||||
private var resizeHeight = 0
|
private var resizeHeight = 0
|
||||||
private var drawColor = 0
|
private var drawColor = 0
|
||||||
|
@ -90,6 +90,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
private var wasDrawCanvasPositioned = false
|
private var wasDrawCanvasPositioned = false
|
||||||
private var oldExif: ExifInterface? = null
|
private var oldExif: ExifInterface? = null
|
||||||
private var filterInitialBitmap: Bitmap? = null
|
private var filterInitialBitmap: Bitmap? = null
|
||||||
|
private var originalUri: Uri? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -99,14 +100,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
initEditActivity()
|
||||||
if (it) {
|
|
||||||
initEditActivity()
|
|
||||||
} else {
|
|
||||||
toast(R.string.no_storage_permissions)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -146,7 +140,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
|
|
||||||
uri = intent.data!!
|
uri = intent.data!!
|
||||||
if (uri.scheme != "file" && uri.scheme != "content") {
|
originalUri = uri
|
||||||
|
if (uri!!.scheme != "file" && uri!!.scheme != "content") {
|
||||||
toast(R.string.unknown_file_location)
|
toast(R.string.unknown_file_location)
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
|
@ -160,14 +155,14 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
else -> Uri.fromFile(File(realPath))
|
else -> Uri.fromFile(File(realPath))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(getRealPathFromURI(uri))?.apply {
|
(getRealPathFromURI(uri!!))?.apply {
|
||||||
uri = Uri.fromFile(File(this))
|
uri = Uri.fromFile(File(this))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveUri = when {
|
saveUri = when {
|
||||||
intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
|
intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
|
||||||
else -> uri
|
else -> uri!!
|
||||||
}
|
}
|
||||||
|
|
||||||
isCropIntent = intent.extras?.get(CROP) == "true"
|
isCropIntent = intent.extras?.get(CROP) == "true"
|
||||||
|
@ -209,7 +204,15 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
.load(uri)
|
.load(uri)
|
||||||
.apply(options)
|
.apply(options)
|
||||||
.listener(object : RequestListener<Bitmap> {
|
.listener(object : RequestListener<Bitmap> {
|
||||||
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean) = false
|
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
|
||||||
|
if (uri != originalUri) {
|
||||||
|
uri = originalUri
|
||||||
|
Handler().post {
|
||||||
|
loadDefaultImageView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResourceReady(bitmap: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
override fun onResourceReady(bitmap: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
||||||
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
||||||
|
@ -304,7 +307,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
var inputStream: InputStream? = null
|
var inputStream: InputStream? = null
|
||||||
try {
|
try {
|
||||||
if (isNougatPlus()) {
|
if (isNougatPlus()) {
|
||||||
inputStream = contentResolver.openInputStream(uri)
|
inputStream = contentResolver.openInputStream(uri!!)
|
||||||
oldExif = ExifInterface(inputStream!!)
|
oldExif = ExifInterface(inputStream!!)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
Loading…
Reference in New Issue