]> git.ktnx.net Git - mobile-ledger-staging.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/CrashReportDialogFragment.java
fcb53193680f8b6c1f7f545203e07755df22dca1
[mobile-ledger-staging.git] / app / src / main / java / net / ktnx / mobileledger / ui / CrashReportDialogFragment.java
1 /*
2  * Copyright © 2019 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.ui;
19
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.content.DialogInterface;
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.widget.ScrollView;
28 import android.widget.TextView;
29
30 import androidx.annotation.NonNull;
31 import androidx.annotation.Nullable;
32 import androidx.fragment.app.DialogFragment;
33
34 import net.ktnx.mobileledger.R;
35 import net.ktnx.mobileledger.utils.Globals;
36
37 public class CrashReportDialogFragment extends DialogFragment {
38     private String mCrashReportText;
39     private ScrollView repScroll = null;
40     @NonNull
41     @Override
42     public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
43         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
44         LayoutInflater inflater = getActivity().getLayoutInflater();
45
46         if (savedInstanceState != null)
47             mCrashReportText = savedInstanceState.getString("crash_text");
48
49         View view = inflater.inflate(R.layout.crash_dialog, null);
50         ((TextView) view.findViewById(R.id.textCrashReport)).setText(mCrashReportText);
51         repScroll = view.findViewById(R.id.scrollText);
52         builder.setTitle(R.string.crash_dialog_title).setView(view)
53                 .setPositiveButton(R.string.btn_send_crash_report,
54                         new DialogInterface.OnClickListener() {
55                             @Override
56                             public void onClick(DialogInterface dialog, int which) {
57                                 // still nothing
58                                 Intent email = new Intent(Intent.ACTION_SEND);
59                                 email.putExtra(Intent.EXTRA_EMAIL,
60                                         new String[]{Globals.developerEmail});
61                                 email.putExtra(Intent.EXTRA_SUBJECT, "MoLe crash report");
62                                 email.putExtra(Intent.EXTRA_TEXT, mCrashReportText);
63                                 email.setType("message/rfc822");
64                                 startActivity(Intent.createChooser(email,
65                                         getResources().getString(R.string.send_crash_via)));
66                             }
67                         })
68                 .setNegativeButton(R.string.btn_not_now, new DialogInterface.OnClickListener() {
69                     @Override
70                     public void onClick(DialogInterface dialog, int which) {
71                         CrashReportDialogFragment.this.getDialog().cancel();
72                     }
73                 })
74                 .setNeutralButton(R.string.btn_show_report, new DialogInterface.OnClickListener() {
75                     @Override
76                     public void onClick(DialogInterface dialog, int which) {
77                     }
78                 });
79
80         AlertDialog dialog = builder.create();
81         dialog.setOnShowListener(new DialogInterface.OnShowListener() {
82             @Override
83             public void onShow(DialogInterface dialogInterface) {
84                 dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
85                         .setOnClickListener(new View.OnClickListener() {
86                             @Override
87                             public void onClick(View v) {
88                                 if (repScroll != null) {
89                                     repScroll.setVisibility(View.VISIBLE);
90                                     v.setVisibility(View.GONE);
91                                 }
92                             }
93                         });
94             }
95         });
96         return dialog;
97     }
98     @Override
99     public void onSaveInstanceState(@NonNull Bundle outState) {
100         super.onSaveInstanceState(outState);
101         outState.putString("crash_text", mCrashReportText);
102     }
103     public void setCrashReportText(String text) {
104         mCrashReportText = text;
105     }
106 }