1 package net.ktnx.mobileledger.ui;
3 import android.app.AlertDialog;
4 import android.app.Dialog;
5 import android.content.DialogInterface;
6 import android.content.Intent;
7 import android.os.Bundle;
8 import androidx.annotation.NonNull;
9 import androidx.annotation.Nullable;
10 import androidx.fragment.app.DialogFragment;
11 import android.view.LayoutInflater;
12 import android.view.View;
13 import android.widget.ScrollView;
14 import android.widget.TextView;
16 import net.ktnx.mobileledger.R;
17 import net.ktnx.mobileledger.utils.Globals;
19 public class CrashReportDialogFragment extends DialogFragment {
20 private String mCrashReportText;
21 private ScrollView repScroll = null;
24 public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
25 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
26 LayoutInflater inflater = getActivity().getLayoutInflater();
28 if (savedInstanceState != null)
29 mCrashReportText = savedInstanceState.getString("crash_text");
31 View view = inflater.inflate(R.layout.crash_dialog, null);
32 ((TextView) view.findViewById(R.id.textCrashReport)).setText(mCrashReportText);
33 repScroll = view.findViewById(R.id.scrollText);
34 builder.setTitle(R.string.crash_dialog_title).setView(view)
35 .setPositiveButton(R.string.btn_send_crash_report,
36 new DialogInterface.OnClickListener() {
38 public void onClick(DialogInterface dialog, int which) {
40 Intent email = new Intent(Intent.ACTION_SEND);
41 email.putExtra(Intent.EXTRA_EMAIL,
42 new String[]{Globals.developerEmail});
43 email.putExtra(Intent.EXTRA_SUBJECT, "MoLe crash report");
44 email.putExtra(Intent.EXTRA_TEXT, mCrashReportText);
45 email.setType("message/rfc822");
46 startActivity(Intent.createChooser(email,
47 getResources().getString(R.string.send_crash_via)));
50 .setNegativeButton(R.string.btn_not_now, new DialogInterface.OnClickListener() {
52 public void onClick(DialogInterface dialog, int which) {
53 CrashReportDialogFragment.this.getDialog().cancel();
56 .setNeutralButton(R.string.btn_show_report, new DialogInterface.OnClickListener() {
58 public void onClick(DialogInterface dialog, int which) {
62 AlertDialog dialog = builder.create();
63 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
65 public void onShow(DialogInterface dialogIinterface) {
66 dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
67 .setOnClickListener(new View.OnClickListener() {
69 public void onClick(View v) {
70 if (repScroll != null) {
71 repScroll.setVisibility(View.VISIBLE);
72 v.setVisibility(View.GONE);
81 public void onSaveInstanceState(@NonNull Bundle outState) {
82 super.onSaveInstanceState(outState);
83 outState.putString("crash_text", mCrashReportText);
85 public void setCrashReportText(String text) {
86 mCrashReportText = text;