#967 - Swipe conversation actions

This commit is contained in:
Moez Bhatti
2018-07-30 20:34:31 -04:00
parent 3f7b615f19
commit 75162c8114
22 changed files with 820 additions and 78 deletions
@@ -4,9 +4,7 @@ import android.app.ProgressDialog
import android.app.TimePickerDialog
import android.content.Context
import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.google.android.material.snackbar.Snackbar
@@ -21,6 +19,7 @@ import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.common.widget.PreferenceView
import com.moez.QKSMS.feature.settings.about.AboutController
import com.moez.QKSMS.feature.settings.swipe.SwipeActionsController
import com.moez.QKSMS.feature.themepicker.ThemePickerController
import com.moez.QKSMS.injection.appComponent
import com.moez.QKSMS.util.Preferences
@@ -28,8 +27,8 @@ import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.settings_activity.*
import kotlinx.android.synthetic.main.settings_activity.view.*
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
@@ -61,7 +60,7 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
init {
appComponent.inject(this)
retainViewMode = RetainViewMode.RETAIN_DETACH
layoutRes = R.layout.settings_activity
layoutRes = R.layout.settings_controller
colors.themeObservable()
.autoDisposable(scope())
@@ -166,6 +165,12 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
override fun showMmsSizePicker() = mmsSizeDialog.show(activity!!)
override fun showSwipeActions() {
router.pushController(RouterTransaction.with(SwipeActionsController())
.pushChangeHandler(FadeChangeHandler(150))
.popChangeHandler(FadeChangeHandler(150)))
}
override fun showThemePicker() {
router.pushController(RouterTransaction.with(ThemePickerController())
.pushChangeHandler(FadeChangeHandler(150))
@@ -117,6 +117,8 @@ class SettingsPresenter @Inject constructor(
R.id.notifications -> navigator.showNotificationSettings()
R.id.swipeActions -> view.showSwipeActions()
R.id.delayed -> view.showDelayDurationDialog()
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
@@ -39,6 +39,7 @@ interface SettingsView : QkViewContract<SettingsState> {
fun showTextSizePicker()
fun showDelayDurationDialog()
fun showMmsSizePicker()
fun showSwipeActions()
fun showThemePicker()
fun showAbout()
}
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.settings.swipe
import android.view.View
import androidx.core.view.isVisible
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.QkDialog
import com.moez.QKSMS.common.base.QkController
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.injection.appComponent
import com.uber.autodispose.kotlin.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 {
@Inject override lateinit var presenter: SwipeActionsPresenter
@Inject lateinit var actionsDialog: QkDialog
@Inject lateinit var colors: Colors
/**
* Allows us to subscribe to [actionClicks] more than once
*/
private val actionClicks: Subject<SwipeActionsView.Action> = PublishSubject.create()
init {
appComponent.inject(this)
layoutRes = R.layout.swipe_actions_controller
actionsDialog.adapter.setData(R.array.settings_swipe_actions)
}
override fun onAttach(view: View) {
super.onAttach(view)
presenter.bindIntents(this)
setTitle(R.string.settings_swipe_actions)
showBackButton(true)
colors.theme().let { theme ->
rightIcon.setBackgroundTint(theme.theme)
rightIcon.setTint(theme.textPrimary)
leftIcon.setBackgroundTint(theme.theme)
leftIcon.setTint(theme.textPrimary)
}
right.postDelayed({ right.animateLayoutChanges = true }, 100)
left.postDelayed({ left.animateLayoutChanges = true }, 100)
Observable.merge(
right.clicks().map { SwipeActionsView.Action.RIGHT },
left.clicks().map { SwipeActionsView.Action.LEFT })
.autoDisposable(scope())
.subscribe(actionClicks)
}
override fun actionClicks(): Observable<SwipeActionsView.Action> = actionClicks
override fun actionSelected(): Observable<Int> = actionsDialog.adapter.menuItemClicks
override fun showSwipeActions(selected: Int) {
actionsDialog.adapter.selectedItem = selected
activity?.let(actionsDialog::show)
}
override fun render(state: SwipeActionsState) {
rightIcon.isVisible = state.rightIcon != 0
rightIcon.setImageResource(state.rightIcon)
rightLabel.text = state.rightLabel
leftIcon.isVisible = state.leftIcon != 0
leftIcon.setImageResource(state.leftIcon)
leftLabel.text = state.leftLabel
}
}
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.settings.swipe
import android.content.Context
import androidx.annotation.DrawableRes
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkPresenter
import com.moez.QKSMS.util.Preferences
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
import javax.inject.Inject
class SwipeActionsPresenter @Inject constructor(
context: Context,
private val prefs: Preferences
) : QkPresenter<SwipeActionsView, SwipeActionsState>(SwipeActionsState()) {
init {
val actionLabels = context.resources.getStringArray(R.array.settings_swipe_actions)
disposables += prefs.swipeRight.asObservable()
.subscribe { action -> newState { copy(rightLabel = actionLabels[action], rightIcon = iconForAction(action)) } }
disposables += prefs.swipeLeft.asObservable()
.subscribe { action -> newState { copy(leftLabel = actionLabels[action], leftIcon = iconForAction(action)) } }
}
override fun bindIntents(view: SwipeActionsView) {
super.bindIntents(view)
view.actionClicks()
.map { action ->
when (action) {
SwipeActionsView.Action.RIGHT -> prefs.swipeRight.get()
SwipeActionsView.Action.LEFT -> prefs.swipeLeft.get()
}
}
.autoDisposable(view.scope())
.subscribe(view::showSwipeActions)
view.actionSelected()
.withLatestFrom(view.actionClicks()) { actionId, action ->
when (action) {
SwipeActionsView.Action.RIGHT -> prefs.swipeRight.set(actionId)
SwipeActionsView.Action.LEFT -> prefs.swipeLeft.set(actionId)
}
}
.autoDisposable(view.scope())
.subscribe()
}
@DrawableRes
private fun iconForAction(action: Int) = when (action) {
Preferences.SWIPE_ACTION_ARCHIVE -> R.drawable.ic_archive_black_24dp
Preferences.SWIPE_ACTION_DELETE -> R.drawable.ic_delete_white_24dp
Preferences.SWIPE_ACTION_CALL -> R.drawable.ic_call_white_24dp
Preferences.SWIPE_ACTION_READ -> R.drawable.ic_check_white_24dp
else -> 0
}
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.settings.swipe
import androidx.annotation.DrawableRes
import com.moez.QKSMS.R
data class SwipeActionsState(
@DrawableRes val rightIcon: Int = R.drawable.ic_archive_black_24dp,
val rightLabel: String = "",
@DrawableRes val leftIcon: Int = R.drawable.ic_archive_black_24dp,
val leftLabel: String = ""
)
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.settings.swipe
import com.moez.QKSMS.common.base.QkViewContract
import io.reactivex.Observable
interface SwipeActionsView : QkViewContract<SwipeActionsState> {
enum class Action { LEFT, RIGHT }
fun actionClicks(): Observable<Action>
fun actionSelected(): Observable<Int>
fun showSwipeActions(selected: Int)
}