fedilab-Android-App/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainApplication.java

90 lines
3.6 KiB
Java
Raw Normal View History

2017-05-05 16:36:04 +02:00
package fr.gouv.etalab.mastodon.activities;
/* Copyright 2017 Thomas Schneider
*
2017-07-10 10:33:24 +02:00
* This file is a part of Mastalab
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.
*
2017-07-10 10:33:24 +02:00
* Mastalab 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.
*
2017-08-04 11:11:27 +02:00
* You should have received a copy of the GNU General Public License along with Mastalab; 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;
import android.os.StrictMode;
2018-12-11 19:27:21 +01:00
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
2018-12-22 08:28:14 +01:00
import android.support.v4.content.ContextCompat;
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;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
2018-11-25 10:45:16 +01:00
import es.dmoral.toasty.Toasty;
2018-12-22 08:28:14 +01:00
import fr.gouv.etalab.mastodon.R;
2018-11-24 18:56:12 +01:00
import fr.gouv.etalab.mastodon.helper.Helper;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.jobs.ApplicationJob;
2017-08-29 16:22:57 +02:00
import fr.gouv.etalab.mastodon.jobs.NotificationsSyncJob;
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 29/04/2017.
* Main application, jobs are launched here.
2017-05-05 16:36:04 +02:00
*/
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
@Override
public void onCreate() {
super.onCreate();
JobManager.create(this).addJobCreator(new ApplicationJob());
2017-08-29 16:22:57 +02:00
NotificationsSyncJob.schedule(false);
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<>();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
2018-12-16 17:26:19 +01:00
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, null);
if( defaultLocaleString != null){
Locale defaultLocale;
if( defaultLocaleString.equals("zh-CN"))
defaultLocale = Locale.SIMPLIFIED_CHINESE;
else if( defaultLocaleString.equals("zh-TW"))
defaultLocale = Locale.TRADITIONAL_CHINESE;
else
defaultLocale = new Locale(defaultLocaleString);
SUPPORTED_LOCALES.add(defaultLocale);
}else {
SUPPORTED_LOCALES.add(Locale.getDefault());
}
2018-11-24 18:56:12 +01:00
LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES);
}catch (Exception ignored){ignored.printStackTrace();}
2018-12-22 08:28:14 +01:00
Toasty.Config.getInstance()
.setErrorColor(ContextCompat.getColor(getApplicationContext(), R.color.toasty_background))
.setInfoColor(ContextCompat.getColor(getApplicationContext(), R.color.toasty_background))
.setSuccessColor(ContextCompat.getColor(getApplicationContext(), R.color.toasty_background))
.setWarningColor(ContextCompat.getColor(getApplicationContext(), R.color.toasty_background))
.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.toasty_text))
.apply();
Toasty.Config.getInstance().apply();
}
2018-12-11 19:27:21 +01:00
@Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext(base);
MultiDex.install(MainApplication.this);
}
2017-05-05 16:36:04 +02:00
}