Mercury-IM/app/src/main/java/org/mercury_im/messenger/MercuryImApplication.java

68 lines
1.8 KiB
Java
Raw Normal View History

2019-05-13 03:19:17 +02:00
package org.mercury_im.messenger;
import android.app.Application;
import android.content.Intent;
import android.os.Build;
import org.mercury_im.messenger.di.component.AppComponent;
2019-12-06 15:52:50 +01:00
import org.mercury_im.messenger.di.component.DaggerAppComponent;
2019-05-13 03:19:17 +02:00
import org.mercury_im.messenger.di.module.AppModule;
2019-12-09 13:50:26 +01:00
import org.mercury_im.messenger.service.MercuryConnectionService;
2019-05-13 03:19:17 +02:00
2019-08-12 00:34:19 +02:00
2019-11-18 23:51:27 +01:00
public class MercuryImApplication extends Application {
2019-05-13 03:19:17 +02:00
2019-08-20 01:15:30 +02:00
static {
// Initialize Smack etc.
2019-12-06 15:52:50 +01:00
// new MercuryConfiguration();
2019-08-20 01:15:30 +02:00
}
2019-05-13 03:19:17 +02:00
private static MercuryImApplication INSTANCE;
private AppComponent appComponent;
private ClientStateHandler clientStateHandler = new ClientStateHandler();
2019-08-30 15:11:03 +02:00
2019-05-13 03:19:17 +02:00
public static MercuryImApplication getApplication() {
return INSTANCE;
}
2019-08-12 00:34:19 +02:00
2019-05-13 03:19:17 +02:00
@Override
public void onCreate() {
super.onCreate();
INSTANCE = this;
2019-08-03 19:05:50 +02:00
appComponent = createAppComponent();
registerActivityLifecycleCallbacks(clientStateHandler);
Notifications.initializeNotificationChannels(this);
2019-05-13 03:19:17 +02:00
startForegroundService();
2019-05-13 03:19:17 +02:00
}
2019-08-03 19:05:50 +02:00
/**
* Create the Dependency Injection graph.
*/
public AppComponent createAppComponent() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(new AppModule(this))
.build();
appComponent.inject(this);
return appComponent;
}
2019-05-13 03:19:17 +02:00
public AppComponent getAppComponent() {
return appComponent;
}
2019-08-30 15:11:03 +02:00
private void startForegroundService() {
Intent foregroundService = new Intent(getApplicationContext(), MercuryConnectionService.class);
foregroundService.setAction(MercuryConnectionService.ACTION_START);
if (Build.VERSION.SDK_INT < 26) {
startService(foregroundService);
} else {
startForegroundService(foregroundService);
2019-08-30 15:11:03 +02:00
}
}
2019-05-13 03:19:17 +02:00
}