Restrict theme picker for QKSMS+

This commit is contained in:
Moez Bhatti
2018-03-27 15:31:11 -04:00
parent 66346562c0
commit 40ae8d61c3
7 changed files with 45 additions and 15 deletions
@@ -29,14 +29,14 @@ class ThemePagerAdapter @Inject constructor(private val context: Context) : Page
override fun instantiateItem(container: ViewGroup, position: Int): Any { override fun instantiateItem(container: ViewGroup, position: Int): Any {
return when (position) { return when (position) {
1 -> container.findViewById(R.id.rgbPicker) 1 -> container.findViewById(R.id.hsvPicker)
else -> container.findViewById(R.id.materialColors) else -> container.findViewById(R.id.materialColors)
} }
} }
override fun getPageTitle(position: Int): CharSequence? { override fun getPageTitle(position: Int): CharSequence? {
return when (position) { return when (position) {
1 -> context.getString(R.string.theme_rgb) 1 -> context.getString(R.string.theme_plus)
else -> context.getString(R.string.theme_material) else -> context.getString(R.string.theme_material)
} }
} }
@@ -19,6 +19,7 @@
package feature.themepicker package feature.themepicker
import android.os.Bundle import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import com.jakewharton.rxbinding2.view.clicks import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R import com.moez.QKSMS.R
@@ -29,11 +30,12 @@ import common.util.extensions.setBackgroundTint
import common.util.extensions.setTint import common.util.extensions.setTint
import common.util.extensions.setVisible import common.util.extensions.setVisible
import injection.appComponent import injection.appComponent
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.theme_picker_activity.* import kotlinx.android.synthetic.main.theme_picker_activity.*
import kotlinx.android.synthetic.main.theme_picker_hsv.* import kotlinx.android.synthetic.main.theme_picker_hsv.*
import javax.inject.Inject import javax.inject.Inject
class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePickerView { class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePickerView {
override val viewModelClass = ThemePickerViewModel::class override val viewModelClass = ThemePickerViewModel::class
@@ -41,6 +43,7 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
override val hsvThemeSelectedIntent by lazy { picker.selectedColor } override val hsvThemeSelectedIntent by lazy { picker.selectedColor }
override val hsvThemeClearedIntent by lazy { clear.clicks() } override val hsvThemeClearedIntent by lazy { clear.clicks() }
override val hsvThemeAppliedIntent by lazy { apply.clicks() } override val hsvThemeAppliedIntent by lazy { apply.clicks() }
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
@Inject lateinit var themeAdapter: ThemeAdapter @Inject lateinit var themeAdapter: ThemeAdapter
@Inject lateinit var themePagerAdapter: ThemePagerAdapter @Inject lateinit var themePagerAdapter: ThemePagerAdapter
@@ -74,6 +77,13 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
.subscribe { color -> clear.setTint(color) } .subscribe { color -> clear.setTint(color) }
} }
override fun showQksmsPlusSnackbar() {
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
setAction(R.string.button_more, { viewQksmsPlusIntent.onNext(Unit) })
show()
}
}
override fun render(state: ThemePickerState) { override fun render(state: ThemePickerState) {
tabs.setThreadId(state.threadId) tabs.setThreadId(state.threadId)
@@ -20,6 +20,7 @@ package feature.themepicker
import common.base.QkView import common.base.QkView
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.subjects.Subject
interface ThemePickerView : QkView<ThemePickerState> { interface ThemePickerView : QkView<ThemePickerState> {
@@ -27,7 +28,9 @@ interface ThemePickerView : QkView<ThemePickerState> {
val hsvThemeSelectedIntent: Observable<Int> val hsvThemeSelectedIntent: Observable<Int>
val hsvThemeClearedIntent: Observable<*> val hsvThemeClearedIntent: Observable<*>
val hsvThemeAppliedIntent: Observable<*> val hsvThemeAppliedIntent: Observable<*>
val viewQksmsPlusIntent: Subject<Unit>
fun setCurrentTheme(color: Int) fun setCurrentTheme(color: Int)
fun showQksmsPlusSnackbar()
} }
@@ -22,7 +22,9 @@ import android.content.Intent
import com.f2prateek.rx.preferences2.Preference import com.f2prateek.rx.preferences2.Preference
import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable import com.uber.autodispose.kotlin.autoDisposable
import common.Navigator
import common.base.QkViewModel import common.base.QkViewModel
import common.util.BillingManager
import common.util.Colors import common.util.Colors
import injection.appComponent import injection.appComponent
import io.reactivex.rxkotlin.Observables import io.reactivex.rxkotlin.Observables
@@ -32,7 +34,9 @@ import javax.inject.Inject
class ThemePickerViewModel(intent: Intent) : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState()) { class ThemePickerViewModel(intent: Intent) : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState()) {
@Inject lateinit var billingManager: BillingManager
@Inject lateinit var colors: Colors @Inject lateinit var colors: Colors
@Inject lateinit var navigator: Navigator
@Inject lateinit var prefs: Preferences @Inject lateinit var prefs: Preferences
private val threadId = intent.extras?.getLong("threadId") ?: 0L private val threadId = intent.extras?.getLong("threadId") ?: 0L
@@ -74,8 +78,20 @@ class ThemePickerViewModel(intent: Intent) : QkViewModel<ThemePickerView, ThemeP
// Update the theme, when apply is clicked // Update the theme, when apply is clicked
view.hsvThemeAppliedIntent view.hsvThemeAppliedIntent
.withLatestFrom(view.hsvThemeSelectedIntent, { _, color -> color }) .withLatestFrom(view.hsvThemeSelectedIntent, { _, color -> color })
.withLatestFrom(billingManager.plusStatus, { color, upgradeStatus ->
if (upgradeStatus == BillingManager.UpgradeStatus.REGULAR) {
view.showQksmsPlusSnackbar()
} else {
theme.set(color)
}
})
.autoDisposable(view.scope()) .autoDisposable(view.scope())
.subscribe { color -> theme.set(color) } .subscribe()
// Show QKSMS+ activity
view.viewQksmsPlusIntent
.autoDisposable(view.scope())
.subscribe { navigator.showQksmsPlusActivity() }
// Reset the theme // Reset the theme
view.hsvThemeClearedIntent view.hsvThemeClearedIntent
@@ -146,6 +146,13 @@
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginBottom="8dp" /> android:layout_marginBottom="8dp" />
<common.widget.PreferenceView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_palette_black_24dp"
app:summary="@string/qksms_plus_themes_summary"
app:title="@string/qksms_plus_themes_title" />
<common.widget.PreferenceView <common.widget.PreferenceView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -172,14 +179,6 @@
android:textStyle="bold" android:textStyle="bold"
app:textColor="primary" /> app:textColor="primary" />
<common.widget.PreferenceView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.25"
app:icon="@drawable/ic_palette_black_24dp"
app:summary="@string/qksms_plus_themes_summary"
app:title="@string/qksms_plus_themes_title" />
<common.widget.PreferenceView <common.widget.PreferenceView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -17,9 +17,11 @@
~ You should have received a copy of the GNU General Public License ~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>. ~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout android:id="@+id/contentView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/toolbar" /> <include layout="@layout/toolbar" />
@@ -48,7 +50,7 @@
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<include <include
android:id="@+id/rgbPicker" android:id="@+id/hsvPicker"
layout="@layout/theme_picker_hsv" layout="@layout/theme_picker_hsv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
+1 -1
View File
@@ -141,7 +141,7 @@
<string name="widget_more">View more conversations</string> <string name="widget_more">View more conversations</string>
<string name="theme_material">Material</string> <string name="theme_material">Material</string>
<string name="theme_rgb">RGB</string> <string name="theme_plus">QKSMS+</string>
<string name="theme_apply">Apply</string> <string name="theme_apply">Apply</string>
<string name="notification_reply">Reply</string> <string name="notification_reply">Reply</string>