diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 086cc83dc..9e9b0cf5b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -44,6 +44,7 @@ import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.adapters.MyPagerAdapter import com.simplemobiletools.gallery.pro.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.pro.dialogs.DeleteWithRememberDialog +import com.simplemobiletools.gallery.pro.dialogs.ResizeWithPathDialog import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog import com.simplemobiletools.gallery.pro.dialogs.SlideshowDialog import com.simplemobiletools.gallery.pro.extensions.* @@ -918,7 +919,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun resizeImage() { + val currentPath = getCurrentPath() + val originalSize = currentPath.getImageResolution() ?: return + ResizeWithPathDialog(this, originalSize, currentPath) { + } } private fun checkDeleteConfirmation() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeWithPathDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeWithPathDialog.kt new file mode 100644 index 000000000..f3863943d --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeWithPathDialog.kt @@ -0,0 +1,98 @@ +package com.simplemobiletools.gallery.pro.dialogs + +import android.graphics.Point +import android.widget.EditText +import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.dialogs.FilePickerDialog +import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.gallery.pro.R +import com.simplemobiletools.gallery.pro.extensions.config +import kotlinx.android.synthetic.main.dialog_resize_image.view.image_height +import kotlinx.android.synthetic.main.dialog_resize_image.view.image_width +import kotlinx.android.synthetic.main.dialog_resize_image_with_path.view.* + +class ResizeWithPathDialog(val activity: BaseSimpleActivity, val size: Point, val path: String, val callback: (newSize: Point) -> Unit) { + init { + var realPath = path.getParentPath() + val view = activity.layoutInflater.inflate(R.layout.dialog_resize_image_with_path, null).apply { + image_path.text = "${activity.humanizePath(realPath).trimEnd('/')}/" + + val fullName = path.getFilenameFromPath() + val dotAt = fullName.lastIndexOf(".") + var name = fullName + + if (dotAt > 0) { + name = fullName.substring(0, dotAt) + val extension = fullName.substring(dotAt + 1) + image_extension.setText(extension) + } + + image_name.setText(name) + image_path.setOnClickListener { + FilePickerDialog(activity, realPath, false, activity.config.shouldShowHidden, true, true) { + image_path.text = activity.humanizePath(it) + realPath = it + } + } + } + + val widthView = view.image_width + val heightView = view.image_height + + widthView.setText(size.x.toString()) + heightView.setText(size.y.toString()) + + val ratio = size.x / size.y.toFloat() + + widthView.onTextChangeListener { + if (widthView.hasFocus()) { + var width = getViewValue(widthView) + if (width > size.x) { + widthView.setText(size.x.toString()) + width = size.x + } + + heightView.setText((width / ratio).toInt().toString()) + } + } + + heightView.onTextChangeListener { + if (heightView.hasFocus()) { + var height = getViewValue(heightView) + if (height > size.y) { + heightView.setText(size.y.toString()) + height = size.y + } + + widthView.setText((height * ratio).toInt().toString()) + } + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) { + showKeyboard(view.image_width) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val width = getViewValue(widthView) + val height = getViewValue(heightView) + if (width <= 0 || height <= 0) { + activity.toast(R.string.invalid_values) + return@setOnClickListener + } + + val newSize = Point(getViewValue(widthView), getViewValue(heightView)) + callback(newSize) + dismiss() + } + } + } + } + + private fun getViewValue(view: EditText): Int { + val textValue = view.value + return if (textValue.isEmpty()) 0 else textValue.toInt() + } +} diff --git a/app/src/main/res/layout/dialog_resize_image_with_path.xml b/app/src/main/res/layout/dialog_resize_image_with_path.xml new file mode 100644 index 000000000..c1defcff2 --- /dev/null +++ b/app/src/main/res/layout/dialog_resize_image_with_path.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + +