make "Save as" the only saving option in the editor
This commit is contained in:
parent
267317c7c2
commit
96b25a43b8
2 changed files with 15 additions and 44 deletions
|
@ -22,7 +22,6 @@ import java.io.OutputStream
|
||||||
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
||||||
val TAG: String = EditActivity::class.java.simpleName
|
val TAG: String = EditActivity::class.java.simpleName
|
||||||
|
|
||||||
var overrideOriginal = false
|
|
||||||
lateinit var uri: Uri
|
lateinit var uri: Uri
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -56,8 +55,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.save -> {
|
R.id.save_as -> {
|
||||||
overrideOriginal = true
|
|
||||||
crop_image_view.getCroppedImageAsync()
|
crop_image_view.getCroppedImageAsync()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -65,47 +63,30 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
crop_image_view.rotateImage(90)
|
crop_image_view.rotateImage(90)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.save_as -> {
|
|
||||||
saveAs()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveAs() {
|
|
||||||
overrideOriginal = false
|
|
||||||
crop_image_view.getCroppedImageAsync()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
|
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
|
||||||
if (result.error == null) {
|
if (result.error == null) {
|
||||||
if (uri.scheme == "file") {
|
if (uri.scheme == "file") {
|
||||||
if (overrideOriginal)
|
SaveAsDialog(this, uri.path, object : SaveAsDialog.OnSaveAsListener {
|
||||||
saveBitmapToFile(result.bitmap, uri.path)
|
override fun onSaveAsSuccess(filename: String) {
|
||||||
else {
|
val parent = File(uri.path).parent
|
||||||
SaveAsDialog(this, uri.path, object : SaveAsDialog.OnSaveAsListener {
|
val path = File(parent, filename).absolutePath
|
||||||
|
saveBitmapToFile(result.bitmap, path)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (uri.scheme == "content") {
|
||||||
|
val newPath = Utils.getRealPathFromURI(applicationContext, uri) ?: ""
|
||||||
|
if (!newPath.isEmpty()) {
|
||||||
|
SaveAsDialog(this, newPath, object : SaveAsDialog.OnSaveAsListener {
|
||||||
override fun onSaveAsSuccess(filename: String) {
|
override fun onSaveAsSuccess(filename: String) {
|
||||||
val parent = File(uri.path).parent
|
val parent = File(uri.path).parent
|
||||||
val path = File(parent, filename).absolutePath
|
val path = File(parent, filename).absolutePath
|
||||||
saveBitmapToFile(result.bitmap, path)
|
saveBitmapToFile(result.bitmap, path)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
} else if (uri.scheme == "content") {
|
|
||||||
val newPath = Utils.getRealPathFromURI(applicationContext, uri) ?: ""
|
|
||||||
if (!newPath.isEmpty()) {
|
|
||||||
if (overrideOriginal) {
|
|
||||||
saveBitmapToFile(result.bitmap, newPath)
|
|
||||||
} else {
|
|
||||||
SaveAsDialog(this, newPath, object : SaveAsDialog.OnSaveAsListener {
|
|
||||||
override fun onSaveAsSuccess(filename: String) {
|
|
||||||
val parent = File(uri.path).parent
|
|
||||||
val path = File(parent, filename).absolutePath
|
|
||||||
saveBitmapToFile(result.bitmap, path)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.image_editing_failed)
|
toast(R.string.image_editing_failed)
|
||||||
finish()
|
finish()
|
||||||
|
@ -121,11 +102,6 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
|
|
||||||
private fun saveBitmapToFile(bitmap: Bitmap, path: String) {
|
private fun saveBitmapToFile(bitmap: Bitmap, path: String) {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
if (overrideOriginal && !file.exists()) {
|
|
||||||
toast(R.string.error_saving_file)
|
|
||||||
finish()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var out: OutputStream? = null
|
var out: OutputStream? = null
|
||||||
try {
|
try {
|
||||||
|
@ -162,8 +138,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overrideOriginal)
|
finish()
|
||||||
finish()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,9 @@
|
||||||
android:icon="@mipmap/rotate"
|
android:icon="@mipmap/rotate"
|
||||||
android:title="@string/rotate"
|
android:title="@string/rotate"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom"/>
|
||||||
<item
|
|
||||||
android:id="@+id/save"
|
|
||||||
android:icon="@mipmap/check"
|
|
||||||
android:title="@string/save"
|
|
||||||
app:showAsAction="ifRoom"/>
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/save_as"
|
android:id="@+id/save_as"
|
||||||
|
android:icon="@mipmap/check"
|
||||||
android:title="@string/save_as"
|
android:title="@string/save_as"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="ifRoom"/>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
Loading…
Reference in a new issue