forked from upstream-mirrors/quik
Revert "Implement ViewBinding"
This reverts commit 37d8c45379.
# Conflicts:
# build.gradle
# presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt
# presentation/src/main/java/com/moez/QKSMS/common/widget/TextInputDialog.kt
# presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt
# presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt
# presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt
# presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt
# presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt
# presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsController.kt
This commit is contained in:
@@ -20,17 +20,17 @@ package com.moez.QKSMS.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.viewBinding
|
||||
import com.moez.QKSMS.databinding.AvatarViewBinding
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.avatar_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class AvatarView @JvmOverloads constructor(
|
||||
@@ -39,21 +39,21 @@ class AvatarView @JvmOverloads constructor(
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var navigator: Navigator
|
||||
private lateinit var theme: Colors.Theme
|
||||
|
||||
private val binding = viewBinding(AvatarViewBinding::inflate)
|
||||
|
||||
private var lookupKey: String? = null
|
||||
private var fullName: String? = null
|
||||
private var photoUri: String? = null
|
||||
private var lastUpdated: Long? = null
|
||||
private var theme: Colors.Theme
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
theme = colors.theme()
|
||||
}
|
||||
|
||||
theme = colors.theme()
|
||||
|
||||
View.inflate(context, R.layout.avatar_view, this)
|
||||
setBackgroundResource(R.drawable.circle)
|
||||
clipToOutline = true
|
||||
}
|
||||
@@ -81,8 +81,8 @@ class AvatarView @JvmOverloads constructor(
|
||||
private fun updateView() {
|
||||
// Apply theme
|
||||
setBackgroundTint(theme.theme)
|
||||
binding.initial.setTextColor(theme.textPrimary)
|
||||
binding.icon.setTint(theme.textPrimary)
|
||||
initial.setTextColor(theme.textPrimary)
|
||||
icon.setTint(theme.textPrimary)
|
||||
|
||||
val initials = fullName
|
||||
?.substringBefore(',')
|
||||
@@ -93,18 +93,18 @@ class AvatarView @JvmOverloads constructor(
|
||||
.map { initial -> initial.toString() }
|
||||
|
||||
if (initials.isNotEmpty()) {
|
||||
binding.initial.text = if (initials.size > 1) initials.first() + initials.last() else initials.first()
|
||||
binding.icon.visibility = GONE
|
||||
initial.text = if (initials.size > 1) initials.first() + initials.last() else initials.first()
|
||||
icon.visibility = GONE
|
||||
} else {
|
||||
binding.initial.text = null
|
||||
binding.icon.visibility = VISIBLE
|
||||
initial.text = null
|
||||
icon.visibility = VISIBLE
|
||||
}
|
||||
|
||||
binding.photo.setImageDrawable(null)
|
||||
photo.setImageDrawable(null)
|
||||
photoUri?.let { photoUri ->
|
||||
GlideApp.with(binding.photo)
|
||||
GlideApp.with(photo)
|
||||
.load(photoUri)
|
||||
.into(binding.photo)
|
||||
.into(photo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,16 @@ package com.moez.QKSMS.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.extensions.getColorCompat
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.viewBinding
|
||||
import com.moez.QKSMS.databinding.GroupAvatarViewBinding
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import kotlinx.android.synthetic.main.group_avatar_view.view.*
|
||||
|
||||
class GroupAvatarView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null
|
||||
@@ -40,7 +41,9 @@ class GroupAvatarView @JvmOverloads constructor(
|
||||
updateView()
|
||||
}
|
||||
|
||||
private val binding = viewBinding(GroupAvatarViewBinding::inflate)
|
||||
init {
|
||||
View.inflate(context, R.layout.group_avatar_view, this)
|
||||
}
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
@@ -51,18 +54,18 @@ class GroupAvatarView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
binding.avatar1Frame.setBackgroundTint(when (recipients.size > 1) {
|
||||
avatar1Frame.setBackgroundTint(when (recipients.size > 1) {
|
||||
true -> context.resolveThemeColor(android.R.attr.windowBackground)
|
||||
false -> context.getColorCompat(android.R.color.transparent)
|
||||
})
|
||||
binding.avatar1Frame.updateLayoutParams<LayoutParams> {
|
||||
avatar1Frame.updateLayoutParams<LayoutParams> {
|
||||
matchConstraintPercentWidth = if (recipients.size > 1) 0.75f else 1.0f
|
||||
}
|
||||
binding.avatar2.isVisible = recipients.size > 1
|
||||
avatar2.isVisible = recipients.size > 1
|
||||
|
||||
|
||||
recipients.getOrNull(0).run(binding.avatar1::setRecipient)
|
||||
recipients.getOrNull(1).run(binding.avatar2::setRecipient)
|
||||
recipients.getOrNull(0).run(avatar1::setRecipient)
|
||||
recipients.getOrNull(1).run(avatar2::setRecipient)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.forEach
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.databinding.TabViewBinding
|
||||
import com.moez.QKSMS.extensions.Optional
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
@@ -36,6 +36,7 @@ import com.uber.autodispose.android.ViewScopeProvider
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.tab_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PagerTitleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
||||
@@ -65,11 +66,11 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
removeAllViews()
|
||||
|
||||
pager?.adapter?.count?.forEach { position ->
|
||||
val binding = TabViewBinding.inflate(LayoutInflater.from(context), this, false)
|
||||
binding.label.text = pager?.adapter?.getPageTitle(position)
|
||||
binding.root.setOnClickListener { pager?.currentItem = position }
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.tab_view, this, false)
|
||||
view.label.text = pager?.adapter?.getPageTitle(position)
|
||||
view.setOnClickListener { pager?.currentItem = position }
|
||||
|
||||
addView(binding.root)
|
||||
addView(view)
|
||||
}
|
||||
|
||||
childCount.forEach { index ->
|
||||
|
||||
@@ -28,9 +28,8 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColorStateList
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.util.extensions.viewBinding
|
||||
import com.moez.QKSMS.databinding.PreferenceViewBinding
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import kotlinx.android.synthetic.main.preference_view.view.*
|
||||
|
||||
class PreferenceView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null
|
||||
@@ -43,7 +42,7 @@ class PreferenceView @JvmOverloads constructor(
|
||||
if (isInEditMode) {
|
||||
findViewById<TextView>(R.id.titleView).text = value
|
||||
} else {
|
||||
binding.titleView.text = value
|
||||
titleView.text = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,23 +57,22 @@ class PreferenceView @JvmOverloads constructor(
|
||||
setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
} else {
|
||||
binding.summaryView.text = value
|
||||
binding.summaryView.setVisible(value?.isNotEmpty() == true)
|
||||
summaryView.text = value
|
||||
summaryView.setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
}
|
||||
|
||||
val binding: PreferenceViewBinding = viewBinding(PreferenceViewBinding::inflate)
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
View.inflate(context, R.layout.preference_view, this)
|
||||
setBackgroundResource(context.resolveThemeAttribute(R.attr.selectableItemBackground))
|
||||
orientation = HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
|
||||
binding.icon.imageTintList = context.resolveThemeColorStateList(android.R.attr.textColorSecondary)
|
||||
icon.imageTintList = context.resolveThemeColorStateList(android.R.attr.textColorSecondary)
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.PreferenceView).run {
|
||||
title = getString(R.styleable.PreferenceView_title)
|
||||
@@ -82,21 +80,17 @@ class PreferenceView @JvmOverloads constructor(
|
||||
|
||||
// If there's a custom view used for the preference's widget, inflate it
|
||||
getResourceId(R.styleable.PreferenceView_widget, -1).takeIf { it != -1 }?.let { id ->
|
||||
View.inflate(context, id, binding.widgetFrame)
|
||||
View.inflate(context, id, widgetFrame)
|
||||
}
|
||||
|
||||
// If an icon is being used, set up the icon view
|
||||
getResourceId(R.styleable.PreferenceView_icon, -1).takeIf { it != -1 }?.let { id ->
|
||||
binding.icon.setVisible(true)
|
||||
binding.icon.setImageResource(id)
|
||||
icon.setVisible(true)
|
||||
icon.setImageResource(id)
|
||||
}
|
||||
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : View> widget(): T {
|
||||
return binding.widgetFrame.getChildAt(0) as T
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,15 +19,17 @@
|
||||
package com.moez.QKSMS.common.widget
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.LayoutInflater
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.databinding.QkDialogBinding
|
||||
import kotlinx.android.synthetic.main.qk_dialog.view.*
|
||||
|
||||
class QkDialog(private val context: Activity) : AlertDialog(context) {
|
||||
|
||||
private val binding = QkDialogBinding.inflate(context.layoutInflater)
|
||||
private val view = LayoutInflater.from(context).inflate(R.layout.qk_dialog, null)
|
||||
|
||||
@StringRes
|
||||
var titleRes: Int? = null
|
||||
@@ -39,8 +41,8 @@ class QkDialog(private val context: Activity) : AlertDialog(context) {
|
||||
var title: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
binding.title.text = value
|
||||
binding.title.isVisible = !value.isNullOrBlank()
|
||||
view.title.text = value
|
||||
view.title.isVisible = !value.isNullOrBlank()
|
||||
}
|
||||
|
||||
@StringRes
|
||||
@@ -53,15 +55,15 @@ class QkDialog(private val context: Activity) : AlertDialog(context) {
|
||||
var subtitle: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
binding.subtitle.text = value
|
||||
binding.subtitle.isVisible = !value.isNullOrBlank()
|
||||
view.subtitle.text = value
|
||||
view.subtitle.isVisible = !value.isNullOrBlank()
|
||||
}
|
||||
|
||||
var adapter: QkAdapter<*, *>? = null
|
||||
var adapter: QkAdapter<*>? = null
|
||||
set(value) {
|
||||
field = value
|
||||
binding.list.isVisible = value != null
|
||||
binding.list.adapter = value
|
||||
view.list.isVisible = value != null
|
||||
view.list.adapter = value
|
||||
}
|
||||
|
||||
var positiveButtonListener: (() -> Unit)? = null
|
||||
@@ -70,9 +72,9 @@ class QkDialog(private val context: Activity) : AlertDialog(context) {
|
||||
var positiveButton: Int? = null
|
||||
set(value) {
|
||||
field = value
|
||||
value?.run(binding.positiveButton::setText)
|
||||
binding.positiveButton.isVisible = value != null
|
||||
binding.positiveButton.setOnClickListener {
|
||||
value?.run(view.positiveButton::setText)
|
||||
view.positiveButton.isVisible = value != null
|
||||
view.positiveButton.setOnClickListener {
|
||||
positiveButtonListener?.invoke() ?: dismiss()
|
||||
}
|
||||
}
|
||||
@@ -83,9 +85,9 @@ class QkDialog(private val context: Activity) : AlertDialog(context) {
|
||||
var negativeButton: Int? = null
|
||||
set(value) {
|
||||
field = value
|
||||
value?.run(binding.negativeButton::setText)
|
||||
binding.negativeButton.isVisible = value != null
|
||||
binding.negativeButton.setOnClickListener {
|
||||
value?.run(view.negativeButton::setText)
|
||||
view.negativeButton.isVisible = value != null
|
||||
view.negativeButton.setOnClickListener {
|
||||
negativeButtonListener?.invoke() ?: dismiss()
|
||||
}
|
||||
}
|
||||
@@ -97,7 +99,7 @@ class QkDialog(private val context: Activity) : AlertDialog(context) {
|
||||
}
|
||||
|
||||
init {
|
||||
setView(binding.root)
|
||||
setView(view)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,8 @@ import com.moez.QKSMS.common.util.extensions.forwardTouches
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.util.extensions.viewBinding
|
||||
import com.moez.QKSMS.databinding.RadioPreferenceViewBinding
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import kotlinx.android.synthetic.main.radio_preference_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class RadioPreferenceView @JvmOverloads constructor(
|
||||
@@ -48,7 +47,7 @@ class RadioPreferenceView @JvmOverloads constructor(
|
||||
if (isInEditMode) {
|
||||
findViewById<TextView>(R.id.titleView).text = value
|
||||
} else {
|
||||
binding.titleView.text = value
|
||||
titleView.text = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,18 +62,17 @@ class RadioPreferenceView @JvmOverloads constructor(
|
||||
setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
} else {
|
||||
binding.summaryView.text = value
|
||||
binding.summaryView.setVisible(value?.isNotEmpty() == true)
|
||||
summaryView.text = value
|
||||
summaryView.setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
}
|
||||
|
||||
val binding: RadioPreferenceViewBinding = viewBinding(RadioPreferenceViewBinding::inflate)
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
View.inflate(context, R.layout.radio_preference_view, this)
|
||||
setBackgroundResource(context.resolveThemeAttribute(R.attr.selectableItemBackground))
|
||||
|
||||
val states = arrayOf(
|
||||
@@ -86,8 +84,8 @@ class RadioPreferenceView @JvmOverloads constructor(
|
||||
false -> colors.theme().theme
|
||||
}
|
||||
val textSecondary = context.resolveThemeColor(android.R.attr.textColorTertiary)
|
||||
binding.radioButton.buttonTintList = ColorStateList(states, intArrayOf(themeColor, textSecondary))
|
||||
binding.radioButton.forwardTouches(this)
|
||||
radioButton.buttonTintList = ColorStateList(states, intArrayOf(themeColor, textSecondary))
|
||||
radioButton.forwardTouches(this)
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.RadioPreferenceView)?.run {
|
||||
title = getString(R.styleable.RadioPreferenceView_title)
|
||||
@@ -95,11 +93,11 @@ class RadioPreferenceView @JvmOverloads constructor(
|
||||
|
||||
// If there's a custom view used for the preference's widget, inflate it
|
||||
getResourceId(R.styleable.RadioPreferenceView_widget, -1).takeIf { it != -1 }?.let { id ->
|
||||
View.inflate(context, id, binding.widgetFrame)
|
||||
View.inflate(context, id, widgetFrame)
|
||||
}
|
||||
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,27 +20,28 @@ package com.moez.QKSMS.common.widget
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.view.LayoutInflater
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.databinding.TextInputDialogBinding
|
||||
import kotlinx.android.synthetic.main.text_input_dialog.view.*
|
||||
|
||||
class TextInputDialog(context: Activity, hint: String, listener: (String) -> Unit) : AlertDialog(context) {
|
||||
|
||||
private val binding = TextInputDialogBinding.inflate(context.layoutInflater)
|
||||
private val layout = LayoutInflater.from(context).inflate(R.layout.text_input_dialog, null)
|
||||
|
||||
init {
|
||||
binding.field.hint = hint
|
||||
layout.field.hint = hint
|
||||
|
||||
setView(binding.root)
|
||||
setView(layout)
|
||||
setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.button_cancel)) { _, _ -> }
|
||||
setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.button_delete)) { _, _ -> listener("") }
|
||||
setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.button_save)) { _, _ ->
|
||||
listener(binding.field.text.toString())
|
||||
listener(layout.field.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
fun setText(text: String): TextInputDialog {
|
||||
binding.field.setText(text)
|
||||
layout.field.setText(text)
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user