Skip to content

Commit

Permalink
added a crash dialog so users can report app crashes via email
Browse files Browse the repository at this point in the history
  • Loading branch information
MahmoudRH committed Jul 26, 2022
1 parent 3fc58b6 commit a80da8d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ dependencies {
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"

// ACRA crash report library
implementation "ch.acra:acra-mail:5.9.5"
implementation "ch.acra:acra-dialog:5.9.5"





}
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
package com.mahmoudrh.roomxml.application

import android.app.Application
import android.content.Context
import com.mahmoudrh.roomxml.BuildConfig
import com.mahmoudrh.roomxml.R
import com.mahmoudrh.roomxml.data.NotesDB
import com.mahmoudrh.roomxml.data.NotesRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.acra.config.dialog
import org.acra.config.mailSender
import org.acra.data.StringFormat
import org.acra.ktx.initAcra

class NotesApplication: Application() {

val applicationScope = CoroutineScope(SupervisorJob())

val database by lazy { NotesDB.getInstance(this,applicationScope) }
val repository by lazy { NotesRepository(database.NoteDAO()) }

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)

initAcra {
buildConfigClass = BuildConfig::class.java
reportFormat = StringFormat.JSON

dialog {
text = getString(R.string.dialog_text)
title = getString(R.string.dialog_title)
positiveButtonText = getString(R.string.dialog_positive)
negativeButtonText = getString(R.string.dialog_negative)
commentPrompt = getString(R.string.dialog_comment)
resIcon = R.drawable.ic_dialog_icon
resTheme = R.style.Theme_Material3_Light_Dialog
}

mailSender {
mailTo = "[email protected]"
subject = "D-Note Crash Report"
reportFileName = "Crash.txt"
}
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_dialog_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM15.5,11c0.83,0 1.5,-0.67 1.5,-1.5S16.33,8 15.5,8 14,8.67 14,9.5s0.67,1.5 1.5,1.5zM8.5,11c0.83,0 1.5,-0.67 1.5,-1.5S9.33,8 8.5,8 7,8.67 7,9.5 7.67,11 8.5,11zM12,14c-2.33,0 -4.31,1.46 -5.11,3.5h10.22c-0.8,-2.04 -2.78,-3.5 -5.11,-3.5z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
<string name="title_activity_note">NoteActivity</string>
<string name="title_activity_notes">NotesActivity</string>
<string name="search_hint">Search Notes</string>
<string name="dialog_text">Sorry.. Tha application crashed. Please send a report to the developers.</string>
<string name="dialog_title">D Note Crashed</string>
<string name="dialog_positive">Send</string>
<string name="dialog_negative">Don\'t Send</string>
<string name="dialog_comment">You can add a comment here:</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.Material3.Light.Dialog" />
</resources>

0 comments on commit a80da8d

Please sign in to comment.