From 0c4364609bf2cb6110075a95b0f2ecf5c5a88751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 24 May 2020 20:03:46 +0200 Subject: [PATCH] Show `check for updates` dialog before report a bug (#834) --- .../io/github/wulkanowy/ui/base/ErrorDialog.kt | 17 ++++++++++++++++- .../wulkanowy/ui/modules/about/AboutFragment.kt | 9 +++++++-- .../ui/modules/about/AboutPresenter.kt | 5 ++++- .../wulkanowy/ui/modules/about/AboutView.kt | 2 ++ .../github/wulkanowy/utils/ContextExtension.kt | 8 +++++++- app/src/main/res/values-de/strings.xml | 3 +++ app/src/main/res/values-pl/strings.xml | 3 +++ app/src/main/res/values-ru/strings.xml | 3 +++ app/src/main/res/values-uk/strings.xml | 3 +++ app/src/main/res/values/strings.xml | 5 +++++ 10 files changed, 53 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt b/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt index 5fd6a86a5..896e4ff1c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import android.widget.HorizontalScrollView import android.widget.Toast import android.widget.Toast.LENGTH_LONG +import androidx.appcompat.app.AlertDialog import androidx.core.content.getSystemService import io.github.wulkanowy.R import io.github.wulkanowy.databinding.DialogErrorBinding @@ -17,6 +18,7 @@ import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException import io.github.wulkanowy.sdk.exception.ServiceUnavailableException import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.getString +import io.github.wulkanowy.utils.openAppInMarket import io.github.wulkanowy.utils.openEmailClient import io.github.wulkanowy.utils.openInternetBrowser import java.io.InterruptedIOException @@ -74,7 +76,9 @@ class ErrorDialog : BaseDialogFragment() { Toast.makeText(context, R.string.all_copied, LENGTH_LONG).show() } errorDialogCancel.setOnClickListener { dismiss() } - errorDialogReport.setOnClickListener { openEmailClient(stringWriter.toString()) } + errorDialogReport.setOnClickListener { + openConfirmDialog { openEmailClient(stringWriter.toString()) } + } errorDialogMessage.text = resources.getString(error) errorDialogReport.isEnabled = when (error) { is UnknownHostException, @@ -88,6 +92,17 @@ class ErrorDialog : BaseDialogFragment() { } } + private fun openConfirmDialog(callback: () -> Unit) { + AlertDialog.Builder(requireContext()) + .setTitle(R.string.dialog_error_check_update) + .setMessage(R.string.dialog_error_check_update_message) + .setNeutralButton(R.string.about_feedback) { _, _ -> callback() } + .setPositiveButton(R.string.dialog_error_check_update) { _, _ -> + requireContext().openAppInMarket(::showMessage) + } + .show() + } + private fun openEmailClient(content: String) { requireContext().openEmailClient( chooserTitle = getString(R.string.about_feedback), diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt index 3828a2bc4..d85d01e9e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt @@ -14,6 +14,7 @@ import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.getCompatDrawable +import io.github.wulkanowy.utils.openAppInMarket import io.github.wulkanowy.utils.openEmailClient import io.github.wulkanowy.utils.openInternetBrowser import javax.inject.Inject @@ -98,8 +99,12 @@ class AboutFragment : BaseFragment(R.layout.fragment_about } } + override fun openAppInMarket() { + context?.openAppInMarket(::showMessage) + } + override fun openLogViewer() { - if (appInfo.isDebug) (activity as? MainActivity)?.pushView(LogViewerFragment.newInstance()) + (activity as? MainActivity)?.pushView(LogViewerFragment.newInstance()) } override fun openDiscordInvite() { @@ -115,7 +120,7 @@ class AboutFragment : BaseFragment(R.layout.fragment_about chooserTitle = getString(R.string.about_feedback), email = "wulkanowyinc@gmail.com", subject = "Zgłoszenie błędu", - body = requireContext().getString(R.string.about_feedback_template, + body = getString(R.string.about_feedback_template, "${appInfo.systemManufacturer} ${appInfo.systemModel}", appInfo.systemVersion.toString(), appInfo.versionName ), onActivityNotFound = { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutPresenter.kt index 27237ea6f..ee892adfc 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutPresenter.kt @@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.modules.about import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.ErrorHandler +import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.SchedulersProvider import timber.log.Timber @@ -12,6 +13,7 @@ class AboutPresenter @Inject constructor( schedulers: SchedulersProvider, errorHandler: ErrorHandler, studentRepository: StudentRepository, + private val appInfo: AppInfo, private val analytics: FirebaseAnalyticsHelper ) : BasePresenter(errorHandler, studentRepository, schedulers) { @@ -27,7 +29,8 @@ class AboutPresenter @Inject constructor( when (name) { versionRes?.first -> { Timber.i("Opening log viewer") - openLogViewer() + if (appInfo.isDebug) openLogViewer() + else openAppInMarket() analytics.logEvent("about_open", "name" to "log_viewer") } feedbackRes?.first -> { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutView.kt index 79b700ea3..4c4b002f9 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutView.kt @@ -25,6 +25,8 @@ interface AboutView : BaseView { fun updateData(data: List>) + fun openAppInMarket() + fun openLogViewer() fun openDiscordInvite() diff --git a/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt index 489e7e6fb..2b40cb476 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt @@ -10,7 +10,7 @@ import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils -import io.github.wulkanowy.R +import io.github.wulkanowy.BuildConfig.APPLICATION_ID @ColorInt fun Context.getThemeAttrColor(@AttrRes colorAttr: Int): Int { @@ -39,6 +39,12 @@ fun Context.openInternetBrowser(uri: String, onActivityNotFound: (uri: String) - } } +fun Context.openAppInMarket(onActivityNotFound: (uri: String) -> Unit) { + openInternetBrowser("market://details?id=${APPLICATION_ID}") { + openInternetBrowser("https://github.com/wulkanowy/wulkanowy/releases", onActivityNotFound) + } +} + fun Context.openEmailClient(chooserTitle: String, email: String, subject: String, body: String, onActivityNotFound: () -> Unit = {}) { val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")).apply { putExtra(Intent.EXTRA_EMAIL, arrayOf(email)) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 084e3a86d..4b1669371 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -269,6 +269,9 @@ Logs teilen Aktualisieren + + Check for updates + Before reporting a bug, check first if an update with the bug fix is available Inhalt Wiederhol diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 4bcfbb774..ffd66912c 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -289,6 +289,9 @@ Udostępnij logi Odśwież + + Sprawdź aktualizację + Przed zgłoszeniem błędu sprawdź wcześniej, czy dostępna jest już aktualizacja z poprawką błędu Treść Ponów diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 41771a3cf..c0c751960 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -289,6 +289,9 @@ Поделиться логами Обновить + + Check for updates + Before reporting a bug, check first if an update with the bug fix is available Содержание Повторить diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 652249c68..a63e5682a 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -289,6 +289,9 @@ Поділитися логами Оновити + + Check for updates + Before reporting a bug, check first if an update with the bug fix is available Зміст Повторити diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f13e031d..7793cd9c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -317,6 +317,11 @@ Refresh + + Check for updates + Before reporting a bug, check first if an update with the bug fix is available + + Content Retry