Integrate crash reporting (#418)

Disable minify to get proper logs

Enable it by default

Integrate crash reporting

Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/418
Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
M M Arif 2020-04-17 23:39:49 +00:00 committed by 6543
parent 30165f27ba
commit 0c6c596208
9 changed files with 138 additions and 6 deletions

View File

@ -36,6 +36,7 @@ dependencies {
def lifecycle_version = "2.2.0"
def markwon_version = '4.3.1'
def fastadapter = "3.3.1"
def acra = "5.5.0"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.1.0"
@ -85,4 +86,8 @@ dependencies {
implementation "com.mikepenz:fastadapter:$fastadapter"
implementation "com.mikepenz:fastadapter-commons:$fastadapter"
implementation "com.mikepenz:fastadapter-extensions:$fastadapter"
implementation "ch.acra:acra-mail:$acra"
implementation "ch.acra:acra-limiter:$acra"
implementation "ch.acra:acra-notification:$acra"
}

View File

@ -2,15 +2,28 @@ package org.mian.gitnex.activities;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import org.acra.ACRA;
import org.acra.BuildConfig;
import org.acra.annotation.AcraNotification;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.LimiterConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.FontsOverride;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
/**
* Author M M Arif
*/
@AcraNotification(resIcon = R.mipmap.app_logo,
resTitle = R.string.crashTitle,
resChannelName = R.string.setCrashReports,
resText = R.string.crashMessage)
public abstract class BaseActivity extends AppCompatActivity {
@Override
@ -71,6 +84,22 @@ public abstract class BaseActivity extends AppCompatActivity {
tinyDb.putString("enableCounterBadgesInit", "yes");
}
// enable crash reports by default
if(tinyDb.getString("crashReportingEnabledInit").isEmpty()) {
tinyDb.putBoolean("crashReportingEnabled", true);
tinyDb.putString("crashReportingEnabledInit", "yes");
}
if (tinyDb.getBoolean("crashReportingEnabled")) {
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setReportAsFile(true).setMailTo(getResources().getString(R.string.appEmail)).setSubject(getResources().getString(R.string.crashReportEmailSubject, AppUtil.getAppBuildNo(getApplicationContext()))).setEnabled(true);
ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class).setEnabled(true);
ACRA.init(getApplication(), ACRABuilder);
}
}
protected abstract int getLayoutResourceId();

View File

@ -76,6 +76,7 @@ public class SettingsFragment extends Fragment {
Switch counterBadgesSwitch = v.findViewById(R.id.switchCounterBadge);
Switch pdfModeSwitch = v.findViewById(R.id.switchPdfMode);
Switch crashReportsSwitch = v.findViewById(R.id.crashReportsSwitch);
TextView helpTranslate = v.findViewById(R.id.helpTranslate);
helpTranslate.setOnClickListener(v12 -> {
@ -158,6 +159,13 @@ public class SettingsFragment extends Fragment {
pdfModeSwitch.setChecked(false);
}
if(tinyDb.getBoolean("crashReportingEnabled")) {
crashReportsSwitch.setChecked(true);
}
else {
crashReportsSwitch.setChecked(false);
}
// fileviewer srouce code theme selection dialog
sourceCodeThemeFrame.setOnClickListener(view -> {
@ -239,6 +247,20 @@ public class SettingsFragment extends Fragment {
});
// crash reports switcher
crashReportsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(isChecked) {
tinyDb.putBoolean("crashReportingEnabled", true);
Toasty.info(getContext(), getResources().getString(R.string.settingsSave));
}
else {
tinyDb.putBoolean("crashReportingEnabled", false);
Toasty.info(getContext(), getResources().getString(R.string.settingsSave));
}
});
// theme selection dialog
themeFrame.setOnClickListener(view -> {

View File

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#368F73" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>
</vector>

View File

@ -7,7 +7,7 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor" >
android:background="?attr/primaryBackgroundColor">
<RelativeLayout
android:layout_width="match_parent"
@ -60,6 +60,20 @@
android:id="@+id/langLayout"
layout="@layout/settings_languages" />
<View
android:id="@+id/crashReportsDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="44dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_below="@id/langLayout" />
<include
android:id="@+id/reportingLayout"
layout="@layout/settings_reporting" />
</RelativeLayout>
</ScrollView>

View File

@ -23,15 +23,14 @@
android:id="@+id/pdfMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/pdfModeHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginTop="10dp"
android:layout_marginStart="44dp"
android:layout_marginEnd="4dp"
android:text="@string/settingsPdfModeHeaderText"

View File

@ -55,7 +55,6 @@
android:layout_marginEnd="4dp"
android:autoLink="web"
android:layout_marginTop="20dp"
android:layout_marginBottom="30dp"
android:text="@string/settingsHelpTranslateText"
android:textColor="@color/lightBlue"/>

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layoutReportingView"
android:orientation="vertical"
android:layout_below="@+id/crashReportsDivider"
android:background="?attr/primaryBackgroundColor">
<TextView
android:id="@+id/reportViewAppearance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:drawableStart="@drawable/ic_bug_report"
android:drawablePadding="20dp"
android:text="@string/reportViewerHeader"
android:textStyle="bold"
android:textColor="@color/colorDarkGreen"/>
<RelativeLayout
android:id="@+id/enableSendReports"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/enableReportsHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginStart="44dp"
android:layout_marginEnd="4dp"
android:text="@string/settingsEnableReportsText"
android:textColor="?attr/primaryTextColor"/>
<Switch
android:id="@+id/crashReportsSwitch"
android:layout_toEndOf="@+id/enableReportsHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:switchMinWidth="56dp"
android:layout_alignParentEnd="true"
android:gravity="end"
android:layout_gravity="end"
android:layout_marginBottom="30dp" />
</RelativeLayout>
</LinearLayout>

View File

@ -2,7 +2,7 @@
<string name="app_name" translatable="false">GitNex</string>
<string name="appAuthor" translatable="false">Developer : M M Arif</string>
<string name="appEmail" translatable="false">gitnex@gitnex.com</string>
<string name="appEmail" translatable="false">gitnex@swatian.com</string>
<string name="appRepo" translatable="false">Source code</string>
<string name="appRepoLink" translatable="false">https://gitea.com/gitnex/GitNex</string>
<string name="appRepoIssuesLink" translatable="false">https://gitea.com/gitnex/GitNex/issues</string>
@ -15,6 +15,7 @@
<string name="appVerBuild" translatable="false">%1$s / build %2$d</string>
<string name="appDesc" translatable="false">GitNex is a free, open-source Android client for Git repository management tool Gitea. GitNex is Licensed under GPLv3.\n\nThanks to all the contributors and donators for your generous work and donations.</string>
<string name="crowdInLink" translatable="false">https://crowdin.com/project/gitnex</string>
<string name="crashReportEmailSubject" translatable="false">[GitNex] - Crash Report #%1$d</string>
<string name="appRepoIssuesText" translatable="false">Report issues at Gitea</string>
<string name="supportText" translatable="false">Support the App on Liberapay</string>
@ -616,4 +617,10 @@
<string name="tabIssueOpen">Open</string>
<string name="tabIssueClosed">Closed</string>
<string name="reportViewerHeader">Crash Reports</string>
<string name="settingsEnableReportsText">Enable Crash Reports</string>
<string name="crashTitle">GitNex has stopped :(</string>
<string name="setCrashReports">Crash reports</string>
<string name="crashMessage">You can tap the OK button to send the crash report by email. It will help to fix it :)\n\nYou can also add additional content in the email. Thank you!</string>
</resources>