diff --git a/app/src/fdroid/java/com/geeksville/mesh/android/GeeksvilleApplication.kt b/app/src/fdroid/java/com/geeksville/mesh/android/GeeksvilleApplication.kt index 66857d719..af47b17fd 100644 --- a/app/src/fdroid/java/com/geeksville/mesh/android/GeeksvilleApplication.kt +++ b/app/src/fdroid/java/com/geeksville/mesh/android/GeeksvilleApplication.kt @@ -8,9 +8,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.content.edit import com.geeksville.mesh.analytics.AnalyticsProvider -@Suppress("UNUSED_PARAMETER") -fun isGooglePlayAvailable(context: Context): Boolean = false - open class GeeksvilleApplication : Application(), Logging { companion object { @@ -55,3 +52,5 @@ open class GeeksvilleApplication : Application(), Logging { isAnalyticsAllowed = false } } + +fun Context.isGooglePlayAvailable(): Boolean = false \ No newline at end of file diff --git a/app/src/google/java/com/geeksville/mesh/android/GeeksvilleApplication.kt b/app/src/google/java/com/geeksville/mesh/android/GeeksvilleApplication.kt index 4c98cb571..d391bdf77 100644 --- a/app/src/google/java/com/geeksville/mesh/android/GeeksvilleApplication.kt +++ b/app/src/google/java/com/geeksville/mesh/android/GeeksvilleApplication.kt @@ -12,12 +12,6 @@ import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.GoogleApiAvailabilityLight import com.suddenh4x.ratingdialog.AppRating -fun isGooglePlayAvailable(context: Context): Boolean { - val a = GoogleApiAvailabilityLight.getInstance() - val r = a.isGooglePlayServicesAvailable(context) - return r != ConnectionResult.SERVICE_MISSING && r != ConnectionResult.SERVICE_INVALID -} - /** * Created by kevinh on 1/4/15. */ @@ -55,7 +49,8 @@ open class GeeksvilleApplication : Application(), Logging { /** Ask user to rate in play store */ fun askToRate(activity: AppCompatActivity) { - if (!isGooglePlayAvailable(this)) return + if (!isGooglePlayAvailable()) return + exceptionReporter { // we don't want to crash our app because of bugs in this optional feature AppRating.Builder(activity) .setMinimumLaunchTimes(10) // default is 5, 3 means app is launched 3 or more times @@ -76,3 +71,12 @@ open class GeeksvilleApplication : Application(), Logging { isAnalyticsAllowed = isAnalyticsAllowed } } + +fun Context.isGooglePlayAvailable(): Boolean { + return GoogleApiAvailabilityLight.getInstance() + .isGooglePlayServicesAvailable(this) + .let { + it != ConnectionResult.SERVICE_MISSING && + it != ConnectionResult.SERVICE_INVALID + } +} \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index 251d8b458..c3aab5e09 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -372,7 +372,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { } val app = (requireContext().applicationContext as GeeksvilleApplication) - val isGooglePlayAvailable = isGooglePlayAvailable(requireContext()) + val isGooglePlayAvailable = requireContext().isGooglePlayAvailable() val isAnalyticsAllowed = app.isAnalyticsAllowed && isGooglePlayAvailable // Set analytics checkbox @@ -387,19 +387,21 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { // report bug button only enabled if analytics is allowed binding.reportBugButton.isEnabled = isAnalyticsAllowed - binding.reportBugButton.setOnClickListener { - MaterialAlertDialogBuilder(requireContext()) - .setTitle(R.string.report_a_bug) - .setMessage(getString(R.string.report_bug_text)) - .setNeutralButton(R.string.cancel) { _, _ -> - debug("Decided not to report a bug") - } - .setPositiveButton(getString(R.string.report)) { _, _ -> - reportError("Clicked Report A Bug") - model.showSnackbar("Bug report sent!") - } - .show() - } + binding.reportBugButton.setOnClickListener(::showReportBugDialog) + } + + private fun showReportBugDialog(view: View) { + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.report_a_bug) + .setMessage(getString(R.string.report_bug_text)) + .setNeutralButton(R.string.cancel) { _, _ -> + debug("Decided not to report a bug") + } + .setPositiveButton(getString(R.string.report)) { _, _ -> + reportError("Clicked Report A Bug") + model.showSnackbar("Bug report sent!") + } + .show() } private fun addDeviceButton(device: BTScanModel.DeviceListEntry, enabled: Boolean) {