Commit 96a47795 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Show a dialog to rate the app by chance

parent ef9900a0
......@@ -133,6 +133,17 @@ class MainActivity : NavigationDrawerActivity() {
}, getString(R.string.dialog_crashreporting_negative) to { dialog, _ ->
dialog.dismiss()
}, null)
} else if(getPreferences().totalAppLaunches > 6 && !getPreferences().hasAskedRateApp
&& Random.nextInt(0, 100) <= 15 && isPackageInstalled(this, "com.android.vending")) {
showInfoTextDialog(this, getString(R.string.dialog_raterequest_title),
getString(R.string.dialog_raterequest_message),
getString(R.string.dialog_join_group_positive) to { dialog, _ ->
dialog.dismiss()
rateApp()
}, getString(R.string.dialog_crashreporting_negative) to { dialog, _ ->
dialog.dismiss()
}, null)
getPreferences().hasAskedRateApp = true
}
if(resources.getBoolean(R.bool.add_default_hostsources)) {
val versionToStartFrom = getPreferences().hostSourcesVersion.let {
......@@ -229,7 +240,15 @@ class MainActivity : NavigationDrawerActivity() {
iconLeft = getDrawable(R.drawable.ic_star),
onLongClick = null,
onSimpleClick = { _, _, _ ->
rateApp()
AlertDialog.Builder(this@MainActivity, getPreferences().theme.dialogStyle)
.setMessage(R.string.dialog_rate_confirmation)
.setPositiveButton(R.string.all_yes) { _, _ ->
rateApp()
}
.setNegativeButton(R.string.all_no) { dialog, _ ->
dialog.dismiss()
}
.show()
false
})
}
......@@ -258,34 +277,33 @@ class MainActivity : NavigationDrawerActivity() {
}
}
private fun askRateApp() {
}
private fun rateApp() {
val appPackageName = this.packageName
val openStore = {
try {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$appPackageName")
)
)
} catch (e: ActivityNotFoundException) {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appPackageName")))
} catch (e: ActivityNotFoundException) {
try {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")
)
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(this, R.string.error_no_webbrowser_installed, Toast.LENGTH_LONG).show()
}
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(this, R.string.error_no_webbrowser_installed, Toast.LENGTH_LONG)
.show()
}
getPreferences().hasRatedApp = true
}
AlertDialog.Builder(this, getPreferences().theme.dialogStyle)
.setMessage(R.string.dialog_rate_confirmation)
.setPositiveButton(R.string.all_yes) { _, _ ->
openStore()
}
.setNegativeButton(R.string.all_no) { dialog, _ ->
dialog.dismiss()
}
.show()
getPreferences().hasRatedApp = true
}
override fun createStyleOptions(): StyleOptions {
......
......@@ -159,6 +159,7 @@ class AppSettingsSharedPreferences(context: Context) : AppSettings, SimpleTypedP
})
override var hasRatedApp: Boolean by booleanPref("has_rated_app", false)
var hasAskedRateApp:Boolean by booleanPref("asked_rate_app", false)
override var previousInstalledVersion:Int by nonOptionalOf(intPref("previous_version"),true, BuildConfig.VERSION_CODE)
override var showChangelog:Boolean by booleanPref("show_changelog", true)
override var exportedQueryCount:Int by intPref("exported_query_count", 0)
......
......@@ -179,4 +179,7 @@
<string name="dialog_vpninformation_title">How this app works</string>
<string name="dialog_vpninformation_message">Nebulo works by using a dummy VPN to capture all your DNS requests, which are then forwarded to a secure server of your choice.\nThis dummy VPN is not a real VPN and neither does it hide your identity, nor does it change your IP address.\n\nNo actual data, except for DNS requests, is transmitted using this app.</string>
<string name="dialog_raterequest_title">Are you enjoying Nebulo?</string>
<string name="dialog_raterequest_message">Hey there! If you are enjoying Nebulo, would you please take a moment to rate it on the store?</string>
</resources>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment