mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
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,26 +20,26 @@ package com.moez.QKSMS.common
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.ArrayRes
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.databinding.MenuListItemBinding
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.menu_list_item.*
|
||||
import kotlinx.android.synthetic.main.menu_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
data class MenuItem(val title: String, val actionId: Int)
|
||||
|
||||
class MenuItemAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors
|
||||
) : QkAdapter<MenuItem, MenuListItemBinding>() {
|
||||
class MenuItemAdapter @Inject constructor(private val context: Context, private val colors: Colors) : QkAdapter<MenuItem>() {
|
||||
|
||||
val menuItemClicks: Subject<Int> = PublishSubject.create()
|
||||
|
||||
@@ -47,13 +47,13 @@ class MenuItemAdapter @Inject constructor(
|
||||
|
||||
var selectedItem: Int? = null
|
||||
set(value) {
|
||||
val old = data.map { it.actionId }.indexOfFirst { it == field }.takeIf { it != -1 }
|
||||
val new = data.map { it.actionId }.indexOfFirst { it == value }.takeIf { it != -1 }
|
||||
val old = data.map { it.actionId }.indexOfFirst { it == field }
|
||||
val new = data.map { it.actionId }.indexOfFirst { it == value }
|
||||
|
||||
field = value
|
||||
|
||||
old?.let(::notifyItemChanged)
|
||||
new?.let(::notifyItemChanged)
|
||||
old.let { notifyItemChanged(it) }
|
||||
new.let { notifyItemChanged(it) }
|
||||
}
|
||||
|
||||
fun setData(@ArrayRes titles: Int, @ArrayRes values: Int = -1) {
|
||||
@@ -63,28 +63,31 @@ class MenuItemAdapter @Inject constructor(
|
||||
.mapIndexed { index, title -> MenuItem(title, valueInts?.getOrNull(index) ?: index) }
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<MenuListItemBinding> {
|
||||
return QkViewHolder(parent, MenuListItemBinding::inflate).apply {
|
||||
val states = arrayOf(
|
||||
intArrayOf(android.R.attr.state_activated),
|
||||
intArrayOf(-android.R.attr.state_activated))
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val view = layoutInflater.inflate(R.layout.menu_list_item, parent, false)
|
||||
|
||||
val text = parent.context.resolveThemeColor(android.R.attr.textColorTertiary)
|
||||
binding.check.imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, text))
|
||||
val states = arrayOf(
|
||||
intArrayOf(android.R.attr.state_activated),
|
||||
intArrayOf(-android.R.attr.state_activated))
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
val text = parent.context.resolveThemeColor(android.R.attr.textColorTertiary)
|
||||
view.check.imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, text))
|
||||
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val menuItem = getItem(adapterPosition)
|
||||
menuItemClicks.onNext(menuItem.actionId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<MenuListItemBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val menuItem = getItem(position)
|
||||
|
||||
holder.binding.title.text = menuItem.title
|
||||
holder.binding.check.isActivated = (menuItem.actionId == selectedItem)
|
||||
holder.binding.check.setVisible(selectedItem != null)
|
||||
holder.title.text = menuItem.title
|
||||
holder.check.isActivated = (menuItem.actionId == selectedItem)
|
||||
holder.check.setVisible(selectedItem != null)
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||
|
||||
@@ -20,7 +20,6 @@ package com.moez.QKSMS.common.base
|
||||
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
||||
@@ -28,7 +27,7 @@ import io.reactivex.disposables.Disposable
|
||||
* Base RecyclerView.Adapter that provides some convenience when creating a new Adapter, such as
|
||||
* data list handing and item animations
|
||||
*/
|
||||
abstract class FlowableAdapter<T, Binding: ViewBinding> : QkAdapter<T, Binding>() {
|
||||
abstract class FlowableAdapter<T> : QkAdapter<T>() {
|
||||
|
||||
var flowable: Flowable<List<T>>? = null
|
||||
set(value) {
|
||||
|
||||
@@ -22,20 +22,14 @@ import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.widget.QkTextView
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.toolbar.*
|
||||
|
||||
abstract class QkActivity : AppCompatActivity() {
|
||||
|
||||
val toolbar by lazy { findViewById<Toolbar>(R.id.toolbar)!! }
|
||||
|
||||
protected val menu: Subject<Menu> = BehaviorSubject.create()
|
||||
protected val toolbarTitle by lazy { findViewById<QkTextView>(R.id.toolbarTitle) }
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -53,8 +47,8 @@ abstract class QkActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun setContentView(view: View?) {
|
||||
super.setContentView(view)
|
||||
override fun setContentView(layoutResID: Int) {
|
||||
super.setContentView(layoutResID)
|
||||
setSupportActionBar(toolbar)
|
||||
title = title // The title may have been set before layout inflation
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
@@ -31,7 +30,7 @@ import io.reactivex.subjects.Subject
|
||||
* Base RecyclerView.Adapter that provides some convenience when creating a new Adapter, such as
|
||||
* data list handing and item animations
|
||||
*/
|
||||
abstract class QkAdapter<T, Binding: ViewBinding> : RecyclerView.Adapter<QkViewHolder<Binding>>() {
|
||||
abstract class QkAdapter<T> : RecyclerView.Adapter<QkViewHolder>() {
|
||||
|
||||
var data: List<T> = ArrayList()
|
||||
set(value) {
|
||||
|
||||
@@ -21,17 +21,15 @@ package com.moez.QKSMS.common.base
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.bluelinelabs.conductor.archlifecycle.LifecycleController
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.widget.QkTextView
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.*
|
||||
import kotlinx.android.synthetic.main.toolbar.view.*
|
||||
|
||||
abstract class QkController<ViewContract : QkViewContract<State>, State, Presenter : QkPresenter<ViewContract, State>, Binding : ViewBinding>(
|
||||
private val bindingInflater: (LayoutInflater, ViewGroup, Boolean) -> Binding
|
||||
) : LifecycleController() {
|
||||
abstract class QkController<ViewContract : QkViewContract<State>, State, Presenter : QkPresenter<ViewContract, State>> : LifecycleController(), LayoutContainer {
|
||||
|
||||
abstract var presenter: Presenter
|
||||
|
||||
@@ -41,15 +39,16 @@ abstract class QkController<ViewContract : QkViewContract<State>, State, Present
|
||||
protected val themedActivity: QkThemedActivity?
|
||||
get() = activity as? QkThemedActivity
|
||||
|
||||
private val toolbar by lazy { view?.findViewById<Toolbar>(R.id.toolbar) }
|
||||
private val toolbarTitle by lazy { view?.findViewById<QkTextView>(R.id.toolbarTitle) }
|
||||
override var containerView: View? = null
|
||||
|
||||
lateinit var binding: Binding
|
||||
@LayoutRes
|
||||
var layoutRes: Int = 0
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
binding = bindingInflater(inflater, container, false)
|
||||
onViewCreated()
|
||||
return binding.root
|
||||
return inflater.inflate(layoutRes, container, false).also {
|
||||
containerView = it
|
||||
onViewCreated()
|
||||
}
|
||||
}
|
||||
|
||||
open fun onViewCreated() {
|
||||
@@ -61,13 +60,18 @@ abstract class QkController<ViewContract : QkViewContract<State>, State, Present
|
||||
|
||||
fun setTitle(title: CharSequence?) {
|
||||
activity?.title = title
|
||||
toolbarTitle?.text = title
|
||||
view?.toolbarTitle?.text = title
|
||||
}
|
||||
|
||||
fun showBackButton(show: Boolean) {
|
||||
appCompatActivity?.supportActionBar?.setDisplayHomeAsUpEnabled(show)
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
containerView = null
|
||||
clearFindViewByIdCache()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
presenter.onCleared()
|
||||
|
||||
@@ -20,7 +20,6 @@ package com.moez.QKSMS.common.base
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
@@ -31,8 +30,7 @@ import io.realm.RealmRecyclerViewAdapter
|
||||
import io.realm.RealmResults
|
||||
import timber.log.Timber
|
||||
|
||||
abstract class QkRealmAdapter<T : RealmModel, Binding : ViewBinding>
|
||||
: RealmRecyclerViewAdapter<T, QkViewHolder<Binding>>(null, true) {
|
||||
abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkViewHolder>(null, true) {
|
||||
|
||||
/**
|
||||
* This view can be set, and the adapter will automatically control the visibility of this view
|
||||
|
||||
@@ -44,6 +44,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.toolbar.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -133,7 +134,7 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
|
||||
// Set the color for the overflow and navigation icon
|
||||
val textSecondary = resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
toolbar.overflowIcon = toolbar.overflowIcon?.apply { setTint(textSecondary) }
|
||||
toolbar?.overflowIcon = toolbar?.overflowIcon?.apply { setTint(textSecondary) }
|
||||
|
||||
// Update the colours of the menu items
|
||||
Observables.combineLatest(menu, theme) { menu, theme ->
|
||||
|
||||
@@ -18,16 +18,10 @@
|
||||
*/
|
||||
package com.moez.QKSMS.common.base
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
class QkViewHolder<T : ViewBinding>(val binding: T) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
constructor(
|
||||
parent: ViewGroup,
|
||||
bindingInflator: (LayoutInflater, ViewGroup, Boolean) -> T
|
||||
) : this(bindingInflator(LayoutInflater.from(parent.context), parent, false))
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
|
||||
class QkViewHolder(view: View) : RecyclerView.ViewHolder(view), LayoutContainer {
|
||||
override val containerView: View = view
|
||||
}
|
||||
|
||||
@@ -20,10 +20,7 @@ package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
fun Activity.dismissKeyboard() {
|
||||
window.currentFocus?.let { focus ->
|
||||
@@ -33,9 +30,3 @@ fun Activity.dismissKeyboard() {
|
||||
focus.clearFocus()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T : ViewBinding> AppCompatActivity.viewBinding(
|
||||
crossinline bindingInflater: (LayoutInflater) -> T
|
||||
): Lazy<T> = lazy(LazyThreadSafetyMode.NONE) {
|
||||
bindingInflater(layoutInflater)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -32,7 +31,6 @@ import android.widget.EditText
|
||||
import android.widget.ImageView
|
||||
import android.widget.ProgressBar
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
|
||||
var ViewGroup.animateLayoutChanges: Boolean
|
||||
@@ -125,7 +123,3 @@ fun RecyclerView.scrapViews() {
|
||||
recycledViewPool.clear()
|
||||
adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inline fun <T : ViewBinding> ViewGroup.viewBinding(crossinline bindingInflater: (LayoutInflater, ViewGroup) -> T): T {
|
||||
return bindingInflater(LayoutInflater.from(context), this)
|
||||
}
|
||||
|
||||
@@ -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