From 6efc30b17d09c6d7c227cb4ed0eec507ada8d7d3 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 19 Jan 2022 23:40:03 -0500 Subject: [PATCH] In-app rate flow --- app/build.gradle | 5 +++++ .../java/io/heckel/ntfy/util/RateHelper.kt | 7 +++++++ .../java/io/heckel/ntfy/ui/MainActivity.kt | 20 +++++++++++++------ .../main/res/menu/menu_main_action_bar.xml | 5 +++-- app/src/main/res/values/strings.xml | 8 +++++--- .../java/io/heckel/ntfy/util/RateHelper.kt | 15 ++++++++++++++ .../metadata/android/en-US/changelog/17.txt | 1 + 7 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 app/src/fdroid/java/io/heckel/ntfy/util/RateHelper.kt create mode 100644 app/src/play/java/io/heckel/ntfy/util/RateHelper.kt diff --git a/app/build.gradle b/app/build.gradle index 58f6175..d652514 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } diff --git a/app/src/fdroid/java/io/heckel/ntfy/util/RateHelper.kt b/app/src/fdroid/java/io/heckel/ntfy/util/RateHelper.kt new file mode 100644 index 0000000..a83273e --- /dev/null +++ b/app/src/fdroid/java/io/heckel/ntfy/util/RateHelper.kt @@ -0,0 +1,7 @@ +package io.heckel.ntfy.util + +import android.app.Activity + +fun rateApp(activity: Activity) { + // Dummy to keep F-Droid flavor happy +} diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt index 9a2a22f..325cf3c 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -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) diff --git a/app/src/main/res/menu/menu_main_action_bar.xml b/app/src/main/res/menu/menu_main_action_bar.xml index bd213aa..4f50c91 100644 --- a/app/src/main/res/menu/menu_main_action_bar.xml +++ b/app/src/main/res/menu/menu_main_action_bar.xml @@ -6,6 +6,7 @@ - - + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 00b01d1..33bf4eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,9 +38,11 @@ Notifications disabled Notifications disabled until %1$s Settings - Report a bug - https://github.com/binwiederhier/ntfy/issues - Visit ntfy.sh + Report a bug + https://github.com/binwiederhier/ntfy/issues + Read the docs + https://ntfy.sh/docs + Rate this app ⭐ Unsubscribe diff --git a/app/src/play/java/io/heckel/ntfy/util/RateHelper.kt b/app/src/play/java/io/heckel/ntfy/util/RateHelper.kt new file mode 100644 index 0000000..5a388f8 --- /dev/null +++ b/app/src/play/java/io/heckel/ntfy/util/RateHelper.kt @@ -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) + } + } +} diff --git a/fastlane/metadata/android/en-US/changelog/17.txt b/fastlane/metadata/android/en-US/changelog/17.txt index d275cbe..ae30037 100644 --- a/fastlane/metadata/android/en-US/changelog/17.txt +++ b/fastlane/metadata/android/en-US/changelog/17.txt @@ -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)