Implement ViewBinding

This commit is contained in:
Moez Bhatti
2020-03-13 22:47:55 -04:00
parent 582a823876
commit 37d8c45379
77 changed files with 1212 additions and 1201 deletions
@@ -36,11 +36,12 @@ import com.moez.QKSMS.common.util.extensions.autoScrollToStart
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.common.util.extensions.viewBinding
import com.moez.QKSMS.databinding.QkreplyActivityBinding
import com.moez.QKSMS.feature.compose.MessagesAdapter
import dagger.android.AndroidInjection
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.qkreply_activity.*
import javax.inject.Inject
class QkReplyActivity : QkThemedActivity(), QkReplyView {
@@ -49,10 +50,11 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
override val menuItemIntent: Subject<Int> = PublishSubject.create()
override val textChangedIntent by lazy { message.textChanges() }
override val changeSimIntent by lazy { sim.clicks() }
override val sendIntent by lazy { send.clicks() }
override val textChangedIntent by lazy { binding.message.textChanges() }
override val changeSimIntent by lazy { binding.sim.clicks() }
override val sendIntent by lazy { binding.send.clicks() }
private val binding by viewBinding(QkreplyActivityBinding::inflate)
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[QkReplyViewModel::class.java] }
override fun onCreate(savedInstanceState: Bundle?) {
@@ -61,27 +63,27 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
super.onCreate(savedInstanceState)
setFinishOnTouchOutside(prefs.qkreplyTapDismiss.get())
setContentView(R.layout.qkreply_activity)
setContentView(binding.root)
window.setBackgroundDrawable(null)
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewModel.bindView(this)
toolbar.clipToOutline = true
binding.toolbar.clipToOutline = true
messages.adapter = adapter
messages.adapter?.autoScrollToStart(messages)
messages.adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() = messages.scrollToPosition(adapter.itemCount - 1)
binding.messages.adapter = adapter
binding.messages.adapter?.autoScrollToStart(binding.messages)
binding.messages.adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() = binding.messages.scrollToPosition(adapter.itemCount - 1)
})
// These theme attributes don't apply themselves on API 21
if (Build.VERSION.SDK_INT <= 22) {
toolbar.setBackgroundTint(resolveThemeColor(R.attr.colorPrimary))
background.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
messageBackground.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
composeBackgroundGradient.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
composeBackgroundSolid.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
binding.toolbar.setBackgroundTint(resolveThemeColor(R.attr.colorPrimary))
binding.background.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
binding.messageBackground.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
binding.composeBackgroundGradient.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
binding.composeBackgroundSolid.setBackgroundTint(resolveThemeColor(android.R.attr.windowBackground))
}
}
@@ -94,24 +96,24 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
title = state.title
toolbar.menu.findItem(R.id.expand)?.isVisible = !state.expanded
toolbar.menu.findItem(R.id.collapse)?.isVisible = state.expanded
binding.toolbar.menu.findItem(R.id.expand)?.isVisible = !state.expanded
binding.toolbar.menu.findItem(R.id.collapse)?.isVisible = state.expanded
adapter.data = state.data
counter.text = state.remaining
counter.setVisible(counter.text.isNotBlank())
binding.counter.text = state.remaining
binding.counter.setVisible(binding.counter.text.isNotBlank())
sim.setVisible(state.subscription != null)
sim.contentDescription = getString(R.string.compose_sim_cd, state.subscription?.displayName)
simIndex.text = "${state.subscription?.simSlotIndex?.plus(1)}"
binding.sim.setVisible(state.subscription != null)
binding.sim.contentDescription = getString(R.string.compose_sim_cd, state.subscription?.displayName)
binding.simIndex.text = "${state.subscription?.simSlotIndex?.plus(1)}"
send.isEnabled = state.canSend
send.imageAlpha = if (state.canSend) 255 else 128
binding.send.isEnabled = state.canSend
binding.send.imageAlpha = if (state.canSend) 255 else 128
}
override fun setDraft(draft: String) {
message.setText(draft)
binding.message.setText(draft)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {