summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/app/fedilab/android/MainApplication.java
blob: a2d40e7d0dc2f53fae46e18d6b6d8a202d5fa0ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package app.fedilab.android;
/* Copyright 2021 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */


import android.content.Context;
import android.content.SharedPreferences;
import android.os.StrictMode;

import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import androidx.preference.PreferenceManager;

import com.jaredrummler.cyanea.Cyanea;
import com.jaredrummler.cyanea.prefs.CyaneaTheme;

import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.DialogConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;

import java.util.List;

import es.dmoral.toasty.Toasty;


public class MainApplication extends MultiDexApplication {


    private static MainApplication app;

    public static MainApplication getApp() {
        return app;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this);


        Cyanea.init(this, super.getResources());
        List<CyaneaTheme> list = CyaneaTheme.Companion.from(getAssets(), "themes/cyanea_themes.json");
        boolean custom_theme = sharedpreferences.getBoolean("use_custom_theme", false);
        boolean no_theme_set = sharedpreferences.getBoolean("no_theme_set", true);
        if (no_theme_set && !custom_theme) {
            list.get(0).apply(Cyanea.getInstance());
            SharedPreferences.Editor editor = sharedpreferences.edit();
            editor.putBoolean("no_theme_set", false);
            editor.apply();
        }
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());

        Toasty.Config.getInstance().apply();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(MainApplication.this);
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this);
        boolean send_crash_reports = sharedpreferences.getBoolean(getString(R.string.SET_SEND_CRASH_REPORTS), false);
        if (send_crash_reports) {
            ACRA.init(this, new CoreConfigurationBuilder()
                    //core configuration:
                    .withBuildConfigClass(BuildConfig.class)
                    .withReportFormat(StringFormat.KEY_VALUE_LIST)
                    .withPluginConfigurations(
                            new MailSenderConfigurationBuilder()
                                    .withMailTo("hello@fedilab.app")
                                    .withReportAsFile(true)
                                    .withReportFileName("crash_report.txt")
                                    .withSubject("[Fedilab] - Crash Report " + BuildConfig.VERSION_CODE)
                                    .build(),
                            new DialogConfigurationBuilder()
                                    .withResIcon(R.mipmap.ic_launcher)
                                    .withText(getString(R.string.crash_title))
                                    .withCommentPrompt(getString(R.string.crash_message))
                                    .withResTheme(R.style.DialogDark)
                                    .withPositiveButtonText(getString(R.string.send_email))
                                    .withNegativeButtonText(getString(R.string.cancel))
                                    .build()
                    ).withReportContent(
                            ReportField.INSTALLATION_ID,
                            ReportField.APP_VERSION_CODE,
                            ReportField.ANDROID_VERSION,
                            ReportField.PHONE_MODEL,
                            ReportField.TOTAL_MEM_SIZE,
                            ReportField.AVAILABLE_MEM_SIZE,
                            ReportField.USER_CRASH_DATE,
                            ReportField.STACK_TRACE)
            );
        }
    }
}