]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/CrashReportDialogFragment.java
more pronounced day/month delimiters in the transaction list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / CrashReportDialogFragment.java
1 /*
2  * Copyright © 2020 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.Intent;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.widget.ScrollView;
27 import android.widget.TextView;
28
29 import androidx.annotation.NonNull;
30 import androidx.annotation.Nullable;
31 import androidx.fragment.app.DialogFragment;
32
33 import net.ktnx.mobileledger.R;
34 import net.ktnx.mobileledger.utils.Globals;
35
36 public class CrashReportDialogFragment extends DialogFragment {
37     private String mCrashReportText;
38     private ScrollView repScroll = null;
39     @NonNull
40     @Override
41     public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
42         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
43         LayoutInflater inflater = getActivity().getLayoutInflater();
44
45         if (savedInstanceState != null)
46             mCrashReportText = savedInstanceState.getString("crash_text");
47
48         View view = inflater.inflate(R.layout.crash_dialog, null);
49         ((TextView) view.findViewById(R.id.textCrashReport)).setText(mCrashReportText);
50         repScroll = view.findViewById(R.id.scrollText);
51         builder.setTitle(R.string.crash_dialog_title)
52                .setView(view)
53                .setPositiveButton(R.string.btn_send_crash_report, (dialog, which) -> {
54                    // still nothing
55                    Intent email = new Intent(Intent.ACTION_SEND);
56                    email.putExtra(Intent.EXTRA_EMAIL, new String[]{Globals.developerEmail});
57                    email.putExtra(Intent.EXTRA_SUBJECT, "MoLe crash report");
58                    email.putExtra(Intent.EXTRA_TEXT, mCrashReportText);
59                    email.setType("message/rfc822");
60                    startActivity(Intent.createChooser(email,
61                            getResources().getString(R.string.send_crash_via)));
62                })
63                .setNegativeButton(R.string.btn_not_now,
64                        (dialog, which) -> CrashReportDialogFragment.this.getDialog()
65                                                                         .cancel())
66                .setNeutralButton(R.string.btn_show_report, (dialog, which) -> {
67                });
68
69         AlertDialog dialog = builder.create();
70         dialog.setOnShowListener(dialogInterface -> dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
71                                                           .setOnClickListener(v -> {
72                                                               if (repScroll != null) {
73                                                                   repScroll.setVisibility(
74                                                                           View.VISIBLE);
75                                                                   v.setVisibility(View.GONE);
76                                                               }
77                                                           }));
78         return dialog;
79     }
80     @Override
81     public void onSaveInstanceState(@NonNull Bundle outState) {
82         super.onSaveInstanceState(outState);
83         outState.putString("crash_text", mCrashReportText);
84     }
85     public void setCrashReportText(String text) {
86         mCrashReportText = text;
87     }
88 }