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;
|
2017-07-18 19:55:27 +02:00
|
|
|
import android.os.StrictMode;
|
2018-12-11 19:27:21 +01:00
|
|
|
import android.support.multidex.MultiDex;
|
|
|
|
import android.support.multidex.MultiDexApplication;
|
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-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.HomeTimelineSyncJob;
|
|
|
|
import fr.gouv.etalab.mastodon.jobs.NotificationsSyncJob;
|
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
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
HomeTimelineSyncJob.schedule(false);
|
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<>();
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
2018-12-15 10:59:43 +01:00
|
|
|
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, Helper.getDefaultLocale());
|
2018-12-15 11:17:03 +01:00
|
|
|
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);
|
2018-11-24 18:56:12 +01:00
|
|
|
SUPPORTED_LOCALES.add(defaultLocale);
|
|
|
|
LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES);
|
|
|
|
}catch (Exception ignored){ignored.printStackTrace();}
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.Config.getInstance().apply();
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
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
|
|
|
}
|