diff --git a/android-smsmms/src/main/res/drawable/ic_forward_black_24dp.xml b/android-smsmms/src/main/res/drawable/ic_forward_black_24dp.xml
new file mode 100644
index 00000000..06ceeb50
--- /dev/null
+++ b/android-smsmms/src/main/res/drawable/ic_forward_black_24dp.xml
@@ -0,0 +1,27 @@
+
+
+
+
diff --git a/qksms/src/main/AndroidManifest.xml b/qksms/src/main/AndroidManifest.xml
index 56bafb4b..0a0a18a6 100644
--- a/qksms/src/main/AndroidManifest.xml
+++ b/qksms/src/main/AndroidManifest.xml
@@ -60,6 +60,8 @@
+
+
diff --git a/qksms/src/main/java/common/di/AppComponent.kt b/qksms/src/main/java/common/di/AppComponent.kt
index 21715c01..9131f102 100644
--- a/qksms/src/main/java/common/di/AppComponent.kt
+++ b/qksms/src/main/java/common/di/AppComponent.kt
@@ -27,10 +27,14 @@ import presentation.feature.compose.ComposeViewModel
import presentation.feature.compose.DetailedChipView
import presentation.feature.main.MainActivity
import presentation.feature.main.MainViewModel
+import presentation.feature.plus.PlusActivity
+import presentation.feature.plus.PlusViewModel
import presentation.feature.settings.SettingsActivity
import presentation.feature.settings.SettingsViewModel
import presentation.feature.setup.SetupActivity
import presentation.feature.setup.SetupViewModel
+import presentation.feature.themepicker.ThemePickerActivity
+import presentation.feature.themepicker.ThemePickerViewModel
import presentation.receiver.*
import javax.inject.Singleton
@@ -43,7 +47,9 @@ interface AppComponent {
fun inject(activity: MainActivity)
fun inject(activity: SetupActivity)
fun inject(activity: ComposeActivity)
+ fun inject(activity: PlusActivity)
fun inject(activity: SettingsActivity)
+ fun inject(activity: ThemePickerActivity)
fun inject(receiver: DefaultSmsChangedReceiver)
fun inject(receiver: SmsReceiver)
@@ -67,7 +73,9 @@ interface AppComponent {
fun inject(viewModel: MainViewModel)
fun inject(viewModel: SetupViewModel)
fun inject(viewModel: ComposeViewModel)
+ fun inject(viewModel: PlusViewModel)
fun inject(viewModel: SettingsViewModel)
+ fun inject(viewModel: ThemePickerViewModel)
fun inject(fetcher: ContactImageLoader.ContactImageFetcher)
diff --git a/qksms/src/main/java/common/util/BillingManager.kt b/qksms/src/main/java/common/util/BillingManager.kt
index 1a73f57c..e2e374bb 100644
--- a/qksms/src/main/java/common/util/BillingManager.kt
+++ b/qksms/src/main/java/common/util/BillingManager.kt
@@ -30,13 +30,21 @@ import javax.inject.Inject
class BillingManager @Inject constructor(context: Context) : PurchasesUpdatedListener {
- val purchases: Observable> = BehaviorSubject.create()
- val iabs: Observable> = BehaviorSubject.create()
- val subs: Observable> = BehaviorSubject.create()
+ enum class UpgradeStatus { REGULAR, LEGACY, SUPPORTER, DONOR, PHILANTHROPIST }
- private val iabSkus = listOf("remove_ads")
- private val subSkus = listOf("qksms_plus_3", "qksms_plus_5", "qksms_plus_10")
+ companion object {
+ const val SKU_LEGACY = "remove_ads"
+ const val SKU_3 = "qksms_plus_3"
+ const val SKU_5 = "qksms_plus_5"
+ const val SKU_10 = "qksms_plus_10"
+ }
+
+ val subscriptions: Observable> = BehaviorSubject.create()
+ val plusStatus: Observable
+
+ private val subSkus = listOf(SKU_3, SKU_5, SKU_10)
private val purchaseList = mutableListOf()
+ private val purchaseListObservable: Observable> = BehaviorSubject.create()
private val billingClient: BillingClient = BillingClient.newBuilder(context).setListener(this).build()
private var isServiceConnected = false
@@ -46,6 +54,17 @@ class BillingManager @Inject constructor(context: Context) : PurchasesUpdatedLis
queryPurchases()
querySkuDetailsAsync()
}
+
+ plusStatus = purchaseListObservable
+ .map { purchases ->
+ when {
+ purchases.any { it.sku == SKU_10 } -> UpgradeStatus.PHILANTHROPIST
+ purchases.any { it.sku == SKU_5 } -> UpgradeStatus.DONOR
+ purchases.any { it.sku == SKU_3 } -> UpgradeStatus.SUPPORTER
+ purchases.any { it.sku == SKU_LEGACY } -> UpgradeStatus.LEGACY
+ else -> UpgradeStatus.PHILANTHROPIST
+ }
+ }
}
private fun queryPurchases() {
@@ -62,7 +81,7 @@ class BillingManager @Inject constructor(context: Context) : PurchasesUpdatedLis
// Handle purchase result
purchaseList.clear()
purchaseList.addAll(purchasesResult.purchasesList)
- (this.purchases as Subject).onNext(purchaseList)
+ (this.purchaseListObservable as Subject).onNext(purchaseList)
}
}
@@ -84,25 +103,22 @@ class BillingManager @Inject constructor(context: Context) : PurchasesUpdatedLis
private fun querySkuDetailsAsync() {
executeServiceRequest {
- val iabParams = SkuDetailsParams.newBuilder().setSkusList(iabSkus).setType(BillingClient.SkuType.INAPP)
- billingClient.querySkuDetailsAsync(iabParams.build()) { responseCode, skuDetailsList ->
- if (responseCode == BillingResponse.OK) {
- (iabs as Subject).onNext(skuDetailsList)
- }
- }
-
val subParams = SkuDetailsParams.newBuilder().setSkusList(subSkus).setType(BillingClient.SkuType.SUBS)
billingClient.querySkuDetailsAsync(subParams.build()) { responseCode, skuDetailsList ->
if (responseCode == BillingResponse.OK) {
- (subs as Subject).onNext(skuDetailsList)
+ (subscriptions as Subject).onNext(skuDetailsList)
}
}
}
}
- fun initiatePurchaseFlow(activity: Activity) {
+ fun initiatePurchaseFlow(activity: Activity, sku: String) {
executeServiceRequest {
- val params = BillingFlowParams.newBuilder().setSku("qksms_plus_3").setType(SkuType.SUBS)
+ val oldSkus = purchaseList
+ .filter { product -> subSkus.contains(product.sku) }
+ .map { product -> product.sku }
+
+ val params = BillingFlowParams.newBuilder().setSku(sku).setType(SkuType.SUBS).setOldSkus(ArrayList(oldSkus))
billingClient.launchBillingFlow(activity, params.build())
}
}
@@ -117,8 +133,9 @@ class BillingManager @Inject constructor(context: Context) : PurchasesUpdatedLis
override fun onPurchasesUpdated(resultCode: Int, purchases: List?) {
when (resultCode) {
BillingResponse.OK -> {
- purchases?.forEach { purchaseList.add(it) }
- (this.purchases as Subject).onNext(purchaseList)
+ purchaseList.clear()
+ purchases?.let { purchaseList.addAll(it) }
+ (this.purchaseListObservable as Subject).onNext(purchaseList)
}
else -> {
diff --git a/qksms/src/main/java/common/util/Colors.kt b/qksms/src/main/java/common/util/Colors.kt
index 4926b557..5998a639 100644
--- a/qksms/src/main/java/common/util/Colors.kt
+++ b/qksms/src/main/java/common/util/Colors.kt
@@ -32,9 +32,29 @@ import javax.inject.Singleton
@Singleton
class Colors @Inject constructor(private val context: Context, prefs: Preferences) {
- companion object {
- private const val MINIMUM_CONTRAST_RATIO = 2
- }
+ val materialColors = listOf(
+ listOf(0xffffebee, 0xffffcdd2, 0xffef9a9a, 0xffe57373, 0xffef5350, 0xfff44336, 0xffe53935, 0xffd32f2f, 0xffc62828, 0xffb71c1c),
+ listOf(0xffFCE4EC, 0xffF8BBD0, 0xffF48FB1, 0xffF06292, 0xffEC407A, 0xffE91E63, 0xffD81B60, 0xffC2185B, 0xffAD1457, 0xff880E4F),
+ listOf(0xffF3E5F5, 0xffE1BEE7, 0xffCE93D8, 0xffBA68C8, 0xffAB47BC, 0xff9C27B0, 0xff8E24AA, 0xff7B1FA2, 0xff6A1B9A, 0xff4A148C),
+ listOf(0xffEDE7F6, 0xffD1C4E9, 0xffB39DDB, 0xff9575CD, 0xff7E57C2, 0xff673AB7, 0xff5E35B1, 0xff512DA8, 0xff4527A0, 0xff311B92),
+ listOf(0xffE8EAF6, 0xffC5CAE9, 0xff9FA8DA, 0xff7986CB, 0xff5C6BC0, 0xff3F51B5, 0xff3949AB, 0xff303F9F, 0xff283593, 0xff1A237E),
+ listOf(0xffE3F2FD, 0xffBBDEFB, 0xff90CAF9, 0xff64B5F6, 0xff42A5F5, 0xff2196F3, 0xff1E88E5, 0xff1976D2, 0xff1565C0, 0xff0D47A1),
+ listOf(0xffE1F5FE, 0xffB3E5FC, 0xff81D4FA, 0xff4FC3F7, 0xff29B6F6, 0xff03A9F4, 0xff039BE5, 0xff0288D1, 0xff0277BD, 0xff01579B),
+ listOf(0xffE0F7FA, 0xffB2EBF2, 0xff80DEEA, 0xff4DD0E1, 0xff26C6DA, 0xff00BCD4, 0xff00ACC1, 0xff0097A7, 0xff00838F, 0xff006064),
+ listOf(0xffE0F2F1, 0xffB2DFDB, 0xff80CBC4, 0xff4DB6AC, 0xff26A69A, 0xff009688, 0xff00897B, 0xff00796B, 0xff00695C, 0xff004D40),
+ listOf(0xffE8F5E9, 0xffC8E6C9, 0xffA5D6A7, 0xff81C784, 0xff66BB6A, 0xff4CAF50, 0xff43A047, 0xff388E3C, 0xff2E7D32, 0xff1B5E20),
+ listOf(0xffF1F8E9, 0xffDCEDC8, 0xffC5E1A5, 0xffAED581, 0xff9CCC65, 0xff8BC34A, 0xff7CB342, 0xff689F38, 0xff558B2F, 0xff33691E),
+ listOf(0xffF9FBE7, 0xffF0F4C3, 0xffE6EE9C, 0xffDCE775, 0xffD4E157, 0xffCDDC39, 0xffC0CA33, 0xffAFB42B, 0xff9E9D24, 0xff827717),
+ listOf(0xffFFFDE7, 0xffFFF9C4, 0xffFFF59D, 0xffFFF176, 0xffFFEE58, 0xffFFEB3B, 0xffFDD835, 0xffFBC02D, 0xffF9A825, 0xffF57F17),
+ listOf(0xffFFF8E1, 0xffFFECB3, 0xffFFE082, 0xffFFD54F, 0xffFFCA28, 0xffFFC107, 0xffFFB300, 0xffFFA000, 0xffFF8F00, 0xffFF6F00),
+ listOf(0xffFFF3E0, 0xffFFE0B2, 0xffFFCC80, 0xffFFB74D, 0xffFFA726, 0xffFF9800, 0xffFB8C00, 0xffF57C00, 0xffEF6C00, 0xffE65100),
+ listOf(0xffFBE9E7, 0xffFFCCBC, 0xffFFAB91, 0xffFF8A65, 0xffFF7043, 0xffFF5722, 0xffF4511E, 0xffE64A19, 0xffD84315, 0xffBF360C),
+ listOf(0xffEFEBE9, 0xffD7CCC8, 0xffBCAAA4, 0xffA1887F, 0xff8D6E63, 0xff795548, 0xff6D4C41, 0xff5D4037, 0xff4E342E, 0xff3E2723),
+ listOf(0xffFAFAFA, 0xffF5F5F5, 0xffEEEEEE, 0xffE0E0E0, 0xffBDBDBD, 0xff9E9E9E, 0xff757575, 0xff616161, 0xff424242, 0xff212121),
+ listOf(0xffECEFF1, 0xffCFD8DC, 0xffB0BEC5, 0xff90A4AE, 0xff78909C, 0xff607D8B, 0xff546E7A, 0xff455A64, 0xff37474F, 0xff263238))
+ .map { it.map { it.toInt() } }
+
+ private val minimumContrastRatio = 2
// Cache these values so they don't need to be recalculated
private val primaryTextLuminance = measureLuminance(getColor(R.color.textPrimaryDark))
@@ -104,7 +124,7 @@ class Colors @Inject constructor(private val context: Context, prefs: Preference
val textPrimaryOnTheme: Observable = prefs.theme.asObservable()
.map { theme -> measureLuminance(theme) }
.map { themeLuminance -> primaryTextLuminance / themeLuminance }
- .map { contrastRatio -> contrastRatio < MINIMUM_CONTRAST_RATIO }
+ .map { contrastRatio -> contrastRatio < minimumContrastRatio }
.map { contrastRatio -> if (contrastRatio) R.color.textPrimary else R.color.textPrimaryDark }
.map { res -> getColor(res) }
.distinctUntilChanged()
@@ -112,7 +132,7 @@ class Colors @Inject constructor(private val context: Context, prefs: Preference
val textSecondaryOnTheme: Observable = prefs.theme.asObservable()
.map { theme -> measureLuminance(theme) }
.map { themeLuminance -> secondaryTextLuminance / themeLuminance }
- .map { contrastRatio -> contrastRatio < MINIMUM_CONTRAST_RATIO }
+ .map { contrastRatio -> contrastRatio < minimumContrastRatio }
.map { contrastRatio -> if (contrastRatio) R.color.textSecondary else R.color.textSecondaryDark }
.map { res -> getColor(res) }
.distinctUntilChanged()
@@ -120,7 +140,7 @@ class Colors @Inject constructor(private val context: Context, prefs: Preference
val textTertiaryOnTheme: Observable = prefs.theme.asObservable()
.map { theme -> measureLuminance(theme) }
.map { themeLuminance -> tertiaryTextLuminance / themeLuminance }
- .map { contrastRatio -> contrastRatio < MINIMUM_CONTRAST_RATIO }
+ .map { contrastRatio -> contrastRatio < minimumContrastRatio }
.map { contrastRatio -> if (contrastRatio) R.color.textTertiary else R.color.textTertiaryDark }
.map { res -> getColor(res) }
.distinctUntilChanged()
@@ -155,7 +175,7 @@ class Colors @Inject constructor(private val context: Context, prefs: Preference
}
/**
- * Measures the luminance value of a color to be able to measure the contrast ratio between two colors
+ * Measures the luminance value of a color to be able to measure the contrast ratio between two materialColors
* Based on https://stackoverflow.com/a/9733420
*/
private fun measureLuminance(color: Int): Double {
diff --git a/qksms/src/main/java/presentation/common/Navigator.kt b/qksms/src/main/java/presentation/common/Navigator.kt
index 7831a52b..e98c15b7 100644
--- a/qksms/src/main/java/presentation/common/Navigator.kt
+++ b/qksms/src/main/java/presentation/common/Navigator.kt
@@ -32,14 +32,17 @@ import common.util.NotificationManager
import presentation.feature.compose.ComposeActivity
import presentation.feature.compose.ComposeViewModel
import presentation.feature.main.MainViewModel
+import presentation.feature.plus.PlusActivity
+import presentation.feature.plus.PlusViewModel
import presentation.feature.settings.SettingsActivity
import presentation.feature.settings.SettingsViewModel
import presentation.feature.setup.SetupActivity
import presentation.feature.setup.SetupViewModel
+import presentation.feature.themepicker.ThemePickerActivity
+import presentation.feature.themepicker.ThemePickerViewModel
import javax.inject.Inject
import javax.inject.Singleton
-
@Singleton
class Navigator @Inject constructor(val context: Context) {
@@ -53,6 +56,11 @@ class Navigator @Inject constructor(val context: Context) {
startActivity(intent)
}
+ fun showQksmsPlusActivity() {
+ val intent = Intent(context, PlusActivity::class.java)
+ startActivity(intent)
+ }
+
fun showDefaultSmsDialog() {
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
if (Telephony.Sms.getDefaultSmsPackage(context) != context.packageName) {
@@ -78,6 +86,11 @@ class Navigator @Inject constructor(val context: Context) {
startActivity(intent)
}
+ fun showThemePicker() {
+ val intent = Intent(context, ThemePickerActivity::class.java)
+ startActivity(intent)
+ }
+
fun makePhoneCall(address: String) {
val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:$address"))
startActivity(intent)
@@ -110,9 +123,11 @@ class Navigator @Inject constructor(val context: Context) {
override fun create(modelClass: Class): T {
return when (modelClass) {
MainViewModel::class.java -> MainViewModel()
+ PlusViewModel::class.java -> PlusViewModel()
SetupViewModel::class.java -> SetupViewModel()
ComposeViewModel::class.java -> ComposeViewModel(intent)
SettingsViewModel::class.java -> SettingsViewModel()
+ ThemePickerViewModel::class.java -> ThemePickerViewModel()
else -> throw IllegalArgumentException("Invalid ViewModel class. If this is a new ViewModel, please add it to Navigator.kt")
} as T
}
diff --git a/qksms/src/main/java/presentation/common/widget/PreferenceView.kt b/qksms/src/main/java/presentation/common/widget/PreferenceView.kt
index ef2f5592..8f63eee5 100644
--- a/qksms/src/main/java/presentation/common/widget/PreferenceView.kt
+++ b/qksms/src/main/java/presentation/common/widget/PreferenceView.kt
@@ -22,11 +22,13 @@ import android.content.Context
import android.support.v7.widget.LinearLayoutCompat
import android.util.AttributeSet
import android.view.View
+import android.widget.TextView
import com.moez.QKSMS.R
import com.uber.autodispose.android.scope
import com.uber.autodispose.kotlin.autoDisposable
import common.di.appComponent
import common.util.Colors
+import common.util.extensions.getColorCompat
import common.util.extensions.setTint
import common.util.extensions.setVisible
import kotlinx.android.synthetic.main.preference_view.view.*
@@ -39,18 +41,34 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut
var title: String? = null
set(value) {
field = value
- titleView.text = value
+
+ if (isInEditMode) {
+ findViewById(R.id.titleView).text = value
+ } else {
+ titleView.text = value
+ }
}
var summary: String? = null
set(value) {
field = value
- summaryView.text = value
- summaryView.setVisible(value?.isNotEmpty() == true)
+
+
+ if (isInEditMode) {
+ findViewById(R.id.summaryView).run {
+ text = value
+ setVisible(value?.isNotEmpty() == true)
+ }
+ } else {
+ summaryView.text = value
+ summaryView.setVisible(value?.isNotEmpty() == true)
+ }
}
init {
- appComponent.inject(this)
+ if (!isInEditMode) {
+ appComponent.inject(this)
+ }
View.inflate(context, R.layout.preference_view, this)
setBackgroundResource(R.drawable.ripple)
@@ -77,9 +95,14 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut
override fun onAttachedToWindow() {
super.onAttachedToWindow()
- colors.textSecondary
- .autoDisposable(scope())
- .subscribe { icon.setTint(it) }
+
+ if (isInEditMode) {
+ icon.setTint(context.getColorCompat(R.color.textSecondary))
+ } else {
+ colors.textSecondary
+ .autoDisposable(scope())
+ .subscribe { icon.setTint(it) }
+ }
}
}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/common/widget/QkTextView.kt b/qksms/src/main/java/presentation/common/widget/QkTextView.kt
index 586ced26..9ecf341b 100644
--- a/qksms/src/main/java/presentation/common/widget/QkTextView.kt
+++ b/qksms/src/main/java/presentation/common/widget/QkTextView.kt
@@ -22,46 +22,101 @@ import android.content.Context
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSet
import com.moez.QKSMS.R
-import com.uber.autodispose.android.scope
-import com.uber.autodispose.kotlin.autoDisposable
import common.di.appComponent
import common.util.Colors
+import common.util.extensions.getColorCompat
import io.reactivex.Observable
+import io.reactivex.disposables.Disposable
import javax.inject.Inject
open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
: AppCompatTextView(context, attrs) {
+ companion object {
+ const val COLOR_PRIMARY = 0
+ const val COLOR_SECONDARY = 1
+ const val COLOR_TERTIARY = 2
+ const val COLOR_PRIMARY_ON_THEME = 3
+ const val COLOR_SECONDARY_ON_THEME = 4
+ const val COLOR_TERTIARY_ON_THEME = 5
+ }
+
@Inject lateinit var colors: Colors
+ private var textColorDisposable: Disposable? = null
private var textColorObservable: Observable? = null
+ set(value) {
+ if (field !== value) {
+ field = value
+
+ if (isAttachedToWindow) {
+ textColorDisposable?.let { disposable ->
+ if (!disposable.isDisposed) {
+ disposable.dispose()
+ }
+ }
+
+ subscribeColorChanges()
+ }
+ }
+ }
init {
- appComponent.inject(this)
+ if (!isInEditMode) {
+ appComponent.inject(this)
+ }
context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
- textColorObservable = when (getInt(R.styleable.QkTextView_textColor, -1)) {
- 0 -> colors.textPrimary
- 1 -> colors.textSecondary
- 2 -> colors.textTertiary
- 3 -> colors.textPrimaryOnTheme
- 4 -> colors.textSecondaryOnTheme
- 5 -> colors.textTertiaryOnTheme
- else -> null
+ val colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
+ if (isInEditMode) {
+ setTextColor(context.getColorCompat(when (colorAttr) {
+ COLOR_PRIMARY -> R.color.textPrimary
+ COLOR_SECONDARY -> R.color.textSecondary
+ COLOR_TERTIARY -> R.color.textTertiary
+ COLOR_PRIMARY_ON_THEME -> R.color.textPrimaryDark
+ COLOR_SECONDARY_ON_THEME -> R.color.textSecondaryDark
+ COLOR_TERTIARY_ON_THEME -> R.color.textTertiaryDark
+ else -> R.color.textPrimary
+ }))
+ } else {
+ setColor(colorAttr)
}
recycle()
}
}
- override fun onAttachedToWindow() {
- super.onAttachedToWindow()
- textColorObservable
- ?.autoDisposable(scope())
+ fun setColor(colorAttr: Int) {
+ textColorObservable = when (colorAttr) {
+ COLOR_PRIMARY -> colors.textPrimary
+ COLOR_SECONDARY -> colors.textSecondary
+ COLOR_TERTIARY -> colors.textTertiary
+ COLOR_PRIMARY_ON_THEME -> colors.textPrimaryOnTheme
+ COLOR_SECONDARY_ON_THEME -> colors.textSecondaryOnTheme
+ COLOR_TERTIARY_ON_THEME -> colors.textTertiaryOnTheme
+ else -> null
+ }
+ }
+
+ private fun subscribeColorChanges() {
+ textColorDisposable = textColorObservable
?.subscribe { color ->
setTextColor(color)
setLinkTextColor(color)
}
}
+ override fun onAttachedToWindow() {
+ super.onAttachedToWindow()
+
+ if (textColorDisposable?.isDisposed != false) {
+ subscribeColorChanges()
+ }
+ }
+
+ override fun onDetachedFromWindow() {
+ super.onDetachedFromWindow()
+ textColorDisposable?.dispose()
+ }
+
}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/common/widget/Separator.kt b/qksms/src/main/java/presentation/common/widget/Separator.kt
index 1d686b68..a8b81c33 100644
--- a/qksms/src/main/java/presentation/common/widget/Separator.kt
+++ b/qksms/src/main/java/presentation/common/widget/Separator.kt
@@ -21,10 +21,12 @@ package presentation.common.widget
import android.content.Context
import android.util.AttributeSet
import android.view.View
+import com.moez.QKSMS.R
import com.uber.autodispose.android.scope
import com.uber.autodispose.kotlin.autoDisposable
import common.di.appComponent
import common.util.Colors
+import common.util.extensions.getColorCompat
import javax.inject.Inject
class Separator @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs) {
@@ -32,14 +34,20 @@ class Separator @JvmOverloads constructor(context: Context, attrs: AttributeSet?
@Inject lateinit var colors: Colors
init {
- appComponent.inject(this)
+ if (!isInEditMode) {
+ appComponent.inject(this)
+ }
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
- colors.separator
- .autoDisposable(scope())
- .subscribe { color -> setBackgroundColor(color) }
+ if (isInEditMode) {
+ setBackgroundColor(context.getColorCompat(R.color.separatorLight))
+ } else {
+ colors.separator
+ .autoDisposable(scope())
+ .subscribe { color -> setBackgroundColor(color) }
+ }
}
}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/main/MainActivity.kt b/qksms/src/main/java/presentation/feature/main/MainActivity.kt
index 0e9bb88b..8d6b015d 100644
--- a/qksms/src/main/java/presentation/feature/main/MainActivity.kt
+++ b/qksms/src/main/java/presentation/feature/main/MainActivity.kt
@@ -74,6 +74,7 @@ class MainActivity : QkActivity(), MainView {
scheduled.clicks().map { DrawerItem.SCHEDULED },
blocked.clicks().map { DrawerItem.BLOCKED },
settings.clicks().map { DrawerItem.SETTINGS },
+ plus.clicks().map { DrawerItem.PLUS },
help.clicks().map { DrawerItem.HELP }))
}
override val conversationClickIntent by lazy { conversationsAdapter.clicks }
@@ -159,6 +160,7 @@ class MainActivity : QkActivity(), MainView {
.doOnNext { tintList -> scheduledIcon.imageTintList = tintList }
.doOnNext { tintList -> blockedIcon.imageTintList = tintList }
.doOnNext { tintList -> settingsIcon.imageTintList = tintList }
+ .doOnNext { tintList -> plusIcon.imageTintList = tintList }
.doOnNext { tintList -> helpIcon.imageTintList = tintList }
.autoDisposable(scope())
.subscribe()
diff --git a/qksms/src/main/java/presentation/feature/main/MainView.kt b/qksms/src/main/java/presentation/feature/main/MainView.kt
index 8823c047..3ff54570 100644
--- a/qksms/src/main/java/presentation/feature/main/MainView.kt
+++ b/qksms/src/main/java/presentation/feature/main/MainView.kt
@@ -39,4 +39,4 @@ interface MainView : QkView {
}
-enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKED, SETTINGS, HELP }
\ No newline at end of file
+enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKED, SETTINGS, PLUS, HELP }
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/main/MainViewModel.kt b/qksms/src/main/java/presentation/feature/main/MainViewModel.kt
index c64e8983..cec77cb6 100644
--- a/qksms/src/main/java/presentation/feature/main/MainViewModel.kt
+++ b/qksms/src/main/java/presentation/feature/main/MainViewModel.kt
@@ -27,7 +27,6 @@ import com.moez.QKSMS.R
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import common.di.appComponent
-import common.util.BillingManager
import common.util.extensions.toFlowable
import common.util.filter.ConversationFilter
import data.model.MenuItem
@@ -40,14 +39,12 @@ import io.reactivex.rxkotlin.withLatestFrom
import io.realm.Realm
import presentation.common.Navigator
import presentation.common.base.QkViewModel
-import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class MainViewModel : QkViewModel(MainState()) {
@Inject lateinit var context: Context
- @Inject lateinit var billingManager: BillingManager
@Inject lateinit var navigator: Navigator
@Inject lateinit var conversationFilter: ConversationFilter
@Inject lateinit var messageRepo: MessageRepository
@@ -116,10 +113,6 @@ class MainViewModel : QkViewModel(MainState()) {
}
markAllSeen.execute(Unit)
-
- billingManager.purchases.subscribe { purchases -> Timber.v("Purchases: $purchases") }
- billingManager.iabs.subscribe { iabs -> Timber.v("IABs: $iabs") }
- billingManager.subs.subscribe { subs -> Timber.v("Subs: $subs") }
}
override fun bindView(view: MainView) {
@@ -157,6 +150,7 @@ class MainViewModel : QkViewModel(MainState()) {
view.drawerItemIntent
.doOnNext { newState { it.copy(drawerOpen = false) } }
.doOnNext { if (it == DrawerItem.SETTINGS) navigator.showSettings() }
+ .doOnNext { if (it == DrawerItem.PLUS) navigator.showQksmsPlusActivity() }
.doOnNext { if (it == DrawerItem.HELP) navigator.showSupport() }
.distinctUntilChanged()
.doOnNext {
diff --git a/qksms/src/main/java/presentation/feature/plus/PlusActivity.kt b/qksms/src/main/java/presentation/feature/plus/PlusActivity.kt
new file mode 100644
index 00000000..f2c2b5dd
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/plus/PlusActivity.kt
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.plus
+
+import android.os.Bundle
+import com.jakewharton.rxbinding2.view.clicks
+import com.moez.QKSMS.R
+import com.uber.autodispose.android.lifecycle.scope
+import com.uber.autodispose.kotlin.autoDisposable
+import common.di.appComponent
+import common.util.BillingManager
+import common.util.extensions.setBackgroundTint
+import common.util.extensions.setTint
+import common.util.extensions.setVisible
+import kotlinx.android.synthetic.main.qksms_plus_activity.*
+import presentation.common.base.QkActivity
+import presentation.common.widget.QkTextView
+
+class PlusActivity : QkActivity(), PlusView {
+
+ override val viewModelClass = PlusViewModel::class
+ override val supporterSelectedIntent by lazy { supporter.clicks() }
+ override val donorSelectedIntent by lazy { donor.clicks() }
+ override val philanthropistSelectedIntent by lazy { philanthropist.clicks() }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ appComponent.inject(this)
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.qksms_plus_activity)
+ setTitle(R.string.title_qksms_plus)
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+ viewModel.bindView(this)
+
+ colors.textPrimary
+ .autoDisposable(scope())
+ .subscribe { color ->
+ collapsingToolbar.setCollapsedTitleTextColor(color)
+ collapsingToolbar.setExpandedTitleColor(color)
+ }
+
+ colors.background
+ .autoDisposable(scope())
+ .subscribe { color -> window.decorView.setBackgroundColor(color) }
+
+ colors.separator
+ .autoDisposable(scope())
+ .subscribe { color -> thanks.setBackgroundTint(color) }
+
+ colors.theme
+ .autoDisposable(scope())
+ .subscribe { color ->
+ thanksIcon.setTint(color)
+ supporter.setBackgroundTint(color)
+ donor.setBackgroundTint(color)
+ philanthropist.setBackgroundTint(color)
+ }
+ }
+
+ override fun render(state: PlusState) {
+ description.text = getString(R.string.qksms_plus_description_summary, state.supporterPrice)
+
+ thanks.setVisible(state.currentPlan != BillingManager.UpgradeStatus.REGULAR)
+
+ val supportedSelected = state.currentPlan == BillingManager.UpgradeStatus.SUPPORTER
+ supporter.isSelected = supportedSelected
+ supporterPrice.text = state.supporterPrice
+ supporterName.setColor(getPrimaryTextColorAttr(supportedSelected))
+ supporterPrice.setColor(getPrimaryTextColorAttr(supportedSelected))
+ supporterPeriod.setColor(getSecondaryTextColorAttr(supportedSelected))
+
+ val donorSelected = state.currentPlan == BillingManager.UpgradeStatus.DONOR
+ donor.isSelected = donorSelected
+ donorPrice.text = state.donorPrice
+ donorName.setColor(getPrimaryTextColorAttr(donorSelected))
+ donorPrice.setColor(getPrimaryTextColorAttr(donorSelected))
+ donorPeriod.setColor(getSecondaryTextColorAttr(donorSelected))
+
+ val philanthropistSelected = state.currentPlan == BillingManager.UpgradeStatus.PHILANTHROPIST
+ philanthropist.isSelected = philanthropistSelected
+ philanthropistPrice.text = state.philanthropistPrice
+ philanthropistName.setColor(getPrimaryTextColorAttr(philanthropistSelected))
+ philanthropistPrice.setColor(getPrimaryTextColorAttr(philanthropistSelected))
+ philanthropistPeriod.setColor(getSecondaryTextColorAttr(philanthropistSelected))
+ }
+
+ private fun getPrimaryTextColorAttr(selected: Boolean): Int {
+ return if (selected) QkTextView.COLOR_PRIMARY_ON_THEME else QkTextView.COLOR_PRIMARY
+ }
+
+ private fun getSecondaryTextColorAttr(selected: Boolean): Int {
+ return if (selected) QkTextView.COLOR_SECONDARY_ON_THEME else QkTextView.COLOR_SECONDARY
+ }
+
+ override fun initiatePurchaseFlow(billingManager: BillingManager, sku: String) {
+ billingManager.initiatePurchaseFlow(this, sku)
+ }
+
+}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/plus/PlusState.kt b/qksms/src/main/java/presentation/feature/plus/PlusState.kt
new file mode 100644
index 00000000..df42ccca
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/plus/PlusState.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.plus
+
+import common.util.BillingManager
+
+data class PlusState(
+ val currentPlan: BillingManager.UpgradeStatus = BillingManager.UpgradeStatus.REGULAR,
+ val supporterPrice: String = "",
+ val donorPrice: String = "",
+ val philanthropistPrice: String = ""
+)
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/plus/PlusView.kt b/qksms/src/main/java/presentation/feature/plus/PlusView.kt
new file mode 100644
index 00000000..1a06a36a
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/plus/PlusView.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.plus
+
+import common.util.BillingManager
+import io.reactivex.Observable
+import presentation.common.base.QkView
+
+interface PlusView : QkView {
+
+ val supporterSelectedIntent: Observable
+ val donorSelectedIntent: Observable
+ val philanthropistSelectedIntent: Observable
+
+ fun initiatePurchaseFlow(billingManager: BillingManager, sku: String)
+
+}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/plus/PlusViewModel.kt b/qksms/src/main/java/presentation/feature/plus/PlusViewModel.kt
new file mode 100644
index 00000000..b02d902e
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/plus/PlusViewModel.kt
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.plus
+
+import com.uber.autodispose.android.lifecycle.scope
+import com.uber.autodispose.kotlin.autoDisposable
+import common.di.appComponent
+import common.util.BillingManager
+import io.reactivex.Observable
+import io.reactivex.rxkotlin.plusAssign
+import presentation.common.base.QkViewModel
+import javax.inject.Inject
+
+class PlusViewModel : QkViewModel(PlusState()) {
+
+ @Inject lateinit var billingManager: BillingManager
+
+ init {
+ appComponent.inject(this)
+
+ disposables += billingManager.plusStatus
+ .subscribe { plan ->
+ newState { it.copy(currentPlan = plan) }
+ }
+
+ disposables += billingManager.subscriptions
+ .subscribe { subs ->
+ newState {
+ it.copy(
+ supporterPrice = subs.firstOrNull { it.sku == BillingManager.SKU_3 }?.price ?: "",
+ donorPrice = subs.firstOrNull { it.sku == BillingManager.SKU_5 }?.price ?: "",
+ philanthropistPrice = subs.firstOrNull { it.sku == BillingManager.SKU_10 }?.price ?: "")
+ }
+ }
+ }
+
+ override fun bindView(view: PlusView) {
+ super.bindView(view)
+
+ Observable.merge(
+ view.supporterSelectedIntent.map { BillingManager.SKU_3 },
+ view.donorSelectedIntent.map { BillingManager.SKU_5 },
+ view.philanthropistSelectedIntent.map { BillingManager.SKU_10 })
+ .autoDisposable(view.scope())
+ .subscribe { sku -> view.initiatePurchaseFlow(billingManager, sku) }
+ }
+
+}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/settings/SettingsActivity.kt b/qksms/src/main/java/presentation/feature/settings/SettingsActivity.kt
index 3fa8cbc5..76bd40cd 100644
--- a/qksms/src/main/java/presentation/feature/settings/SettingsActivity.kt
+++ b/qksms/src/main/java/presentation/feature/settings/SettingsActivity.kt
@@ -28,7 +28,6 @@ import android.os.Build
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
-import com.google.android.flexbox.FlexboxLayoutManager
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.uber.autodispose.android.lifecycle.scope
@@ -37,7 +36,6 @@ import common.di.appComponent
import common.util.extensions.dpToPx
import common.util.extensions.setVisible
import data.model.MenuItem
-import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.settings_activity.*
@@ -53,7 +51,6 @@ class SettingsActivity : QkActivity(), SettingsView {
override val viewModelClass = SettingsViewModel::class
override val preferenceClickIntent: Subject = PublishSubject.create()
- override val themeSelectedIntent: Observable by lazy { themeAdapter.colorSelected }
override val ringtoneSelectedIntent: Subject = PublishSubject.create()
override val mmsSizeSelectedIntent: Subject by lazy { menuItemAdapter.menuItemClicks }
@@ -66,50 +63,6 @@ class SettingsActivity : QkActivity(), SettingsView {
}
}
- private val themeDialog by lazy {
- AlertDialog.Builder(this)
- .setTitle(R.string.settings_dialog_theme_title)
- .setView(themeRecyclerView)
- .setCancelable(false)
- .create()
- }
-
- private val themeRecyclerView by lazy {
- RecyclerView(this).apply {
- val padding = 8.dpToPx(context)
- setPadding(padding, padding, padding, padding)
- adapter = themeAdapter
- clipToPadding = false
- clipChildren = false
- layoutManager = FlexboxLayoutManager(this@SettingsActivity)
- }
- }
-
- private val themeAdapter by lazy {
- ThemeAdapter(this@SettingsActivity).apply {
- data = listOf(
- -0x21f24, -0x64245, -0x96678, -0xc93a0, -0x17b1c0, -0x1ae3dd, -0x22e6e3, -0x2fe8ea, -0x3bebef, -0x4fedf6,
- -0x31b14, -0x74430, -0xb704f, -0xf9d6e, -0x13bf86, -0x16e19d, -0x27e4a0, -0x3de7a5, -0x52eba9, -0x77f1b1,
- -0xc1a0b, -0x1e4119, -0x316c28, -0x459738, -0x54b844, -0x63d850, -0x71db56, -0x84e05e, -0x95e466, -0xb5eb74,
- -0x12180a, -0x2e3b17, -0x4c6225, -0x6a8a33, -0x81a83e, -0x98c549, -0xa1ca4f, -0xaed258, -0xbad860, -0xcee46e,
- -0x17150a, -0x3a3517, -0x605726, -0x867935, -0xa39440, -0xc0ae4b, -0xc6b655, -0xcfc061, -0xd7ca6d, -0xe5dc82,
- -0x181603, -0x2f2601, -0x504001, -0x6e5801, -0x8c7002, -0xa98804, -0xb19311, -0xbaa122, -0xc4af32, -0xd5c94f,
- -0x1e0a02, -0x4c1a04, -0x7e2b06, -0xb03c09, -0xd6490a, -0xfc560c, -0xfc641b, -0xfd772f, -0xfd8843, -0xfea865,
- -0x1f0806, -0x4d140e, -0x7f2116, -0xb22f1f, -0xd93926, -0xff432c, -0xff533f, -0xff6859, -0xff7c71, -0xff9f9c,
- -0x1f0d0f, -0x4d2025, -0x7f343c, -0xb24954, -0xd95966, -0xff6978, -0xff7685, -0xff8695, -0xff96a4, -0xffb2c0,
- -0x2f0732, -0x5c165c, -0x8d2a8e, -0xbd42bf, -0xd450d5, -0xda64dc, -0xf570f8, -0xf581f9, -0xfa9100, -0xf2acfe,
- -0xe0717, -0x231238, -0x3a1e5b, -0x512a7f, -0x63339b, -0x743cb6, -0x834cbe, -0x9760c8, -0xaa74d1, -0xcc96e2,
- -0x60419, -0xf0b3d, -0x191164, -0x23188b, -0x2b1ea9, -0x3223c7, -0x3f35cd, -0x504bd5, -0x6162dc, -0x7d88e9,
- -0x219, -0x63c, -0xa63, -0xe8a, -0x11a8, -0x14c5, -0x227cb, -0x43fd3, -0x657db, -0xa80e9,
- -0x71f, -0x134d, -0x1f7e, -0x2ab1, -0x35d8, -0x3ef9, -0x4d00, -0x6000, -0x7100, -0x9100,
- -0xc20, -0x1f4e, -0x3380, -0x48b3, -0x58da, -0x6800, -0x47400, -0xa8400, -0x109400, -0x19af00,
- -0x41619, -0x3344, -0x546f, -0x759b, -0x8fbd, -0xa8de, -0xbaee2, -0x19b5e7, -0x27bceb, -0x40c9f4,
- -0x101417, -0x283338, -0x43555c, -0x5e7781, -0x72919d, -0x86aab8, -0x92b3bf, -0xa2bfc9, -0xb1cbd2,
- -0x50506, -0xa0a0b, -0x111112, -0x1f1f20, -0x424243, -0x616162, -0x8a8a8b, -0x9e9e9f, -0xbdbdbe, -0xdededf, -0x1000000, -0x1,
- -0x13100f, -0x13100f, -0x4f413b, -0x6f5b52, -0x876f64, -0x9f8275, -0xab9186, -0xbaa59c, -0xc8b8b1, -0xd9cdc8)
- }
- }
-
private val mmsSizeDialog by lazy {
menuItemAdapter.data = arrayListOf(
MenuItem(R.string.menu_mms_size_100kb, 100),
@@ -161,9 +114,6 @@ class SettingsActivity : QkActivity(), SettingsView {
}
override fun render(state: SettingsState) {
- if (themeDialog.isShowing && !state.selectingTheme) themeDialog.dismiss()
- else if (!themeDialog.isShowing && state.selectingTheme) themeDialog.show()
-
if (progressDialog.isShowing && !state.syncing) progressDialog.dismiss()
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
diff --git a/qksms/src/main/java/presentation/feature/settings/SettingsState.kt b/qksms/src/main/java/presentation/feature/settings/SettingsState.kt
index a9b3e1eb..6b770d35 100644
--- a/qksms/src/main/java/presentation/feature/settings/SettingsState.kt
+++ b/qksms/src/main/java/presentation/feature/settings/SettingsState.kt
@@ -19,7 +19,6 @@
package presentation.feature.settings
data class SettingsState(
- val selectingTheme: Boolean = false,
val syncing: Boolean = false,
val isDefaultSmsApp: Boolean = false,
diff --git a/qksms/src/main/java/presentation/feature/settings/SettingsView.kt b/qksms/src/main/java/presentation/feature/settings/SettingsView.kt
index a128947d..1f8badf5 100644
--- a/qksms/src/main/java/presentation/feature/settings/SettingsView.kt
+++ b/qksms/src/main/java/presentation/feature/settings/SettingsView.kt
@@ -27,7 +27,6 @@ import presentation.common.widget.PreferenceView
interface SettingsView : QkView {
val preferenceClickIntent: Subject
- val themeSelectedIntent: Observable
val ringtoneSelectedIntent: Observable
val mmsSizeSelectedIntent: Observable
diff --git a/qksms/src/main/java/presentation/feature/settings/SettingsViewModel.kt b/qksms/src/main/java/presentation/feature/settings/SettingsViewModel.kt
index 54f77b4e..978f0f3a 100644
--- a/qksms/src/main/java/presentation/feature/settings/SettingsViewModel.kt
+++ b/qksms/src/main/java/presentation/feature/settings/SettingsViewModel.kt
@@ -94,7 +94,7 @@ class SettingsViewModel : QkViewModel(SettingsState
when (it.id) {
R.id.defaultSms -> navigator.showDefaultSmsDialog()
- R.id.theme -> newState { it.copy(selectingTheme = true) }
+ R.id.theme -> navigator.showThemePicker()
R.id.dark -> prefs.dark.set(!prefs.dark.get())
@@ -125,13 +125,6 @@ class SettingsViewModel : QkViewModel(SettingsState
}
}
- view.themeSelectedIntent
- .autoDisposable(view.scope())
- .subscribe { color ->
- prefs.theme.set(color)
- newState { it.copy(selectingTheme = false) }
- }
-
view.ringtoneSelectedIntent
.autoDisposable(view.scope())
.subscribe { ringtone -> prefs.ringtone.set(ringtone) }
diff --git a/qksms/src/main/java/presentation/feature/settings/ThemeAdapter.kt b/qksms/src/main/java/presentation/feature/settings/ThemeAdapter.kt
deleted file mode 100644
index 62a68705..00000000
--- a/qksms/src/main/java/presentation/feature/settings/ThemeAdapter.kt
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2017 Moez Bhatti
- *
- * 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 .
- */
-package presentation.feature.settings
-
-import android.content.Context
-import android.view.LayoutInflater
-import android.view.ViewGroup
-import com.moez.QKSMS.R
-import common.util.extensions.setBackgroundTint
-import presentation.common.base.QkAdapter
-import presentation.common.base.QkViewHolder
-import io.reactivex.subjects.PublishSubject
-import io.reactivex.subjects.Subject
-import kotlinx.android.synthetic.main.theme_list_item.view.*
-
-class ThemeAdapter(private val context: Context) : QkAdapter() {
-
- val colorSelected: Subject = PublishSubject.create()
-
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
- val view = LayoutInflater.from(context).inflate(R.layout.theme_list_item, parent, false)
- return QkViewHolder(view)
- }
-
- override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
- val theme = getItem(position)
- val view = holder.itemView
-
- view.setOnClickListener { colorSelected.onNext(theme) }
-
- view.theme.setBackgroundTint(theme)
- }
-
-}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/themepicker/ThemeAdapter.kt b/qksms/src/main/java/presentation/feature/themepicker/ThemeAdapter.kt
new file mode 100644
index 00000000..641bb1c9
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/themepicker/ThemeAdapter.kt
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+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>() {
+
+ val colorSelected: Subject = 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()
+ }
+
+}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/themepicker/ThemePickerActivity.kt b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerActivity.kt
new file mode 100644
index 00000000..83334318
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerActivity.kt
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.themepicker
+
+import android.os.Bundle
+import android.support.v7.widget.LinearLayoutManager
+import com.moez.QKSMS.R
+import com.uber.autodispose.android.lifecycle.scope
+import com.uber.autodispose.kotlin.autoDisposable
+import common.di.appComponent
+import io.reactivex.Observable
+import kotlinx.android.synthetic.main.theme_picker_activity.*
+import presentation.common.base.QkActivity
+import javax.inject.Inject
+
+class ThemePickerActivity : QkActivity(), ThemePickerView {
+
+ override val viewModelClass = ThemePickerViewModel::class
+ override val themeSelectedIntent: Observable by lazy { themeAdapter.colorSelected }
+
+ @Inject lateinit var themeAdapter: ThemeAdapter
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ appComponent.inject(this)
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.theme_picker_activity)
+ setTitle(R.string.title_theme)
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+ viewModel.bindView(this)
+
+ themeAdapter.data = colors.materialColors
+
+ materialColors.layoutManager = LinearLayoutManager(this)
+ materialColors.adapter = themeAdapter
+
+ colors.background
+ .autoDisposable(scope())
+ .subscribe { color -> window.decorView.setBackgroundColor(color) }
+ }
+
+ override fun render(state: ThemePickerState) {
+ themeAdapter.selectedColor = state.selectedColor
+ }
+
+}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/themepicker/ThemePickerState.kt b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerState.kt
new file mode 100644
index 00000000..3b5857b6
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerState.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.themepicker
+
+data class ThemePickerState(
+
+ val selectedColor: Int = -1
+
+)
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/themepicker/ThemePickerView.kt b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerView.kt
new file mode 100644
index 00000000..cfedcf4d
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerView.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.themepicker
+
+import io.reactivex.Observable
+import presentation.common.base.QkView
+
+interface ThemePickerView : QkView {
+
+ val themeSelectedIntent: Observable
+
+}
\ No newline at end of file
diff --git a/qksms/src/main/java/presentation/feature/themepicker/ThemePickerViewModel.kt b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerViewModel.kt
new file mode 100644
index 00000000..c7031bd3
--- /dev/null
+++ b/qksms/src/main/java/presentation/feature/themepicker/ThemePickerViewModel.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 Moez Bhatti
+ *
+ * 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 .
+ */
+package presentation.feature.themepicker
+
+import com.uber.autodispose.android.lifecycle.scope
+import com.uber.autodispose.kotlin.autoDisposable
+import common.di.appComponent
+import common.util.Preferences
+import io.reactivex.rxkotlin.plusAssign
+import presentation.common.base.QkViewModel
+import javax.inject.Inject
+
+class ThemePickerViewModel : QkViewModel(ThemePickerState()) {
+
+ @Inject lateinit var prefs: Preferences
+
+ init {
+ appComponent.inject(this)
+
+ disposables += prefs.theme.asObservable()
+ .subscribe { color -> newState { it.copy(selectedColor = color) } }
+ }
+
+ override fun bindView(view: ThemePickerView) {
+ super.bindView(view)
+
+ view.themeSelectedIntent
+ .autoDisposable(view.scope())
+ .subscribe { color -> prefs.theme.set(color) }
+ }
+
+}
\ No newline at end of file
diff --git a/qksms/src/main/res/drawable/ic_av_timer_black_24dp.xml b/qksms/src/main/res/drawable/ic_av_timer_black_24dp.xml
new file mode 100644
index 00000000..59f37793
--- /dev/null
+++ b/qksms/src/main/res/drawable/ic_av_timer_black_24dp.xml
@@ -0,0 +1,27 @@
+
+
+
+
diff --git a/qksms/src/main/res/drawable/ic_backup_black_24dp.xml b/qksms/src/main/res/drawable/ic_backup_black_24dp.xml
new file mode 100644
index 00000000..2ad4a6dd
--- /dev/null
+++ b/qksms/src/main/res/drawable/ic_backup_black_24dp.xml
@@ -0,0 +1,27 @@
+
+
+
+
diff --git a/qksms/src/main/res/drawable/ic_favorite_black_24dp.xml b/qksms/src/main/res/drawable/ic_favorite_black_24dp.xml
new file mode 100644
index 00000000..d26c91de
--- /dev/null
+++ b/qksms/src/main/res/drawable/ic_favorite_black_24dp.xml
@@ -0,0 +1,27 @@
+
+
+
+
diff --git a/qksms/src/main/res/drawable/ic_invert_colors_black_24dp.xml b/qksms/src/main/res/drawable/ic_invert_colors_black_24dp.xml
new file mode 100644
index 00000000..b64ef577
--- /dev/null
+++ b/qksms/src/main/res/drawable/ic_invert_colors_black_24dp.xml
@@ -0,0 +1,27 @@
+
+
+
+
diff --git a/qksms/src/main/res/drawable/ic_more_horiz_black_24dp.xml b/qksms/src/main/res/drawable/ic_more_horiz_black_24dp.xml
new file mode 100644
index 00000000..090f162f
--- /dev/null
+++ b/qksms/src/main/res/drawable/ic_more_horiz_black_24dp.xml
@@ -0,0 +1,27 @@
+
+
+
+
diff --git a/qksms/src/main/res/drawable/ic_palette_black_24dp.xml b/qksms/src/main/res/drawable/ic_palette_black_24dp.xml
new file mode 100644
index 00000000..88343a0c
--- /dev/null
+++ b/qksms/src/main/res/drawable/ic_palette_black_24dp.xml
@@ -0,0 +1,27 @@
+
+
+
+
diff --git a/qksms/src/main/res/drawable/ripple.xml b/qksms/src/main/res/drawable/ripple.xml
index b8836f48..eef2532d 100644
--- a/qksms/src/main/res/drawable/ripple.xml
+++ b/qksms/src/main/res/drawable/ripple.xml
@@ -19,10 +19,27 @@
-->
+
-
-
+
+
+ -
+
+
-
+
+
+
+
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/qksms/src/main/res/layout/drawer_view.xml b/qksms/src/main/res/layout/drawer_view.xml
index 3c7beea3..f0db39f8 100644
--- a/qksms/src/main/res/layout/drawer_view.xml
+++ b/qksms/src/main/res/layout/drawer_view.xml
@@ -18,6 +18,7 @@
~ along with QKSMS. If not, see .
-->
+
+
+
+
+
+
+
+
diff --git a/qksms/src/main/res/layout/qksms_plus_activity.xml b/qksms/src/main/res/layout/qksms_plus_activity.xml
new file mode 100644
index 00000000..891cc403
--- /dev/null
+++ b/qksms/src/main/res/layout/qksms_plus_activity.xml
@@ -0,0 +1,360 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/qksms/src/main/res/layout/theme_list_item.xml b/qksms/src/main/res/layout/theme_list_item.xml
index e8e46056..4a55f7e0 100644
--- a/qksms/src/main/res/layout/theme_list_item.xml
+++ b/qksms/src/main/res/layout/theme_list_item.xml
@@ -27,8 +27,15 @@
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center"
- android:layout_margin="8dp"
android:background="@drawable/circle"
tools:backgroundTint="@color/tools_theme" />
+
+
\ No newline at end of file
diff --git a/qksms/src/main/res/layout/theme_palette_list_item.xml b/qksms/src/main/res/layout/theme_palette_list_item.xml
new file mode 100644
index 00000000..3bf4168a
--- /dev/null
+++ b/qksms/src/main/res/layout/theme_palette_list_item.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/qksms/src/main/res/layout/theme_picker_activity.xml b/qksms/src/main/res/layout/theme_picker_activity.xml
new file mode 100644
index 00000000..5ce56e01
--- /dev/null
+++ b/qksms/src/main/res/layout/theme_picker_activity.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/qksms/src/main/res/values/strings.xml b/qksms/src/main/res/values/strings.xml
index bf63b316..076008c6 100644
--- a/qksms/src/main/res/values/strings.xml
+++ b/qksms/src/main/res/values/strings.xml
@@ -24,8 +24,10 @@
Scheduled
Blocked
Settings
+ Theme
Search inbox…
Type a name or number
+ QKSMS+
Love texting again
Make QKSMS your default SMS app
@@ -58,6 +60,7 @@
Blocked
More
Settings
+ QKSMS+
Help & feedback
Your conversations will appear here
@@ -85,6 +88,36 @@
Sync messages
Re-sync your messages with the native Android SMS database
+ Pay what you like, unlock everything
+ You can save a starving developer for as little as %s a year
+ Supporter
+ Donor
+ Philanthropist
+ /year
+ Upgrade to QKSMS+
+ Thank you for supporting QKSMS!
+ You now have access to all QKSMS+ features
+ Premium themes
+ Unlock beautiful theme colors not available on the Material Design palette
+ Custom auto-emoji
+ Create custom auto-emoji shortcuts
+ Message backup
+ Automatically back up your messages. Never again worry about losing your history if you change phones or your phone gets lost
+ Scheduled messages
+ Wait a few seconds before sending your message
+ Delayed sending
+ Wait a few seconds before sending your message
+ Automatic night mode
+ Enable night mode based on the time of day
+ Advanced blocking
+ Block messages that contain keywords or match patterns
+ Auto-forward
+ Automatically forward messages from certain senders
+ Auto-respond
+ Automatically respond to incoming messages with a preset response
+ More
+ QKSMS is under active development, and your subscription will include all future QKSMS+ features!
+
Theme
Reply
diff --git a/qksms/src/main/res/values/styles.xml b/qksms/src/main/res/values/styles.xml
index 2981fd4c..f4cc9730 100644
--- a/qksms/src/main/res/values/styles.xml
+++ b/qksms/src/main/res/values/styles.xml
@@ -49,6 +49,14 @@
- tertiary
+
+
+
+