Skip to content

Commit

Permalink
migrate everything to view binding
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyMuse committed Jul 26, 2023
1 parent 8104f93 commit ccce65d
Show file tree
Hide file tree
Showing 54 changed files with 575 additions and 545 deletions.
7 changes: 7 additions & 0 deletions commons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kapt)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.parcelize)
`maven-publish`
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ 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)
}
}

activity.getAlertDialogBuilder()
.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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,57 @@ 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) {
if (value == null) {
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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
}

Expand Down
Loading

0 comments on commit ccce65d

Please sign in to comment.