migrate everything to view binding

This commit is contained in:
FunkyMuse 2023-07-26 17:13:01 +02:00
parent 8104f9354f
commit ccce65da89
54 changed files with 575 additions and 545 deletions

View file

@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kapt)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.parcelize)
`maven-publish`
}
@ -74,6 +75,12 @@ dependencies {
implementation(libs.androidx.biometric.ktx)
implementation(libs.ez.vcard)
implementation(libs.bundles.lifecycle)
implementation(libs.bundles.compose)
implementation(libs.bundles.accompanist)
debugImplementation(libs.bundles.compose.preview)
api(libs.joda.time)
api(libs.recyclerView.fastScroller)
api(libs.reprint)

View file

@ -26,7 +26,7 @@ class FilepickerFavoritesAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val path = paths[position]
holder.bindView(path, true, false) { itemView, adapterPosition ->
holder.bindView(path, allowSingleClick = true, allowLongClick = false) { itemView, adapterPosition ->
setupView(FilepickerFavoriteBinding.bind(itemView), path)
}
bindViewHolder(holder)

View file

@ -46,7 +46,7 @@ class FilepickerItemsAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val fileDirItem = fileDirItems[position]
holder.bindView(fileDirItem, true, false) { itemView, adapterPosition ->
holder.bindView(fileDirItem, allowSingleClick = true, allowLongClick = false) { itemView, adapterPosition ->
setupView(ItemFilepickerListBinding.bind(itemView), fileDirItem)
}
bindViewHolder(holder)

View file

@ -53,7 +53,7 @@ class ManageBlockedNumbersAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val blockedNumber = blockedNumbers[position]
holder.bindView(blockedNumber, true, true) { itemView, _ ->
holder.bindView(blockedNumber, allowSingleClick = true, allowLongClick = true) { itemView, _ ->
setupView(ItemManageBlockedNumberBinding.bind(itemView), blockedNumber)
}
bindViewHolder(holder)

View file

@ -3,15 +3,15 @@ package com.simplemobiletools.commons.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogAddBlockedNumberBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.BlockedNumber
import kotlinx.android.synthetic.main.dialog_add_blocked_number.view.*
class AddBlockedNumberDialog(val activity: BaseSimpleActivity, val originalNumber: BlockedNumber? = null, val callback: () -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_add_blocked_number, null).apply {
val view = DialogAddBlockedNumberBinding.inflate(activity.layoutInflater, null, false).apply {
if (originalNumber != null) {
add_blocked_number_edittext.setText(originalNumber.number)
addBlockedNumberEdittext.setText(originalNumber.number)
}
}
@ -19,10 +19,10 @@ class AddBlockedNumberDialog(val activity: BaseSimpleActivity, val originalNumbe
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
alertDialog.showKeyboard(view.add_blocked_number_edittext)
activity.setupDialogStuff(view.root, this) { alertDialog ->
alertDialog.showKeyboard(view.addBlockedNumberEdittext)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
var newBlockedNumber = view.add_blocked_number_edittext.value
var newBlockedNumber = view.addBlockedNumberEdittext.value
if (originalNumber != null && newBlockedNumber != originalNumber.number) {
activity.deleteBlockedNumber(originalNumber.number)
}

View file

@ -5,29 +5,29 @@ import android.text.Html
import android.text.method.LinkMovementMethod
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogTextviewBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.getStringsPackageName
import com.simplemobiletools.commons.extensions.launchViewIntent
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_textview.view.*
class AppSideloadedDialog(val activity: Activity, val callback: () -> Unit) {
private var dialog: AlertDialog? = null
private val url = "https://play.google.com/store/apps/details?id=${activity.getStringsPackageName()}"
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_textview, null).apply {
val view = DialogTextviewBinding.inflate(activity.layoutInflater, null, false).apply {
val text = String.format(activity.getString(R.string.sideloaded_app), url)
text_view.text = Html.fromHtml(text)
text_view.movementMethod = LinkMovementMethod.getInstance()
textView.text = Html.fromHtml(text)
textView.movementMethod = LinkMovementMethod.getInstance()
}
activity.getAlertDialogBuilder()
.setNegativeButton(R.string.cancel) { dialog, which -> negativePressed() }
.setNegativeButton(R.string.cancel) { _, _ -> negativePressed() }
.setPositiveButton(R.string.download, null)
.setOnCancelListener { negativePressed() }
.apply {
activity.setupDialogStuff(view, this, R.string.app_corrupt) { alertDialog ->
activity.setupDialogStuff(view.root, this, R.string.app_corrupt) { alertDialog ->
dialog = alertDialog
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
downloadApp()

View file

@ -2,38 +2,29 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import android.content.res.Resources
import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.exifinterface.media.ExifInterface
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FileDirItem
import kotlinx.android.synthetic.main.dialog_properties.view.*
import kotlinx.android.synthetic.main.item_property.view.*
import java.io.File
import java.util.*
import com.simplemobiletools.commons.databinding.DialogPropertiesBinding
import com.simplemobiletools.commons.databinding.ItemPropertyBinding
import com.simplemobiletools.commons.extensions.copyToClipboard
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.extensions.showLocationOnMap
import com.simplemobiletools.commons.extensions.value
abstract class BasePropertiesDialog(activity: Activity) {
protected val mInflater: LayoutInflater
protected val mPropertyView: ViewGroup
protected val mResources: Resources
protected val mActivity: Activity = activity
protected val mDialogView: View
protected val mDialogView: DialogPropertiesBinding
init {
mInflater = LayoutInflater.from(activity)
mResources = activity.resources
mDialogView = mInflater.inflate(R.layout.dialog_properties, null)
mPropertyView = mDialogView.properties_holder!!
mDialogView = DialogPropertiesBinding.inflate(mInflater, null, false)
mPropertyView = mDialogView.propertiesHolder
}
protected fun addProperty(labelId: Int, value: String?, viewId: Int = 0) {
@ -41,27 +32,27 @@ abstract class BasePropertiesDialog(activity: Activity) {
return
}
mInflater.inflate(R.layout.item_property, mPropertyView, false).apply {
property_value.setTextColor(mActivity.getProperTextColor())
property_label.setTextColor(mActivity.getProperTextColor())
ItemPropertyBinding.inflate(mInflater, null, false).apply {
propertyValue.setTextColor(mActivity.getProperTextColor())
propertyLabel.setTextColor(mActivity.getProperTextColor())
property_label.text = mResources.getString(labelId)
property_value.text = value
mPropertyView.properties_holder.addView(this)
propertyLabel.text = mResources.getString(labelId)
propertyValue.text = value
mPropertyView.findViewById<LinearLayout>(R.id.properties_holder).addView(root)
setOnLongClickListener {
mActivity.copyToClipboard(property_value.value)
root.setOnLongClickListener {
mActivity.copyToClipboard(propertyValue.value)
true
}
if (labelId == R.string.gps_coordinates) {
setOnClickListener {
root.setOnClickListener {
mActivity.showLocationOnMap(value)
}
}
if (viewId != 0) {
id = viewId
root.id = viewId
}
}
}

View file

@ -3,8 +3,8 @@ package com.simplemobiletools.commons.dialogs
import android.os.Bundle
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.adapters.setupSimpleListItem
import com.simplemobiletools.commons.databinding.ItemSimpleListBinding
import com.simplemobiletools.commons.fragments.BaseBottomSheetDialogFragment
import com.simplemobiletools.commons.models.SimpleListItem
@ -15,11 +15,11 @@ open class BottomSheetChooserDialog : BaseBottomSheetDialogFragment() {
override fun setupContentView(parent: ViewGroup) {
val listItems = arguments?.getParcelableArray(ITEMS) as Array<SimpleListItem>
listItems.forEach { item ->
val view = layoutInflater.inflate(R.layout.item_simple_list, parent, false)
val view = ItemSimpleListBinding.inflate(layoutInflater, parent, false)
setupSimpleListItem(view, item) {
onItemClick?.invoke(it)
}
parent.addView(view)
parent.addView(view.root)
}
}

View file

@ -3,23 +3,23 @@ package com.simplemobiletools.commons.dialogs
import android.view.animation.AnimationUtils
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogCallConfirmationBinding
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_call_confirmation.view.*
class CallConfirmationDialog(val activity: BaseSimpleActivity, val callee: String, private val callback: () -> Unit) {
private var view = activity.layoutInflater.inflate(R.layout.dialog_call_confirmation, null)
private var view = DialogCallConfirmationBinding.inflate(activity.layoutInflater, null, false)
init {
view.call_confirm_phone.applyColorFilter(activity.getProperTextColor())
view.callConfirmPhone.applyColorFilter(activity.getProperTextColor())
activity.getAlertDialogBuilder()
.setNegativeButton(R.string.cancel, null)
.apply {
val title = String.format(activity.getString(R.string.confirm_calling_person), callee)
activity.setupDialogStuff(view, this, titleText = title) { alertDialog ->
view.call_confirm_phone.apply {
activity.setupDialogStuff(view.root, this, titleText = title) { alertDialog ->
view.callConfirmPhone.apply {
startAnimation(AnimationUtils.loadAnimation(activity, R.anim.shake_pulse_animation))
setOnClickListener {
callback.invoke()

View file

@ -3,40 +3,40 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import android.text.format.DateFormat
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.R.id.*
import com.simplemobiletools.commons.databinding.DialogChangeDateTimeFormatBinding
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.*
import kotlinx.android.synthetic.main.dialog_change_date_time_format.view.*
import java.util.*
import java.util.Calendar
import java.util.Locale
class ChangeDateTimeFormatDialog(val activity: Activity, val callback: () -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_change_date_time_format, null)!!
private val view = DialogChangeDateTimeFormatBinding.inflate(activity.layoutInflater, null, false)
private val sampleTS = 1613422500000 // February 15, 2021
init {
view.apply {
change_date_time_dialog_radio_one.text = formatDateSample(DATE_FORMAT_ONE)
change_date_time_dialog_radio_two.text = formatDateSample(DATE_FORMAT_TWO)
change_date_time_dialog_radio_three.text = formatDateSample(DATE_FORMAT_THREE)
change_date_time_dialog_radio_four.text = formatDateSample(DATE_FORMAT_FOUR)
change_date_time_dialog_radio_five.text = formatDateSample(DATE_FORMAT_FIVE)
change_date_time_dialog_radio_six.text = formatDateSample(DATE_FORMAT_SIX)
change_date_time_dialog_radio_seven.text = formatDateSample(DATE_FORMAT_SEVEN)
change_date_time_dialog_radio_eight.text = formatDateSample(DATE_FORMAT_EIGHT)
changeDateTimeDialogRadioOne.text = formatDateSample(DATE_FORMAT_ONE)
changeDateTimeDialogRadioTwo.text = formatDateSample(DATE_FORMAT_TWO)
changeDateTimeDialogRadioThree.text = formatDateSample(DATE_FORMAT_THREE)
changeDateTimeDialogRadioFour.text = formatDateSample(DATE_FORMAT_FOUR)
changeDateTimeDialogRadioFive.text = formatDateSample(DATE_FORMAT_FIVE)
changeDateTimeDialogRadioSix.text = formatDateSample(DATE_FORMAT_SIX)
changeDateTimeDialogRadioSeven.text = formatDateSample(DATE_FORMAT_SEVEN)
changeDateTimeDialogRadioEight.text = formatDateSample(DATE_FORMAT_EIGHT)
change_date_time_dialog_24_hour.isChecked = activity.baseConfig.use24HourFormat
changeDateTimeDialog24Hour.isChecked = activity.baseConfig.use24HourFormat
val formatButton = when (activity.baseConfig.dateFormat) {
DATE_FORMAT_ONE -> change_date_time_dialog_radio_one
DATE_FORMAT_TWO -> change_date_time_dialog_radio_two
DATE_FORMAT_THREE -> change_date_time_dialog_radio_three
DATE_FORMAT_FOUR -> change_date_time_dialog_radio_four
DATE_FORMAT_FIVE -> change_date_time_dialog_radio_five
DATE_FORMAT_SIX -> change_date_time_dialog_radio_six
DATE_FORMAT_SEVEN -> change_date_time_dialog_radio_seven
else -> change_date_time_dialog_radio_eight
DATE_FORMAT_ONE -> changeDateTimeDialogRadioOne
DATE_FORMAT_TWO -> changeDateTimeDialogRadioTwo
DATE_FORMAT_THREE -> changeDateTimeDialogRadioThree
DATE_FORMAT_FOUR -> changeDateTimeDialogRadioFour
DATE_FORMAT_FIVE -> changeDateTimeDialogRadioFive
DATE_FORMAT_SIX -> changeDateTimeDialogRadioSix
DATE_FORMAT_SEVEN -> changeDateTimeDialogRadioSeven
else -> changeDateTimeDialogRadioEight
}
formatButton.isChecked = true
}
@ -45,23 +45,23 @@ class ChangeDateTimeFormatDialog(val activity: Activity, val callback: () -> Uni
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
activity.setupDialogStuff(view.root, this)
}
}
private fun dialogConfirmed() {
activity.baseConfig.dateFormat = when (view.change_date_time_dialog_radio_group.checkedRadioButtonId) {
change_date_time_dialog_radio_one -> DATE_FORMAT_ONE
change_date_time_dialog_radio_two -> DATE_FORMAT_TWO
change_date_time_dialog_radio_three -> DATE_FORMAT_THREE
change_date_time_dialog_radio_four -> DATE_FORMAT_FOUR
change_date_time_dialog_radio_five -> DATE_FORMAT_FIVE
change_date_time_dialog_radio_six -> DATE_FORMAT_SIX
change_date_time_dialog_radio_seven -> DATE_FORMAT_SEVEN
activity.baseConfig.dateFormat = when (view.changeDateTimeDialogRadioGroup.checkedRadioButtonId) {
view.changeDateTimeDialogRadioOne.id -> DATE_FORMAT_ONE
view.changeDateTimeDialogRadioTwo.id -> DATE_FORMAT_TWO
view.changeDateTimeDialogRadioThree.id -> DATE_FORMAT_THREE
view.changeDateTimeDialogRadioFour.id -> DATE_FORMAT_FOUR
view.changeDateTimeDialogRadioFive.id -> DATE_FORMAT_FIVE
view.changeDateTimeDialogRadioSix.id -> DATE_FORMAT_SIX
view.changeDateTimeDialogRadioSeven.id -> DATE_FORMAT_SEVEN
else -> DATE_FORMAT_EIGHT
}
activity.baseConfig.use24HourFormat = view.change_date_time_dialog_24_hour.isChecked
activity.baseConfig.use24HourFormat = view.changeDateTimeDialog24Hour.isChecked
callback()
}

View file

@ -1,41 +1,38 @@
package com.simplemobiletools.commons.dialogs
import android.view.View
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogChangeViewTypeBinding
import com.simplemobiletools.commons.extensions.baseConfig
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
import kotlinx.android.synthetic.main.dialog_change_view_type.view.change_view_type_dialog_radio
import kotlinx.android.synthetic.main.dialog_change_view_type.view.change_view_type_dialog_radio_grid
import kotlinx.android.synthetic.main.dialog_change_view_type.view.change_view_type_dialog_radio_list
class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) {
private var view: View
private var view: DialogChangeViewTypeBinding
private var config = activity.baseConfig
init {
view = activity.layoutInflater.inflate(R.layout.dialog_change_view_type, null).apply {
view = DialogChangeViewTypeBinding.inflate(activity.layoutInflater, null, false).apply {
val viewToCheck = when (config.viewType) {
VIEW_TYPE_GRID -> change_view_type_dialog_radio_grid.id
else -> change_view_type_dialog_radio_list.id
VIEW_TYPE_GRID -> changeViewTypeDialogRadioGrid.id
else -> changeViewTypeDialogRadioList.id
}
change_view_type_dialog_radio.check(viewToCheck)
changeViewTypeDialogRadio.check(viewToCheck)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
activity.setupDialogStuff(view.root, this)
}
}
private fun dialogConfirmed() {
val viewType = if (view.change_view_type_dialog_radio_grid.isChecked) {
val viewType = if (view.changeViewTypeDialogRadioGrid.isChecked) {
VIEW_TYPE_GRID
} else {
VIEW_TYPE_LIST

View file

@ -1,5 +1,6 @@
package com.simplemobiletools.commons.dialogs
import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.Color
import android.view.MotionEvent
@ -11,15 +12,16 @@ import android.widget.EditText
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogColorPickerBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isQPlus
import com.simplemobiletools.commons.views.ColorPickerSquare
import kotlinx.android.synthetic.main.dialog_color_picker.view.*
import java.util.LinkedList
private const val RECENT_COLORS_NUMBER = 5
// forked from https://github.com/yukuku/ambilwarna
@SuppressLint("ClickableViewAccessibility")
class ColorPickerDialog(
val activity: Activity,
color: Int,
@ -45,28 +47,28 @@ class ColorPickerDialog(
init {
Color.colorToHSV(color, currentColorHsv)
val view = activity.layoutInflater.inflate(R.layout.dialog_color_picker, null).apply {
val view = DialogColorPickerBinding.inflate(activity.layoutInflater, null, false).apply {
if (isQPlus()) {
isForceDarkAllowed = false
root.isForceDarkAllowed = false
}
viewHue = color_picker_hue
viewSatVal = color_picker_square
viewCursor = color_picker_hue_cursor
viewHue = colorPickerHue
viewSatVal = colorPickerSquare
viewCursor = colorPickerHueCursor
viewNewColor = color_picker_new_color
viewTarget = color_picker_cursor
viewContainer = color_picker_holder
newHexField = color_picker_new_hex
viewNewColor = colorPickerNewColor
viewTarget = colorPickerCursor
viewContainer = colorPickerHolder
newHexField = colorPickerNewHex
viewSatVal.setHue(getHue())
viewNewColor.setFillWithStroke(getColor(), backgroundColor)
color_picker_old_color.setFillWithStroke(color, backgroundColor)
colorPickerOldColor.setFillWithStroke(color, backgroundColor)
val hexCode = getHexCode(color)
color_picker_old_hex.text = "#$hexCode"
color_picker_old_hex.setOnLongClickListener {
colorPickerOldHex.text = "#$hexCode"
colorPickerOldHex.setOnLongClickListener {
activity.copyToClipboard(hexCode)
true
}
@ -152,33 +154,33 @@ class ColorPickerDialog(
}
builder.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(view.root, this) { alertDialog ->
dialog = alertDialog
view.color_picker_arrow.applyColorFilter(textColor)
view.color_picker_hex_arrow.applyColorFilter(textColor)
view.colorPickerArrow.applyColorFilter(textColor)
view.colorPickerHexArrow.applyColorFilter(textColor)
viewCursor.applyColorFilter(textColor)
}
}
view.onGlobalLayout {
view.root.onGlobalLayout {
moveHuePicker()
moveColorPicker()
}
}
private fun View.setupRecentColors() {
val recentColors = baseConfig.colorPickerRecentColors
if (recentColors.isNotEmpty()) {
recent_colors.beVisible()
val squareSize = context.resources.getDimensionPixelSize(R.dimen.colorpicker_hue_width)
recentColors.take(RECENT_COLORS_NUMBER).forEach { recentColor ->
val recentColorView = ImageView(context)
private fun DialogColorPickerBinding.setupRecentColors() {
val colorPickerRecentColors = baseConfig.colorPickerRecentColors
if (colorPickerRecentColors.isNotEmpty()) {
recentColors.beVisible()
val squareSize = root.context.resources.getDimensionPixelSize(R.dimen.colorpicker_hue_width)
colorPickerRecentColors.take(RECENT_COLORS_NUMBER).forEach { recentColor ->
val recentColorView = ImageView(root.context)
recentColorView.id = View.generateViewId()
recentColorView.layoutParams = ViewGroup.LayoutParams(squareSize, squareSize)
recentColorView.setFillWithStroke(recentColor, backgroundColor)
recentColorView.setOnClickListener { newHexField.setText(getHexCode(recentColor)) }
recent_colors.addView(recentColorView)
recent_colors_flow.addView(recentColorView)
recentColors.addView(recentColorView)
recentColorsFlow.addView(recentColorView)
}
}
}

View file

@ -3,9 +3,9 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogMessageBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_message.view.*
// similar fo ConfirmationDialog, but has a callback for negative button too
class ConfirmationAdvancedDialog(
@ -15,14 +15,14 @@ class ConfirmationAdvancedDialog(
private var dialog: AlertDialog? = null
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_message, null)
view.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message
val view = DialogMessageBinding.inflate(activity.layoutInflater, null, false)
view.message.text = message.ifEmpty { activity.resources.getString(messageId) }
val builder = activity.getAlertDialogBuilder()
.setPositiveButton(positive) { dialog, which -> positivePressed() }
.setPositiveButton(positive) { _, _ -> positivePressed() }
if (negative != 0) {
builder.setNegativeButton(negative) { dialog, which -> negativePressed() }
builder.setNegativeButton(negative) { _, _ -> negativePressed() }
}
if (!cancelOnTouchOutside) {
@ -30,7 +30,7 @@ class ConfirmationAdvancedDialog(
}
builder.apply {
activity.setupDialogStuff(view, this, cancelOnTouchOutside = cancelOnTouchOutside) { alertDialog ->
activity.setupDialogStuff(view.root, this, cancelOnTouchOutside = cancelOnTouchOutside) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -3,9 +3,9 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogMessageBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
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
@ -24,18 +24,18 @@ class ConfirmationDialog(
private var dialog: AlertDialog? = null
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_message, null)
view.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message
val view = DialogMessageBinding.inflate(activity.layoutInflater, null, false)
view.message.text = message.ifEmpty { activity.resources.getString(messageId) }
val builder = activity.getAlertDialogBuilder()
.setPositiveButton(positive) { dialog, which -> dialogConfirmed() }
.setPositiveButton(positive) { _, _ -> dialogConfirmed() }
if (negative != 0) {
builder.setNegativeButton(negative, null)
}
builder.apply {
activity.setupDialogStuff(view, this, titleText = dialogTitle, cancelOnTouchOutside = cancelOnTouchOutside) { alertDialog ->
activity.setupDialogStuff(view.root, this, titleText = dialogTitle, cancelOnTouchOutside = cancelOnTouchOutside) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -4,24 +4,24 @@ import android.view.View
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogCreateNewFolderBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isRPlus
import kotlinx.android.synthetic.main.dialog_create_new_folder.view.*
import java.io.File
class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String, val callback: (path: String) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_create_new_folder, null)
view.folder_path.setText("${activity.humanizePath(path).trimEnd('/')}/")
val view = DialogCreateNewFolderBinding.inflate(activity.layoutInflater, null, false)
view.folderPath.setText("${activity.humanizePath(path).trimEnd('/')}/")
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.create_new_folder) { alertDialog ->
alertDialog.showKeyboard(view.folder_name)
activity.setupDialogStuff(view.root, this, R.string.create_new_folder) { alertDialog ->
alertDialog.showKeyboard(view.folderName)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
val name = view.folder_name.value
val name = view.folderName.value
when {
name.isEmpty() -> activity.toast(R.string.empty_name)
name.isAValidFilename() -> {

View file

@ -4,53 +4,52 @@ import android.app.Activity
import android.content.DialogInterface
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogCustomIntervalPickerBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.DAY_SECONDS
import com.simplemobiletools.commons.helpers.HOUR_SECONDS
import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
import kotlinx.android.synthetic.main.dialog_custom_interval_picker.view.*
class CustomIntervalPickerDialog(val activity: Activity, val selectedSeconds: Int = 0, val showSeconds: Boolean = false, val callback: (minutes: Int) -> Unit) {
private var dialog: AlertDialog? = null
private var view = (activity.layoutInflater.inflate(R.layout.dialog_custom_interval_picker, null) as ViewGroup)
private var view = DialogCustomIntervalPickerBinding.inflate(activity.layoutInflater, null, false)
init {
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialogInterface, i -> confirmReminder() }
.setPositiveButton(R.string.ok) { _, _ -> confirmReminder() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(view.root, this) { alertDialog ->
dialog = alertDialog
alertDialog.showKeyboard(view.findViewById(R.id.dialog_custom_interval_value))
alertDialog.showKeyboard(view.dialogCustomIntervalValue)
}
}
view.apply {
dialog_radio_seconds.beVisibleIf(showSeconds)
dialogRadioSeconds.beVisibleIf(showSeconds)
when {
selectedSeconds == 0 -> dialog_radio_view.check(R.id.dialog_radio_minutes)
selectedSeconds == 0 -> dialogRadioView.check(R.id.dialog_radio_minutes)
selectedSeconds % DAY_SECONDS == 0 -> {
dialog_radio_view.check(R.id.dialog_radio_days)
dialog_custom_interval_value.setText((selectedSeconds / DAY_SECONDS).toString())
dialogRadioView.check(R.id.dialog_radio_days)
dialogCustomIntervalValue.setText((selectedSeconds / DAY_SECONDS).toString())
}
selectedSeconds % HOUR_SECONDS == 0 -> {
dialog_radio_view.check(R.id.dialog_radio_hours)
dialog_custom_interval_value.setText((selectedSeconds / HOUR_SECONDS).toString())
dialogRadioView.check(R.id.dialog_radio_hours)
dialogCustomIntervalValue.setText((selectedSeconds / HOUR_SECONDS).toString())
}
selectedSeconds % MINUTE_SECONDS == 0 -> {
dialog_radio_view.check(R.id.dialog_radio_minutes)
dialog_custom_interval_value.setText((selectedSeconds / MINUTE_SECONDS).toString())
dialogRadioView.check(R.id.dialog_radio_minutes)
dialogCustomIntervalValue.setText((selectedSeconds / MINUTE_SECONDS).toString())
}
else -> {
dialog_radio_view.check(R.id.dialog_radio_seconds)
dialog_custom_interval_value.setText(selectedSeconds.toString())
dialogRadioView.check(R.id.dialog_radio_seconds)
dialogCustomIntervalValue.setText(selectedSeconds.toString())
}
}
dialog_custom_interval_value.setOnKeyListener(object : View.OnKeyListener {
dialogCustomIntervalValue.setOnKeyListener(object : View.OnKeyListener {
override fun onKey(v: View?, keyCode: Int, event: KeyEvent): Boolean {
if (event.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
dialog?.getButton(DialogInterface.BUTTON_POSITIVE)?.performClick()
@ -64,9 +63,9 @@ class CustomIntervalPickerDialog(val activity: Activity, val selectedSeconds: In
}
private fun confirmReminder() {
val value = view.dialog_custom_interval_value.value
val multiplier = getMultiplier(view.dialog_radio_view.checkedRadioButtonId)
val minutes = Integer.valueOf(if (value.isEmpty()) "0" else value)
val value = view.dialogCustomIntervalValue.value
val multiplier = getMultiplier(view.dialogRadioView.checkedRadioButtonId)
val minutes = Integer.valueOf(value.ifEmpty { "0" })
callback(minutes * multiplier)
activity.hideKeyboard()
dialog?.dismiss()

View file

@ -4,25 +4,25 @@ import android.app.Activity
import android.text.Html
import android.text.method.LinkMovementMethod
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogDonateBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_donate.view.*
class DonateDialog(val activity: Activity) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_donate, null).apply {
dialog_donate_image.applyColorFilter(activity.getProperTextColor())
dialog_donate_text.text = Html.fromHtml(activity.getString(R.string.donate_short))
dialog_donate_text.movementMethod = LinkMovementMethod.getInstance()
dialog_donate_image.setOnClickListener {
val view = DialogDonateBinding.inflate(activity.layoutInflater,null, false).apply {
dialogDonateImage.applyColorFilter(activity.getProperTextColor())
dialogDonateText.text = Html.fromHtml(activity.getString(R.string.donate_short))
dialogDonateText.movementMethod = LinkMovementMethod.getInstance()
dialogDonateImage.setOnClickListener {
activity.launchViewIntent(R.string.thank_you_url)
}
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.purchase) { dialog, which -> activity.launchViewIntent(R.string.thank_you_url) }
.setPositiveButton(R.string.purchase) { _, _ -> activity.launchViewIntent(R.string.thank_you_url) }
.setNegativeButton(R.string.later, null)
.apply {
activity.setupDialogStuff(view, this, cancelOnTouchOutside = false)
activity.setupDialogStuff(view.root, this, cancelOnTouchOutside = false)
}
}
}

View file

@ -1,11 +1,10 @@
package com.simplemobiletools.commons.dialogs
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogEnterPasswordBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_enter_password.view.password
class EnterPasswordDialog(
val activity: BaseSimpleActivity,
@ -14,14 +13,14 @@ class EnterPasswordDialog(
) {
private var dialog: AlertDialog? = null
private val view: View = activity.layoutInflater.inflate(R.layout.dialog_enter_password, null)
private val view: DialogEnterPasswordBinding = DialogEnterPasswordBinding.inflate(activity.layoutInflater, null, false)
init {
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.enter_password) { alertDialog ->
activity.setupDialogStuff(view.root, this, R.string.enter_password) { alertDialog ->
dialog = alertDialog
alertDialog.showKeyboard(view.password)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {

View file

@ -3,10 +3,10 @@ package com.simplemobiletools.commons.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogExportBlockedNumbersBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.BLOCKED_NUMBERS_EXPORT_EXTENSION
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import kotlinx.android.synthetic.main.dialog_export_blocked_numbers.view.*
import java.io.File
class ExportBlockedNumbersDialog(
@ -15,21 +15,21 @@ class ExportBlockedNumbersDialog(
val hidePath: Boolean,
callback: (file: File) -> Unit,
) {
private var realPath = if (path.isEmpty()) activity.internalStoragePath else path
private var realPath = path.ifEmpty { activity.internalStoragePath }
private val config = activity.baseConfig
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_export_blocked_numbers, null).apply {
export_blocked_numbers_folder.text = activity.humanizePath(realPath)
export_blocked_numbers_filename.setText("${activity.getString(R.string.blocked_numbers)}_${activity.getCurrentFormattedDateTime()}")
val view = DialogExportBlockedNumbersBinding.inflate(activity.layoutInflater, null, false).apply {
exportBlockedNumbersFolder.text = activity.humanizePath(realPath)
exportBlockedNumbersFilename.setText("${activity.getString(R.string.blocked_numbers)}_${activity.getCurrentFormattedDateTime()}")
if (hidePath) {
export_blocked_numbers_folder_label.beGone()
export_blocked_numbers_folder.beGone()
exportBlockedNumbersFolderLabel.beGone()
exportBlockedNumbersFolder.beGone()
} else {
export_blocked_numbers_folder.setOnClickListener {
exportBlockedNumbersFolder.setOnClickListener {
FilePickerDialog(activity, realPath, false, showFAB = true) {
export_blocked_numbers_folder.text = activity.humanizePath(it)
exportBlockedNumbersFolder.text = activity.humanizePath(it)
realPath = it
}
}
@ -40,10 +40,10 @@ class ExportBlockedNumbersDialog(
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.export_blocked_numbers) { alertDialog ->
alertDialog.showKeyboard(view.export_blocked_numbers_filename)
activity.setupDialogStuff(view.root, this, R.string.export_blocked_numbers) { alertDialog ->
alertDialog.showKeyboard(view.exportBlockedNumbersFilename)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.export_blocked_numbers_filename.value
val filename = view.exportBlockedNumbersFilename.value
when {
filename.isEmpty() -> activity.toast(R.string.empty_name)
filename.isAValidFilename() -> {

View file

@ -3,8 +3,8 @@ package com.simplemobiletools.commons.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogExportSettingsBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_export_settings.view.*
class ExportSettingsDialog(
val activity: BaseSimpleActivity, val defaultFilename: String, val hidePath: Boolean,
@ -18,16 +18,16 @@ class ExportSettingsDialog(
activity.internalStoragePath
}
val view = activity.layoutInflater.inflate(R.layout.dialog_export_settings, null).apply {
export_settings_filename.setText(defaultFilename.removeSuffix(".txt"))
val view = DialogExportSettingsBinding.inflate(activity.layoutInflater, null, false).apply {
exportSettingsFilename.setText(defaultFilename.removeSuffix(".txt"))
if (hidePath) {
export_settings_path_hint.beGone()
exportSettingsPathHint.beGone()
} else {
export_settings_path.setText(activity.humanizePath(folder))
export_settings_path.setOnClickListener {
exportSettingsPath.setText(activity.humanizePath(folder))
exportSettingsPath.setOnClickListener {
FilePickerDialog(activity, folder, false, showFAB = true) {
export_settings_path.setText(activity.humanizePath(it))
exportSettingsPath.setText(activity.humanizePath(it))
folder = it
}
}
@ -38,9 +38,9 @@ class ExportSettingsDialog(
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.export_settings) { alertDialog ->
activity.setupDialogStuff(view.root, this, R.string.export_settings) { alertDialog ->
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
var filename = view.export_settings_filename.value
var filename = view.exportSettingsFilename.value
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener

View file

@ -3,28 +3,27 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import android.text.Html
import android.text.method.LinkMovementMethod
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogFeatureLockedBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_feature_locked.view.*
class FeatureLockedDialog(val activity: Activity, val callback: () -> Unit) {
private var dialog: AlertDialog? = null
init {
val view: View = activity.layoutInflater.inflate(R.layout.dialog_feature_locked, null)
view.feature_locked_image.applyColorFilter(activity.getProperTextColor())
val view = DialogFeatureLockedBinding.inflate(activity.layoutInflater, null, false)
view.featureLockedImage.applyColorFilter(activity.getProperTextColor())
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.purchase, null)
.setNegativeButton(R.string.later) { dialog, which -> dismissDialog() }
.setNegativeButton(R.string.later) { _, _ -> dismissDialog() }
.setOnDismissListener { dismissDialog() }
.apply {
activity.setupDialogStuff(view, this, cancelOnTouchOutside = false) { alertDialog ->
activity.setupDialogStuff(view.root, this, cancelOnTouchOutside = false) { alertDialog ->
dialog = alertDialog
view.feature_locked_description.text = Html.fromHtml(activity.getString(R.string.features_locked))
view.feature_locked_description.movementMethod = LinkMovementMethod.getInstance()
view.featureLockedDescription.text = Html.fromHtml(activity.getString(R.string.features_locked))
view.featureLockedDescription.movementMethod = LinkMovementMethod.getInstance()
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
activity.launchPurchaseThankYouIntent()

View file

@ -2,9 +2,7 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.R.id.conflict_dialog_radio_keep_both
import com.simplemobiletools.commons.R.id.conflict_dialog_radio_merge
import com.simplemobiletools.commons.R.id.conflict_dialog_radio_skip
import com.simplemobiletools.commons.databinding.DialogFileConflictBinding
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
@ -14,48 +12,47 @@ import com.simplemobiletools.commons.helpers.CONFLICT_MERGE
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
import com.simplemobiletools.commons.models.FileDirItem
import kotlinx.android.synthetic.main.dialog_file_conflict.view.*
class FileConflictDialog(
val activity: Activity, val fileDirItem: FileDirItem, val showApplyToAllCheckbox: Boolean,
val callback: (resolution: Int, applyForAll: Boolean) -> Unit
) {
val view = activity.layoutInflater.inflate(R.layout.dialog_file_conflict, null)!!
val view = DialogFileConflictBinding.inflate(activity.layoutInflater, null, false)
init {
view.apply {
val stringBase = if (fileDirItem.isDirectory) R.string.folder_already_exists else R.string.file_already_exists
conflict_dialog_title.text = String.format(activity.getString(stringBase), fileDirItem.name)
conflict_dialog_apply_to_all.isChecked = activity.baseConfig.lastConflictApplyToAll
conflict_dialog_apply_to_all.beVisibleIf(showApplyToAllCheckbox)
conflict_dialog_divider.beVisibleIf(showApplyToAllCheckbox)
conflict_dialog_radio_merge.beVisibleIf(fileDirItem.isDirectory)
conflictDialogTitle.text = String.format(activity.getString(stringBase), fileDirItem.name)
conflictDialogApplyToAll.isChecked = activity.baseConfig.lastConflictApplyToAll
conflictDialogApplyToAll.beVisibleIf(showApplyToAllCheckbox)
conflictDialogDivider.root.beVisibleIf(showApplyToAllCheckbox)
conflictDialogRadioMerge.beVisibleIf(fileDirItem.isDirectory)
val resolutionButton = when (activity.baseConfig.lastConflictResolution) {
CONFLICT_OVERWRITE -> conflict_dialog_radio_overwrite
CONFLICT_MERGE -> conflict_dialog_radio_merge
else -> conflict_dialog_radio_skip
CONFLICT_OVERWRITE -> conflictDialogRadioOverwrite
CONFLICT_MERGE -> conflictDialogRadioMerge
else -> conflictDialogRadioSkip
}
resolutionButton.isChecked = true
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
activity.setupDialogStuff(view.root, this)
}
}
private fun dialogConfirmed() {
val resolution = when (view.conflict_dialog_radio_group.checkedRadioButtonId) {
conflict_dialog_radio_skip -> CONFLICT_SKIP
conflict_dialog_radio_merge -> CONFLICT_MERGE
conflict_dialog_radio_keep_both -> CONFLICT_KEEP_BOTH
val resolution = when (view.conflictDialogRadioGroup.checkedRadioButtonId) {
view.conflictDialogRadioSkip.id -> CONFLICT_SKIP
view.conflictDialogRadioMerge.id -> CONFLICT_MERGE
view.conflictDialogRadioKeepBoth.id -> CONFLICT_KEEP_BOTH
else -> CONFLICT_OVERWRITE
}
val applyToAll = view.conflict_dialog_apply_to_all.isChecked
val applyToAll = view.conflictDialogApplyToAll.isChecked
activity.baseConfig.apply {
lastConflictApplyToAll = applyToAll
lastConflictResolution = resolution

View file

@ -12,11 +12,11 @@ import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.FilepickerFavoritesAdapter
import com.simplemobiletools.commons.adapters.FilepickerItemsAdapter
import com.simplemobiletools.commons.databinding.DialogFilepickerBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.Breadcrumbs
import kotlinx.android.synthetic.main.dialog_filepicker.view.*
import java.io.File
/**
@ -47,7 +47,7 @@ class FilePickerDialog(
private var mScrollStates = HashMap<String, Parcelable>()
private var mDialog: AlertDialog? = null
private var mDialogView = activity.layoutInflater.inflate(R.layout.dialog_filepicker, null)
private var mDialogView = DialogFilepickerBinding.inflate(activity.layoutInflater, null, false)
init {
if (!activity.getDoesFilePathExist(currPath)) {
@ -63,7 +63,7 @@ class FilePickerDialog(
currPath = activity.internalStoragePath
}
mDialogView.filepicker_breadcrumbs.apply {
mDialogView.filepickerBreadcrumbs.apply {
listener = this@FilePickerDialog
updateFontSize(activity.getTextSize(), false)
isShownInDialog = true
@ -76,7 +76,7 @@ class FilePickerDialog(
.setNegativeButton(R.string.cancel, null)
.setOnKeyListener { dialogInterface, i, keyEvent ->
if (keyEvent.action == KeyEvent.ACTION_UP && i == KeyEvent.KEYCODE_BACK) {
val breadcrumbs = mDialogView.filepicker_breadcrumbs
val breadcrumbs = mDialogView.filepickerBreadcrumbs
if (breadcrumbs.getItemCount() > 1) {
breadcrumbs.removeBreadcrumb()
currPath = breadcrumbs.getLastItem().path.trimEnd('/')
@ -93,20 +93,20 @@ class FilePickerDialog(
}
if (showFAB) {
mDialogView.filepicker_fab.apply {
mDialogView.filepickerFab.apply {
beVisible()
setOnClickListener { createNewFolder() }
}
}
val secondaryFabBottomMargin = activity.resources.getDimension(if (showFAB) R.dimen.secondary_fab_bottom_margin else R.dimen.activity_margin).toInt()
mDialogView.filepicker_fabs_holder.apply {
mDialogView.filepickerFabsHolder.apply {
(layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = secondaryFabBottomMargin
}
mDialogView.filepicker_placeholder.setTextColor(activity.getProperTextColor())
mDialogView.filepicker_fastscroller.updateColors(activity.getProperPrimaryColor())
mDialogView.filepicker_fab_show_hidden.apply {
mDialogView.filepickerPlaceholder.setTextColor(activity.getProperTextColor())
mDialogView.filepickerFastscroller.updateColors(activity.getProperPrimaryColor())
mDialogView.filepickerFabShowHidden.apply {
beVisibleIf(!showHidden && canAddShowHiddenButton)
setOnClickListener {
activity.handleHiddenFolderPasswordProtection {
@ -117,11 +117,11 @@ class FilePickerDialog(
}
}
mDialogView.filepicker_favorites_label.text = "${activity.getString(R.string.favorites)}:"
mDialogView.filepicker_fab_show_favorites.apply {
mDialogView.filepickerFavoritesLabel.text = "${activity.getString(R.string.favorites)}:"
mDialogView.filepickerFabShowFavorites.apply {
beVisibleIf(showFavoritesButton && context.baseConfig.favorites.isNotEmpty())
setOnClickListener {
if (mDialogView.filepicker_favorites_holder.isVisible()) {
if (mDialogView.filepickerFavoritesHolder.isVisible()) {
hideFavorites()
} else {
showFavorites()
@ -130,7 +130,7 @@ class FilePickerDialog(
}
builder.apply {
activity.setupDialogStuff(mDialogView, this, getTitle()) { alertDialog ->
activity.setupDialogStuff(mDialogView.root, this, getTitle()) { alertDialog ->
mDialog = alertDialog
}
}
@ -155,7 +155,7 @@ class FilePickerDialog(
ensureBackgroundThread {
getItems(currPath) {
activity.runOnUiThread {
mDialogView.filepicker_placeholder.beGone()
mDialogView.filepickerPlaceholder.beGone()
updateItems(it as ArrayList<FileDirItem>)
}
}
@ -168,8 +168,8 @@ class FilePickerDialog(
return
}
val sortedItems = items.sortedWith(compareBy({ !it.isDirectory }, { it.name.toLowerCase() }))
val adapter = FilepickerItemsAdapter(activity, sortedItems, mDialogView.filepicker_list) {
val sortedItems = items.sortedWith(compareBy({ !it.isDirectory }, { it.name.lowercase() }))
val adapter = FilepickerItemsAdapter(activity, sortedItems, mDialogView.filepickerList) {
if ((it as FileDirItem).isDirectory) {
activity.handleLockedFolderOpening(it.path) { success ->
if (success) {
@ -183,15 +183,15 @@ class FilePickerDialog(
}
}
val layoutManager = mDialogView.filepicker_list.layoutManager as LinearLayoutManager
val layoutManager = mDialogView.filepickerList.layoutManager as LinearLayoutManager
mScrollStates[mPrevPath.trimEnd('/')] = layoutManager.onSaveInstanceState()!!
mDialogView.apply {
filepicker_list.adapter = adapter
filepicker_breadcrumbs.setBreadcrumb(currPath)
filepickerList.adapter = adapter
filepickerBreadcrumbs.setBreadcrumb(currPath)
if (context.areSystemAnimationsEnabled) {
filepicker_list.scheduleLayoutAnimation()
if (root.context.areSystemAnimationsEnabled) {
filepickerList.scheduleLayoutAnimation()
}
layoutManager.onRestoreInstanceState(mScrollStates[currPath.trimEnd('/')])
@ -313,29 +313,29 @@ class FilePickerDialog(
private fun containsDirectory(items: List<FileDirItem>) = items.any { it.isDirectory }
private fun setupFavorites() {
FilepickerFavoritesAdapter(activity, activity.baseConfig.favorites.toMutableList(), mDialogView.filepicker_favorites_list) {
FilepickerFavoritesAdapter(activity, activity.baseConfig.favorites.toMutableList(), mDialogView.filepickerFavoritesList) {
currPath = it as String
verifyPath()
}.apply {
mDialogView.filepicker_favorites_list.adapter = this
mDialogView.filepickerFavoritesList.adapter = this
}
}
private fun showFavorites() {
mDialogView.apply {
filepicker_favorites_holder.beVisible()
filepicker_files_holder.beGone()
filepickerFavoritesHolder.beVisible()
filepickerFilesHolder.beGone()
val drawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder_vector, activity.getProperPrimaryColor().getContrastColor())
filepicker_fab_show_favorites.setImageDrawable(drawable)
filepickerFabShowFavorites.setImageDrawable(drawable)
}
}
private fun hideFavorites() {
mDialogView.apply {
filepicker_favorites_holder.beGone()
filepicker_files_holder.beVisible()
filepickerFavoritesHolder.beGone()
filepickerFilesHolder.beVisible()
val drawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_star_vector, activity.getProperPrimaryColor().getContrastColor())
filepicker_fab_show_favorites.setImageDrawable(drawable)
filepickerFabShowFavorites.setImageDrawable(drawable)
}
}
@ -346,7 +346,7 @@ class FilePickerDialog(
tryUpdateItems()
}
} else {
val item = mDialogView.filepicker_breadcrumbs.getItem(id)
val item = mDialogView.filepickerBreadcrumbs.getItem(id)
if (currPath != item.path.trimEnd('/')) {
currPath = item.path
tryUpdateItems()

View file

@ -2,22 +2,22 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogTextviewBinding
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_textview.view.*
class FolderLockingNoticeDialog(val activity: Activity, val callback: () -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_textview, null).apply {
text_view.text = activity.getString(R.string.lock_folder_notice)
val view = DialogTextviewBinding.inflate(activity.layoutInflater, null, false).apply {
textView.text = activity.getString(R.string.lock_folder_notice)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.disclaimer)
activity.setupDialogStuff(view.root, this, R.string.disclaimer)
}
}

View file

@ -1,14 +1,13 @@
package com.simplemobiletools.commons.dialogs
import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import com.google.android.material.appbar.MaterialToolbar
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogLineColorPickerBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.interfaces.LineColorPickerListener
import kotlinx.android.synthetic.main.dialog_line_color_picker.view.*
class LineColorPickerDialog(
val activity: BaseSimpleActivity, val color: Int, val isPrimaryColorPicker: Boolean, val primaryColors: Int = R.array.md_primary_colors,
@ -21,28 +20,28 @@ class LineColorPickerDialog(
private var wasDimmedBackgroundRemoved = false
private var dialog: AlertDialog? = null
private var view: View = activity.layoutInflater.inflate(R.layout.dialog_line_color_picker, null)
private var view = DialogLineColorPickerBinding.inflate(activity.layoutInflater, null, false)
init {
view.apply {
hex_code.text = color.toHex()
hex_code.setOnLongClickListener {
activity.copyToClipboard(hex_code.value.substring(1))
hexCode.text = color.toHex()
hexCode.setOnLongClickListener {
activity.copyToClipboard(hexCode.value.substring(1))
true
}
line_color_picker_icon.beGoneIf(isPrimaryColorPicker)
lineColorPickerIcon.beGoneIf(isPrimaryColorPicker)
val indexes = getColorIndexes(color)
val primaryColorIndex = indexes.first
primaryColorChanged(primaryColorIndex)
primary_line_color_picker.updateColors(getColors(primaryColors), primaryColorIndex)
primary_line_color_picker.listener = object : LineColorPickerListener {
primaryLineColorPicker.updateColors(getColors(primaryColors), primaryColorIndex)
primaryLineColorPicker.listener = object : LineColorPickerListener {
override fun colorChanged(index: Int, color: Int) {
val secondaryColors = getColorsForIndex(index)
secondary_line_color_picker.updateColors(secondaryColors)
secondaryLineColorPicker.updateColors(secondaryColors)
val newColor = if (isPrimaryColorPicker) secondary_line_color_picker.getCurrentColor() else color
val newColor = if (isPrimaryColorPicker) secondaryLineColorPicker.getCurrentColor() else color
colorUpdated(newColor)
if (!isPrimaryColorPicker) {
@ -51,9 +50,9 @@ class LineColorPickerDialog(
}
}
secondary_line_color_picker.beVisibleIf(isPrimaryColorPicker)
secondary_line_color_picker.updateColors(getColorsForIndex(primaryColorIndex), indexes.second)
secondary_line_color_picker.listener = object : LineColorPickerListener {
secondaryLineColorPicker.beVisibleIf(isPrimaryColorPicker)
secondaryLineColorPicker.updateColors(getColorsForIndex(primaryColorIndex), indexes.second)
secondaryLineColorPicker.listener = object : LineColorPickerListener {
override fun colorChanged(index: Int, color: Int) {
colorUpdated(color)
}
@ -65,16 +64,16 @@ class LineColorPickerDialog(
.setNegativeButton(R.string.cancel) { dialog, which -> dialogDismissed() }
.setOnCancelListener { dialogDismissed() }
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(view.root, this) { alertDialog ->
dialog = alertDialog
}
}
}
fun getSpecificColor() = view.secondary_line_color_picker.getCurrentColor()
fun getSpecificColor() = view.secondaryLineColorPicker.getCurrentColor()
private fun colorUpdated(color: Int) {
view.hex_code.text = color.toHex()
view.hexCode.text = color.toHex()
if (isPrimaryColorPicker) {
if (toolbar != null) {
@ -105,7 +104,7 @@ class LineColorPickerDialog(
}
private fun primaryColorChanged(index: Int) {
view.line_color_picker_icon.setImageResource(appIconIDs?.getOrNull(index) ?: 0)
view.lineColorPickerIcon.setImageResource(appIconIDs?.getOrNull(index) ?: 0)
}
private fun getDefaultColorPair() = Pair(DEFAULT_PRIMARY_COLOR_INDEX, DEFAULT_SECONDARY_COLOR_INDEX)
@ -115,7 +114,7 @@ class LineColorPickerDialog(
}
private fun dialogConfirmed() {
val targetView = if (isPrimaryColorPicker) view.secondary_line_color_picker else view.primary_line_color_picker
val targetView = if (isPrimaryColorPicker) view.secondaryLineColorPicker else view.primaryLineColorPicker
val color = targetView.getCurrentColor()
callback(true, color)
}

View file

@ -4,27 +4,27 @@ import android.app.Activity
import android.text.Html
import android.text.method.LinkMovementMethod
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogTextviewBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_textview.view.*
class NewAppDialog(val activity: Activity, val packageName: String, val title: String, val packageName2: String, val title2: String) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_textview, null).apply {
val view = DialogTextviewBinding.inflate(activity.layoutInflater, null, false).apply {
val text = String.format(
activity.getString(R.string.new_app),
"https://play.google.com/store/apps/details?id=$packageName", title,
"https://play.google.com/store/apps/details?id=$packageName2", title2
)
text_view.text = Html.fromHtml(text)
text_view.movementMethod = LinkMovementMethod.getInstance()
textView.text = Html.fromHtml(text)
textView.movementMethod = LinkMovementMethod.getInstance()
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.apply {
activity.setupDialogStuff(view, this, cancelOnTouchOutside = false)
activity.setupDialogStuff(view.root, this, cancelOnTouchOutside = false)
}
}
}

View file

@ -4,14 +4,14 @@ import android.app.Activity
import android.text.Html
import android.text.method.LinkMovementMethod
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogNewAppsIconsBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.launchViewIntent
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_new_apps_icons.view.*
class NewAppsIconsDialog(val activity: Activity) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_new_apps_icons, null).apply {
val view = DialogNewAppsIconsBinding.inflate(activity.layoutInflater, null, false).apply {
val dialerUrl = "https://play.google.com/store/apps/details?id=com.simplemobiletools.dialer"
val smsMessengerUrl = "https://play.google.com/store/apps/details?id=com.simplemobiletools.smsmessenger"
val voiceRecorderUrl = "https://play.google.com/store/apps/details?id=com.simplemobiletools.voicerecorder"
@ -23,18 +23,18 @@ class NewAppsIconsDialog(val activity: Activity) {
voiceRecorderUrl, activity.getString(R.string.simple_voice_recorder)
)
new_apps_text.text = Html.fromHtml(text)
new_apps_text.movementMethod = LinkMovementMethod.getInstance()
newAppsText.text = Html.fromHtml(text)
newAppsText.movementMethod = LinkMovementMethod.getInstance()
new_apps_dialer.setOnClickListener { activity.launchViewIntent(dialerUrl) }
new_apps_sms_messenger.setOnClickListener { activity.launchViewIntent(smsMessengerUrl) }
new_apps_voice_recorder.setOnClickListener { activity.launchViewIntent(voiceRecorderUrl) }
newAppsDialer.setOnClickListener { activity.launchViewIntent(dialerUrl) }
newAppsSmsMessenger.setOnClickListener { activity.launchViewIntent(smsMessengerUrl) }
newAppsVoiceRecorder.setOnClickListener { activity.launchViewIntent(voiceRecorderUrl) }
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.apply {
activity.setupDialogStuff(view, this, cancelOnTouchOutside = false)
activity.setupDialogStuff(view.root, this, cancelOnTouchOutside = false)
}
}
}

View file

@ -3,9 +3,9 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogMessageBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_message.view.*
class PermissionRequiredDialog(
val activity: Activity,
@ -16,14 +16,14 @@ class PermissionRequiredDialog(
private var dialog: AlertDialog? = null
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_message, null)
val view = DialogMessageBinding.inflate(activity.layoutInflater, null, false)
view.message.text = activity.getString(textId)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.grant_permission) { _, _ -> positiveActionCallback() }
.setNegativeButton(R.string.cancel) { _, _ -> negativeActionCallback?.invoke() }.apply {
val title = activity.getString(R.string.permission_required)
activity.setupDialogStuff(view, this, titleText = title) { alertDialog ->
activity.setupDialogStuff(view.root, this, titleText = title) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -6,7 +6,6 @@ import android.os.Environment
import android.provider.MediaStore
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.exifinterface.media.ExifInterface
import com.simplemobiletools.commons.R
@ -14,8 +13,7 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FileDirItem
import kotlinx.android.synthetic.main.dialog_properties.view.*
import kotlinx.android.synthetic.main.item_property.view.*
import com.simplemobiletools.commons.views.MyTextView
import java.io.File
import java.util.*
@ -48,7 +46,7 @@ class PropertiesDialog : BasePropertiesDialog {
}
builder.apply {
mActivity.setupDialogStuff(mDialogView, this, R.string.properties) { alertDialog ->
mActivity.setupDialogStuff(mDialogView.root, this, R.string.properties) { alertDialog ->
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener {
removeEXIFFromPath(path)
}
@ -73,11 +71,11 @@ class PropertiesDialog : BasePropertiesDialog {
}
this.mActivity.runOnUiThread {
(mDialogView.findViewById<LinearLayout>(R.id.properties_size).property_value as TextView).text = size
(mDialogView.propertiesHolder.findViewById<LinearLayout>(R.id.properties_size).findViewById<MyTextView>(R.id.property_value)).text = size
if (fileDirItem.isDirectory) {
(mDialogView.findViewById<LinearLayout>(R.id.properties_file_count).property_value as TextView).text = fileCount.toString()
(mDialogView.findViewById<LinearLayout>(R.id.properties_direct_children_count).property_value as TextView).text =
(mDialogView.propertiesHolder.findViewById<LinearLayout>(R.id.properties_file_count).findViewById<MyTextView>(R.id.property_value)).text = fileCount.toString()
(mDialogView.propertiesHolder.findViewById<LinearLayout>(R.id.properties_direct_children_count).findViewById<MyTextView>(R.id.property_value)).text =
directChildrenCount.toString()
}
}
@ -91,9 +89,9 @@ class PropertiesDialog : BasePropertiesDialog {
cursor?.use {
if (cursor.moveToFirst()) {
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
updateLastModified(mActivity, mDialogView, dateModified)
updateLastModified(mActivity, mDialogView.root, dateModified)
} else {
updateLastModified(mActivity, mDialogView, fileDirItem.getLastModified(mActivity))
updateLastModified(mActivity, mDialogView.root, fileDirItem.getLastModified(mActivity))
}
}
@ -140,15 +138,18 @@ class PropertiesDialog : BasePropertiesDialog {
addProperty(R.string.direct_children_count, "", R.id.properties_direct_children_count)
addProperty(R.string.files_count, "", R.id.properties_file_count)
}
fileDirItem.path.isImageSlow() -> {
fileDirItem.getResolution(mActivity)?.let { addProperty(R.string.resolution, it.formatAsResolution()) }
}
fileDirItem.path.isAudioSlow() -> {
fileDirItem.getDuration(mActivity)?.let { addProperty(R.string.duration, it) }
fileDirItem.getTitle(mActivity)?.let { addProperty(R.string.song_title, it) }
fileDirItem.getArtist(mActivity)?.let { addProperty(R.string.artist, it) }
fileDirItem.getAlbum(mActivity)?.let { addProperty(R.string.album, it) }
}
fileDirItem.path.isVideoSlow() -> {
fileDirItem.getDuration(mActivity)?.let { addProperty(R.string.duration, it) }
fileDirItem.getResolution(mActivity)?.let { addProperty(R.string.resolution, it.formatAsResolution()) }
@ -179,9 +180,9 @@ class PropertiesDialog : BasePropertiesDialog {
mActivity.runOnUiThread {
if (md5 != null) {
(mDialogView.findViewById<LinearLayout>(R.id.properties_md5).property_value as TextView).text = md5
(mDialogView.propertiesHolder.findViewById<LinearLayout>(R.id.properties_md5).findViewById<MyTextView>(R.id.property_value)).text = md5
} else {
mDialogView.findViewById<LinearLayout>(R.id.properties_md5).beGone()
mDialogView.propertiesHolder.findViewById<LinearLayout>(R.id.properties_md5).beGone()
}
}
}
@ -191,7 +192,7 @@ class PropertiesDialog : BasePropertiesDialog {
private fun updateLastModified(activity: Activity, view: View, timestamp: Long) {
activity.runOnUiThread {
(view.findViewById<LinearLayout>(R.id.properties_last_modified).property_value as TextView).text = timestamp.formatDate(activity)
(view.findViewById<LinearLayout>(R.id.properties_last_modified).findViewById<MyTextView>(R.id.property_value)).text = timestamp.formatDate(activity)
}
}
@ -225,8 +226,8 @@ class PropertiesDialog : BasePropertiesDialog {
val fileCount = fileDirItems.sumByInt { it.getProperFileCount(activity, countHiddenItems) }
val size = fileDirItems.sumByLong { it.getProperSize(activity, countHiddenItems) }.formatSize()
activity.runOnUiThread {
(mDialogView.findViewById<LinearLayout>(R.id.properties_size).property_value as TextView).text = size
(mDialogView.findViewById<LinearLayout>(R.id.properties_file_count).property_value as TextView).text = fileCount.toString()
(mDialogView.propertiesHolder.findViewById<LinearLayout>(R.id.properties_size).findViewById<MyTextView>(R.id.property_value)).text = size
(mDialogView.propertiesHolder.findViewById<LinearLayout>(R.id.properties_file_count).findViewById<MyTextView>(R.id.property_value)).text = fileCount.toString()
}
}
@ -240,7 +241,7 @@ class PropertiesDialog : BasePropertiesDialog {
}
builder.apply {
mActivity.setupDialogStuff(mDialogView, this, R.string.properties) { alertDialog ->
mActivity.setupDialogStuff(mDialogView.root, this, R.string.properties) { alertDialog ->
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener {
removeEXIFFromPaths(paths)
}
@ -288,8 +289,7 @@ class PropertiesDialog : BasePropertiesDialog {
try {
ExifInterface(path).removeValues()
mActivity.toast(R.string.exif_removed)
mPropertyView.properties_holder.removeAllViews()
mPropertyView.findViewById<LinearLayout>(R.id.properties_holder).removeAllViews()
addProperties(path)
} catch (e: Exception) {
mActivity.showErrorToast(e)

View file

@ -4,27 +4,27 @@ import android.app.Activity
import android.text.Html
import android.text.method.LinkMovementMethod
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogPurchaseThankYouBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_purchase_thank_you.view.*
class PurchaseThankYouDialog(val activity: Activity) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_purchase_thank_you, null).apply {
val view = DialogPurchaseThankYouBinding.inflate(activity.layoutInflater, null, false).apply {
var text = activity.getString(R.string.purchase_thank_you)
if (activity.baseConfig.appId.removeSuffix(".debug").endsWith(".pro")) {
text += "<br><br>${activity.getString(R.string.shared_theme_note)}"
}
purchase_thank_you.text = Html.fromHtml(text)
purchase_thank_you.movementMethod = LinkMovementMethod.getInstance()
purchase_thank_you.removeUnderlines()
purchaseThankYou.text = Html.fromHtml(text)
purchaseThankYou.movementMethod = LinkMovementMethod.getInstance()
purchaseThankYou.removeUnderlines()
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.purchase) { dialog, which -> activity.launchPurchaseThankYouIntent() }
.setPositiveButton(R.string.purchase) { _, _ -> activity.launchPurchaseThankYouIntent() }
.setNegativeButton(R.string.later, null)
.apply {
activity.setupDialogStuff(view, this, cancelOnTouchOutside = false)
activity.setupDialogStuff(view.root, this, cancelOnTouchOutside = false)
}
}
}

View file

@ -7,11 +7,11 @@ import android.widget.RadioButton
import android.widget.RadioGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogRadioGroupBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.onGlobalLayout
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.dialog_radio_group.view.*
class RadioGroupDialog(
val activity: Activity, val items: ArrayList<RadioItem>, val checkedItemId: Int = -1, val titleId: Int = 0,
@ -22,8 +22,8 @@ class RadioGroupDialog(
private var selectedItemId = -1
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null)
view.dialog_radio_group.apply {
val view = DialogRadioGroupBinding.inflate(activity.layoutInflater, null, false)
view.dialogRadioGroup.apply {
for (i in 0 until items.size) {
val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
text = items[i].title
@ -48,15 +48,15 @@ class RadioGroupDialog(
}
builder.apply {
activity.setupDialogStuff(view, this, titleId) { alertDialog ->
activity.setupDialogStuff(view.root, this, titleId) { alertDialog ->
dialog = alertDialog
}
}
if (selectedItemId != -1) {
view.dialog_radio_holder.apply {
view.dialogRadioHolder.apply {
onGlobalLayout {
scrollY = view.dialog_radio_group.findViewById<View>(selectedItemId).bottom - height
scrollY = view.dialogRadioGroup.findViewById<View>(selectedItemId).bottom - height
}
}
}

View file

@ -3,34 +3,34 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogRateStarsBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_rate_stars.view.*
class RateStarsDialog(val activity: Activity) {
private var dialog: AlertDialog? = null
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_rate_stars, null).apply {
val view = DialogRateStarsBinding.inflate(activity.layoutInflater, null, false).apply {
val primaryColor = activity.getProperPrimaryColor()
arrayOf(rate_star_1, rate_star_2, rate_star_3, rate_star_4, rate_star_5).forEach {
arrayOf(rateStar1, rateStar2, rateStar3, rateStar4, rateStar5).forEach {
it.applyColorFilter(primaryColor)
}
rate_star_1.setOnClickListener { dialogCancelled(true) }
rate_star_2.setOnClickListener { dialogCancelled(true) }
rate_star_3.setOnClickListener { dialogCancelled(true) }
rate_star_4.setOnClickListener { dialogCancelled(true) }
rate_star_5.setOnClickListener {
rateStar1.setOnClickListener { dialogCancelled(true) }
rateStar2.setOnClickListener { dialogCancelled(true) }
rateStar3.setOnClickListener { dialogCancelled(true) }
rateStar4.setOnClickListener { dialogCancelled(true) }
rateStar5.setOnClickListener {
activity.redirectToRateUs()
dialogCancelled(true)
}
}
activity.getAlertDialogBuilder()
.setNegativeButton(R.string.later) { dialog, which -> dialogCancelled(false) }
.setNegativeButton(R.string.later) { _, _ -> dialogCancelled(false) }
.setOnCancelListener { dialogCancelled(false) }
.apply {
activity.setupDialogStuff(view, this, cancelOnTouchOutside = false) { alertDialog ->
activity.setupDialogStuff(view.root, this, cancelOnTouchOutside = false) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -6,45 +6,45 @@ import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.RenameAdapter
import com.simplemobiletools.commons.databinding.DialogRenameBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.RENAME_PATTERN
import com.simplemobiletools.commons.helpers.RENAME_SIMPLE
import com.simplemobiletools.commons.views.MyViewPager
import kotlinx.android.synthetic.main.dialog_rename.view.*
class RenameDialog(val activity: BaseSimpleActivity, val paths: ArrayList<String>, val useMediaFileExtension: Boolean, val callback: () -> Unit) {
var dialog: AlertDialog? = null
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_rename, null)
val view = DialogRenameBinding.inflate(LayoutInflater.from(activity), null, false)
var tabsAdapter: RenameAdapter
var viewPager: MyViewPager
init {
view.apply {
viewPager = findViewById(R.id.dialog_tab_view_pager)
viewPager = dialogTabViewPager
tabsAdapter = RenameAdapter(activity, paths)
viewPager.adapter = tabsAdapter
viewPager.onPageChangeListener {
dialog_tab_layout.getTabAt(it)!!.select()
dialogTabLayout.getTabAt(it)!!.select()
}
viewPager.currentItem = activity.baseConfig.lastRenameUsed
if (activity.baseConfig.isUsingSystemTheme) {
dialog_tab_layout.setBackgroundColor(activity.resources.getColor(R.color.you_dialog_background_color))
dialogTabLayout.setBackgroundColor(activity.resources.getColor(R.color.you_dialog_background_color))
} else {
dialog_tab_layout.setBackgroundColor(context.getProperBackgroundColor())
dialogTabLayout.setBackgroundColor(root.context.getProperBackgroundColor())
}
val textColor = context.getProperTextColor()
dialog_tab_layout.setTabTextColors(textColor, textColor)
dialog_tab_layout.setSelectedTabIndicatorColor(context.getProperPrimaryColor())
val textColor = root.context.getProperTextColor()
dialogTabLayout.setTabTextColors(textColor, textColor)
dialogTabLayout.setSelectedTabIndicatorColor(root.context.getProperPrimaryColor())
if (activity.baseConfig.isUsingSystemTheme) {
dialog_tab_layout.setBackgroundColor(activity.resources.getColor(R.color.you_dialog_background_color))
dialogTabLayout.setBackgroundColor(activity.resources.getColor(R.color.you_dialog_background_color))
}
dialog_tab_layout.onTabSelectionChanged(tabSelectedAction = {
dialogTabLayout.onTabSelectionChanged(tabSelectedAction = {
viewPager.currentItem = when {
it.text.toString().equals(resources.getString(R.string.simple_renaming), true) -> RENAME_SIMPLE
it.text.toString().equals(root.context.resources.getString(R.string.simple_renaming), true) -> RENAME_SIMPLE
else -> RENAME_PATTERN
}
})
@ -52,9 +52,9 @@ class RenameDialog(val activity: BaseSimpleActivity, val paths: ArrayList<String
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel) { dialog, which -> dismissDialog() }
.setNegativeButton(R.string.cancel) { _, _ -> dismissDialog() }
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(view.root, this) { alertDialog ->
dialog = alertDialog
alertDialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {

View file

@ -3,8 +3,8 @@ package com.simplemobiletools.commons.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogRenameItemBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_rename_item.view.*
class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val callback: (newPath: String) -> Unit) {
init {
@ -13,31 +13,31 @@ class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val c
val dotAt = fullName.lastIndexOf(".")
var name = fullName
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_item, null).apply {
val view = DialogRenameItemBinding.inflate(activity.layoutInflater, null, false).apply {
if (dotAt > 0 && !activity.getIsPathDirectory(path)) {
name = fullName.substring(0, dotAt)
val extension = fullName.substring(dotAt + 1)
rename_item_extension.setText(extension)
renameItemExtension.setText(extension)
} else {
rename_item_extension_hint.beGone()
renameItemExtensionHint.beGone()
}
rename_item_name.setText(name)
renameItemName.setText(name)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.rename) { alertDialog ->
alertDialog.showKeyboard(view.rename_item_name)
activity.setupDialogStuff(view.root, this, R.string.rename) { alertDialog ->
alertDialog.showKeyboard(view.renameItemName)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (ignoreClicks) {
return@setOnClickListener
}
var newName = view.rename_item_name.value
val newExtension = view.rename_item_extension.value
var newName = view.renameItemName.value
val newExtension = view.renameItemExtension.value
if (newName.isEmpty()) {
activity.toast(R.string.empty_name)

View file

@ -3,28 +3,28 @@ package com.simplemobiletools.commons.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogRenameItemsBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_rename_items.view.*
// used at renaming folders
class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList<String>, val callback: () -> Unit) {
init {
var ignoreClicks = false
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_items, null)
val view = DialogRenameItemsBinding.inflate(activity.layoutInflater,null, false)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.rename) { alertDialog ->
alertDialog.showKeyboard(view.rename_items_value)
activity.setupDialogStuff(view.root, this, R.string.rename) { alertDialog ->
alertDialog.showKeyboard(view.renameItemsValue)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (ignoreClicks) {
return@setOnClickListener
}
val valueToAdd = view.rename_items_value.text.toString()
val append = view.rename_items_radio_group.checkedRadioButtonId == view.rename_items_radio_append.id
val valueToAdd = view.renameItemsValue.text.toString()
val append = view.renameItemsRadioGroup.checkedRadioButtonId == view.renameItemsRadioAppend.id
if (valueToAdd.isEmpty()) {
callback()

View file

@ -7,11 +7,11 @@ import androidx.biometric.auth.AuthPromptHost
import androidx.fragment.app.FragmentActivity
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.adapters.PasswordTypesAdapter
import com.simplemobiletools.commons.databinding.DialogSecurityBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.interfaces.HashListener
import com.simplemobiletools.commons.views.MyDialogViewPager
import kotlinx.android.synthetic.main.dialog_security.view.*
class SecurityDialog(
private val activity: Activity,
@ -20,26 +20,26 @@ class SecurityDialog(
private val callback: (hash: String, type: Int, success: Boolean) -> Unit
) : HashListener {
private var dialog: AlertDialog? = null
private val view = LayoutInflater.from(activity).inflate(R.layout.dialog_security, null)
private val view = DialogSecurityBinding.inflate(LayoutInflater.from(activity), null, false)
private var tabsAdapter: PasswordTypesAdapter
private var viewPager: MyDialogViewPager
init {
view.apply {
viewPager = findViewById(R.id.dialog_tab_view_pager)
viewPager = dialogTabViewPager
viewPager.offscreenPageLimit = 2
tabsAdapter = PasswordTypesAdapter(
context = context,
context = root.context,
requiredHash = requiredHash,
hashListener = this@SecurityDialog,
scrollView = dialog_scrollview,
scrollView = dialogScrollview,
biometricPromptHost = AuthPromptHost(activity as FragmentActivity),
showBiometricIdTab = shouldShowBiometricIdTab(),
showBiometricAuthentication = showTabIndex == PROTECTION_FINGERPRINT && isRPlus()
)
viewPager.adapter = tabsAdapter
viewPager.onPageChangeListener {
dialog_tab_layout.getTabAt(it)?.select()
dialogTabLayout.getTabAt(it)?.select()
}
viewPager.onGlobalLayout {
@ -47,31 +47,31 @@ class SecurityDialog(
}
if (showTabIndex == SHOW_ALL_TABS) {
val textColor = context.getProperTextColor()
val textColor = root.context.getProperTextColor()
if (shouldShowBiometricIdTab()) {
val tabTitle = if (isRPlus()) R.string.biometrics else R.string.fingerprint
dialog_tab_layout.addTab(dialog_tab_layout.newTab().setText(tabTitle), PROTECTION_FINGERPRINT)
dialogTabLayout.addTab(dialogTabLayout.newTab().setText(tabTitle), PROTECTION_FINGERPRINT)
}
if (activity.baseConfig.isUsingSystemTheme) {
dialog_tab_layout.setBackgroundColor(activity.resources.getColor(R.color.you_dialog_background_color))
dialogTabLayout.setBackgroundColor(activity.resources.getColor(R.color.you_dialog_background_color))
} else {
dialog_tab_layout.setBackgroundColor(context.getProperBackgroundColor())
dialogTabLayout.setBackgroundColor(root.context.getProperBackgroundColor())
}
dialog_tab_layout.setTabTextColors(textColor, textColor)
dialog_tab_layout.setSelectedTabIndicatorColor(context.getProperPrimaryColor())
dialog_tab_layout.onTabSelectionChanged(tabSelectedAction = {
dialogTabLayout.setTabTextColors(textColor, textColor)
dialogTabLayout.setSelectedTabIndicatorColor(root.context.getProperPrimaryColor())
dialogTabLayout.onTabSelectionChanged(tabSelectedAction = {
viewPager.currentItem = when {
it.text.toString().equals(resources.getString(R.string.pattern), true) -> PROTECTION_PATTERN
it.text.toString().equals(resources.getString(R.string.pin), true) -> PROTECTION_PIN
it.text.toString().equals(root.context.resources.getString(R.string.pattern), true) -> PROTECTION_PATTERN
it.text.toString().equals(root.context.resources.getString(R.string.pin), true) -> PROTECTION_PIN
else -> PROTECTION_FINGERPRINT
}
updateTabVisibility()
})
} else {
dialog_tab_layout.beGone()
dialogTabLayout.beGone()
viewPager.currentItem = showTabIndex
viewPager.allowSwiping = false
}
@ -81,7 +81,7 @@ class SecurityDialog(
.setOnCancelListener { onCancelFail() }
.setNegativeButton(R.string.cancel) { _, _ -> onCancelFail() }
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(view.root, this) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -11,12 +11,12 @@ import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogSelectAlarmSoundBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SILENT
import com.simplemobiletools.commons.models.AlarmSound
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.MyCompatRadioButton
import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.*
class SelectAlarmSoundDialog(
val activity: BaseSimpleActivity, val currentUri: String, val audioStream: Int, val pickAudioIntentId: Int,
@ -25,7 +25,7 @@ class SelectAlarmSoundDialog(
) {
private val ADD_NEW_SOUND_ID = -2
private val view = activity.layoutInflater.inflate(R.layout.dialog_select_alarm_sound, null)
private val view = DialogSelectAlarmSoundBinding.inflate(activity.layoutInflater, null, false)
private var systemAlarmSounds = ArrayList<AlarmSound>()
private var yourAlarmSounds = ArrayList<AlarmSound>()
private var mediaPlayer: MediaPlayer? = null
@ -38,17 +38,17 @@ class SelectAlarmSoundDialog(
gotSystemAlarms()
}
view.dialog_select_alarm_your_label.setTextColor(activity.getProperPrimaryColor())
view.dialog_select_alarm_system_label.setTextColor(activity.getProperPrimaryColor())
view.dialogSelectAlarmYourLabel.setTextColor(activity.getProperPrimaryColor())
view.dialogSelectAlarmSystemLabel.setTextColor(activity.getProperPrimaryColor())
addYourAlarms()
activity.getAlertDialogBuilder()
.setOnDismissListener { mediaPlayer?.stop() }
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(view.root, this) { alertDialog ->
dialog = alertDialog
alertDialog.window?.volumeControlStream = audioStream
}
@ -56,18 +56,18 @@ class SelectAlarmSoundDialog(
}
private fun addYourAlarms() {
view.dialog_select_alarm_your_radio.removeAllViews()
view.dialogSelectAlarmYourRadio.removeAllViews()
val token = object : TypeToken<ArrayList<AlarmSound>>() {}.type
yourAlarmSounds = Gson().fromJson<ArrayList<AlarmSound>>(config.yourAlarmSounds, token) ?: ArrayList()
yourAlarmSounds.add(AlarmSound(ADD_NEW_SOUND_ID, activity.getString(R.string.add_new_sound), ""))
yourAlarmSounds.forEach {
addAlarmSound(it, view.dialog_select_alarm_your_radio)
addAlarmSound(it, view.dialogSelectAlarmYourRadio)
}
}
private fun gotSystemAlarms() {
systemAlarmSounds.forEach {
addAlarmSound(it, view.dialog_select_alarm_system_radio)
addAlarmSound(it, view.dialogSelectAlarmSystemRadio)
}
}
@ -80,14 +80,14 @@ class SelectAlarmSoundDialog(
setOnClickListener {
alarmClicked(alarmSound)
if (holder == view.dialog_select_alarm_system_radio) {
view.dialog_select_alarm_your_radio.clearCheck()
if (holder == view.dialogSelectAlarmSystemRadio) {
view.dialogSelectAlarmYourRadio.clearCheck()
} else {
view.dialog_select_alarm_system_radio.clearCheck()
view.dialogSelectAlarmSystemRadio.clearCheck()
}
}
if (alarmSound.id != -2 && holder == view.dialog_select_alarm_your_radio) {
if (alarmSound.id != -2 && holder == view.dialogSelectAlarmYourRadio) {
setOnLongClickListener {
val items = arrayListOf(RadioItem(1, context.getString(R.string.remove)))
@ -146,20 +146,20 @@ class SelectAlarmSoundDialog(
config.yourAlarmSounds = Gson().toJson(yourAlarmSounds)
addYourAlarms()
if (alarmSound.id == view.dialog_select_alarm_your_radio.checkedRadioButtonId) {
view.dialog_select_alarm_your_radio.clearCheck()
view.dialog_select_alarm_system_radio.check(systemAlarmSounds.firstOrNull()?.id ?: 0)
if (alarmSound.id == view.dialogSelectAlarmYourRadio.checkedRadioButtonId) {
view.dialogSelectAlarmYourRadio.clearCheck()
view.dialogSelectAlarmSystemRadio.check(systemAlarmSounds.firstOrNull()?.id ?: 0)
}
onAlarmSoundDeleted(alarmSound)
}
private fun dialogConfirmed() {
if (view.dialog_select_alarm_your_radio.checkedRadioButtonId != -1) {
val checkedId = view.dialog_select_alarm_your_radio.checkedRadioButtonId
if (view.dialogSelectAlarmYourRadio.checkedRadioButtonId != -1) {
val checkedId = view.dialogSelectAlarmYourRadio.checkedRadioButtonId
onAlarmPicked(yourAlarmSounds.firstOrNull { it.id == checkedId })
} else {
val checkedId = view.dialog_select_alarm_system_radio.checkedRadioButtonId
val checkedId = view.dialogSelectAlarmSystemRadio.checkedRadioButtonId
onAlarmPicked(systemAlarmSounds.firstOrNull { it.id == checkedId })
}
}

View file

@ -2,13 +2,13 @@ package com.simplemobiletools.commons.dialogs
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.RadioButton
import android.widget.RadioGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogRadioGroupBinding
import com.simplemobiletools.commons.databinding.RadioButtonBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_radio_group.view.*
/**
* A dialog for choosing between internal, root, SD card (optional) storage
@ -52,11 +52,11 @@ class StoragePickerDialog(
val inflater = LayoutInflater.from(activity)
val resources = activity.resources
val layoutParams = RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
val view = inflater.inflate(R.layout.dialog_radio_group, null)
radioGroup = view.dialog_radio_group
val view = DialogRadioGroupBinding.inflate(inflater, null, false)
radioGroup = view.dialogRadioGroup
val basePath = currPath.getBasePath(activity)
val internalButton = inflater.inflate(R.layout.radio_button, null) as RadioButton
val internalButton = RadioButtonBinding.inflate(inflater, null, false).root
internalButton.apply {
id = ID_INTERNAL
text = resources.getString(R.string.internal)
@ -69,7 +69,7 @@ class StoragePickerDialog(
radioGroup.addView(internalButton, layoutParams)
if (activity.hasExternalSDCard()) {
val sdButton = inflater.inflate(R.layout.radio_button, null) as RadioButton
val sdButton = RadioButtonBinding.inflate(inflater, null, false).root
sdButton.apply {
id = ID_SD
text = resources.getString(R.string.sd_card)
@ -83,7 +83,7 @@ class StoragePickerDialog(
}
if (activity.hasOTGConnected()) {
val otgButton = inflater.inflate(R.layout.radio_button, null) as RadioButton
val otgButton = RadioButtonBinding.inflate(inflater, null, false).root
otgButton.apply {
id = ID_OTG
text = resources.getString(R.string.usb)
@ -98,7 +98,7 @@ class StoragePickerDialog(
// allow for example excluding the root folder at the gallery
if (showRoot) {
val rootButton = inflater.inflate(R.layout.radio_button, null) as RadioButton
val rootButton = RadioButtonBinding.inflate(inflater, null, false).root
rootButton.apply {
id = ID_ROOT
text = resources.getString(R.string.root)
@ -112,7 +112,7 @@ class StoragePickerDialog(
}
activity.getAlertDialogBuilder().apply {
activity.setupDialogStuff(view, this, R.string.select_storage) { alertDialog ->
activity.setupDialogStuff(view.root, this, R.string.select_storage) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -3,25 +3,25 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogUpgradeToProBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.launchUpgradeToProIntent
import com.simplemobiletools.commons.extensions.launchViewIntent
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_upgrade_to_pro.view.*
class UpgradeToProDialog(val activity: Activity) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_upgrade_to_pro, null).apply {
upgrade_to_pro.text = activity.getString(R.string.upgrade_to_pro_long)
val view = DialogUpgradeToProBinding.inflate(activity.layoutInflater, null, false).apply {
upgradeToPro.text = activity.getString(R.string.upgrade_to_pro_long)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.upgrade) { dialog, which -> upgradeApp() }
.setPositiveButton(R.string.upgrade) { _, _ -> upgradeApp() }
.setNeutralButton(R.string.more_info, null) // do not dismiss the dialog on pressing More Info
.setNegativeButton(R.string.later, null)
.apply {
activity.setupDialogStuff(view, this, R.string.upgrade_to_pro, cancelOnTouchOutside = false) { alertDialog ->
activity.setupDialogStuff(view.root, this, R.string.upgrade_to_pro, cancelOnTouchOutside = false) { alertDialog ->
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener {
moreInfo()
}

View file

@ -3,20 +3,20 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import android.view.LayoutInflater
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogWhatsNewBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.models.Release
import kotlinx.android.synthetic.main.dialog_whats_new.view.*
class WhatsNewDialog(val activity: Activity, val releases: List<Release>) {
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_whats_new, null)
view.whats_new_content.text = getNewReleases()
val view = DialogWhatsNewBinding.inflate(LayoutInflater.from(activity), null, false)
view.whatsNewContent.text = getNewReleases()
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.apply {
activity.setupDialogStuff(view, this, R.string.whats_new, cancelOnTouchOutside = false)
activity.setupDialogStuff(view.root, this, R.string.whats_new, cancelOnTouchOutside = false)
}
}

View file

@ -7,11 +7,11 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogWritePermissionBinding
import com.simplemobiletools.commons.databinding.DialogWritePermissionOtgBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_write_permission.view.*
import kotlinx.android.synthetic.main.dialog_write_permission_otg.view.*
class WritePermissionDialog(activity: Activity, val mode: Mode, val callback: () -> Unit) {
sealed class Mode {
@ -24,51 +24,59 @@ class WritePermissionDialog(activity: Activity, val mode: Mode, val callback: ()
private var dialog: AlertDialog? = null
init {
val layout = if (mode == Mode.SdCard) R.layout.dialog_write_permission else R.layout.dialog_write_permission_otg
val view = activity.layoutInflater.inflate(layout, null)
val sdCardView = DialogWritePermissionBinding.inflate(activity.layoutInflater, null, false)
val otgView = DialogWritePermissionOtgBinding.inflate(
activity.layoutInflater,
null,
false
)
var dialogTitle = R.string.confirm_storage_access_title
val glide = Glide.with(activity)
val crossFade = DrawableTransitionOptions.withCrossFade()
when (mode) {
Mode.Otg -> {
view.write_permissions_dialog_otg_text.setText(R.string.confirm_usb_storage_access_text)
glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(view.write_permissions_dialog_otg_image)
otgView.writePermissionsDialogOtgText.setText(R.string.confirm_usb_storage_access_text)
glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(otgView.writePermissionsDialogOtgImage)
}
Mode.SdCard -> {
glide.load(R.drawable.img_write_storage).transition(crossFade).into(view.write_permissions_dialog_image)
glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(view.write_permissions_dialog_image_sd)
glide.load(R.drawable.img_write_storage).transition(crossFade).into(sdCardView.writePermissionsDialogImage)
glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(sdCardView.writePermissionsDialogImageSd)
}
is Mode.OpenDocumentTreeSDK30 -> {
dialogTitle = R.string.confirm_folder_access_title
val humanizedPath = activity.humanizePath(mode.path)
view.write_permissions_dialog_otg_text.text =
otgView.writePermissionsDialogOtgText.text =
Html.fromHtml(activity.getString(R.string.confirm_storage_access_android_text_specific, humanizedPath))
glide.load(R.drawable.img_write_storage_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image)
glide.load(R.drawable.img_write_storage_sdk_30).transition(crossFade).into(otgView.writePermissionsDialogOtgImage)
view.write_permissions_dialog_otg_image.setOnClickListener {
otgView.writePermissionsDialogOtgImage.setOnClickListener {
dialogConfirmed()
}
}
Mode.CreateDocumentSDK30 -> {
dialogTitle = R.string.confirm_folder_access_title
view.write_permissions_dialog_otg_text.text = Html.fromHtml(activity.getString(R.string.confirm_create_doc_for_new_folder_text))
glide.load(R.drawable.img_write_storage_create_doc_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image)
otgView.writePermissionsDialogOtgText.text = Html.fromHtml(activity.getString(R.string.confirm_create_doc_for_new_folder_text))
glide.load(R.drawable.img_write_storage_create_doc_sdk_30).transition(crossFade).into(otgView.writePermissionsDialogOtgImage)
view.write_permissions_dialog_otg_image.setOnClickListener {
otgView.writePermissionsDialogOtgImage.setOnClickListener {
dialogConfirmed()
}
}
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
.setOnCancelListener {
BaseSimpleActivity.funAfterSAFPermission?.invoke(false)
BaseSimpleActivity.funAfterSAFPermission = null
}
.apply {
activity.setupDialogStuff(view, this, dialogTitle) { alertDialog ->
activity.setupDialogStuff(if (mode == Mode.Otg) otgView.root else sdCardView.root, this, dialogTitle) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -25,7 +25,6 @@ import android.view.Window
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.biometric.BiometricPrompt
@ -38,12 +37,12 @@ import androidx.fragment.app.FragmentActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogTitleBinding
import com.simplemobiletools.commons.dialogs.*
import com.simplemobiletools.commons.dialogs.WritePermissionDialog.Mode
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.*
import com.simplemobiletools.commons.views.MyTextView
import kotlinx.android.synthetic.main.dialog_title.view.*
import java.io.*
import java.util.*
@ -1532,10 +1531,10 @@ fun Activity.setupDialogStuff(
callback?.invoke(this)
}
} else {
var title: TextView? = null
var title: DialogTitleBinding? = null
if (titleId != 0 || titleText.isNotEmpty()) {
title = layoutInflater.inflate(R.layout.dialog_title, null) as TextView
title.dialog_title_textview.apply {
title = DialogTitleBinding.inflate(layoutInflater, null, false)
title.dialogTitleTextview.apply {
if (titleText.isNotEmpty()) {
text = titleText
} else {
@ -1555,7 +1554,7 @@ fun Activity.setupDialogStuff(
dialog.create().apply {
setView(view)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setCustomTitle(title)
setCustomTitle(title?.root)
setCanceledOnTouchOutside(cancelOnTouchOutside)
if (!isFinishing) {
show()

View file

@ -8,8 +8,8 @@ import android.view.ViewGroup
import androidx.core.content.res.ResourcesCompat
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.DialogBottomSheetBinding
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_bottom_sheet.view.*
abstract class BaseBottomSheetDialogFragment : BottomSheetDialogFragment() {
@ -18,27 +18,27 @@ abstract class BaseBottomSheetDialogFragment : BottomSheetDialogFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.dialog_bottom_sheet, container, false)
val view = DialogBottomSheetBinding.inflate(inflater, container, false)
val context = requireContext()
val config = context.baseConfig
if (requireContext().isBlackAndWhiteTheme()) {
view.background = ResourcesCompat.getDrawable(context.resources, R.drawable.bottom_sheet_bg_black, context.theme)
view.root.background = ResourcesCompat.getDrawable(context.resources, R.drawable.bottom_sheet_bg_black, context.theme)
} else if (!config.isUsingSystemTheme) {
view.background = ResourcesCompat.getDrawable(context.resources, R.drawable.bottom_sheet_bg, context.theme).apply {
view.root.background = ResourcesCompat.getDrawable(context.resources, R.drawable.bottom_sheet_bg, context.theme).apply {
(this as LayerDrawable).findDrawableByLayerId(R.id.bottom_sheet_background).applyColorFilter(context.getProperBackgroundColor())
}
}
return view
return view.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val title = arguments?.getInt(BOTTOM_SHEET_TITLE).takeIf { it != 0 }
view.apply {
bottom_sheet_title.setTextColor(context.getProperTextColor())
bottom_sheet_title.setTextOrBeGone(title)
setupContentView(bottom_sheet_content_holder)
DialogBottomSheetBinding.bind(view).apply {
bottomSheetTitle.setTextColor(view.context.getProperTextColor())
bottomSheetTitle.setTextOrBeGone(title)
setupContentView(bottomSheetContentHolder)
}
}

View file

@ -1,7 +1,7 @@
package com.simplemobiletools.commons.models
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
import kotlinx.parcelize.Parcelize
@Parcelize
data class SimpleListItem(val id: Int, val textRes: Int, val imageRes: Int? = null, val selected: Boolean = false) : Parcelable {

View file

@ -2,29 +2,30 @@ package com.simplemobiletools.commons.views
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.biometric.auth.AuthPromptHost
import androidx.constraintlayout.widget.ConstraintLayout
import com.simplemobiletools.commons.databinding.TabBiometricIdBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.DARK_GREY
import com.simplemobiletools.commons.interfaces.HashListener
import com.simplemobiletools.commons.interfaces.SecurityTab
import kotlinx.android.synthetic.main.tab_biometric_id.view.*
class BiometricIdTab(context: Context, attrs: AttributeSet) : ConstraintLayout(context, attrs), SecurityTab {
private lateinit var hashListener: HashListener
private lateinit var biometricPromptHost: AuthPromptHost
val binding = TabBiometricIdBinding.inflate(LayoutInflater.from(context), this, true)
override fun onFinishInflate() {
super.onFinishInflate()
context.updateTextColors(biometric_lock_holder)
context.updateTextColors(binding.biometricLockHolder)
val textColor = if (context.isWhiteTheme()) {
DARK_GREY
} else {
context.getProperPrimaryColor().getContrastColor()
}
open_biometric_dialog.setTextColor(textColor)
open_biometric_dialog.setOnClickListener {
binding.openBiometricDialog.setTextColor(textColor)
binding.openBiometricDialog.setOnClickListener {
biometricPromptHost.activity?.showBiometricPrompt(successCallback = hashListener::receivedHash)
}
}
@ -39,7 +40,7 @@ class BiometricIdTab(context: Context, attrs: AttributeSet) : ConstraintLayout(c
this.biometricPromptHost = biometricPromptHost
hashListener = listener
if (showBiometricAuthentication) {
open_biometric_dialog.performClick()
binding.openBiometricDialog.performClick()
}
}

View file

@ -12,9 +12,10 @@ import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.ItemBreadcrumbBinding
import com.simplemobiletools.commons.databinding.ItemBreadcrumbFirstBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.FileDirItem
import kotlinx.android.synthetic.main.item_breadcrumb.view.breadcrumb_text
class Breadcrumbs(context: Context, attrs: AttributeSet) : HorizontalScrollView(context, attrs) {
private val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
@ -171,25 +172,26 @@ class Breadcrumbs(context: Context, attrs: AttributeSet) : HorizontalScrollView(
context.getProperBackgroundColor()
}
inflater.inflate(R.layout.item_breadcrumb_first, itemsLayout, false).apply {
ItemBreadcrumbFirstBinding.inflate(inflater, itemsLayout, false).apply {
resources.apply {
breadcrumb_text.background = ContextCompat.getDrawable(context, R.drawable.button_background)
breadcrumb_text.background.applyColorFilter(textColor)
breadcrumbText.background = ContextCompat.getDrawable(context, R.drawable.button_background)
breadcrumbText.background.applyColorFilter(textColor)
elevation = 1f
background = ColorDrawable(firstItemBgColor)
val medium = getDimension(R.dimen.medium_margin).toInt()
breadcrumb_text.setPadding(medium, medium, medium, medium)
breadcrumbText.setPadding(medium, medium, medium, medium)
setPadding(rootStartPadding, 0, 0, 0)
}
isActivated = item.path.trimEnd('/') == lastPath.trimEnd('/')
breadcrumb_text.text = item.name
breadcrumb_text.setTextColor(textColorStateList)
breadcrumb_text.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
breadcrumbText.text = item.name
breadcrumbText.setTextColor(textColorStateList)
breadcrumbText.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
itemsLayout.addView(this)
itemsLayout.addView(this.root)
breadcrumb_text.setOnClickListener {
breadcrumbText.setOnClickListener {
if (itemsLayout.getChildAt(index) != null) {
listener?.breadcrumbClicked(index)
}
@ -198,7 +200,7 @@ class Breadcrumbs(context: Context, attrs: AttributeSet) : HorizontalScrollView(
tag = item
}
} else {
inflater.inflate(R.layout.item_breadcrumb, itemsLayout, false).apply {
ItemBreadcrumbBinding.inflate(inflater, itemsLayout, false).apply {
var textToAdd = item.name
if (addPrefix) {
textToAdd = "> $textToAdd"
@ -206,11 +208,11 @@ class Breadcrumbs(context: Context, attrs: AttributeSet) : HorizontalScrollView(
isActivated = item.path.trimEnd('/') == lastPath.trimEnd('/')
breadcrumb_text.text = textToAdd
breadcrumb_text.setTextColor(textColorStateList)
breadcrumb_text.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
breadcrumbText.text = textToAdd
breadcrumbText.setTextColor(textColorStateList)
breadcrumbText.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
itemsLayout.addView(this)
itemsLayout.addView(root)
setOnClickListener { v ->
if (itemsLayout.getChildAt(index) != null && itemsLayout.getChildAt(index) == v) {

View file

@ -5,17 +5,18 @@ import android.content.Intent
import android.os.Handler
import android.provider.Settings
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import androidx.biometric.auth.AuthPromptHost
import com.github.ajalt.reprint.core.AuthenticationFailureReason
import com.github.ajalt.reprint.core.AuthenticationListener
import com.github.ajalt.reprint.core.Reprint
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.TabFingerprintBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_FINGERPRINT
import com.simplemobiletools.commons.interfaces.HashListener
import com.simplemobiletools.commons.interfaces.SecurityTab
import kotlinx.android.synthetic.main.tab_fingerprint.view.*
class FingerprintTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs), SecurityTab {
private val RECHECK_PERIOD = 3000L
@ -23,13 +24,15 @@ class FingerprintTab(context: Context, attrs: AttributeSet) : RelativeLayout(con
lateinit var hashListener: HashListener
private val binding = TabFingerprintBinding.inflate(LayoutInflater.from(context), this, true)
override fun onFinishInflate() {
super.onFinishInflate()
val textColor = context.getProperTextColor()
context.updateTextColors(fingerprint_lock_holder)
fingerprint_image.applyColorFilter(textColor)
context.updateTextColors(binding.fingerprintLockHolder)
binding.fingerprintImage.applyColorFilter(textColor)
fingerprint_settings.setOnClickListener {
binding.fingerprintSettings.setOnClickListener {
context.startActivity(Intent(Settings.ACTION_SETTINGS))
}
}
@ -54,8 +57,8 @@ class FingerprintTab(context: Context, attrs: AttributeSet) : RelativeLayout(con
private fun checkRegisteredFingerprints() {
val hasFingerprints = Reprint.hasFingerprintRegistered()
fingerprint_settings.beGoneIf(hasFingerprints)
fingerprint_label.text = context.getString(if (hasFingerprints) R.string.place_finger else R.string.no_fingerprints_registered)
binding.fingerprintSettings.beGoneIf(hasFingerprints)
binding.fingerprintLabel.text = context.getString(if (hasFingerprints) R.string.place_finger else R.string.no_fingerprints_registered)
Reprint.authenticate(object : AuthenticationListener {
override fun onSuccess(moduleTag: Int) {

View file

@ -3,13 +3,14 @@ package com.simplemobiletools.commons.views
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import com.google.android.material.appbar.AppBarLayout
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.MenuSearchBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LOWER_ALPHA
import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA
import kotlinx.android.synthetic.main.menu_search.view.*
class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context, attrs) {
var isSearchOpen = false
@ -19,67 +20,65 @@ class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context
var onSearchTextChangedListener: ((text: String) -> Unit)? = null
var onNavigateBackClickListener: (() -> Unit)? = null
init {
inflate(context, R.layout.menu_search, this)
}
private val binding = MenuSearchBinding.inflate(LayoutInflater.from(context), this, true)
fun getToolbar() = top_toolbar
fun getToolbar() = binding.topToolbar
fun setupMenu() {
top_toolbar_search_icon.setOnClickListener {
binding.topToolbarSearchIcon.setOnClickListener {
if (isSearchOpen) {
closeSearch()
} else if (useArrowIcon && onNavigateBackClickListener != null) {
onNavigateBackClickListener!!()
} else {
top_toolbar_search.requestFocus()
(context as? Activity)?.showKeyboard(top_toolbar_search)
binding.topToolbarSearch.requestFocus()
(context as? Activity)?.showKeyboard(binding.topToolbarSearch)
}
}
post {
top_toolbar_search.setOnFocusChangeListener { v, hasFocus ->
binding.topToolbarSearch.setOnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
openSearch()
}
}
}
top_toolbar_search.onTextChangeListener { text ->
binding.topToolbarSearch.onTextChangeListener { text ->
onSearchTextChangedListener?.invoke(text)
}
}
fun focusView() {
top_toolbar_search.requestFocus()
binding.topToolbarSearch.requestFocus()
}
private fun openSearch() {
isSearchOpen = true
onSearchOpenListener?.invoke()
top_toolbar_search_icon.setImageResource(R.drawable.ic_arrow_left_vector)
top_toolbar_search_icon.contentDescription = resources.getString(R.string.back)
binding.topToolbarSearchIcon.setImageResource(R.drawable.ic_arrow_left_vector)
binding.topToolbarSearchIcon.contentDescription = resources.getString(R.string.back)
}
fun closeSearch() {
isSearchOpen = false
onSearchClosedListener?.invoke()
top_toolbar_search.setText("")
binding.topToolbarSearch.setText("")
if (!useArrowIcon) {
top_toolbar_search_icon.setImageResource(R.drawable.ic_search_vector)
top_toolbar_search_icon.contentDescription = resources.getString(R.string.search)
binding.topToolbarSearchIcon.setImageResource(R.drawable.ic_search_vector)
binding.topToolbarSearchIcon.contentDescription = resources.getString(R.string.search)
}
(context as? Activity)?.hideKeyboard()
}
fun getCurrentQuery() = top_toolbar_search.text.toString()
fun getCurrentQuery() = binding.topToolbarSearch.text.toString()
fun updateHintText(text: String) {
top_toolbar_search.hint = text
binding.topToolbarSearch.hint = text
}
fun toggleHideOnScroll(hideOnScroll: Boolean) {
val params = top_app_bar_layout.layoutParams as LayoutParams
val params = binding.topAppBarLayout.layoutParams as LayoutParams
if (hideOnScroll) {
params.scrollFlags = LayoutParams.SCROLL_FLAG_SCROLL or LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
} else {
@ -95,8 +94,8 @@ class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context
Pair(R.drawable.ic_search_vector, R.string.search)
}
top_toolbar_search_icon.setImageResource(icon)
top_toolbar_search_icon.contentDescription = resources.getString(accessibilityString)
binding.topToolbarSearchIcon.setImageResource(icon)
binding.topToolbarSearchIcon.contentDescription = resources.getString(accessibilityString)
}
fun updateColors() {
@ -104,11 +103,11 @@ class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context
val contrastColor = backgroundColor.getContrastColor()
setBackgroundColor(backgroundColor)
top_app_bar_layout.setBackgroundColor(backgroundColor)
top_toolbar_search_icon.applyColorFilter(contrastColor)
top_toolbar_holder.background?.applyColorFilter(context.getProperPrimaryColor().adjustAlpha(LOWER_ALPHA))
top_toolbar_search.setTextColor(contrastColor)
top_toolbar_search.setHintTextColor(contrastColor.adjustAlpha(MEDIUM_ALPHA))
(context as? BaseSimpleActivity)?.updateTopBarColors(top_toolbar, backgroundColor)
binding.topAppBarLayout.setBackgroundColor(backgroundColor)
binding.topToolbarSearchIcon.applyColorFilter(contrastColor)
binding.topToolbarHolder.background?.applyColorFilter(context.getProperPrimaryColor().adjustAlpha(LOWER_ALPHA))
binding.topToolbarSearch.setTextColor(contrastColor)
binding.topToolbarSearch.setHintTextColor(contrastColor.adjustAlpha(MEDIUM_ALPHA))
(context as? BaseSimpleActivity)?.updateTopBarColors(binding.topToolbar, backgroundColor)
}
}

View file

@ -1,8 +1,10 @@
package com.simplemobiletools.commons.views
import android.annotation.SuppressLint
import android.content.Context
import android.os.Handler
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent
import android.widget.RelativeLayout
import androidx.biometric.auth.AuthPromptHost
@ -10,11 +12,11 @@ import com.andrognito.patternlockview.PatternLockView
import com.andrognito.patternlockview.listener.PatternLockViewListener
import com.andrognito.patternlockview.utils.PatternLockUtils
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.TabPatternBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_PATTERN
import com.simplemobiletools.commons.interfaces.HashListener
import com.simplemobiletools.commons.interfaces.SecurityTab
import kotlinx.android.synthetic.main.tab_pattern.view.*
class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs), SecurityTab {
private var hash = ""
@ -22,12 +24,15 @@ class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context
private var scrollView: MyScrollView? = null
lateinit var hashListener: HashListener
private val binding = TabPatternBinding.inflate(LayoutInflater.from(context), this, false)
@SuppressLint("ClickableViewAccessibility")
override fun onFinishInflate() {
super.onFinishInflate()
val textColor = context.getProperTextColor()
context.updateTextColors(pattern_lock_holder)
context.updateTextColors(binding.patternLockHolder)
pattern_lock_view.setOnTouchListener { v, event ->
binding.patternLockView.setOnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> scrollView?.isScrollable = false
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> scrollView?.isScrollable = true
@ -35,11 +40,11 @@ class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context
false
}
pattern_lock_view.correctStateColor = context.getProperPrimaryColor()
pattern_lock_view.normalStateColor = textColor
pattern_lock_view.addPatternLockListener(object : PatternLockViewListener {
binding.patternLockView.correctStateColor = context.getProperPrimaryColor()
binding.patternLockView.normalStateColor = textColor
binding.patternLockView.addPatternLockListener(object : PatternLockViewListener {
override fun onComplete(pattern: MutableList<PatternLockView.Dot>?) {
receivedHash(PatternLockUtils.patternToSha1(pattern_lock_view, pattern))
receivedHash(PatternLockUtils.patternToSha1(binding.patternLockView, pattern))
}
override fun onCleared() {}
@ -67,23 +72,23 @@ class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context
when {
hash.isEmpty() -> {
hash = newHash
pattern_lock_view.clearPattern()
pattern_lock_title.setText(R.string.repeat_pattern)
binding.patternLockView.clearPattern()
binding.patternLockTitle.setText(R.string.repeat_pattern)
}
hash == newHash -> {
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.CORRECT)
binding.patternLockView.setViewMode(PatternLockView.PatternViewMode.CORRECT)
Handler().postDelayed({
hashListener.receivedHash(hash, PROTECTION_PATTERN)
}, 300)
}
else -> {
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.WRONG)
binding.patternLockView.setViewMode(PatternLockView.PatternViewMode.WRONG)
context.toast(R.string.wrong_pattern)
Handler().postDelayed({
pattern_lock_view.clearPattern()
binding.patternLockView.clearPattern()
if (requiredHash.isEmpty()) {
hash = ""
pattern_lock_title.setText(R.string.insert_pattern)
binding.patternLockTitle.setText(R.string.insert_pattern)
}
}, 1000)
}

View file

@ -2,14 +2,15 @@ package com.simplemobiletools.commons.views
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import androidx.biometric.auth.AuthPromptHost
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.databinding.TabPinBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_PIN
import com.simplemobiletools.commons.interfaces.HashListener
import com.simplemobiletools.commons.interfaces.SecurityTab
import kotlinx.android.synthetic.main.tab_pin.view.*
import java.math.BigInteger
import java.security.MessageDigest
import java.util.*
@ -20,23 +21,25 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
private var pin = ""
lateinit var hashListener: HashListener
private val binding = TabPinBinding.inflate(LayoutInflater.from(context), this, false)
override fun onFinishInflate() {
super.onFinishInflate()
context.updateTextColors(pin_lock_holder)
context.updateTextColors(binding.pinLockHolder)
pin_0.setOnClickListener { addNumber("0") }
pin_1.setOnClickListener { addNumber("1") }
pin_2.setOnClickListener { addNumber("2") }
pin_3.setOnClickListener { addNumber("3") }
pin_4.setOnClickListener { addNumber("4") }
pin_5.setOnClickListener { addNumber("5") }
pin_6.setOnClickListener { addNumber("6") }
pin_7.setOnClickListener { addNumber("7") }
pin_8.setOnClickListener { addNumber("8") }
pin_9.setOnClickListener { addNumber("9") }
pin_c.setOnClickListener { clear() }
pin_ok.setOnClickListener { confirmPIN() }
pin_ok.applyColorFilter(context.getProperTextColor())
binding.pin0.setOnClickListener { addNumber("0") }
binding.pin1.setOnClickListener { addNumber("1") }
binding.pin2.setOnClickListener { addNumber("2") }
binding.pin3.setOnClickListener { addNumber("3") }
binding.pin4.setOnClickListener { addNumber("4") }
binding.pin5.setOnClickListener { addNumber("5") }
binding.pin6.setOnClickListener { addNumber("6") }
binding.pin7.setOnClickListener { addNumber("7") }
binding.pin8.setOnClickListener { addNumber("8") }
binding.pin9.setOnClickListener { addNumber("9") }
binding.pinC.setOnClickListener { clear() }
binding.pinOk.setOnClickListener { confirmPIN() }
binding.pinOk.applyColorFilter(context.getProperTextColor())
}
override fun initTab(
@ -74,7 +77,7 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
} else if (hash.isEmpty()) {
hash = newHash
resetPin()
pin_lock_title.setText(R.string.repeat_pin)
binding.pinLockTitle.setText(R.string.repeat_pin)
} else if (hash == newHash) {
hashListener.receivedHash(hash, PROTECTION_PIN)
} else {
@ -82,7 +85,7 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
context.toast(R.string.wrong_pin)
if (requiredHash.isEmpty()) {
hash = ""
pin_lock_title.setText(R.string.enter_pin)
binding.pinLockTitle.setText(R.string.enter_pin)
}
}
performHapticFeedback()
@ -90,11 +93,11 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
private fun resetPin() {
pin = ""
pin_lock_current_pin.text = ""
binding.pinLockCurrentPin.text = ""
}
private fun updatePinCode() {
pin_lock_current_pin.text = "*".repeat(pin.length)
binding.pinLockCurrentPin.text = "*".repeat(pin.length)
if (hash.isNotEmpty() && hash == getHashedPin()) {
hashListener.receivedHash(hash, PROTECTION_PIN)
}

View file

@ -5,16 +5,17 @@ import android.content.Context
import android.provider.MediaStore
import android.text.format.DateFormat
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import androidx.exifinterface.media.ExifInterface
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.DialogRenameItemsPatternBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.commons.interfaces.RenameTab
import com.simplemobiletools.commons.models.Android30RenameFormat
import com.simplemobiletools.commons.models.FileDirItem
import kotlinx.android.synthetic.main.dialog_rename_items_pattern.view.*
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
@ -28,15 +29,17 @@ class RenamePatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(c
var activity: BaseSimpleActivity? = null
var paths = ArrayList<String>()
private val binding = DialogRenameItemsPatternBinding.inflate(LayoutInflater.from(context), this, false)
override fun onFinishInflate() {
super.onFinishInflate()
context.updateTextColors(rename_items_holder)
context.updateTextColors(binding.renameItemsHolder)
}
override fun initTab(activity: BaseSimpleActivity, paths: ArrayList<String>) {
this.activity = activity
this.paths = paths
rename_items_value.setText(activity.baseConfig.lastRenamePatternUsed)
binding.renameItemsValue.setText(activity.baseConfig.lastRenamePatternUsed)
}
override fun dialogConfirmed(useMediaFileExtension: Boolean, callback: (success: Boolean) -> Unit) {
@ -45,7 +48,7 @@ class RenamePatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(c
return
}
val newNameRaw = rename_items_value.value
val newNameRaw = binding.renameItemsValue.value
if (newNameRaw.isEmpty()) {
callback(false)
return
@ -59,7 +62,7 @@ class RenamePatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(c
return
}
activity?.baseConfig?.lastRenamePatternUsed = rename_items_value.value
activity?.baseConfig?.lastRenamePatternUsed = binding.renameItemsValue.value
activity?.handleSAFDialog(sdFilePath) {
if (!it) {
return@handleSAFDialog
@ -132,7 +135,7 @@ class RenamePatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(c
val minutes = (cal.get(Calendar.MINUTE)).ensureTwoDigits()
val seconds = (cal.get(Calendar.SECOND)).ensureTwoDigits()
var newName = rename_items_value.value
var newName = binding.renameItemsValue.value
.replace("%Y", year, false)
.replace("%M", month, false)
.replace("%D", day, false)

View file

@ -4,14 +4,15 @@ import android.content.ContentValues
import android.content.Context
import android.provider.MediaStore
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.databinding.TabRenameSimpleBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.interfaces.RenameTab
import com.simplemobiletools.commons.models.Android30RenameFormat
import com.simplemobiletools.commons.models.FileDirItem
import kotlinx.android.synthetic.main.tab_rename_simple.view.*
import java.io.File
class RenameSimpleTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs), RenameTab {
@ -20,9 +21,11 @@ class RenameSimpleTab(context: Context, attrs: AttributeSet) : RelativeLayout(co
var activity: BaseSimpleActivity? = null
var paths = ArrayList<String>()
private val binding = TabRenameSimpleBinding.inflate(LayoutInflater.from(context), this, true)
override fun onFinishInflate() {
super.onFinishInflate()
context.updateTextColors(rename_simple_holder)
context.updateTextColors(binding.renameSimpleHolder)
}
override fun initTab(activity: BaseSimpleActivity, paths: ArrayList<String>) {
@ -32,8 +35,8 @@ class RenameSimpleTab(context: Context, attrs: AttributeSet) : RelativeLayout(co
override fun dialogConfirmed(useMediaFileExtension: Boolean, callback: (success: Boolean) -> Unit) {
stopLooping = false
val valueToAdd = rename_simple_value.text.toString()
val append = rename_simple_radio_group.checkedRadioButtonId == rename_simple_radio_append.id
val valueToAdd = binding.renameSimpleValue.text.toString()
val append = binding.renameSimpleRadioGroup.checkedRadioButtonId == binding.renameSimpleRadioAppend.id
if (valueToAdd.isEmpty()) {
callback(false)

View file

@ -1,8 +1,5 @@
[versions]
#jetbrains
ezVcard = "0.11.3"
gson = "2.10.1"
jodaTime = "2.12.4"
kotlin = "1.9.0"
#KSP
kotlinxSerializationJson = "1.5.1"
@ -38,8 +35,12 @@ accompanist = "0.31.5-beta"
glide = "4.15.1"
#Room
room = "2.5.2"
#Publish
androidMavenGradlePlugin = "2.1"
#ezVcard
ezVcard = "0.11.3"
#gson
gson = "2.10.1"
#jodaTime
jodaTime = "2.12.4"
#Gradle
gradlePlugins-agp = "8.0.1"
#build

View file

@ -14,7 +14,6 @@ android {
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
isMinifyEnabled = true
@ -25,6 +24,20 @@ android {
}
}
compileOptions {
val currentJavaVersionFromLibs = JavaVersion.valueOf(libs.versions.app.build.javaVersion.get().toString())
sourceCompatibility = currentJavaVersionFromLibs
targetCompatibility = currentJavaVersionFromLibs
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get()
kotlinOptions.freeCompilerArgs = listOf(
"-opt-in=kotlin.RequiresOptIn",
"-Xcontext-receivers"
)
}
buildFeatures {
buildConfig = true
viewBinding = true