From c5f56edf66ef656fdc7a687e4cc1b11de1957143 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jul 2022 11:37:15 +0200 Subject: [PATCH] updating commons with initial dialog updates --- app/build.gradle | 2 +- .../gallery/pro/activities/MediaActivity.kt | 2 +- .../dialogs/ChangeFileThumbnailStyleDialog.kt | 9 ++- .../ChangeFolderThumbnailStyleDialog.kt | 19 ++--- .../pro/dialogs/ChangeGroupingDialog.kt | 6 +- .../pro/dialogs/ChangeSortingDialog.kt | 10 +-- .../pro/dialogs/ChangeViewTypeDialog.kt | 6 +- .../pro/dialogs/ConfirmDeleteFolderDialog.kt | 21 ++--- .../pro/dialogs/CustomAspectRatioDialog.kt | 29 +++---- .../pro/dialogs/DeleteWithRememberDialog.kt | 20 ++--- .../pro/dialogs/ExcludeFolderDialog.kt | 18 ++--- .../gallery/pro/dialogs/FilterMediaDialog.kt | 6 +- .../pro/dialogs/ManageBottomActionsDialog.kt | 14 ++-- .../dialogs/ManageExtendedDetailsDialog.kt | 14 ++-- .../pro/dialogs/OtherAspectRatioDialog.kt | 23 ++++-- .../pro/dialogs/PickDirectoryDialog.kt | 15 ++-- .../gallery/pro/dialogs/PickMediumDialog.kt | 25 +++--- .../gallery/pro/dialogs/ResizeDialog.kt | 34 ++++----- .../pro/dialogs/ResizeWithPathDialog.kt | 76 +++++++++---------- .../gallery/pro/dialogs/SaveAsDialog.kt | 17 ++--- .../gallery/pro/dialogs/SlideshowDialog.kt | 38 +++++----- 21 files changed, 204 insertions(+), 200 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6d3f7e0da..ebd055e0c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:ab6a89e3b9' + implementation 'com.github.SimpleMobileTools:Simple-Commons:2327fff588' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 398c34578..570a58828 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -390,7 +390,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { mPath == config.OTGPath -> getString(R.string.usb) else -> getHumanizedFilename(mPath) } - updateActionBarTitle(if (mShowAll) resources.getString(R.string.all_folders) else dirName) + //updateActionBarTitle(if (mShowAll) resources.getString(R.string.all_folders) else dirName) getMedia() setupLayoutManager() } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFileThumbnailStyleDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFileThumbnailStyleDialog.kt index fca5eb4b4..7517c53f3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFileThumbnailStyleDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFileThumbnailStyleDialog.kt @@ -2,9 +2,9 @@ package com.simplemobiletools.gallery.pro.dialogs import android.content.DialogInterface import android.view.View -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.RadioGroupDialog +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.gallery.pro.R @@ -39,7 +39,8 @@ class ChangeFileThumbnailStyleDialog(val activity: BaseSimpleActivity) : DialogI RadioItem(8, "8x"), RadioItem(16, "16x"), RadioItem(32, "32x"), - RadioItem(64, "64x")) + RadioItem(64, "64x") + ) RadioGroupDialog(activity, items, thumbnailSpacing) { thumbnailSpacing = it as Int @@ -50,10 +51,10 @@ class ChangeFileThumbnailStyleDialog(val activity: BaseSimpleActivity) : DialogI updateThumbnailSpacingText() - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, this) .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFolderThumbnailStyleDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFolderThumbnailStyleDialog.kt index 864015872..0b2e3ba28 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFolderThumbnailStyleDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeFolderThumbnailStyleDialog.kt @@ -1,18 +1,13 @@ package com.simplemobiletools.gallery.pro.dialogs import android.content.DialogInterface -import android.view.View import android.widget.RelativeLayout -import androidx.appcompat.app.AlertDialog import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.request.RequestOptions import com.simplemobiletools.commons.activities.BaseSimpleActivity -import com.simplemobiletools.commons.extensions.beGone -import com.simplemobiletools.commons.extensions.beVisible -import com.simplemobiletools.commons.extensions.getProperTextColor -import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.helpers.* @@ -21,17 +16,15 @@ import kotlinx.android.synthetic.main.directory_item_grid_square.view.* class ChangeFolderThumbnailStyleDialog(val activity: BaseSimpleActivity, val callback: () -> Unit) : DialogInterface.OnClickListener { private var config = activity.config - private var view: View + private var view = activity.layoutInflater.inflate(R.layout.dialog_change_folder_thumbnail_style, null).apply { + dialog_folder_limit_title.isChecked = config.limitFolderTitle + } init { - view = activity.layoutInflater.inflate(R.layout.dialog_change_folder_thumbnail_style, null).apply { - dialog_folder_limit_title.isChecked = config.limitFolderTitle - } - - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, this) .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this) { setupStyle() setupMediaCount() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeGroupingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeGroupingDialog.kt index fb968708a..422c2c188 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeGroupingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeGroupingDialog.kt @@ -2,9 +2,9 @@ package com.simplemobiletools.gallery.pro.dialogs import android.content.DialogInterface import android.view.View -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config @@ -25,10 +25,10 @@ class ChangeGroupingDialog(val activity: BaseSimpleActivity, val path: String = grouping_dialog_radio_folder.beVisibleIf(path.isEmpty()) } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, this) .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this, R.string.group_by) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt index a08c4257c..6a40e23c0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt @@ -2,12 +2,8 @@ package com.simplemobiletools.gallery.pro.dialogs import android.content.DialogInterface import android.view.View -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity -import com.simplemobiletools.commons.extensions.beGoneIf -import com.simplemobiletools.commons.extensions.beVisibleIf -import com.simplemobiletools.commons.extensions.isVisible -import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config @@ -38,10 +34,10 @@ class ChangeSortingDialog( sorting_dialog_radio_custom.beVisibleIf(isDirectorySorting) } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, this) .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this, R.string.sort_by) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt index e2364be6f..ebe343e48 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt @@ -1,9 +1,9 @@ package com.simplemobiletools.gallery.pro.dialogs import android.view.View -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST @@ -46,10 +46,10 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val fromFoldersView } } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ConfirmDeleteFolderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ConfirmDeleteFolderDialog.kt index 27f3a59c9..5861481ed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ConfirmDeleteFolderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ConfirmDeleteFolderDialog.kt @@ -2,30 +2,31 @@ package com.simplemobiletools.gallery.pro.dialogs import android.app.Activity import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import kotlinx.android.synthetic.main.dialog_confirm_delete_folder.view.* class ConfirmDeleteFolderDialog(activity: Activity, message: String, warningMessage: String, val callback: () -> Unit) { - var dialog: AlertDialog + private var dialog: AlertDialog? = null init { val view = activity.layoutInflater.inflate(R.layout.dialog_confirm_delete_folder, null) view.message.text = message view.message_warning.text = warningMessage - val builder = AlertDialog.Builder(activity) - .setPositiveButton(R.string.yes) { dialog, which -> dialogConfirmed() } - - builder.setNegativeButton(R.string.no, null) - - dialog = builder.create().apply { - activity.setupDialogStuff(view, this) - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.yes) { dialog, which -> dialogConfirmed() } + .setNegativeButton(R.string.no, null) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + dialog = alertDialog + } + } } private fun dialogConfirmed() { - dialog.dismiss() + dialog?.dismiss() callback() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt index 47df4b89e..874422538 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt @@ -3,33 +3,36 @@ package com.simplemobiletools.gallery.pro.dialogs import android.widget.EditText import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.showKeyboard import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.gallery.pro.R import kotlinx.android.synthetic.main.dialog_custom_aspect_ratio.view.* -class CustomAspectRatioDialog(val activity: BaseSimpleActivity, val defaultCustomAspectRatio: Pair?, val callback: (aspectRatio: Pair) -> Unit) { +class CustomAspectRatioDialog( + val activity: BaseSimpleActivity, val defaultCustomAspectRatio: Pair?, val callback: (aspectRatio: Pair) -> Unit +) { init { val view = activity.layoutInflater.inflate(R.layout.dialog_custom_aspect_ratio, null).apply { aspect_ratio_width.setText(defaultCustomAspectRatio?.first?.toInt()?.toString() ?: "") aspect_ratio_height.setText(defaultCustomAspectRatio?.second?.toInt()?.toString() ?: "") } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) { - showKeyboard(view.aspect_ratio_width) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val width = getViewValue(view.aspect_ratio_width) - val height = getViewValue(view.aspect_ratio_height) - callback(Pair(width, height)) - dismiss() - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + alertDialog.showKeyboard(view.aspect_ratio_width) + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val width = getViewValue(view.aspect_ratio_width) + val height = getViewValue(view.aspect_ratio_height) + callback(Pair(width, height)) + alertDialog.dismiss() } } + } } private fun getViewValue(view: EditText): Float { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt index c570820b8..db401b0e2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt @@ -2,27 +2,29 @@ package com.simplemobiletools.gallery.pro.dialogs import android.app.Activity import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import kotlinx.android.synthetic.main.dialog_delete_with_remember.view.* class DeleteWithRememberDialog(val activity: Activity, val message: String, val callback: (remember: Boolean) -> Unit) { - private var dialog: AlertDialog + private var dialog: AlertDialog? = null val view = activity.layoutInflater.inflate(R.layout.dialog_delete_with_remember, null)!! init { view.delete_remember_title.text = message - val builder = AlertDialog.Builder(activity) - .setPositiveButton(R.string.yes) { dialog, which -> dialogConfirmed() } - .setNegativeButton(R.string.no, null) - - dialog = builder.create().apply { - activity.setupDialogStuff(view, this) - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.yes) { dialog, which -> dialogConfirmed() } + .setNegativeButton(R.string.no, null) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + dialog = alertDialog + } + } } private fun dialogConfirmed() { - dialog.dismiss() + dialog?.dismiss() callback(view.delete_remember_checkbox.isChecked) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ExcludeFolderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ExcludeFolderDialog.kt index 8575f75a4..d610b2387 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ExcludeFolderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ExcludeFolderDialog.kt @@ -3,9 +3,9 @@ package com.simplemobiletools.gallery.pro.dialogs import android.view.ViewGroup import android.widget.RadioButton import android.widget.RadioGroup -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.getBasePath import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R @@ -13,8 +13,8 @@ import com.simplemobiletools.gallery.pro.extensions.config import kotlinx.android.synthetic.main.dialog_exclude_folder.view.* class ExcludeFolderDialog(val activity: BaseSimpleActivity, val selectedPaths: List, val callback: () -> Unit) { - val alternativePaths = getAlternativePathsList() - var radioGroup: RadioGroup? = null + private val alternativePaths = getAlternativePathsList() + private var radioGroup: RadioGroup? = null init { val view = activity.layoutInflater.inflate(R.layout.dialog_exclude_folder, null).apply { @@ -33,12 +33,12 @@ class ExcludeFolderDialog(val activity: BaseSimpleActivity, val selectedPaths: L radioGroup!!.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) + } } private fun dialogConfirmed() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/FilterMediaDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/FilterMediaDialog.kt index f694bfd4b..f29b8020c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/FilterMediaDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/FilterMediaDialog.kt @@ -1,7 +1,7 @@ package com.simplemobiletools.gallery.pro.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config @@ -22,10 +22,10 @@ class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: filter_media_portraits.isChecked = filterMedia and TYPE_PORTRAITS != 0 } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this, R.string.filter_media) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageBottomActionsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageBottomActionsDialog.kt index cfbe131f8..da86d9abd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageBottomActionsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageBottomActionsDialog.kt @@ -1,7 +1,7 @@ package com.simplemobiletools.gallery.pro.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config @@ -31,12 +31,12 @@ class ManageBottomActionsDialog(val activity: BaseSimpleActivity, val callback: manage_bottom_actions_resize.isChecked = actions and BOTTOM_ACTION_RESIZE != 0 } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) + } } private fun dialogConfirmed() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageExtendedDetailsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageExtendedDetailsDialog.kt index 6c52c3408..8e369452f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageExtendedDetailsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ManageExtendedDetailsDialog.kt @@ -1,7 +1,7 @@ package com.simplemobiletools.gallery.pro.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config @@ -25,12 +25,12 @@ class ManageExtendedDetailsDialog(val activity: BaseSimpleActivity, val callback manage_extended_details_gps_coordinates.isChecked = details and EXT_GPS != 0 } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) + } } private fun dialogConfirmed() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt index 76f7e7e78..049184cd8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt @@ -2,12 +2,17 @@ package com.simplemobiletools.gallery.pro.dialogs import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import kotlinx.android.synthetic.main.dialog_other_aspect_ratio.view.* -class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspectRatio: Pair?, val callback: (aspectRatio: Pair) -> Unit) { - private val dialog: AlertDialog +class OtherAspectRatioDialog( + val activity: BaseSimpleActivity, + val lastOtherAspectRatio: Pair?, + val callback: (aspectRatio: Pair) -> Unit +) { + private var dialog: AlertDialog? = null init { val view = activity.layoutInflater.inflate(R.layout.dialog_other_aspect_ratio, null).apply { @@ -53,22 +58,24 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe } } - dialog = AlertDialog.Builder(activity) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) + activity.getAlertDialogBuilder() + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + dialog = alertDialog } + } } private fun customRatioPicked() { CustomAspectRatioDialog(activity, lastOtherAspectRatio) { callback(it) - dialog.dismiss() + dialog?.dismiss() } } private fun ratioPicked(pair: Pair) { callback(pair) - dialog.dismiss() + dialog?.dismiss() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt index 326fcb4d7..768567c7b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt @@ -24,7 +24,7 @@ class PickDirectoryDialog( val isPickingFolderForWidget: Boolean, val callback: (path: String) -> Unit ) { - private var dialog: AlertDialog + private var dialog: AlertDialog? = null private var shownDirectories = ArrayList() private var allDirectories = ArrayList() private var openedSubfolders = arrayListOf("") @@ -41,7 +41,7 @@ class PickDirectoryDialog( view.directories_fastscroller.updateColors(activity.getProperPrimaryColor()) - val builder = AlertDialog.Builder(activity) + val builder = activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .setOnKeyListener { dialogInterface, i, keyEvent -> @@ -55,8 +55,9 @@ class PickDirectoryDialog( builder.setNeutralButton(R.string.other_folder) { dialogInterface, i -> showOtherFolder() } } - dialog = builder.create().apply { - activity.setupDialogStuff(view, this, R.string.select_destination) { + builder.apply { + activity.setupDialogStuff(view, this, R.string.select_destination) { alertDialog -> + dialog = alertDialog view.directories_show_hidden.beVisibleIf(!context.config.shouldShowHidden) view.directories_show_hidden.setOnClickListener { activity.handleHiddenFolderPasswordProtection { @@ -125,7 +126,7 @@ class PickDirectoryDialog( callback(path) } } - dialog.dismiss() + dialog?.dismiss() } } else { currentPathPrefix = path @@ -144,14 +145,14 @@ class PickDirectoryDialog( private fun backPressed() { if (activity.config.groupDirectSubfolders) { if (currentPathPrefix.isEmpty()) { - dialog.dismiss() + dialog?.dismiss() } else { openedSubfolders.removeAt(openedSubfolders.size - 1) currentPathPrefix = openedSubfolders.last() gotDirectories(allDirectories) } } else { - dialog.dismiss() + dialog?.dismiss() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt index e15877f4d..3253f79ac 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.pro.dialogs import androidx.appcompat.app.AlertDialog import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID @@ -20,12 +21,12 @@ import com.simplemobiletools.gallery.pro.models.ThumbnailSection import kotlinx.android.synthetic.main.dialog_medium_picker.view.* class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val callback: (path: String) -> Unit) { - var dialog: AlertDialog - var shownMedia = ArrayList() - val view = activity.layoutInflater.inflate(R.layout.dialog_medium_picker, null) - val config = activity.config - val viewType = config.getFolderViewType(if (config.showAll) SHOW_ALL else path) - var isGridViewType = viewType == VIEW_TYPE_GRID + private var dialog: AlertDialog? = null + private var shownMedia = ArrayList() + private val view = activity.layoutInflater.inflate(R.layout.dialog_medium_picker, null) + private val config = activity.config + private val viewType = config.getFolderViewType(if (config.showAll) SHOW_ALL else path) + private var isGridViewType = viewType == VIEW_TYPE_GRID init { (view.media_grid.layoutManager as MyGridLayoutManager).apply { @@ -35,12 +36,14 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c view.media_fastscroller.updateColors(activity.getProperPrimaryColor()) - dialog = AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .setNeutralButton(R.string.other_folder) { dialogInterface, i -> showOtherFolder() } - .create().apply { - activity.setupDialogStuff(view, this, R.string.select_photo) + .apply { + activity.setupDialogStuff(view, this, R.string.select_photo) { alertDialog -> + dialog = alertDialog + } } activity.getCachedMedia(path) { @@ -60,7 +63,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c private fun showOtherFolder() { PickDirectoryDialog(activity, path, true, true, false, false) { callback(it) - dialog.dismiss() + dialog?.dismiss() } } @@ -72,7 +75,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c val adapter = MediaAdapter(activity, shownMedia.clone() as ArrayList, null, true, false, path, view.media_grid) { if (it is Medium) { callback(it.path) - dialog.dismiss() + dialog?.dismiss() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt index 96ef3b50b..f6caebfac 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt @@ -47,26 +47,26 @@ class ResizeDialog(val activity: BaseSimpleActivity, val size: Point, val callba } } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.resize_and_save) { - 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() + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.resize_and_save) { alertDialog -> + alertDialog.showKeyboard(view.image_width) + alertDialog.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) + alertDialog.dismiss() } } + } } private fun getViewValue(view: EditText): Int { 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 index b377f6801..134e21e3b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeWithPathDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeWithPathDialog.kt @@ -68,54 +68,54 @@ class ResizeWithPathDialog(val activity: BaseSimpleActivity, val size: Point, va } } - 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 - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + alertDialog.showKeyboard(view.image_width) + alertDialog.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)) + val newSize = Point(getViewValue(widthView), getViewValue(heightView)) - val filename = view.image_name.value - val extension = view.image_extension.value - if (filename.isEmpty()) { - activity.toast(R.string.filename_cannot_be_empty) - return@setOnClickListener - } + val filename = view.image_name.value + val extension = view.image_extension.value + if (filename.isEmpty()) { + activity.toast(R.string.filename_cannot_be_empty) + return@setOnClickListener + } - if (extension.isEmpty()) { - activity.toast(R.string.extension_cannot_be_empty) - return@setOnClickListener - } + if (extension.isEmpty()) { + activity.toast(R.string.extension_cannot_be_empty) + return@setOnClickListener + } - val newFilename = "$filename.$extension" - val newPath = "${realPath.trimEnd('/')}/$newFilename" - if (!newFilename.isAValidFilename()) { - activity.toast(R.string.filename_invalid_characters) - return@setOnClickListener - } + val newFilename = "$filename.$extension" + val newPath = "${realPath.trimEnd('/')}/$newFilename" + if (!newFilename.isAValidFilename()) { + activity.toast(R.string.filename_invalid_characters) + return@setOnClickListener + } - if (activity.getDoesFilePathExist(newPath)) { - val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) - ConfirmationDialog(activity, title) { - callback(newSize, newPath) - dismiss() - } - } else { + if (activity.getDoesFilePathExist(newPath)) { + val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) + ConfirmationDialog(activity, title) { callback(newSize, newPath) - dismiss() + alertDialog.dismiss() } + } else { + callback(newSize, newPath) + alertDialog.dismiss() } } } + } } private fun getViewValue(view: EditText): Int { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt index 48afaea8b..01829dc16 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt @@ -14,7 +14,6 @@ class SaveAsDialog( val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val cancelCallback: (() -> Unit)? = null, val callback: (savePath: String) -> Unit ) { - init { var realPath = path.getParentPath() if (activity.isRestrictedWithSAFSdk30(realPath) && !activity.isInDownloadDir(realPath)) { @@ -48,14 +47,14 @@ class SaveAsDialog( } } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel) { dialog, which -> cancelCallback?.invoke() } .setOnCancelListener { cancelCallback?.invoke() } - .create().apply { - activity.setupDialogStuff(view, this, R.string.save_as) { - showKeyboard(view.save_as_name) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + .apply { + activity.setupDialogStuff(view, this, R.string.save_as) { alertDialog -> + alertDialog.showKeyboard(view.save_as_name) + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { val filename = view.save_as_name.value val extension = view.save_as_extension.value @@ -87,15 +86,15 @@ class SaveAsDialog( val fileUris = activity.getFileUrisFromFileDirItems(fileDirItem) activity.updateSDK30Uris(fileUris) { success -> if (success) { - selectPath(this, newPath) + selectPath(alertDialog, newPath) } } } else { - selectPath(this, newPath) + selectPath(alertDialog, newPath) } } } else { - selectPath(this, newPath) + selectPath(alertDialog, newPath) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SlideshowDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SlideshowDialog.kt index 66d57fef9..a47a8028c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SlideshowDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SlideshowDialog.kt @@ -4,6 +4,7 @@ import android.view.View import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.RadioGroupDialog +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.value @@ -17,16 +18,12 @@ import com.simplemobiletools.gallery.pro.helpers.SLIDESHOW_DEFAULT_INTERVAL import kotlinx.android.synthetic.main.dialog_slideshow.view.* class SlideshowDialog(val activity: BaseSimpleActivity, val callback: () -> Unit) { - val view: View + private val view: View init { view = activity.layoutInflater.inflate(R.layout.dialog_slideshow, null).apply { interval_value.setOnClickListener { - val text = interval_value.text - if (text.isNotEmpty()) { - text.replace(0, 1, text.subSequence(0, 1), 0, 1) - interval_value.selectAll() - } + interval_value.selectAll() } interval_value.setOnFocusChangeListener { v, hasFocus -> @@ -36,9 +33,10 @@ class SlideshowDialog(val activity: BaseSimpleActivity, val callback: () -> Unit animation_holder.setOnClickListener { val items = arrayListOf( - RadioItem(SLIDESHOW_ANIMATION_NONE, activity.getString(R.string.no_animation)), - RadioItem(SLIDESHOW_ANIMATION_SLIDE, activity.getString(R.string.slide)), - RadioItem(SLIDESHOW_ANIMATION_FADE, activity.getString(R.string.fade))) + RadioItem(SLIDESHOW_ANIMATION_NONE, activity.getString(R.string.no_animation)), + RadioItem(SLIDESHOW_ANIMATION_SLIDE, activity.getString(R.string.slide)), + RadioItem(SLIDESHOW_ANIMATION_FADE, activity.getString(R.string.fade)) + ) RadioGroupDialog(activity, items, activity.config.slideshowAnimation) { activity.config.slideshowAnimation = it as Int @@ -73,19 +71,19 @@ class SlideshowDialog(val activity: BaseSimpleActivity, val callback: () -> Unit } setupValues() - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) { - hideKeyboard() - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - storeValues() - callback() - dismiss() - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + alertDialog.hideKeyboard() + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + storeValues() + callback() + alertDialog.dismiss() } } + } } private fun setupValues() {