Commit 83898b17 authored by Dayona Joseph's avatar Dayona Joseph
Browse files

Remove theme customization in settings

parent 5ad96935
Pipeline #70121 passed with stage
in 10 minutes and 44 seconds
......@@ -32,7 +32,6 @@ import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.common.widget.FieldDialog
import com.moez.QKSMS.feature.blocking.BlockingDialog
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoModule
import com.moez.QKSMS.feature.themepicker.ThemePickerController
import com.moez.QKSMS.injection.appComponent
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
......@@ -99,8 +98,6 @@ class ConversationInfoController(
override fun notificationClicks(): Observable<*> = notifications.clicks()
override fun themeClicks(): Observable<*> = themePrefs.clicks()
override fun archiveClicks(): Observable<*> = archive.clicks()
override fun blockClicks(): Observable<*> = block.clicks()
......@@ -124,8 +121,6 @@ class ConversationInfoController(
notifications.isEnabled = !state.blocked
themePrefs.isEnabled = !state.blocked
archive.isEnabled = !state.blocked
archive.title = activity?.getString(when (state.archived) {
true -> R.string.info_unarchive
......@@ -142,12 +137,6 @@ class ConversationInfoController(
override fun showNameDialog(name: String) = nameDialog.setText(name).show()
override fun showThemePicker(threadId: Long) {
router.pushController(RouterTransaction.with(ThemePickerController(threadId))
.pushChangeHandler(QkChangeHandler())
.popChangeHandler(QkChangeHandler()))
}
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
blockingDialog.show(activity!!, conversations, block)
}
......
......@@ -141,10 +141,6 @@ class ConversationInfoPresenter @Inject constructor(
.subscribe { conversation -> navigator.showNotificationSettings(conversation.id) }
// Show the theme settings for the conversation
view.themeClicks()
.withLatestFrom(conversation) { _, conversation -> conversation }
.autoDisposable(view.scope())
.subscribe { conversation -> view.showThemePicker(conversation.id) }
// Toggle the archived state of the conversation
view.archiveClicks()
......
......@@ -27,14 +27,12 @@ interface ConversationInfoView : QkViewContract<ConversationInfoState> {
fun nameClicks(): Observable<*>
fun nameChanges(): Observable<String>
fun notificationClicks(): Observable<*>
fun themeClicks(): Observable<*>
fun archiveClicks(): Observable<*>
fun blockClicks(): Observable<*>
fun deleteClicks(): Observable<*>
fun confirmDelete(): Observable<*>
fun showNameDialog(name: String)
fun showThemePicker(threadId: Long)
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
fun requestDefaultSms()
fun showDeleteDialog()
......
......@@ -43,7 +43,6 @@ import com.moez.QKSMS.common.widget.FieldDialog
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.repository.SyncRepository
import com.moez.QKSMS.util.Preferences
......@@ -55,7 +54,6 @@ 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 {
......@@ -137,7 +135,6 @@ 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
nightModeDialog.adapter.selectedItem = state.nightModeId
nightStart.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
......@@ -221,12 +218,6 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
.popChangeHandler(QkChangeHandler()))
}
override fun showThemePicker() {
router.pushController(RouterTransaction.with(ThemePickerController())
.pushChangeHandler(QkChangeHandler())
.popChangeHandler(QkChangeHandler()))
}
override fun showAbout() {
router.pushController(RouterTransaction.with(AboutController())
.pushChangeHandler(QkChangeHandler())
......
......@@ -146,7 +146,6 @@ class SettingsPresenter @Inject constructor(
Timber.v("Preference click: ${context.resources.getResourceName(it.id)}")
when (it.id) {
R.id.theme -> view.showThemePicker()
R.id.night -> view.showNightModeDialog()
......
......@@ -42,6 +42,5 @@ interface SettingsView : QkViewContract<SettingsState> {
fun showSignatureDialog(signature: String)
fun showMmsSizePicker()
fun showSwipeActions()
fun showThemePicker()
fun showAbout()
}
/*
* 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.themepicker
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.moez.QKSMS.R
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.common.util.extensions.within
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.hsv_picker_view.view.*
class HSVPickerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ConstraintLayout(context, attrs) {
val selectedColor: Subject<Int> = BehaviorSubject.create()
private val hues = arrayOf(0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF, 0xFFFF0000)
.map { it.toInt() }.toIntArray()
private var min: Float = 0f
private var max = 0f
private var hue = 0f
set(value) {
field = value
updateHue()
}
init {
View.inflate(context, R.layout.hsv_picker_view, this)
var swatchX = 0f
var swatchY = 0f
saturation.setOnTouchListener { _, event ->
setupBounds()
when (event.action) {
MotionEvent.ACTION_DOWN -> {
swatchX = event.x - event.rawX
swatchY = event.y - event.rawY
parent.requestDisallowInterceptTouchEvent(true)
}
MotionEvent.ACTION_MOVE -> {
// Calculate the new x/y position
swatch.x = (event.rawX + swatchX + min).within(min, max)
swatch.y = (event.rawY + swatchY + min).within(min, max)
updateSelectedColor()
}
MotionEvent.ACTION_UP -> {
parent.requestDisallowInterceptTouchEvent(false)
}
else -> return@setOnTouchListener false
}
true
}
var hueThumbX = 0f
hueGroup.setOnTouchListener { _, event ->
setupBounds()
when (event.action) {
MotionEvent.ACTION_DOWN -> {
hueThumbX = event.x - event.rawX
parent.requestDisallowInterceptTouchEvent(true)
}
MotionEvent.ACTION_MOVE -> {
val x = (event.rawX + hueThumbX + min).within(min, max)
hueThumb.x = x
hue = (hueThumb.x - min) / (max - min) * 360
updateSelectedColor()
}
MotionEvent.ACTION_UP -> {
parent.requestDisallowInterceptTouchEvent(false)
}
else -> return@setOnTouchListener false
}
true
}
hueTrack.clipToOutline = true
hueTrack.setImageDrawable(GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, hues))
}
private fun setupBounds() {
if (min == 0f || max == 0f) {
min = saturation.x - swatch.width / 2
max = min + saturation.width
}
}
private fun updateSelectedColor() {
setupBounds()
val range = max - min
val hsv = floatArrayOf(hue, (swatch.x - min) / range, 1 - (swatch.y - min) / range)
val color = Color.HSVToColor(hsv)
swatch.setTint(color)
selectedColor.onNext(color)
}
fun setColor(color: Int) {
// Convert the rgb color to HSV
val hsv = FloatArray(3).apply {
Color.colorToHSV(color, this)
hue = this[0]
}
// Set the position of the swatch
post {
setupBounds()
val range = max - min
hueThumb.x = range * hsv[0] / 360 + min
swatch.x = range * hsv[1] + min
swatch.y = range * (1 - hsv[2]) + min
updateSelectedColor()
}
}
private fun updateHue() {
val hsv = floatArrayOf(hue, 1f, 1f)
val tint = Color.HSVToColor(hsv)
saturation.setBackgroundTint(tint)
}
}
\ No newline at end of file
/*
* 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.themepicker
import android.content.Context
import android.content.res.Resources
import android.view.LayoutInflater
import android.view.ViewGroup
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayout
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.dpToPx
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.common.util.extensions.setVisible
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.theme_list_item.view.*
import kotlinx.android.synthetic.main.theme_palette_list_item.view.*
import javax.inject.Inject
class ThemeAdapter @Inject constructor(
private val context: Context,
private val colors: Colors
) : QkAdapter<List<Int>>() {
val colorSelected: Subject<Int> = PublishSubject.create()
var selectedColor: Int = -1
set(value) {
val oldPosition = data.indexOfFirst { it.contains(field) }
val newPosition = data.indexOfFirst { it.contains(value) }
field = value
iconTint = colors.textPrimaryOnThemeForColor(value)
oldPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
newPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
}
private var iconTint = 0
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.theme_palette_list_item, parent, false)
view.palette.flexWrap = FlexWrap.WRAP
view.palette.flexDirection = FlexDirection.ROW
return QkViewHolder(view)
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val palette = getItem(position)
val view = holder.containerView
val screenWidth = Resources.getSystem().displayMetrics.widthPixels
val minPadding = (16 * 6).dpToPx(context)
val size = if (screenWidth - minPadding > (56 * 5).dpToPx(context)) {
56.dpToPx(context)
} else {
(screenWidth - minPadding) / 5
}
val swatchPadding = (screenWidth - size * 5) / 12
view.palette.removeAllViews()
view.palette.setPadding(swatchPadding, swatchPadding, swatchPadding, swatchPadding)
(palette.subList(0, 5) + palette.subList(5, 10).reversed())
.mapIndexed { index, color ->
LayoutInflater.from(context).inflate(R.layout.theme_list_item, view.palette, false).apply {
// Send clicks to the selected subject
setOnClickListener { colorSelected.onNext(color) }
// Apply the color to the view
theme.setBackgroundTint(color)
// Control the check visibility and tint
check.setVisible(color == selectedColor)
check.setTint(iconTint)
// Update the size so that the spacing is perfectly even
layoutParams = (layoutParams as FlexboxLayout.LayoutParams).apply {
height = size
width = size
isWrapBefore = index % 5 == 0
setMargins(swatchPadding, swatchPadding, swatchPadding, swatchPadding)
}
}
}
.forEach { theme -> view.palette.addView(theme) }
}
}
\ No newline at end of file
/*
* 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.themepicker
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.moez.QKSMS.R
import javax.inject.Inject
class ThemePagerAdapter @Inject constructor(private val context: Context) : PagerAdapter() {
override fun instantiateItem(container: ViewGroup, position: Int): Any {
return when (position) {
1 -> container.findViewById(R.id.hsvPicker)
else -> container.findViewById(R.id.materialColors)
}
}
override fun getPageTitle(position: Int): CharSequence? {
return when (position) {
1 -> context.getString(R.string.theme_plus)
else -> context.getString(R.string.theme_material)
}
}
override fun isViewFromObject(view: View, `object`: Any): Boolean {
return view == `object`
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
}
override fun getCount(): Int {
return 2
}
}
\ No newline at end of file
/*
* 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.themepicker
import android.animation.ObjectAnimator
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkController
import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.common.util.extensions.dpToPx
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.feature.themepicker.injection.ThemePickerModule
import com.moez.QKSMS.injection.appComponent
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.theme_picker_controller.*
import kotlinx.android.synthetic.main.theme_picker_hsv.*
import javax.inject.Inject
class ThemePickerController(val threadId: Long = 0L) : QkController<ThemePickerView, ThemePickerState, ThemePickerPresenter>(), ThemePickerView {
@Inject override lateinit var presenter: ThemePickerPresenter
@Inject lateinit var colors: Colors
@Inject lateinit var themeAdapter: ThemeAdapter
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
private val viewQksmsPlusSubject: Subject<Unit> = PublishSubject.create()
init {
appComponent
.themePickerBuilder()
.themePickerModule(ThemePickerModule(this))
.build()
.inject(this)
layoutRes = R.layout.theme_picker_controller
}
override fun onViewCreated() {
pager.offscreenPageLimit = 1
pager.adapter = themePagerAdapter
tabs.pager = pager
themeAdapter.data = colors.materialColors
materialColors.layoutManager = LinearLayoutManager(activity)
materialColors.adapter = themeAdapter
}
override fun onAttach(view: View) {
super.onAttach(view)
presenter.bindIntents(this)
setTitle(R.string.title_theme)
showBackButton(true)
themedActivity?.supportActionBar?.let { toolbar ->
ObjectAnimator.ofFloat(toolbar, "elevation", toolbar.elevation, 0f).start()
}
}
override fun onDetach(view: View) {
super.onDetach(view)
themedActivity?.supportActionBar?.let { toolbar ->
ObjectAnimator.ofFloat(toolbar, "elevation", toolbar.elevation, 8.dpToPx(toolbar.themedContext).toFloat()).start()
}
}
override fun showQksmsPlusSnackbar() {
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
setAction(R.string.button_more) { viewQksmsPlusSubject.onNext(Unit) }
setActionTextColor(colors.theme().theme)
show()
}
}
override fun themeSelected(): Observable<Int> = themeAdapter.colorSelected
override fun hsvThemeSelected(): Observable<Int> = picker.selectedColor
override fun clearHsvThemeClicks(): Observable<*> = clear.clicks()
override fun applyHsvThemeClicks(): Observable<*> = apply.clicks()
override fun viewQksmsPlusClicks(): Observable<*> = viewQksmsPlusSubject
override fun render(state: ThemePickerState) {
tabs.setThreadId(state.threadId)
hex.setText(Integer.toHexString(state.newColor).takeLast(6))
applyGroup.setVisible(state.applyThemeVisible)
apply.setBackgroundTint(state.newColor)