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

Commit 93c5db70 authored by tibbi's avatar tibbi
Browse files

move setupDialogStuff to activity and make sure it is valid when called

parent eafc7197
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '3.0.13'
        propVersionName = '3.0.15'
        kotlin_version = '1.2.0'
        support_libs = '27.0.2'
    }
+9 −8
Original line number Diff line number Diff line
package com.simplemobiletools.commons.dialogs

import android.content.Context
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
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
@@ -23,7 +22,7 @@ import com.simplemobiletools.commons.views.ColorPickerSquare
import kotlinx.android.synthetic.main.dialog_color_picker.view.*

// forked from https://github.com/yukuku/ambilwarna
class ColorPickerDialog(val context: Context, color: Int, val callback: (color: Int) -> Unit) {
class ColorPickerDialog(val activity: Activity, color: Int, val callback: (color: Int) -> Unit) {
    lateinit var viewHue: View
    lateinit var viewSatVal: ColorPickerSquare
    lateinit var viewCursor: ImageView
@@ -32,13 +31,13 @@ class ColorPickerDialog(val context: Context, color: Int, val callback: (color:
    lateinit var newHexField: EditText
    lateinit var viewContainer: ViewGroup
    val currentColorHsv = FloatArray(3)
    val backgroundColor = context.baseConfig.backgroundColor
    val backgroundColor = activity.baseConfig.backgroundColor
    var isHueBeingDragged = false

    init {
        Color.colorToHSV(color, currentColorHsv)

        val view = LayoutInflater.from(context).inflate(R.layout.dialog_color_picker, null).apply {
        val view = activity.layoutInflater.inflate(R.layout.dialog_color_picker, null).apply {
            viewHue = color_picker_hue
            viewSatVal = color_picker_square
            viewCursor = color_picker_hue_cursor
@@ -128,12 +127,14 @@ class ColorPickerDialog(val context: Context, color: Int, val callback: (color:
            }
        })

        val textColor = context.baseConfig.textColor
        AlertDialog.Builder(context)
        val textColor = activity.baseConfig.textColor
        AlertDialog.Builder(activity)
                .setPositiveButton(R.string.ok, { dialog, which -> callback(getColor()) })
                .setNegativeButton(R.string.cancel, null)
                .create().apply {
            context.setupDialogStuff(view, this)
            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)
+6 −7
Original line number Diff line number Diff line
package com.simplemobiletools.commons.dialogs

import android.content.Context
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_message.view.*

class ConfirmationAdvancedDialog(context: Context, message: String = "", messageId: Int = R.string.proceed_with_deletion, positive: Int = R.string.yes,
class ConfirmationAdvancedDialog(activity: Activity, message: String = "", messageId: Int = R.string.proceed_with_deletion, positive: Int = R.string.yes,
                                 negative: Int, val callback: (result: Boolean) -> Unit) {
    var dialog: AlertDialog

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_message, null)
        view.message.text = if (message.isEmpty()) context.resources.getString(messageId) else message
        val view = activity.layoutInflater.inflate(R.layout.dialog_message, null)
        view.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message

        dialog = AlertDialog.Builder(context)
        dialog = AlertDialog.Builder(activity)
                .setPositiveButton(positive, { dialog, which -> positivePressed() })
                .setNegativeButton(negative, { dialog, which -> negativePressed() })
                .create().apply {
            context.setupDialogStuff(view, this)
            activity.setupDialogStuff(view, this)
        }
    }

+7 −8
Original line number Diff line number Diff line
package com.simplemobiletools.commons.dialogs

import android.content.Context
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_message.view.*
@@ -10,29 +9,29 @@ import kotlinx.android.synthetic.main.dialog_message.view.*
/**
 * A simple dialog without any view, just a messageId, a positive button and optionally a negative button
 *
 * @param context has to be activity context to avoid some Theme.AppCompat issues
 * @param activity has to be activity context to avoid some Theme.AppCompat issues
 * @param message the dialogs message, can be any String. If empty, messageId is used
 * @param messageId the dialogs messageId ID. Used only if message is empty
 * @param positive positive buttons text ID
 * @param negative negative buttons text ID (optional)
 * @param callback an anonymous function
 */
class ConfirmationDialog(val context: Context, message: String = "", messageId: Int = R.string.proceed_with_deletion, positive: Int = R.string.yes,
class ConfirmationDialog(activity: Activity, message: String = "", messageId: Int = R.string.proceed_with_deletion, positive: Int = R.string.yes,
                         negative: Int = R.string.no, val callback: () -> Unit) {
    var dialog: AlertDialog

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_message, null)
        view.message.text = if (message.isEmpty()) context.resources.getString(messageId) else message
        val view = activity.layoutInflater.inflate(R.layout.dialog_message, null)
        view.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message

        val builder = AlertDialog.Builder(context)
        val builder = AlertDialog.Builder(activity)
                .setPositiveButton(positive, { dialog, which -> dialogConfirmed() })

        if (negative != 0)
            builder.setNegativeButton(negative, null)

        dialog = builder.create().apply {
            context.setupDialogStuff(view, this)
            activity.setupDialogStuff(view, this)
        }
    }

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

            getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
                val name = view.folder_name.value
                when {
Loading