move setupDialogStuff to activity and make sure it is valid when called
This commit is contained in:
parent
eafc719787
commit
93c5db701b
12 changed files with 90 additions and 87 deletions
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
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)
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.os.Parcelable
|
|||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.adapters.FilepickerItemsAdapter
|
||||
|
@ -22,7 +21,7 @@ import java.util.*
|
|||
/**
|
||||
* The only filepicker constructor with a couple optional parameters
|
||||
*
|
||||
* @param activity
|
||||
* @param activity has to be activity to avoid some Theme.AppCompat issues
|
||||
* @param currPath initial path of the dialog, defaults to the external storage
|
||||
* @param pickFile toggle used to determine if we are picking a file or a folder
|
||||
* @param showHidden toggle for showing hidden items, whose name starts with a dot
|
||||
|
@ -41,7 +40,7 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
|
|||
var mScrollStates = HashMap<String, Parcelable>()
|
||||
|
||||
lateinit var mDialog: AlertDialog
|
||||
var mDialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_filepicker, null)
|
||||
var mDialogView = activity.layoutInflater.inflate(R.layout.dialog_filepicker, null)
|
||||
|
||||
init {
|
||||
if (!File(currPath).exists()) {
|
||||
|
@ -82,7 +81,7 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
|
|||
}
|
||||
|
||||
mDialog = builder.create().apply {
|
||||
context.setupDialogStuff(mDialogView, this, getTitle())
|
||||
activity.setupDialogStuff(mDialogView, this, getTitle())
|
||||
}
|
||||
|
||||
if (!pickFile) {
|
||||
|
|
|
@ -47,7 +47,7 @@ class LineColorPickerDialog(val activity: BaseSimpleActivity, val color: Int, va
|
|||
.setNegativeButton(R.string.cancel, { dialog, which -> dialogDismissed() })
|
||||
.setOnCancelListener { dialogDismissed() }
|
||||
.create().apply {
|
||||
context.setupDialogStuff(view, this)
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,9 @@ 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)
|
||||
activity.setupDialogStuff(view, this, R.string.rename)
|
||||
if (!activity.setupDialogStuff(view, this, R.string.rename))
|
||||
return@apply
|
||||
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||
var newName = view.rename_item_name.value
|
||||
val newExtension = view.rename_item_extension.value
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.simplemobiletools.commons.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.app.Activity
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
|
@ -13,18 +13,18 @@ import kotlinx.android.synthetic.main.dialog_radio_group.view.*
|
|||
/**
|
||||
* A dialog for choosing between internal, root, SD card (optional) storage
|
||||
*
|
||||
* @param context has to be activity context to avoid some Theme.AppCompat issues
|
||||
* @param activity has to be activity to avoid some Theme.AppCompat issues
|
||||
* @param currPath current path to decide which storage should be preselected
|
||||
* @param callback an anonymous function
|
||||
*
|
||||
*/
|
||||
class StoragePickerDialog(val context: Context, currPath: String, val callback: (pickedPath: String) -> Unit) {
|
||||
class StoragePickerDialog(val activity: Activity, currPath: String, val callback: (pickedPath: String) -> Unit) {
|
||||
var mDialog: AlertDialog
|
||||
|
||||
init {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val resources = context.resources
|
||||
val basePath = currPath.getBasePath(context)
|
||||
val inflater = LayoutInflater.from(activity)
|
||||
val resources = activity.resources
|
||||
val basePath = currPath.getBasePath(activity)
|
||||
val layoutParams = RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
val view = inflater.inflate(R.layout.dialog_radio_group, null)
|
||||
val radioGroup = view.dialog_radio_group
|
||||
|
@ -37,7 +37,7 @@ class StoragePickerDialog(val context: Context, currPath: String, val callback:
|
|||
}
|
||||
radioGroup.addView(internalButton, layoutParams)
|
||||
|
||||
if (context.hasExternalSDCard()) {
|
||||
if (activity.hasExternalSDCard()) {
|
||||
val sdButton = inflater.inflate(R.layout.radio_button, null) as RadioButton
|
||||
sdButton.apply {
|
||||
text = resources.getString(R.string.sd_card)
|
||||
|
@ -55,20 +55,20 @@ class StoragePickerDialog(val context: Context, currPath: String, val callback:
|
|||
}
|
||||
radioGroup.addView(rootButton, layoutParams)
|
||||
|
||||
mDialog = AlertDialog.Builder(context)
|
||||
mDialog = AlertDialog.Builder(activity)
|
||||
.create().apply {
|
||||
context.setupDialogStuff(view, this, R.string.select_storage)
|
||||
activity.setupDialogStuff(view, this, R.string.select_storage)
|
||||
}
|
||||
}
|
||||
|
||||
private fun internalPicked() {
|
||||
mDialog.dismiss()
|
||||
callback(context.internalStoragePath)
|
||||
callback(activity.internalStoragePath)
|
||||
}
|
||||
|
||||
private fun sdPicked() {
|
||||
mDialog.dismiss()
|
||||
callback(context.sdCardPath)
|
||||
callback(activity.sdCardPath)
|
||||
}
|
||||
|
||||
private fun rootPicked() {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
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.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
|
@ -10,21 +9,21 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
|
|||
/**
|
||||
* A dialog for displaying the steps needed to confirm SD card write access on Android 5+
|
||||
*
|
||||
* @param context has to be activity context to avoid some Theme.AppCompat issues
|
||||
* @param activity has to be activity to avoid some Theme.AppCompat issues
|
||||
* @param callback an anonymous function
|
||||
*
|
||||
*/
|
||||
class WritePermissionDialog(context: Context, val callback: () -> Unit) {
|
||||
class WritePermissionDialog(activity: Activity, val callback: () -> Unit) {
|
||||
var dialog: AlertDialog
|
||||
|
||||
init {
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.dialog_write_permission, null)
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_write_permission, null)
|
||||
|
||||
dialog = AlertDialog.Builder(context)
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
|
||||
.setOnCancelListener { BaseSimpleActivity.funAfterSAFPermission = null }
|
||||
.create().apply {
|
||||
context.setupDialogStuff(view, this, R.string.confirm_storage_access_title)
|
||||
activity.setupDialogStuff(view, this, R.string.confirm_storage_access_title)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.ClipData
|
|||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.media.MediaScannerConnection
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
|
@ -14,10 +15,11 @@ import android.os.TransactionTooLargeException
|
|||
import android.provider.DocumentsContract
|
||||
import android.provider.MediaStore
|
||||
import android.support.v4.provider.DocumentFile
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.*
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
|
@ -28,6 +30,8 @@ import com.simplemobiletools.commons.dialogs.WritePermissionDialog
|
|||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.Release
|
||||
import com.simplemobiletools.commons.models.SharedTheme
|
||||
import com.simplemobiletools.commons.views.MyTextView
|
||||
import kotlinx.android.synthetic.main.dialog_title.view.*
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
|
@ -604,3 +608,37 @@ fun Activity.copyToClipboard(text: String) {
|
|||
(getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip = clip
|
||||
toast(R.string.value_copied_to_clipboard)
|
||||
}
|
||||
|
||||
fun Activity.setupDialogStuff(view: View, dialog: AlertDialog, titleId: Int = 0): Boolean {
|
||||
if (isActivityDestroyed()) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (view is ViewGroup)
|
||||
updateTextColors(view)
|
||||
else if (view is MyTextView) {
|
||||
view.setTextColor(baseConfig.textColor)
|
||||
}
|
||||
|
||||
var title: TextView? = null
|
||||
if (titleId != 0) {
|
||||
title = LayoutInflater.from(this).inflate(R.layout.dialog_title, null) as TextView
|
||||
title.dialog_title_textview.apply {
|
||||
setText(titleId)
|
||||
setTextColor(baseConfig.textColor)
|
||||
}
|
||||
}
|
||||
|
||||
dialog.apply {
|
||||
setView(view)
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
setCustomTitle(title)
|
||||
setCanceledOnTouchOutside(true)
|
||||
show()
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(baseConfig.textColor)
|
||||
getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(baseConfig.textColor)
|
||||
getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(baseConfig.textColor)
|
||||
window.setBackgroundDrawable(ColorDrawable(baseConfig.backgroundColor))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.ContentUris
|
|||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.database.Cursor
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
|
@ -18,12 +17,7 @@ import android.provider.OpenableColumns
|
|||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.content.CursorLoader
|
||||
import android.support.v4.content.FileProvider
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.github.ajalt.reprint.core.Reprint
|
||||
import com.simplemobiletools.commons.R
|
||||
|
@ -34,7 +28,6 @@ import com.simplemobiletools.commons.helpers.MyContentProvider.Companion.COL_PRI
|
|||
import com.simplemobiletools.commons.helpers.MyContentProvider.Companion.COL_TEXT_COLOR
|
||||
import com.simplemobiletools.commons.models.SharedTheme
|
||||
import com.simplemobiletools.commons.views.*
|
||||
import kotlinx.android.synthetic.main.dialog_title.view.*
|
||||
import java.io.File
|
||||
|
||||
fun Context.isOnMainThread() = Looper.myLooper() == Looper.getMainLooper()
|
||||
|
@ -77,35 +70,6 @@ fun Context.getLinkTextColor(): Int {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.setupDialogStuff(view: View, dialog: AlertDialog, titleId: Int = 0) {
|
||||
if (view is ViewGroup)
|
||||
updateTextColors(view)
|
||||
else if (view is MyTextView) {
|
||||
view.setTextColor(baseConfig.textColor)
|
||||
}
|
||||
|
||||
var title: TextView? = null
|
||||
if (titleId != 0) {
|
||||
title = LayoutInflater.from(this).inflate(R.layout.dialog_title, null) as TextView
|
||||
title.dialog_title_textview.apply {
|
||||
setText(titleId)
|
||||
setTextColor(baseConfig.textColor)
|
||||
}
|
||||
}
|
||||
|
||||
dialog.apply {
|
||||
setView(view)
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
setCustomTitle(title)
|
||||
setCanceledOnTouchOutside(true)
|
||||
show()
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(baseConfig.textColor)
|
||||
getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(baseConfig.textColor)
|
||||
getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(baseConfig.textColor)
|
||||
window.setBackgroundDrawable(ColorDrawable(baseConfig.backgroundColor))
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.toast(id: Int, length: Int = Toast.LENGTH_SHORT) {
|
||||
Toast.makeText(this, id, length).show()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue