adding a Rate Us dialog prompt with stars

This commit is contained in:
tibbi 2020-03-04 19:30:38 +01:00
parent f34c879e08
commit 3de3b2e5cd
5 changed files with 125 additions and 10 deletions

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.commons.activities
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Build
import android.os.Bundle
@ -148,11 +147,7 @@ class AboutActivity : BaseSimpleActivity() {
} else {
about_rate_us.setOnClickListener {
if (baseConfig.wasBeforeRateShown) {
try {
launchViewIntent("market://details?id=${packageName.removeSuffix(".debug")}")
} catch (ignored: ActivityNotFoundException) {
launchViewIntent(getStoreUrl())
}
redirectToRateUs()
} else {
baseConfig.wasBeforeRateShown = true
val msg = "${getString(R.string.before_rate_read_faq)}\n\n${getString(R.string.make_sure_latest)}"

View file

@ -0,0 +1,43 @@
package com.simplemobiletools.commons.dialogs
import android.app.Activity
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_rate_stars.view.*
class RateStarsDialog(val activity: Activity) {
private var dialog: AlertDialog
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_rate_stars, null).apply {
val textColor = activity.baseConfig.textColor
arrayOf(rate_star_1, rate_star_2, rate_star_3, rate_star_4, rate_star_5).forEach {
it.applyColorFilter(textColor)
}
rate_star_1.setOnClickListener { dialogCancelled(true) }
rate_star_2.setOnClickListener { dialogCancelled(true) }
rate_star_3.setOnClickListener { dialogCancelled(true) }
rate_star_4.setOnClickListener { dialogCancelled(true) }
rate_star_5.setOnClickListener {
activity.redirectToRateUs()
dialogCancelled(true)
}
}
dialog = AlertDialog.Builder(activity)
.setNegativeButton(R.string.cancel) { dialog, which -> dialogCancelled(false) }
.setOnCancelListener { dialogCancelled(false) }
.create().apply {
activity.setupDialogStuff(view, this)
}
}
private fun dialogCancelled(showThankYou: Boolean) {
dialog.dismiss()
if (showThankYou) {
activity.toast(R.string.thank_you)
}
}
}

View file

@ -71,7 +71,7 @@ fun Activity.appLaunched(appId: String) {
if (baseConfig.appRunCount > 60 && !baseConfig.wasRateUsPromptShown) {
baseConfig.wasRateUsPromptShown = true
RateUsDialog(this)
RateStarsDialog(this)
}
if (baseConfig.navigationBarColor == INVALID_NAVIGATION_BAR_COLOR && (window.attributes.flags and WindowManager.LayoutParams.FLAG_FULLSCREEN == 0)) {
@ -170,6 +170,14 @@ fun Activity.launchViewIntent(url: String) {
}
}
fun Activity.redirectToRateUs() {
try {
launchViewIntent("market://details?id=${packageName.removeSuffix(".debug")}")
} catch (ignored: ActivityNotFoundException) {
launchViewIntent(getStoreUrl())
}
}
fun Activity.sharePathIntent(path: String, applicationId: String) {
ensureBackgroundThread {
val newUri = getFinalUriFromPath(path, applicationId) ?: return@ensureBackgroundThread

View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/rate_stars_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:gravity="center_horizontal"
android:text="@string/rate_our_app"
android:textSize="@dimen/bigger_text_size" />
<LinearLayout
android:id="@+id/rate_stars_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="@dimen/activity_margin">
<ImageView
android:id="@+id/rate_star_1"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_margin="@dimen/tiny_margin"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_star_off_vector" />
<ImageView
android:id="@+id/rate_star_2"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_margin="@dimen/tiny_margin"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_star_off_vector" />
<ImageView
android:id="@+id/rate_star_3"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_margin="@dimen/tiny_margin"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_star_off_vector" />
<ImageView
android:id="@+id/rate_star_4"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_margin="@dimen/tiny_margin"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_star_off_vector" />
<ImageView
android:id="@+id/rate_star_5"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_margin="@dimen/tiny_margin"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_star_off_vector" />
</LinearLayout>
</LinearLayout>