2019-05-13 03:19:17 +02:00
|
|
|
package org.mercury_im.messenger;
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
import android.app.NotificationChannel;
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
|
|
import org.mercury_im.messenger.di.component.AppComponent;
|
|
|
|
import org.mercury_im.messenger.di.component.DaggerAppComponent;
|
|
|
|
import org.mercury_im.messenger.di.module.AppModule;
|
|
|
|
import org.mercury_im.messenger.di.module.RepositoryModule;
|
|
|
|
import org.mercury_im.messenger.di.module.RoomModule;
|
2019-06-06 23:32:41 +02:00
|
|
|
import org.mercury_im.messenger.service.XmppConnectionService;
|
2019-05-13 03:19:17 +02:00
|
|
|
|
|
|
|
public class MercuryImApplication extends Application {
|
|
|
|
|
|
|
|
public static final String TAG = "Mercury-IM";
|
|
|
|
|
|
|
|
private static MercuryImApplication INSTANCE;
|
|
|
|
AppComponent appComponent;
|
|
|
|
|
|
|
|
public static MercuryImApplication getApplication() {
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
|
|
|
|
|
|
|
INSTANCE = this;
|
|
|
|
appComponent = DaggerAppComponent.builder()
|
|
|
|
.appModule(new AppModule(this))
|
|
|
|
.roomModule(new RoomModule(this))
|
|
|
|
.repositoryModule(new RepositoryModule())
|
|
|
|
.build();
|
|
|
|
|
|
|
|
appComponent.inject(this);
|
|
|
|
initializeNotificationChannels(this);
|
|
|
|
|
2019-06-06 23:32:41 +02:00
|
|
|
Intent serviceIntent = new Intent(getApplicationContext(), XmppConnectionService.class);
|
2019-05-13 03:19:17 +02:00
|
|
|
|
2019-06-06 23:32:41 +02:00
|
|
|
serviceIntent.setAction(XmppConnectionService.ACTION_START);
|
2019-05-13 03:19:17 +02:00
|
|
|
if (Build.VERSION.SDK_INT < 26) {
|
|
|
|
startService(serviceIntent);
|
|
|
|
} else {
|
|
|
|
startForegroundService(serviceIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initializeNotificationChannels(Context context) {
|
|
|
|
// Only necessary on Android O and upwards.
|
|
|
|
if (Build.VERSION.SDK_INT < 26) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationManager notificationManager =
|
|
|
|
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
|
|
|
// Foreground notification channel
|
|
|
|
String fName = getResources().getString(R.string.channel_name_foreground);
|
|
|
|
String fDescription = getResources().getString(R.string.channel_description_foreground);
|
|
|
|
|
|
|
|
NotificationChannel foreground = new NotificationChannel(Notifications.NOTIFICATION_CHANNEL__FOREGROUND_SERVICE,
|
|
|
|
fName, NotificationManager.IMPORTANCE_DEFAULT);
|
|
|
|
foreground.setDescription(fDescription);
|
|
|
|
foreground.setImportance(NotificationManager.IMPORTANCE_MIN);
|
|
|
|
foreground.setShowBadge(false);
|
|
|
|
notificationManager.createNotificationChannel(foreground);
|
|
|
|
}
|
|
|
|
|
|
|
|
public AppComponent getAppComponent() {
|
|
|
|
return appComponent;
|
|
|
|
}
|
|
|
|
}
|