From 06777bfef129bfd4024f592c0d3b4e24564554e6 Mon Sep 17 00:00:00 2001 From: Avior Date: Wed, 22 Mar 2023 14:32:17 +0100 Subject: [PATCH] feat: change to use strings (#9) --- gradle.properties | 2 ++ .../com/dzeio/crashhandler/CrashHandler.kt | 30 ++++++++++++++----- .../layout/crash_handler_activity_error.xml | 13 ++++---- library/src/main/res/values-fr/strings.xml | 17 +++++++---- library/src/main/res/values/strings.xml | 16 ++++++---- .../com/dzeio/crashhandlertest/Application.kt | 4 +-- .../crashhandlertest/ui/ErrorActivity.kt | 21 ++++++++++--- sample/src/main/res/values-fr/strings.xml | 12 ++++++++ sample/src/main/res/values/strings.xml | 15 ++++++---- 9 files changed, 96 insertions(+), 34 deletions(-) create mode 100644 sample/src/main/res/values-fr/strings.xml diff --git a/gradle.properties b/gradle.properties index 20ffd8a..b81a080 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,3 +16,5 @@ kotlin.code.style=official android.useAndroidX=true android.enableJetifier=false org.gradle.unsafe.configuration-cache=true +org.gradle.caching=true +org.gradle.configureondemand=true \ No newline at end of file diff --git a/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt b/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt index d638b6c..ab45f96 100644 --- a/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt +++ b/library/src/main/java/com/dzeio/crashhandler/CrashHandler.kt @@ -181,7 +181,7 @@ class CrashHandler private constructor( val now = Date().time // prepare to build debug string - var data = "Crash report:\n\n" + var data = "${application.getString(R.string.crash_handler_crash_report)}\n\n" data += prefix ?: "" @@ -193,10 +193,19 @@ class CrashHandler private constructor( "${Build.MANUFACTURER} ${Build.DEVICE}" } - data += "\n\non $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})" + data += "\n\n${application.getString( + R.string.crash_handler_hard_soft_infos, + deviceToReport, + Build.MODEL, + Build.VERSION.RELEASE, + Build.VERSION.SDK_INT + )}" // add the current time to it - data += "\n\nCrash happened at ${Date(now)}" + data += "\n\n${application.getString( + R.string.crash_handler_crash_happened, + Date(now).toString() + )}" // if lib as access to the preferences store if (prefs != null && prefsKey != null) { @@ -204,7 +213,10 @@ class CrashHandler private constructor( val lastCrash = prefs.getLong(prefsKey, 0L) // then add it to the logs :D - data += "\nLast crash happened at ${Date(lastCrash)}" + data += "\n${application.getString( + R.string.crash_handler_previous_crash, + Date(lastCrash).toString() + )}" // if a crash already happened just before it means the Error Activity crashed lul if (lastCrash >= now - 1000) { @@ -217,7 +229,7 @@ class CrashHandler private constructor( // try to send a toast indicating it Toast.makeText( application, - errorReporterCrashKey ?: R.string.error_reporter_crash, + errorReporterCrashKey ?: R.string.crash_handler_reporter_crash, Toast.LENGTH_LONG ).show() @@ -233,10 +245,14 @@ class CrashHandler private constructor( Log.i(TAG, "Collecting Error") // get Thread name and ID - data += "\n\nHappened on Thread \"${paramThread.name}\" (${paramThread.id})" + data += "\n\n${application.getString( + R.string.crash_handler_thread_infos, + paramThread.name, + paramThread.id + )}" // print exception backtrace - data += "\n\nException:\n${paramThrowable.stackTraceToString()}\n\n" + data += "\n\n${application.getString(R.string.crash_handler_error)}\n${paramThrowable.stackTraceToString()}\n\n" data += suffix ?: "" diff --git a/library/src/main/res/layout/crash_handler_activity_error.xml b/library/src/main/res/layout/crash_handler_activity_error.xml index ac66020..310c890 100644 --- a/library/src/main/res/layout/crash_handler_activity_error.xml +++ b/library/src/main/res/layout/crash_handler_activity_error.xml @@ -11,11 +11,12 @@ android:id="@+id/title" style="?textAppearanceHeadline5" android:layout_width="0dp" + android:textAlignment="center" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" - android:text="@string/error_app_crash" + android:text="@string/crash_handler_error_app_crash" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -27,7 +28,8 @@ android:layout_marginStart="8dp" android:layout_marginTop="16dp" android:layout_marginEnd="8dp" - android:text="@string/error_app_report" + android:textAlignment="center" + android:text="@string/crash_handler_error_app_report" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/title" /> @@ -48,7 +50,8 @@ android:id="@+id/error_text" style="?textAppearanceCaption" android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content" + android:textIsSelectable="true" /> @@ -59,7 +62,7 @@ android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginBottom="16dp" - android:text="@string/copy_to_clipboard" + android:text="@string/crash_handler_copy_to_clipboard" app:layout_constraintBottom_toTopOf="@+id/error_quit" app:layout_constraintEnd_toEndOf="@+id/error_quit" app:layout_constraintStart_toStartOf="@+id/error_quit" /> @@ -69,7 +72,7 @@ android:id="@+id/error_quit" android:layout_width="wrap_content" android:layout_height="0dp" - android:text="@string/quit" + android:text="@string/crash_handler_quit" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> diff --git a/library/src/main/res/values-fr/strings.xml b/library/src/main/res/values-fr/strings.xml index 6933b78..caa3ec3 100644 --- a/library/src/main/res/values-fr/strings.xml +++ b/library/src/main/res/values-fr/strings.xml @@ -1,9 +1,16 @@ - Une Erreur est survenu lors de l\'utilisation de l\'application - Merci d\'envoyer le rapport d\'erreur afin que nous puissions améliorer votre experience - Copier dans le presse papier - Quitter - Erreur lors de la géneration d\'un rapport d\'erreur + Une Erreur est survenu lors de l\'utilisation de l\'application + Merci d\'envoyer le rapport d\'erreur afin que nous puissions améliorer votre experience + Copier dans le presse papier + Quitter + Erreur lors de la géneration d\'un rapport d\'erreur + + sur %1$s (%2$s) avec Android %3$s (%4$d) + Plantage arrivé à %1$s + Plantage précédent arrivé à %1$s + Arrivé sur le thread "%1$s" (%2$d) + Erreur : + Rapport d\'erreur : \ No newline at end of file diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml index aeddc99..78fec61 100644 --- a/library/src/main/res/values/strings.xml +++ b/library/src/main/res/values/strings.xml @@ -2,10 +2,16 @@ - An Error Occurred in the application forcing it to close down - Please report it so we can enhance you\'re Android OpenHealth experience - Copy to clipboard - Quit - An error occurred while making the error report + An Error Occurred in the application forcing it to close down + Please report it so we can enhance you\'re Android OpenHealth experience + Copy to clipboard + Quit + An error occurred while making the error report + on%1$s (%2$s) running Android %3$s (%4$d) + Crash happened at %1$s + Previous crash happened at %1$s + Happened on Thread "%1$s" (%2$d) + Exception: + Crash Report: \ No newline at end of file diff --git a/sample/src/main/java/com/dzeio/crashhandlertest/Application.kt b/sample/src/main/java/com/dzeio/crashhandlertest/Application.kt index 3f2669f..b6f9c45 100644 --- a/sample/src/main/java/com/dzeio/crashhandlertest/Application.kt +++ b/sample/src/main/java/com/dzeio/crashhandlertest/Application.kt @@ -22,10 +22,10 @@ class Application : android.app.Application() { .withPrefsKey("com.dzeio.crashhandler.key") // a Prefix to add at the beginning the crash message .withPrefix( - "POKEMON" + "Pokémon" ) // a Suffix to add at the end of the crash message - .withSuffix("WHYYYYY") + .withSuffix("Suffix") // build & start the module .build().setup() } diff --git a/sample/src/main/java/com/dzeio/crashhandlertest/ui/ErrorActivity.kt b/sample/src/main/java/com/dzeio/crashhandlertest/ui/ErrorActivity.kt index 20294ad..23bf2dc 100644 --- a/sample/src/main/java/com/dzeio/crashhandlertest/ui/ErrorActivity.kt +++ b/sample/src/main/java/com/dzeio/crashhandlertest/ui/ErrorActivity.kt @@ -8,6 +8,7 @@ import android.os.Process import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.view.WindowCompat +import com.dzeio.crashhandlertest.R import com.dzeio.crashhandlertest.databinding.ActivityErrorBinding import kotlin.system.exitProcess @@ -48,14 +49,26 @@ class ErrorActivity : AppCompatActivity() { val intent = Intent(Intent.ACTION_SEND) intent.setDataAndType(Uri.parse("mailto:"), "text/plain") intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("report.openhealth@dzeio.com")) - intent.putExtra(Intent.EXTRA_SUBJECT, "Error report for application crash") - intent.putExtra(Intent.EXTRA_TEXT, "Send Report Email\n$data") + intent.putExtra( + Intent.EXTRA_SUBJECT, + getString(R.string.error_report_application_crash) + ) + intent.putExtra(Intent.EXTRA_TEXT, "${getString(R.string.send_email_report)}\n$data") // send intent try { - startActivity(Intent.createChooser(intent, "Send Report Email...")) + startActivity( + Intent.createChooser( + intent, + getString(R.string.send_email_report) + ) + ) } catch (e: ActivityNotFoundException) { - Toast.makeText(this, "Not Email client found :(", Toast.LENGTH_LONG).show() + Toast.makeText( + this, + getString(R.string.no_email_client_found), + Toast.LENGTH_LONG + ).show() } } diff --git a/sample/src/main/res/values-fr/strings.xml b/sample/src/main/res/values-fr/strings.xml new file mode 100644 index 0000000..80af28a --- /dev/null +++ b/sample/src/main/res/values-fr/strings.xml @@ -0,0 +1,12 @@ + + + Faire Planter l\'application + Je suis une erreur + Crash Handler Titre de page + Crash Handler sous-titre de page + E-Mail + Quitter + Aucun client E-Mail trouvé! + Envoyer le rapport de crash par E-Mail + Rapport d\'erreur pour le crash d\'application + \ No newline at end of file diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 991b1d9..833b5ac 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -1,10 +1,13 @@ Crash Handler - Crash app - I am an error - Crash Handler page title - crash handler page subtitle + Crash app + I am an error + Crash Handler page title + crash handler page subtitle Github - E-Mail - Quit + E-Mail + Quit + No E-Mail client found! + Send a Report E-Mail + Error report for the application crash \ No newline at end of file