2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.activities;
|
2017-05-05 16:36:04 +02:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2017-05-05 16:36:04 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-05-05 16:36:04 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
2017-05-05 16:36:04 +02:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2018-11-24 18:56:12 +01:00
|
|
|
|
2018-12-11 19:27:21 +01:00
|
|
|
import android.content.Context;
|
2018-11-24 18:56:12 +01:00
|
|
|
import android.content.SharedPreferences;
|
2017-07-18 19:55:27 +02:00
|
|
|
import android.os.StrictMode;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-06-11 19:38:26 +02:00
|
|
|
import androidx.multidex.MultiDex;
|
|
|
|
import androidx.multidex.MultiDexApplication;
|
2019-11-10 19:20:44 +01:00
|
|
|
import androidx.preference.PreferenceManager;
|
2018-11-24 18:56:12 +01:00
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
import com.evernote.android.job.JobManager;
|
2018-11-24 18:56:12 +01:00
|
|
|
import com.franmontiel.localechanger.LocaleChanger;
|
2019-11-08 18:05:35 +01:00
|
|
|
import com.jaredrummler.cyanea.Cyanea;
|
2019-11-08 18:18:31 +01:00
|
|
|
import com.jaredrummler.cyanea.prefs.CyaneaTheme;
|
2018-11-24 18:56:12 +01:00
|
|
|
|
2019-01-07 15:27:06 +01:00
|
|
|
import net.gotev.uploadservice.UploadService;
|
|
|
|
|
2019-07-19 15:55:28 +02:00
|
|
|
import org.acra.ACRA;
|
|
|
|
import org.acra.annotation.AcraNotification;
|
|
|
|
import org.acra.config.CoreConfigurationBuilder;
|
|
|
|
import org.acra.config.LimiterConfigurationBuilder;
|
|
|
|
import org.acra.config.MailSenderConfigurationBuilder;
|
|
|
|
import org.acra.data.StringFormat;
|
|
|
|
|
2018-11-24 18:56:12 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
import app.fedilab.android.BuildConfig;
|
|
|
|
import app.fedilab.android.R;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.jobs.ApplicationJob;
|
2019-08-28 18:47:55 +02:00
|
|
|
import app.fedilab.android.jobs.BackupNotificationsSyncJob;
|
2019-08-06 15:12:17 +02:00
|
|
|
import app.fedilab.android.jobs.BackupStatusesSyncJob;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.jobs.NotificationsSyncJob;
|
2018-11-25 10:45:16 +01:00
|
|
|
import es.dmoral.toasty.Toasty;
|
2017-05-05 16:36:04 +02:00
|
|
|
|
2019-06-12 10:04:52 +02:00
|
|
|
import static app.fedilab.android.helper.Helper.initNetCipher;
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
/**
|
|
|
|
* Created by Thomas on 29/04/2017.
|
2017-05-20 15:15:02 +02:00
|
|
|
* Main application, jobs are launched here.
|
2017-05-05 16:36:04 +02:00
|
|
|
*/
|
|
|
|
|
2019-07-19 15:55:28 +02:00
|
|
|
@AcraNotification(
|
2019-09-25 13:55:03 +02:00
|
|
|
resIcon = R.mipmap.ic_launcher_bubbles, resTitle = R.string.crash_title, resChannelName = R.string.set_crash_reports, resText = R.string.crash_message)
|
2018-10-08 17:44:43 +02:00
|
|
|
|
2018-12-11 19:27:21 +01:00
|
|
|
public class MainApplication extends MultiDexApplication {
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
|
2019-02-14 10:06:18 +01:00
|
|
|
private static MainApplication app;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
public static MainApplication getApp() {
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2019-02-14 10:06:18 +01:00
|
|
|
app = this;
|
2019-02-13 09:06:00 +01:00
|
|
|
//System.setProperty("java.net.preferIPv4Stack" , "true");
|
2017-05-05 16:36:04 +02:00
|
|
|
JobManager.create(this).addJobCreator(new ApplicationJob());
|
2019-10-22 16:59:31 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
2019-10-21 17:25:13 +02:00
|
|
|
|
2019-10-22 16:59:31 +02:00
|
|
|
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
|
2019-11-15 16:32:25 +01:00
|
|
|
if (Helper.liveNotifType(getApplicationContext()) == Helper.NOTIF_NONE) {
|
|
|
|
NotificationsSyncJob.schedule(false);
|
2019-10-21 17:25:13 +02:00
|
|
|
}
|
2019-11-08 18:18:31 +01:00
|
|
|
|
2019-11-08 18:05:35 +01:00
|
|
|
Cyanea.init(this, super.getResources());
|
2019-11-08 18:18:31 +01:00
|
|
|
List<CyaneaTheme> list = CyaneaTheme.Companion.from(getAssets(), "themes/cyanea_themes.json");
|
|
|
|
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
if (theme == Helper.THEME_LIGHT) {
|
|
|
|
list.get(0).apply(Cyanea.getInstance());
|
|
|
|
} else if (theme == Helper.THEME_BLACK) {
|
|
|
|
list.get(2).apply(Cyanea.getInstance());
|
|
|
|
} else {
|
|
|
|
list.get(1).apply(Cyanea.getInstance());
|
|
|
|
}
|
2019-11-10 19:20:44 +01:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
int accent = prefs.getInt("theme_accent", -1);
|
|
|
|
int primary = prefs.getInt("theme_primary", -1);
|
|
|
|
int pref_color_background = prefs.getInt("pref_color_background", -1);
|
|
|
|
boolean pref_color_navigation_bar = prefs.getBoolean("pref_color_navigation_bar", true);
|
2019-11-13 09:05:20 +01:00
|
|
|
boolean pref_color_status_bar = prefs.getBoolean("pref_color_status_bar", true);
|
2019-11-11 15:47:53 +01:00
|
|
|
Cyanea.Editor editor = Cyanea.getInstance().edit();
|
2019-11-15 16:32:25 +01:00
|
|
|
if (primary != -1) {
|
2019-11-11 15:47:53 +01:00
|
|
|
editor.primary(primary);
|
2019-11-10 19:20:44 +01:00
|
|
|
}
|
2019-11-15 16:32:25 +01:00
|
|
|
if (accent != -1) {
|
2019-11-11 15:47:53 +01:00
|
|
|
editor.accent(accent);
|
2019-11-10 19:20:44 +01:00
|
|
|
}
|
2019-11-15 16:32:25 +01:00
|
|
|
if (pref_color_background != -1) {
|
2019-11-11 15:47:53 +01:00
|
|
|
editor
|
2019-11-15 16:32:25 +01:00
|
|
|
.background(pref_color_background)
|
|
|
|
.backgroundLight(pref_color_background)
|
|
|
|
.backgroundDark(pref_color_background).apply();
|
2019-11-10 19:20:44 +01:00
|
|
|
}
|
2019-11-13 09:05:20 +01:00
|
|
|
editor.shouldTintStatusBar(pref_color_status_bar).apply();
|
2019-11-11 15:47:53 +01:00
|
|
|
editor.shouldTintNavBar(pref_color_navigation_bar).apply();
|
2019-11-08 18:18:31 +01:00
|
|
|
|
2019-10-22 16:59:31 +02:00
|
|
|
ApplicationJob.cancelAllJob(BackupStatusesSyncJob.BACKUP_SYNC);
|
2019-08-06 15:12:17 +02:00
|
|
|
BackupStatusesSyncJob.schedule(false);
|
2019-10-22 16:59:31 +02:00
|
|
|
ApplicationJob.cancelAllJob(BackupNotificationsSyncJob.BACKUP_NOTIFICATIONS_SYNC);
|
2019-08-28 18:47:55 +02:00
|
|
|
BackupNotificationsSyncJob.schedule(false);
|
2019-10-22 16:59:31 +02:00
|
|
|
|
2019-11-07 19:07:19 +01:00
|
|
|
|
2017-07-18 19:55:27 +02:00
|
|
|
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
|
|
|
|
StrictMode.setVmPolicy(builder.build());
|
2018-11-24 18:56:12 +01:00
|
|
|
try {
|
|
|
|
List<Locale> SUPPORTED_LOCALES = new ArrayList<>();
|
2019-07-19 15:55:28 +02:00
|
|
|
|
2018-12-16 17:26:19 +01:00
|
|
|
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, null);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (defaultLocaleString != null) {
|
2018-12-16 17:26:19 +01:00
|
|
|
Locale defaultLocale;
|
2019-09-06 17:55:14 +02:00
|
|
|
if (defaultLocaleString.equals("zh-CN"))
|
2018-12-16 17:26:19 +01:00
|
|
|
defaultLocale = Locale.SIMPLIFIED_CHINESE;
|
2019-09-06 17:55:14 +02:00
|
|
|
else if (defaultLocaleString.equals("zh-TW"))
|
2018-12-16 17:26:19 +01:00
|
|
|
defaultLocale = Locale.TRADITIONAL_CHINESE;
|
|
|
|
else
|
|
|
|
defaultLocale = new Locale(defaultLocaleString);
|
|
|
|
SUPPORTED_LOCALES.add(defaultLocale);
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
2018-12-16 17:26:19 +01:00
|
|
|
SUPPORTED_LOCALES.add(Locale.getDefault());
|
|
|
|
}
|
2018-11-24 18:56:12 +01:00
|
|
|
LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES);
|
2019-09-06 17:55:14 +02:00
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2019-07-19 15:55:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
boolean send_crash_reports = sharedpreferences.getBoolean(Helper.SET_SEND_CRASH_REPORTS, false);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (send_crash_reports) {
|
2019-07-19 15:55:28 +02:00
|
|
|
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
|
|
|
|
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
|
2020-01-19 18:27:02 +01:00
|
|
|
int versionCode = BuildConfig.VERSION_CODE;
|
2020-03-28 12:20:15 +01:00
|
|
|
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setReportAsFile(true).setMailTo("hello@fedilab.app").setSubject("[Fedilab] - Crash Report " + versionCode).setEnabled(true);
|
2019-07-19 15:55:28 +02:00
|
|
|
ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class).setEnabled(true);
|
|
|
|
ACRA.init(this, ACRABuilder);
|
|
|
|
}
|
|
|
|
|
2019-01-07 15:27:06 +01:00
|
|
|
//Initialize upload service
|
|
|
|
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
|
2019-06-12 10:04:52 +02:00
|
|
|
initNetCipher(this);
|
2018-12-22 08:28:14 +01:00
|
|
|
Toasty.Config.getInstance()
|
2019-08-20 09:55:39 +02:00
|
|
|
.allowQueue(false)
|
2018-12-22 09:10:29 +01:00
|
|
|
.apply();
|
2019-09-06 17:55:14 +02:00
|
|
|
Toasty.Config.getInstance().apply();
|
|
|
|
}
|
2018-12-11 19:27:21 +01:00
|
|
|
|
|
|
|
@Override
|
2019-09-06 17:55:14 +02:00
|
|
|
protected void attachBaseContext(Context base) {
|
2018-12-11 19:27:21 +01:00
|
|
|
super.attachBaseContext(base);
|
|
|
|
MultiDex.install(MainApplication.this);
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|