forked from upstream-mirrors/quik
Add UI for rating app
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 mapper
|
||||
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import manager.AnalyticsManager
|
||||
import manager.RatingManager
|
||||
import javax.inject.Inject
|
||||
|
||||
class RatingManagerImpl @Inject constructor(
|
||||
rxPrefs: RxSharedPreferences,
|
||||
private val analyticsManager: AnalyticsManager
|
||||
) : RatingManager {
|
||||
|
||||
companion object {
|
||||
private const val SESSION_THRESHOLD = 100
|
||||
}
|
||||
|
||||
private val sessions = rxPrefs.getInteger("sessions", 0)
|
||||
private val rated = rxPrefs.getBoolean("rated", false)
|
||||
private val dismissed = rxPrefs.getBoolean("dismissed", false)
|
||||
|
||||
override val shouldShowRating = Observables.combineLatest(
|
||||
sessions.asObservable(),
|
||||
rated.asObservable(),
|
||||
dismissed.asObservable(), { sessions, rated, dismissed ->
|
||||
|
||||
sessions > SESSION_THRESHOLD && !rated && !dismissed
|
||||
})
|
||||
|
||||
override fun addSession() {
|
||||
sessions.set(sessions.get() + 1)
|
||||
}
|
||||
|
||||
override fun rate() {
|
||||
analyticsManager.track("Clicked Rate")
|
||||
rated.set(true)
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
analyticsManager.track("Clicked Rate (Dismiss)")
|
||||
dismissed.set(true)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 manager
|
||||
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface RatingManager {
|
||||
|
||||
val shouldShowRating: Observable<Boolean>
|
||||
|
||||
/**
|
||||
* Whether or not we should show the rating UI should depend on the number of sessions
|
||||
*/
|
||||
fun addSession()
|
||||
|
||||
fun rate()
|
||||
|
||||
fun dismiss()
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import android.app.Activity
|
||||
import android.app.ActivityOptions
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
@@ -56,6 +57,7 @@ import manager.NotificationManager
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
@Singleton
|
||||
class Navigator @Inject constructor(private val context: Context, private val notificationManager: NotificationManager) {
|
||||
|
||||
@@ -189,6 +191,20 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
fun showRating() {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${context.packageName}"))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
|
||||
or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
|
||||
or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
|
||||
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName)))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the Play Store and display the Should I Answer? listing
|
||||
*/
|
||||
|
||||
@@ -81,6 +81,8 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
plus.clicks().map { DrawerItem.PLUS },
|
||||
help.clicks().map { DrawerItem.HELP }))
|
||||
}
|
||||
override val dismissRatingIntent by lazy { rateDismiss.clicks() }
|
||||
override val rateIntent by lazy { rateOkay.clicks() }
|
||||
override val conversationClickIntent by lazy { conversationsAdapter.clicks }
|
||||
override val conversationLongClickIntent by lazy { conversationsAdapter.longClicks }
|
||||
override val conversationMenuItemIntent by lazy { dialog.adapter.menuItemClicks }
|
||||
@@ -137,6 +139,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
colors.theme
|
||||
.doOnNext { color -> syncingProgress.indeterminateTintList = ColorStateList.valueOf(color) }
|
||||
.doOnNext { color -> itemTouchCallback.color = color }
|
||||
.doOnNext { color -> rateIcon.setTint(color) }
|
||||
.doOnNext { color -> compose.setBackgroundTint(color) }
|
||||
.autoDisposable(scope())
|
||||
.subscribe()
|
||||
@@ -172,6 +175,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
.doOnNext { color -> inbox.background = rowBackground(color) }
|
||||
.doOnNext { color -> archived.background = rowBackground(color) }
|
||||
.doOnNext { color -> scheduled.background = rowBackground(color) }
|
||||
.doOnNext { color -> rateLayout.setBackgroundTint(color) }
|
||||
.autoDisposable(scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -189,6 +193,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
|
||||
syncing.setVisible(state.syncing)
|
||||
synced.setVisible(!state.syncing)
|
||||
rateLayout.setVisible(state.showRating)
|
||||
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
|
||||
@@ -24,7 +24,8 @@ import model.Conversation
|
||||
data class MainState(
|
||||
val page: MainPage = Inbox(),
|
||||
val drawerOpen: Boolean = false,
|
||||
val syncing: Boolean = false
|
||||
val syncing: Boolean = false,
|
||||
val showRating: Boolean = false
|
||||
)
|
||||
|
||||
sealed class MainPage
|
||||
|
||||
@@ -29,6 +29,8 @@ interface MainView : QkView<MainState> {
|
||||
val composeIntent: Observable<Unit>
|
||||
val drawerOpenIntent: Observable<Boolean>
|
||||
val drawerItemIntent: Observable<DrawerItem>
|
||||
val dismissRatingIntent: Observable<*>
|
||||
val rateIntent: Observable<*>
|
||||
val conversationClickIntent: Observable<Long>
|
||||
val conversationLongClickIntent: Observable<Long>
|
||||
val conversationMenuItemIntent: Observable<Int>
|
||||
|
||||
@@ -42,6 +42,7 @@ import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.realm.Realm
|
||||
import manager.RatingManager
|
||||
import model.SyncLog
|
||||
import repository.MessageRepository
|
||||
import util.Preferences
|
||||
@@ -52,7 +53,6 @@ import javax.inject.Inject
|
||||
class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var conversationFilter: ConversationFilter
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var markAllSeen: MarkAllSeen
|
||||
@@ -61,8 +61,10 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
@Inject lateinit var markUnarchived: MarkUnarchived
|
||||
@Inject lateinit var markBlocked: MarkBlocked
|
||||
@Inject lateinit var migratePreferences: MigratePreferences
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var partialSync: PartialSync
|
||||
@Inject lateinit var prefs: Preferences
|
||||
@Inject lateinit var ratingManager: RatingManager
|
||||
|
||||
private val menuArchive by lazy { MenuItem(context.getString(R.string.inbox_menu_archive), 0) }
|
||||
private val menuUnarchive by lazy { MenuItem(context.getString(R.string.inbox_menu_unarchive), 1) }
|
||||
@@ -95,6 +97,9 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.distinctUntilChanged()
|
||||
.subscribe { syncing -> newState { it.copy(syncing = syncing) } }
|
||||
|
||||
disposables += ratingManager.shouldShowRating
|
||||
.subscribe { show -> newState { it.copy(showRating = show) } }
|
||||
|
||||
// Migrate the preferences from 2.7.3 if necessary
|
||||
migratePreferences.execute(Unit)
|
||||
|
||||
@@ -110,6 +115,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
navigator.showSetupActivity()
|
||||
}
|
||||
|
||||
ratingManager.addSession()
|
||||
markAllSeen.execute(Unit)
|
||||
}
|
||||
|
||||
@@ -162,6 +168,17 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.rateIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
navigator.showRating()
|
||||
ratingManager.rate()
|
||||
}
|
||||
|
||||
view.dismissRatingIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { ratingManager.dismiss() }
|
||||
|
||||
view.conversationClickIntent
|
||||
.doOnNext { view.clearSearch() }
|
||||
.doOnNext { threadId -> navigator.showConversation(threadId) }
|
||||
|
||||
@@ -35,6 +35,7 @@ import manager.KeyManagerImpl
|
||||
import manager.NotificationManager
|
||||
import manager.PermissionManager
|
||||
import manager.PermissionManagerImpl
|
||||
import manager.RatingManager
|
||||
import manager.WidgetManager
|
||||
import manager.WidgetManagerImpl
|
||||
import mapper.CursorToContact
|
||||
@@ -45,8 +46,9 @@ import mapper.CursorToMessage
|
||||
import mapper.CursorToMessageImpl
|
||||
import mapper.CursorToPart
|
||||
import mapper.CursorToPartImpl
|
||||
import mapper.CursorToRecipientImpl
|
||||
import mapper.CursorToRecipient
|
||||
import mapper.CursorToRecipientImpl
|
||||
import mapper.RatingManagerImpl
|
||||
import repository.ContactRepository
|
||||
import repository.ContactRepositoryImpl
|
||||
import repository.ImageRepository
|
||||
@@ -95,6 +97,9 @@ class AppModule(private var application: Application) {
|
||||
@Provides
|
||||
fun providePermissionsManager(manager: PermissionManagerImpl): PermissionManager = manager
|
||||
|
||||
@Provides
|
||||
fun provideRatingManager(manager: RatingManagerImpl): RatingManager = manager
|
||||
|
||||
@Provides
|
||||
fun provideWidgetManager(manager: WidgetManagerImpl): WidgetManager = manager
|
||||
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingTop="8dp">
|
||||
android:paddingTop="8dp"
|
||||
tools:background="@color/white">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/inbox"
|
||||
@@ -134,4 +135,88 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:id="@+id/rateLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:background="@drawable/rounded_rectangle_outline_2dp"
|
||||
android:backgroundTint="@color/separatorLight">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/rateIcon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:src="@drawable/ic_favorite_black_24dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/rateSummary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/rateTitle"
|
||||
tools:tint="@color/tools_theme" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/rateTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/rate_title"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/rateIcon"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:textColor="primary"
|
||||
app:textSize="primary" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/rateSummary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="@string/rate_summary"
|
||||
app:layout_constraintEnd_toEndOf="@id/rateTitle"
|
||||
app:layout_constraintStart_toStartOf="@id/rateTitle"
|
||||
app:layout_constraintTop_toBottomOf="@id/rateTitle"
|
||||
app:textColor="secondary"
|
||||
app:textSize="secondary" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/rateDismiss"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:text="@string/rate_dismiss"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@id/rateOkay"
|
||||
app:layout_constraintTop_toBottomOf="@id/rateSummary"
|
||||
app:textColor="tertiary"
|
||||
app:textSize="secondary" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/rateOkay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="@drawable/ripple"
|
||||
android:padding="16dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/rate_okay"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/rateSummary"
|
||||
app:textColor="secondary"
|
||||
app:textSize="secondary" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -50,6 +50,11 @@
|
||||
<string name="drawer_plus">QKSMS+</string>
|
||||
<string name="drawer_help">Help & feedback</string>
|
||||
|
||||
<string name="rate_title">Enjoying QKSMS?</string>
|
||||
<string name="rate_summary">Share some love and rate us on Google Play!</string>
|
||||
<string name="rate_okay">OKAY!</string>
|
||||
<string name="rate_dismiss">DISMISS</string>
|
||||
|
||||
<string name="inbox_empty_text">Your conversations will appear here</string>
|
||||
<string name="inbox_search_empty_text">No results</string>
|
||||
<string name="inbox_menu_archive">Archive</string>
|
||||
|
||||
Reference in New Issue
Block a user