Enhance ExceptionActivity

https://github.com/nextcloud/news-android/pull/810/files
This commit is contained in:
stefan-niedermann 2020-01-08 17:12:46 +01:00
parent b11ed4da98
commit 48b70a5499

View file

@ -3,6 +3,8 @@ package it.niedermann.owncloud.notes.android.activity;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
@ -10,6 +12,8 @@ import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.nextcloud.android.sso.helper.VersionCheckHelper;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Objects;
@ -17,7 +21,6 @@ import java.util.Objects;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import it.niedermann.owncloud.notes.BuildConfig;
import it.niedermann.owncloud.notes.R;
public class ExceptionActivity extends AppCompatActivity {
@ -41,7 +44,35 @@ public class ExceptionActivity extends AppCompatActivity {
throwable.printStackTrace();
Objects.requireNonNull(getSupportActionBar()).setTitle(getString(R.string.simple_error));
this.message.setText(throwable.getMessage());
this.stacktrace.setText("Version: " + BuildConfig.VERSION_NAME + "\n\n" + getStacktraceOf(throwable));
String debugInfo = "";
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
debugInfo += "App Version: " + pInfo.versionName;
debugInfo += "\nApp Version Code: " + pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
debugInfo += "\nApp Version: " + e.getMessage();
e.printStackTrace();
}
try {
debugInfo += "\nFiles App Version Code: " + VersionCheckHelper.getNextcloudFilesVersionCode(this);
} catch (PackageManager.NameNotFoundException e) {
debugInfo += "\nFiles App Version Code: " + e.getMessage();
e.printStackTrace();
}
debugInfo += "\n\n---\n";
debugInfo += "\nOS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")";
debugInfo += "\nOS API Level: " + android.os.Build.VERSION.SDK_INT;
debugInfo += "\nDevice: " + android.os.Build.DEVICE;
debugInfo += "\nModel (and Product): " + android.os.Build.MODEL + " ("+ android.os.Build.PRODUCT + ")";
debugInfo += "\n\n---";
this.stacktrace.setText(debugInfo + "\n\n" + getStacktraceOf(throwable));
}
private String getStacktraceOf(Throwable e) {
@ -54,7 +85,7 @@ public class ExceptionActivity extends AppCompatActivity {
@OnClick(R.id.copy)
void copyStacktraceToClipboard() {
final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText(getString(R.string.simple_exception), this.stacktrace.getText());
ClipData clipData = ClipData.newPlainText(getString(R.string.simple_exception), "```\n" + this.stacktrace.getText() + "\n```");
clipboardManager.setPrimaryClip(clipData);
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}