Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e74b3014 authored by tibbi's avatar tibbi
Browse files

lets replace setupDialogStuff boolean with an anonymous callback

parent 93c5db70
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@ package com.simplemobiletools.commons.dialogs

import android.app.Activity
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.support.v7.app.AlertDialog
import android.text.Editable
import android.text.TextWatcher
@@ -14,10 +12,7 @@ import android.view.ViewGroup
import android.widget.EditText
import android.widget.ImageView
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.onGlobalLayout
import com.simplemobiletools.commons.extensions.setBackgroundWithStroke
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.views.ColorPickerSquare
import kotlinx.android.synthetic.main.dialog_color_picker.view.*

@@ -132,12 +127,11 @@ class ColorPickerDialog(val activity: Activity, color: Int, val callback: (color
                .setPositiveButton(R.string.ok, { dialog, which -> callback(getColor()) })
                .setNegativeButton(R.string.cancel, null)
                .create().apply {
            if (!activity.setupDialogStuff(view, this))
                return@apply

            view.color_picker_arrow.colorFilter = PorterDuffColorFilter(textColor, PorterDuff.Mode.SRC_IN)
            view.color_picker_hex_arrow.colorFilter = PorterDuffColorFilter(textColor, PorterDuff.Mode.SRC_IN)
            viewCursor.colorFilter = PorterDuffColorFilter(textColor, PorterDuff.Mode.SRC_IN)
            activity.setupDialogStuff(view, this) {
                view.color_picker_arrow.applyColorFilter(textColor)
                view.color_picker_hex_arrow.applyColorFilter(textColor)
                viewCursor.applyColorFilter(textColor)
            }
        }

        view.onGlobalLayout {
+15 −16
Original line number Diff line number Diff line
@@ -19,9 +19,7 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String,
                .setNegativeButton(R.string.cancel, null)
                .create().apply {
            window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
            if (!activity.setupDialogStuff(view, this, R.string.create_new_folder))
                return@apply

            activity.setupDialogStuff(view, this, R.string.create_new_folder) {
                getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
                    val name = view.folder_name.value
                    when {
@@ -40,6 +38,7 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String,
                })
            }
        }
    }

    private fun createFolder(file: File, alertDialog: AlertDialog) {
        if (activity.needsStupidWritePermissions(file.absolutePath)) {
+30 −31
Original line number Diff line number Diff line
@@ -35,10 +35,8 @@ class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val c
                .setNegativeButton(R.string.cancel, null)
                .create().apply {
            window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
            if (!activity.setupDialogStuff(view, this, R.string.rename))
                return@apply

            getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
            activity.setupDialogStuff(view, this, R.string.rename) {
                getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
                    var newName = view.rename_item_name.value
                    val newExtension = view.rename_item_extension.value

@@ -72,7 +70,8 @@ class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val c
                            activity.toast(R.string.unknown_error_occurred)
                        }
                    }
            })
                }
            }
        }
    }

+3 −3
Original line number Diff line number Diff line
@@ -609,9 +609,9 @@ fun Activity.copyToClipboard(text: String) {
    toast(R.string.value_copied_to_clipboard)
}

fun Activity.setupDialogStuff(view: View, dialog: AlertDialog, titleId: Int = 0): Boolean {
fun Activity.setupDialogStuff(view: View, dialog: AlertDialog, titleId: Int = 0, callback: (() -> Unit)? = null) {
    if (isActivityDestroyed()) {
        return false
        return
    }

    if (view is ViewGroup)
@@ -640,5 +640,5 @@ fun Activity.setupDialogStuff(view: View, dialog: AlertDialog, titleId: Int = 0)
        getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(baseConfig.textColor)
        window.setBackgroundDrawable(ColorDrawable(baseConfig.backgroundColor))
    }
    return true
    callback?.invoke()
}