In-app rate flow

This commit is contained in:
Philipp Heckel 2022-01-19 23:40:03 -05:00
parent a135f5b312
commit 6efc30b17d
7 changed files with 50 additions and 11 deletions

View file

@ -41,9 +41,11 @@ android {
productFlavors {
play {
buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'true'
buildConfigField 'boolean', 'RATE_APP_AVAILABLE', 'true'
}
fdroid {
buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'false'
buildConfigField 'boolean', 'RATE_APP_AVAILABLE', 'false'
}
}
@ -96,4 +98,7 @@ dependencies {
// Image viewer
implementation 'com.github.stfalcon-studio:StfalconImageViewer:v1.0.1'
// For "Rate this app" menu item (Google Play only)
playImplementation 'com.google.android.play:core-ktx:1.8.1'
}

View file

@ -0,0 +1,7 @@
package io.heckel.ntfy.util
import android.app.Activity
fun rateApp(activity: Activity) {
// Dummy to keep F-Droid flavor happy
}

View file

@ -17,13 +17,12 @@ import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.work.*
import io.heckel.ntfy.BuildConfig
import io.heckel.ntfy.R
import io.heckel.ntfy.app.Application
import io.heckel.ntfy.db.Repository
@ -260,6 +259,11 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
}
val mutedUntilSeconds = repository.getGlobalMutedUntil()
runOnUiThread {
// Show/hide in-app rate widget
val rateAppItem = menu.findItem(R.id.main_menu_rate)
rateAppItem.isVisible = BuildConfig.RATE_APP_AVAILABLE
// Pause notification icons
val notificationsEnabledItem = menu.findItem(R.id.main_menu_notifications_enabled)
val notificationsDisabledUntilItem = menu.findItem(R.id.main_menu_notifications_disabled_until)
val notificationsDisabledForeverItem = menu.findItem(R.id.main_menu_notifications_disabled_forever)
@ -291,12 +295,16 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
startActivity(Intent(this, SettingsActivity::class.java))
true
}
R.id.main_menu_source -> {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_source_url))))
R.id.main_menu_report_bug -> {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_report_bug_url))))
true
}
R.id.main_menu_website -> {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(appBaseUrl)))
R.id.main_menu_rate -> {
rateApp(this)
true
}
R.id.main_menu_docs -> {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_docs_url))))
true
}
else -> super.onOptionsItemSelected(item)

View file

@ -6,6 +6,7 @@
<item android:id="@+id/main_menu_notifications_disabled_forever" android:title="@string/detail_menu_notifications_disabled_forever"
app:showAsAction="ifRoom" android:icon="@drawable/ic_notifications_off_white_outline_24dp"/>
<item android:id="@+id/main_menu_settings" android:title="@string/main_menu_settings_title"/>
<item android:id="@+id/main_menu_source" android:title="@string/main_menu_source_title"/>
<item android:id="@+id/main_menu_website" android:title="@string/main_menu_website_title"/>
<item android:id="@+id/main_menu_docs" android:title="@string/main_menu_docs_title"/>
<item android:id="@+id/main_menu_rate" android:title="@string/main_menu_rate_title"/>
<item android:id="@+id/main_menu_report_bug" android:title="@string/main_menu_report_bug_title"/>
</menu>

View file

@ -38,9 +38,11 @@
<string name="main_menu_notifications_disabled_forever">Notifications disabled</string>
<string name="main_menu_notifications_disabled_until">Notifications disabled until %1$s</string>
<string name="main_menu_settings_title">Settings</string>
<string name="main_menu_source_title">Report a bug</string>
<string name="main_menu_source_url">https://github.com/binwiederhier/ntfy/issues</string>
<string name="main_menu_website_title">Visit ntfy.sh</string>
<string name="main_menu_report_bug_title">Report a bug</string>
<string name="main_menu_report_bug_url">https://github.com/binwiederhier/ntfy/issues</string>
<string name="main_menu_docs_title">Read the docs</string>
<string name="main_menu_docs_url">https://ntfy.sh/docs</string>
<string name="main_menu_rate_title">Rate this app ⭐</string>
<!-- Main activity: Action mode -->
<string name="main_action_mode_menu_unsubscribe">Unsubscribe</string>

View file

@ -0,0 +1,15 @@
package io.heckel.ntfy.util
import android.app.Activity
import com.google.android.play.core.review.ReviewManagerFactory
// Open the in-app rate dialog, see https://developer.android.com/guide/playcore/in-app-review/kotlin-java
fun rateApp(activity: Activity) {
val manager = ReviewManagerFactory.create(activity)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { task ->
if (task.isSuccessful) {
manager.launchReviewFlow(activity, task.result)
}
}
}

View file

@ -1,4 +1,5 @@
New features:
* Battery improvements: wakelock disabled by default (#76)
* Dark mode: Allow changing app appearance (#102)
* Report logs: Copy/export logs to help troubleshooting (#94)
* WebSockets (experimental): Use WebSockets to subscribe to topics (#96, #100, #97)