Squashed commit of the following:

commit 1f890b96beb893c866ed9b47d8e3a9ac6e20662f
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Wed Jan 31 17:41:22 2018 -0500

    Clean up bindView in PlusViewModel

commit c71f4853d385df66a79f9372ecf29507cb64152b
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Wed Jan 31 02:14:37 2018 -0500

    Move QKSMS+ to sliding menu

commit a23d1dd6d314935cd96c530e3419a3a2ca4cab27
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Wed Jan 31 00:28:42 2018 -0500

    Make selected plan more visible

commit 540cda206ede1d3b81d7d42438257f76f9f07cd4
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Wed Jan 31 00:27:03 2018 -0500

    Allow changing dynamic textcolor programatically

commit 859325dd5ffa7aa5958ae2eb5c9eac62bcb8f7bd
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Tue Jan 30 22:26:41 2018 -0500

    Dark mode support for ripple selected state

commit 6a1d5c387fe0a08ef05573f3f07a1cd82b1a37ec
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Tue Jan 30 22:18:27 2018 -0500

    Remove explicit upgrade button, click plan to buy

commit 4a6e85b0c513c8604f8993f78add2b3910c0b49d
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Tue Jan 30 20:43:09 2018 -0500

    Show thank you UI if user has upgraded

commit 080fccf40b4461b6a833ba77fce1267bd8251281
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Tue Jan 30 17:52:02 2018 -0500

    Allow changing plans

commit ac122f138b1840de39f7a7bd1fb36727056233e1
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Tue Jan 30 16:33:59 2018 -0500

    Allow purchase of subscription

commit 3e689443ec197a929308d9add270ae6777cdeae1
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 23:21:31 2018 -0500

    Allow selection of different plans

commit d51a90160898b39de5ba4e69fdc8351e2fe7093c
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 19:42:56 2018 -0500

    Collapsing toolbar for QKSMS+ activity

commit 06c0d5a834884f144ad7e149b7dea3b0ba38b643
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 18:02:05 2018 -0500

    Display pricing information in QKSMS+ activity

commit c0be51eec5e1b091dbe8ba69f28c48e5379011f3
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 17:26:16 2018 -0500

    Add ability to view QKSMS+ activity from settings

commit 51e7782a274503401d53a22ccbe55eab2523f200
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 15:41:40 2018 -0500

    Indicate currently selected theme

commit 0b3bb3e24b3c40ac517cf05404638061f9b520b8
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 15:19:28 2018 -0500

    Move ThemeAdapter package

commit 828b6fe10afd6493884ee8d1c472dcd39f5371d4
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 15:10:14 2018 -0500

    Evenly space theme swatches with other items and borders

commit 220499c0676f03c282b201dfd67faa10f20a546d
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Mon Jan 29 14:45:47 2018 -0500

    Evenly distribute theme swatches

commit 4d0995da773f720411b22091fc58d03497d38438
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Sun Jan 28 22:53:49 2018 -0500

    Use separate activity for Theme picker

commit 3886c1890a6320667f9999071213f181e4e2de79
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Sun Jan 28 20:00:17 2018 -0500

    Update more text

commit 3e3995fdf58ee849f6fedabd895aff42f521e473
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Sun Jan 28 19:56:04 2018 -0500

    Update text for blocking

commit b8ffbf30761105abe1150279994c8d0ebd7a68b7
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Sun Jan 28 19:49:11 2018 -0500

    Build layout for QKSMS+ activity

commit 90518ad8291d5028ceb765ca60fe1d36a5edb33a
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Sun Jan 28 19:48:59 2018 -0500

    Improve layout preview support for some custom views

commit 3b301b641e1b747d0ac7192bb50e51d494fe6ef8
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Sun Jan 28 02:22:54 2018 -0500

    Use up-to-date material design colors

commit e8c9cec67767c8702f1b6ccf7ee89c22e585132c
Author: Moez Bhatti <moez.bhatti@gmail.com>
Date:   Sun Jan 28 01:21:24 2018 -0500

    Add strings and icons for QKSMS+ features
This commit is contained in:
Moez Bhatti
2018-01-31 21:20:29 -05:00
parent 218b611ae3
commit 317940d4f7
40 changed files with 1443 additions and 172 deletions
@@ -0,0 +1,125 @@
/*
* 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 presentation.feature.themepicker
import android.content.Context
import android.content.res.Resources
import android.support.v7.widget.RecyclerView
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 common.util.Colors
import common.util.extensions.dpToPx
import common.util.extensions.setBackgroundTint
import common.util.extensions.setTint
import common.util.extensions.setVisible
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
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 presentation.common.base.QkAdapter
import presentation.common.base.QkViewHolder
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
oldPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
newPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
}
private var iconTint = 0
private val disposables = CompositeDisposable()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(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.itemView
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) }
}
override fun onAttachedToRecyclerView(recyclerView: RecyclerView?) {
disposables += colors.textPrimaryOnTheme
.subscribe { color -> iconTint = color }
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView?) {
disposables.clear()
}
}