# HG changeset patch # User David Barts # Date 1614134179 28800 # Node ID 648908f492c037590af37b44fa9b08c97504c1de # Parent 474ef75856c2a03b4bdb55deb910eef14322af68 Fix output file names. diff -r 474ef75856c2 -r 648908f492c0 app/src/main/java/com/bartsent/simpleresizer/EditImage.kt --- a/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt Tue Feb 23 15:20:15 2021 -0800 +++ b/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt Tue Feb 23 18:36:19 2021 -0800 @@ -276,30 +276,26 @@ } fun doneClicked(view: View): Unit { - val contentValues = ContentValues().apply { - var fileName = getFileName(State.uri!!) - if (fileName == null) { - val d = java.util.Date() - fileName = "IMG_%tY%tm%td_%tH%tM%tS.jpg".format(d, d, d, d, d, d) - } else { + val image = State.bitmap!! + binding.progressBar.visibility = ProgressBar.VISIBLE + ThreadPools.WORKERS.execute { + val contentValues = ContentValues().apply { + var fileName = getFileName(State.uri!!) + if (fileName == null) { + val d = java.util.Date() + fileName = "IMG_%tY%tm%td_%tH%tM%tS".format(d, d, d, d, d, d) + } val dot = fileName.lastIndexOf('.') - if (dot == -1) { - fileName = fileName + ".jpg" - } else { - val fileExt = fileName.substring(dot).toLowerCase() - if (fileExt !in setOf(".jpg", ".jpeg")) - fileName = fileName.substring(0..dot) + ".jpg" + if (dot != -1) + fileName = fileName.substring(0, dot) + fileName = "${fileName}_${image.width}x${image.height}.jpg" + put(MediaStore.MediaColumns.DISPLAY_NAME, fileName) + put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg") + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + put(MediaStore.MediaColumns.RELATIVE_PATH, + File(Environment.DIRECTORY_PICTURES, getString(R.string.app_name)).path) } } - put(MediaStore.MediaColumns.DISPLAY_NAME, fileName) - put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg") - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { - put(MediaStore.MediaColumns.RELATIVE_PATH, - File(Environment.DIRECTORY_PICTURES, getString(R.string.app_name)).getPath()) - } - } - binding.progressBar.visibility = ProgressBar.VISIBLE - ThreadPools.WORKERS.execute { var errorMessage: String? = null try { val myUri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues) @@ -315,7 +311,7 @@ "jpeg_quality", 85))) Log.d("EditImage", "saving, jpeg_quality = $quality") stream.use { - if (!State.bitmap!!.compress(Bitmap.CompressFormat.JPEG, quality, it)) { + if (!image.compress(Bitmap.CompressFormat.JPEG, quality, it)) { throw IOException(getString(R.string.error_save_bitmap)) } }