Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ dependencies {
}
implementation 'org.jsoup:jsoup:1.18.1'

implementation 'cat.ereza:customactivityoncrash:2.4.0'

testImplementation "junit:junit:4.13.2"
testImplementation "androidx.test:core:1.6.1"
testImplementation "androidx.test:core-ktx:1.6.1"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
android:exported="false">
</activity>

<activity
android:name=".utils.ErrorActivity"
android:exported="true"
android:label="@string/unknown_error"
android:process=":error_activity">
<intent-filter>
<action android:name="cat.ereza.customactivityoncrash.ERROR" />
</intent-filter>
</activity>

<receiver
android:name=".presentation.widget.WidgetProvider"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import com.philkes.notallyx.presentation.viewmodel.preference.SortDirection
import com.philkes.notallyx.presentation.viewmodel.preference.StringPreference
import com.philkes.notallyx.presentation.viewmodel.preference.TextProvider
import com.philkes.notallyx.utils.Operations
import com.philkes.notallyx.utils.Operations.catchNoBrowserInstalled
import com.philkes.notallyx.utils.Operations.reportBug
import com.philkes.notallyx.utils.canAuthenticateWithBiometrics
import com.philkes.notallyx.utils.security.decryptDatabase
import com.philkes.notallyx.utils.security.encryptDatabase
Expand Down Expand Up @@ -351,38 +353,28 @@ class SettingsFragment : Fragment() {
}

private fun createIssue() {
MaterialAlertDialogBuilder(requireContext())
val options =
arrayOf(getString(R.string.report_bug), getString(R.string.make_feature_request))
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.create_github_issue)
.setItems(options) { _, which ->
val intent =
when (which) {
0 -> {
val app = requireContext().applicationContext as Application
val logs = Operations.getLastExceptionLog(app)
Intent(
Intent.ACTION_VIEW,
Uri.parse(
"https://github.com/PhilKes/NotallyX/issues/new?labels=bug&projects=&template=bug_report.yml${logs?.let { "&logs=$it" } ?: ""}"
.take(2000)
),
when (which) {
0 -> {
val app = requireContext().applicationContext as Application
val logs = Operations.getLastExceptionLog(app)
reportBug(logs)
}
else ->
requireContext().catchNoBrowserInstalled {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse(
"https://github.com/PhilKes/NotallyX/issues/new?labels=enhancement&template=feature_request.md"
),
)
)
}
else ->
Intent(
Intent.ACTION_VIEW,
Uri.parse(
"https://github.com/PhilKes/NotallyX/issues/new?labels=enhancement&template=feature_request.md"
),
)
}
try {
startActivity(intent)
} catch (exception: ActivityNotFoundException) {
Toast.makeText(requireContext(), R.string.install_a_browser, Toast.LENGTH_LONG)
.show()
}
}
.setNegativeButton(R.string.cancel, null)
Expand Down
59 changes: 59 additions & 0 deletions app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.philkes.notallyx.utils

import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import cat.ereza.customactivityoncrash.CustomActivityOnCrash
import com.philkes.notallyx.R
import com.philkes.notallyx.presentation.dp
import com.philkes.notallyx.utils.Operations.reportBug

/**
* Activity used when the app is about to crash. Implicitly used by cat.ereza:customactivityoncrash.
*/
class ErrorActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(
cat.ereza.customactivityoncrash.R.layout.customactivityoncrash_default_error_activity
)
findViewById<ImageView>(
cat.ereza.customactivityoncrash.R.id.customactivityoncrash_error_activity_image
)
.apply {
minimumWidth = 100.dp(this@ErrorActivity)
minimumHeight = 100.dp(this@ErrorActivity)
setImageResource(R.drawable.error)
}
findViewById<Button>(
cat.ereza.customactivityoncrash.R.id
.customactivityoncrash_error_activity_restart_button
)
.apply {
setText(
cat.ereza.customactivityoncrash.R.string
.customactivityoncrash_error_activity_restart_app
)
setOnClickListener {
CustomActivityOnCrash.restartApplication(
this@ErrorActivity,
CustomActivityOnCrash.getConfigFromIntent(intent)!!,
)
}
}
val stackTrace = CustomActivityOnCrash.getStackTraceFromIntent(intent)
stackTrace?.let { Operations.log(application, stackTrace = it) }
findViewById<Button>(
cat.ereza.customactivityoncrash.R.id
.customactivityoncrash_error_activity_more_info_button
)
.apply {
setText(R.string.report_bug)
setOnClickListener {
reportBug(CustomActivityOnCrash.getStackTraceFromIntent(intent))
}
}
}
}
37 changes: 35 additions & 2 deletions app/src/main/java/com/philkes/notallyx/utils/Operations.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.philkes.notallyx.utils

import android.app.Application
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.net.Uri
import android.os.Build
import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.android.material.chip.ChipGroup
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.RelativeCornerSize
Expand Down Expand Up @@ -46,7 +50,7 @@ object Operations {
return null
}

fun log(app: Application, throwable: Throwable) {
fun log(app: Application, throwable: Throwable? = null, stackTrace: String? = null) {
Log.e(TAG, "Exception occurred", throwable)
val file = getLog(app)
val output = FileOutputStream(file, !file.exists() || !file.isLargerThan(2048))
Expand All @@ -56,7 +60,8 @@ object Operations {
val time = formatter.format(System.currentTimeMillis())

writer.println("[Start]")
throwable.printStackTrace(writer)
throwable?.printStackTrace(writer)
stackTrace?.let { writer.println(it) }
writer.println("Version code : " + BuildConfig.VERSION_CODE)
writer.println("Version name : " + BuildConfig.VERSION_NAME)
writer.println("Model : " + Build.MODEL)
Expand Down Expand Up @@ -135,6 +140,34 @@ object Operations {
return File(folder, "Log.v1.txt")
}

fun Fragment.reportBug(stackTrace: String?) {
requireContext().catchNoBrowserInstalled {
startActivity(createReportBugIntent(stackTrace))
}
}

fun Context.reportBug(stackTrace: String?) {
catchNoBrowserInstalled { startActivity(createReportBugIntent(stackTrace)) }
}

fun Context.catchNoBrowserInstalled(callback: () -> Unit) {
try {
callback()
} catch (exception: ActivityNotFoundException) {
Toast.makeText(this, R.string.install_a_browser, Toast.LENGTH_LONG).show()
}
}

private fun createReportBugIntent(stackTrace: String?): Intent {
return Intent(
Intent.ACTION_VIEW,
Uri.parse(
"https://github.com/PhilKes/NotallyX/issues/new?labels=bug&projects=&template=bug_report.yml&version=${BuildConfig.VERSION_NAME}&android-version=${Build.VERSION.SDK_INT}${stackTrace?.let { "&logs=$stackTrace"} ?: ""}"
.take(2000)
),
)
}

private fun getOutlinedDrawable(context: Context): MaterialShapeDrawable {
val model =
ShapeAppearanceModel.builder()
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,680Q497,680 508.5,668.5Q520,657 520,640Q520,623 508.5,611.5Q497,600 480,600Q463,600 451.5,611.5Q440,623 440,640Q440,657 451.5,668.5Q463,680 480,680ZM440,520L520,520L520,280L440,280L440,520ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,346 707,253Q614,160 480,160Q346,160 253,253Q160,346 160,480Q160,614 253,707Q346,800 480,800ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
</vector>