Remove unnecessary text view and error handling
This commit is contained in:
parent
726e7c1649
commit
2919b36583
2 changed files with 14 additions and 54 deletions
|
@ -1,11 +1,7 @@
|
||||||
package com.simplemobiletools.gallery.pro.dialogs
|
package com.simplemobiletools.gallery.pro.dialogs
|
||||||
|
|
||||||
import android.graphics.Point
|
import android.graphics.Point
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Looper
|
|
||||||
import android.view.View
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.widget.doAfterTextChanged
|
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
|
@ -14,13 +10,11 @@ import com.simplemobiletools.gallery.pro.extensions.ensureWriteAccess
|
||||||
import com.simplemobiletools.gallery.pro.extensions.rescanPathsAndUpdateLastModified
|
import com.simplemobiletools.gallery.pro.extensions.rescanPathsAndUpdateLastModified
|
||||||
import com.simplemobiletools.gallery.pro.extensions.resizeImage
|
import com.simplemobiletools.gallery.pro.extensions.resizeImage
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_edit_text
|
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_edit_text
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_info
|
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_input_layout
|
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_input_layout
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_progress
|
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_progress
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private const val DEFAULT_RESIZE_FACTOR = "75"
|
private const val DEFAULT_RESIZE_FACTOR = "75"
|
||||||
private const val RESIZE_FACTOR_ERROR_DELAY = 800L
|
|
||||||
|
|
||||||
class ResizeMultipleImagesDialog(
|
class ResizeMultipleImagesDialog(
|
||||||
private val activity: BaseSimpleActivity,
|
private val activity: BaseSimpleActivity,
|
||||||
|
@ -35,7 +29,12 @@ class ResizeMultipleImagesDialog(
|
||||||
private val resizeFactorEditText = view.resize_factor_edit_text
|
private val resizeFactorEditText = view.resize_factor_edit_text
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setupViews(view)
|
resizeFactorEditText.setText(DEFAULT_RESIZE_FACTOR)
|
||||||
|
progressView.apply {
|
||||||
|
max = imagePaths.size
|
||||||
|
setIndicatorColor(activity.getProperPrimaryColor())
|
||||||
|
}
|
||||||
|
|
||||||
activity.getAlertDialogBuilder()
|
activity.getAlertDialogBuilder()
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
@ -48,19 +47,15 @@ class ResizeMultipleImagesDialog(
|
||||||
val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
|
val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
|
||||||
positiveButton.setOnClickListener {
|
positiveButton.setOnClickListener {
|
||||||
val resizeFactorText = resizeFactorEditText.text?.toString()
|
val resizeFactorText = resizeFactorEditText.text?.toString()
|
||||||
val resizeFactor = try {
|
if (resizeFactorText.isNullOrEmpty() || resizeFactorText.toInt() !in 10..90) {
|
||||||
resizeFactorText?.toFloat()?.div(100)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resizeFactor == null) {
|
|
||||||
activity.toast(R.string.resize_factor_error)
|
activity.toast(R.string.resize_factor_error)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val resizeFactor = resizeFactorText.toFloat().div(100)
|
||||||
|
|
||||||
alertDialog.setCanceledOnTouchOutside(false)
|
alertDialog.setCanceledOnTouchOutside(false)
|
||||||
arrayOf(view.resize_factor_input_layout, view.resize_factor_info, positiveButton, negativeButton).forEach {
|
arrayOf(view.resize_factor_input_layout, positiveButton, negativeButton).forEach {
|
||||||
it.isEnabled = false
|
it.isEnabled = false
|
||||||
it.alpha = 0.6f
|
it.alpha = 0.6f
|
||||||
}
|
}
|
||||||
|
@ -120,29 +115,4 @@ class ResizeMultipleImagesDialog(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupViews(view: View) {
|
|
||||||
val handler = Handler(Looper.getMainLooper())
|
|
||||||
val resizeFactorInputLayout = view.resize_factor_input_layout
|
|
||||||
view.resize_factor_edit_text.apply {
|
|
||||||
setText(DEFAULT_RESIZE_FACTOR)
|
|
||||||
doAfterTextChanged {
|
|
||||||
resizeFactorInputLayout.error = null
|
|
||||||
handler.removeCallbacksAndMessages(null)
|
|
||||||
handler.postDelayed({
|
|
||||||
val factorText = it?.toString()
|
|
||||||
if (factorText.isNullOrEmpty() || factorText.toInt() !in 10..90) {
|
|
||||||
resizeFactorInputLayout.error = activity.getString(R.string.resize_factor_error)
|
|
||||||
} else {
|
|
||||||
resizeFactorInputLayout.error = null
|
|
||||||
}
|
|
||||||
}, RESIZE_FACTOR_ERROR_DELAY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
progressView.apply {
|
|
||||||
max = imagePaths.size
|
|
||||||
setIndicatorColor(activity.getProperPrimaryColor())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,27 +14,17 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
|
||||||
android:id="@+id/resize_factor_info"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="@dimen/big_margin"
|
|
||||||
android:layout_marginTop="@dimen/normal_margin"
|
|
||||||
android:text="@string/resize_factor_info"
|
|
||||||
android:textSize="@dimen/normal_text_size"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/resize_progress" />
|
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextInputLayout
|
<com.simplemobiletools.commons.views.MyTextInputLayout
|
||||||
android:id="@+id/resize_factor_input_layout"
|
android:id="@+id/resize_factor_input_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="@dimen/big_margin"
|
android:layout_marginHorizontal="@dimen/big_margin"
|
||||||
android:layout_marginTop="@dimen/medium_margin"
|
android:layout_marginTop="@dimen/normal_margin"
|
||||||
android:hint="@string/resize_factor"
|
android:hint="@string/resize_factor"
|
||||||
app:errorEnabled="true"
|
app:errorEnabled="true"
|
||||||
app:layout_constraintTop_toBottomOf="@id/resize_factor_info"
|
app:helperText="Resize images to the given percentage, value must be within 10 and 90"
|
||||||
|
app:helperTextEnabled="true"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/resize_progress"
|
||||||
app:suffixText="%">
|
app:suffixText="%">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
|
Loading…
Reference in a new issue