forked from upstream-mirrors/quik
Implement ViewBinding
This commit is contained in:
@@ -22,21 +22,22 @@ import android.os.Bundle
|
||||
import com.bluelinelabs.conductor.Conductor
|
||||
import com.bluelinelabs.conductor.Router
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkThemedActivity
|
||||
import com.moez.QKSMS.common.util.extensions.viewBinding
|
||||
import com.moez.QKSMS.databinding.ContainerActivityBinding
|
||||
import dagger.android.AndroidInjection
|
||||
import kotlinx.android.synthetic.main.container_activity.*
|
||||
|
||||
class SettingsActivity : QkThemedActivity() {
|
||||
|
||||
private val binding by viewBinding(ContainerActivityBinding::inflate)
|
||||
private lateinit var router: Router
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.container_activity)
|
||||
setContentView(binding.root)
|
||||
|
||||
router = Conductor.attachRouter(this, container, savedInstanceState)
|
||||
router = Conductor.attachRouter(this, binding.container, savedInstanceState)
|
||||
if (!router.hasRootController()) {
|
||||
router.setRoot(RouterTransaction.with(SettingsController()))
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.widget.FieldDialog
|
||||
import com.moez.QKSMS.common.widget.PreferenceView
|
||||
import com.moez.QKSMS.common.widget.QkSwitch
|
||||
import com.moez.QKSMS.databinding.SettingsControllerBinding
|
||||
import com.moez.QKSMS.feature.settings.about.AboutController
|
||||
import com.moez.QKSMS.feature.settings.swipe.SwipeActionsController
|
||||
import com.moez.QKSMS.feature.themepicker.ThemePickerController
|
||||
@@ -52,13 +54,11 @@ import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.settings_controller.*
|
||||
import kotlinx.android.synthetic.main.settings_controller.view.*
|
||||
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
|
||||
import kotlinx.android.synthetic.main.settings_theme_widget.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class SettingsController : QkController<SettingsView, SettingsState, SettingsPresenter>(), SettingsView {
|
||||
class SettingsController : QkController<SettingsView, SettingsState, SettingsPresenter, SettingsControllerBinding>(
|
||||
SettingsControllerBinding::inflate
|
||||
), SettingsView {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var colors: Colors
|
||||
@@ -78,12 +78,11 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
private val endTimeSelectedSubject: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||
private val signatureSubject: Subject<String> = PublishSubject.create()
|
||||
|
||||
private val progressAnimator by lazy { ObjectAnimator.ofInt(syncingProgress, "progress", 0, 0) }
|
||||
private val progressAnimator by lazy { ObjectAnimator.ofInt(binding.syncingProgress, "progress", 0, 0) }
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
retainViewMode = RetainViewMode.RETAIN_DETACH
|
||||
layoutRes = R.layout.settings_controller
|
||||
|
||||
colors.themeObservable()
|
||||
.autoDisposable(scope())
|
||||
@@ -91,7 +90,7 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
}
|
||||
|
||||
override fun onViewCreated() {
|
||||
preferences.postDelayed({ preferences?.animateLayoutChanges = true }, 100)
|
||||
binding.preferences.postDelayed({ binding.preferences.animateLayoutChanges = true }, 100)
|
||||
|
||||
when (Build.VERSION.SDK_INT >= 29) {
|
||||
true -> nightModeDialog.adapter.setData(R.array.night_modes)
|
||||
@@ -103,7 +102,7 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
sendDelayDialog.adapter.setData(R.array.delayed_sending_labels)
|
||||
mmsSizeDialog.adapter.setData(R.array.mms_sizes, R.array.mms_sizes_ids)
|
||||
|
||||
about.summary = context.getString(R.string.settings_version, BuildConfig.VERSION_NAME)
|
||||
binding.about.summary = context.getString(R.string.settings_version, BuildConfig.VERSION_NAME)
|
||||
}
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
@@ -113,13 +112,13 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
showBackButton(true)
|
||||
}
|
||||
|
||||
override fun preferenceClicks(): Observable<PreferenceView> = (0 until preferences.childCount)
|
||||
.map { index -> preferences.getChildAt(index) }
|
||||
override fun preferenceClicks(): Observable<PreferenceView> = (0 until binding.preferences.childCount)
|
||||
.map { index -> binding.preferences.getChildAt(index) }
|
||||
.mapNotNull { view -> view as? PreferenceView }
|
||||
.map { preference -> preference.clicks().map { preference } }
|
||||
.let { preferences -> Observable.merge(preferences) }
|
||||
|
||||
override fun aboutLongClicks(): Observable<*> = about.longClicks()
|
||||
override fun aboutLongClicks(): Observable<*> = binding.about.longClicks()
|
||||
|
||||
override fun viewQksmsPlusClicks(): Observable<*> = viewQksmsPlusSubject
|
||||
|
||||
@@ -138,56 +137,56 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
override fun mmsSizeSelected(): Observable<Int> = mmsSizeDialog.adapter.menuItemClicks
|
||||
|
||||
override fun render(state: SettingsState) {
|
||||
themePreview.setBackgroundTint(state.theme)
|
||||
night.summary = state.nightModeSummary
|
||||
binding.theme.widget<View>().setBackgroundTint(state.theme)
|
||||
binding.night.summary = state.nightModeSummary
|
||||
nightModeDialog.adapter.selectedItem = state.nightModeId
|
||||
nightStart.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
||||
nightStart.summary = state.nightStart
|
||||
nightEnd.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
||||
nightEnd.summary = state.nightEnd
|
||||
binding.nightStart.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
||||
binding.nightStart.summary = state.nightStart
|
||||
binding.nightEnd.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
||||
binding.nightEnd.summary = state.nightEnd
|
||||
|
||||
black.setVisible(state.nightModeId != Preferences.NIGHT_MODE_OFF)
|
||||
black.checkbox.isChecked = state.black
|
||||
binding.black.setVisible(state.nightModeId != Preferences.NIGHT_MODE_OFF)
|
||||
binding.black.widget<QkSwitch>().isChecked = state.black
|
||||
|
||||
autoEmoji.checkbox.isChecked = state.autoEmojiEnabled
|
||||
binding.autoEmoji.widget<QkSwitch>().isChecked = state.autoEmojiEnabled
|
||||
|
||||
delayed.summary = state.sendDelaySummary
|
||||
binding.delayed.summary = state.sendDelaySummary
|
||||
sendDelayDialog.adapter.selectedItem = state.sendDelayId
|
||||
|
||||
delivery.checkbox.isChecked = state.deliveryEnabled
|
||||
binding.delivery.widget<QkSwitch>().isChecked = state.deliveryEnabled
|
||||
|
||||
signature.summary = state.signature.takeIf { it.isNotBlank() }
|
||||
binding.signature.summary = state.signature.takeIf { it.isNotBlank() }
|
||||
?: context.getString(R.string.settings_signature_summary)
|
||||
|
||||
textSize.summary = state.textSizeSummary
|
||||
binding.textSize.summary = state.textSizeSummary
|
||||
textSizeDialog.adapter.selectedItem = state.textSizeId
|
||||
|
||||
autoColor.checkbox.isChecked = state.autoColor
|
||||
binding.autoColor.widget<QkSwitch>().isChecked = state.autoColor
|
||||
|
||||
systemFont.checkbox.isChecked = state.systemFontEnabled
|
||||
binding.systemFont.widget<QkSwitch>().isChecked = state.systemFontEnabled
|
||||
|
||||
unicode.checkbox.isChecked = state.stripUnicodeEnabled
|
||||
mobileOnly.checkbox.isChecked = state.mobileOnly
|
||||
longAsMms.checkbox.isChecked = state.longAsMms
|
||||
binding.unicode.widget<QkSwitch>().isChecked = state.stripUnicodeEnabled
|
||||
binding.mobileOnly.widget<QkSwitch>().isChecked = state.mobileOnly
|
||||
binding.longAsMms.widget<QkSwitch>().isChecked = state.longAsMms
|
||||
|
||||
mmsSize.summary = state.maxMmsSizeSummary
|
||||
binding.mmsSize.summary = state.maxMmsSizeSummary
|
||||
mmsSizeDialog.adapter.selectedItem = state.maxMmsSizeId
|
||||
|
||||
when (state.syncProgress) {
|
||||
is SyncRepository.SyncProgress.Idle -> syncingProgress.isVisible = false
|
||||
is SyncRepository.SyncProgress.Idle -> binding.syncingProgress.isVisible = false
|
||||
|
||||
is SyncRepository.SyncProgress.Running -> {
|
||||
syncingProgress.isVisible = true
|
||||
syncingProgress.max = state.syncProgress.max
|
||||
progressAnimator.apply { setIntValues(syncingProgress.progress, state.syncProgress.progress) }.start()
|
||||
syncingProgress.isIndeterminate = state.syncProgress.indeterminate
|
||||
binding.syncingProgress.isVisible = true
|
||||
binding.syncingProgress.max = state.syncProgress.max
|
||||
progressAnimator.apply { setIntValues(binding.syncingProgress.progress, state.syncProgress.progress) }.start()
|
||||
binding.syncingProgress.isIndeterminate = state.syncProgress.indeterminate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun showQksmsPlusSnackbar() {
|
||||
view?.run {
|
||||
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
||||
Snackbar.make(binding.root, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
||||
setAction(R.string.button_more) { viewQksmsPlusSubject.onNext(Unit) }
|
||||
setActionTextColor(colors.theme().theme)
|
||||
show()
|
||||
|
||||
@@ -24,22 +24,23 @@ import com.moez.QKSMS.BuildConfig
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkController
|
||||
import com.moez.QKSMS.common.widget.PreferenceView
|
||||
import com.moez.QKSMS.databinding.AboutControllerBinding
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import io.reactivex.Observable
|
||||
import kotlinx.android.synthetic.main.about_controller.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class AboutController : QkController<AboutView, Unit, AboutPresenter>(), AboutView {
|
||||
class AboutController : QkController<AboutView, Unit, AboutPresenter, AboutControllerBinding>(
|
||||
AboutControllerBinding::inflate
|
||||
), AboutView {
|
||||
|
||||
@Inject override lateinit var presenter: AboutPresenter
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
layoutRes = R.layout.about_controller
|
||||
}
|
||||
|
||||
override fun onViewCreated() {
|
||||
version.summary = BuildConfig.VERSION_NAME
|
||||
binding.version.summary = BuildConfig.VERSION_NAME
|
||||
}
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
@@ -49,8 +50,8 @@ class AboutController : QkController<AboutView, Unit, AboutPresenter>(), AboutVi
|
||||
showBackButton(true)
|
||||
}
|
||||
|
||||
override fun preferenceClicks(): Observable<PreferenceView> = (0 until preferences.childCount)
|
||||
.map { index -> preferences.getChildAt(index) }
|
||||
override fun preferenceClicks(): Observable<PreferenceView> = (0 until binding.preferences.childCount)
|
||||
.map { index -> binding.preferences.getChildAt(index) }
|
||||
.mapNotNull { view -> view as? PreferenceView }
|
||||
.map { preference -> preference.clicks().map { preference } }
|
||||
.let { preferences -> Observable.merge(preferences) }
|
||||
|
||||
+20
-17
@@ -28,16 +28,20 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.databinding.SwipeActionsControllerBinding
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.uber.autodispose.android.autoDisposable
|
||||
import com.uber.autodispose.android.lifecycle.autoDisposable
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.swipe_actions_controller.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class SwipeActionsController : QkController<SwipeActionsView, SwipeActionsState, SwipeActionsPresenter>(), SwipeActionsView {
|
||||
class SwipeActionsController :
|
||||
QkController<SwipeActionsView, SwipeActionsState, SwipeActionsPresenter, SwipeActionsControllerBinding>(
|
||||
SwipeActionsControllerBinding::inflate), SwipeActionsView {
|
||||
|
||||
@Inject override lateinit var presenter: SwipeActionsPresenter
|
||||
@Inject lateinit var actionsDialog: QkDialog
|
||||
@@ -50,25 +54,24 @@ class SwipeActionsController : QkController<SwipeActionsView, SwipeActionsState,
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
layoutRes = R.layout.swipe_actions_controller
|
||||
|
||||
actionsDialog.adapter.setData(R.array.settings_swipe_actions)
|
||||
}
|
||||
|
||||
override fun onViewCreated() {
|
||||
colors.theme().let { theme ->
|
||||
rightIcon.setBackgroundTint(theme.theme)
|
||||
rightIcon.setTint(theme.textPrimary)
|
||||
leftIcon.setBackgroundTint(theme.theme)
|
||||
leftIcon.setTint(theme.textPrimary)
|
||||
binding.rightIcon.setBackgroundTint(theme.theme)
|
||||
binding.rightIcon.setTint(theme.textPrimary)
|
||||
binding.leftIcon.setBackgroundTint(theme.theme)
|
||||
binding.leftIcon.setTint(theme.textPrimary)
|
||||
}
|
||||
|
||||
right.postDelayed({ right?.animateLayoutChanges = true }, 100)
|
||||
left.postDelayed({ left?.animateLayoutChanges = true }, 100)
|
||||
binding.right.postDelayed({ binding.right.animateLayoutChanges = true }, 100)
|
||||
binding.left.postDelayed({ binding.left.animateLayoutChanges = true }, 100)
|
||||
|
||||
Observable.merge(
|
||||
right.clicks().map { SwipeActionsView.Action.RIGHT },
|
||||
left.clicks().map { SwipeActionsView.Action.LEFT })
|
||||
binding.right.clicks().map { SwipeActionsView.Action.RIGHT },
|
||||
binding.left.clicks().map { SwipeActionsView.Action.LEFT })
|
||||
.autoDisposable(scope())
|
||||
.subscribe(actionClicks)
|
||||
}
|
||||
@@ -90,13 +93,13 @@ class SwipeActionsController : QkController<SwipeActionsView, SwipeActionsState,
|
||||
}
|
||||
|
||||
override fun render(state: SwipeActionsState) {
|
||||
rightIcon.isVisible = state.rightIcon != 0
|
||||
rightIcon.setImageResource(state.rightIcon)
|
||||
rightLabel.text = state.rightLabel
|
||||
binding.rightIcon.isVisible = state.rightIcon != 0
|
||||
binding.rightIcon.setImageResource(state.rightIcon)
|
||||
binding.rightLabel.text = state.rightLabel
|
||||
|
||||
leftIcon.isVisible = state.leftIcon != 0
|
||||
leftIcon.setImageResource(state.leftIcon)
|
||||
leftLabel.text = state.leftLabel
|
||||
binding.leftIcon.isVisible = state.leftIcon != 0
|
||||
binding.leftIcon.setImageResource(state.leftIcon)
|
||||
binding.leftLabel.text = state.leftLabel
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user