TubeLab-App-Android/app/src/main/java/app/fedilab/fedilabtube/BaseFedilabTube.java

79 lines
3.0 KiB
Java
Raw Normal View History

2020-06-26 18:17:17 +02:00
package app.fedilab.fedilabtube;
2020-07-01 16:36:08 +02:00
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* 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.
*
* TubeLab 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 TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
2020-06-26 18:17:17 +02:00
2020-11-20 18:48:29 +01:00
import android.app.NotificationChannel;
import android.app.NotificationManager;
2020-06-26 18:17:17 +02:00
import android.content.Context;
2020-10-13 14:30:08 +02:00
import android.content.SharedPreferences;
2020-11-20 18:48:29 +01:00
import android.os.Build;
2020-06-26 18:17:17 +02:00
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
2020-11-04 18:39:45 +01:00
import androidx.work.Configuration;
import androidx.work.WorkManager;
2020-06-26 18:17:17 +02:00
2020-11-20 18:48:29 +01:00
import net.gotev.uploadservice.UploadServiceConfig;
import net.gotev.uploadservice.observer.request.GlobalRequestObserver;
import java.util.Objects;
2020-06-30 19:06:54 +02:00
2020-10-13 14:30:08 +02:00
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.ThemeHelper;
2020-11-20 18:48:29 +01:00
import app.fedilab.fedilabtube.services.GlobalUploadObserver;
2020-11-04 18:39:45 +01:00
import app.fedilab.fedilabtube.worker.WorkHelper;
2020-10-13 14:30:08 +02:00
2020-12-14 16:41:29 +01:00
public class BaseFedilabTube extends MultiDexApplication {
2020-11-04 18:39:45 +01:00
2020-11-20 18:48:29 +01:00
static String UPLOAD_CHANNEL_ID = "upload_info_peertube";
2020-11-04 18:39:45 +01:00
@Override
public void onCreate() {
super.onCreate();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int interval = sharedpreferences.getInt(Helper.NOTIFICATION_INTERVAL, 60);
2020-11-11 10:34:28 +01:00
if (interval >= 15) {
2020-11-04 18:39:45 +01:00
WorkHelper.fetchNotifications(this, interval);
}
2020-11-20 18:48:29 +01:00
createNotificationChannel();
2020-12-14 16:41:29 +01:00
UploadServiceConfig.initialize(BaseFedilabTube.this, UPLOAD_CHANNEL_ID, true);
2020-11-20 18:48:29 +01:00
new GlobalRequestObserver(this, new GlobalUploadObserver());
2020-11-04 18:39:45 +01:00
}
2020-06-26 18:17:17 +02:00
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
2020-06-26 19:16:00 +02:00
2020-12-14 16:41:29 +01:00
MultiDex.install(BaseFedilabTube.this);
2020-10-13 14:30:08 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int themePref = sharedpreferences.getInt(Helper.SET_THEME, BuildConfig.default_theme);
2020-10-13 14:30:08 +02:00
ThemeHelper.switchTo(themePref);
2020-11-04 18:39:45 +01:00
2020-06-26 18:17:17 +02:00
}
2020-06-26 19:16:00 +02:00
2020-11-20 18:48:29 +01:00
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(UPLOAD_CHANNEL_ID,
getString(R.string.notification_channel_name),
NotificationManager.IMPORTANCE_LOW);
channel.setSound(null, null);
((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
}
}
2020-06-26 18:17:17 +02:00
}