68 lines
1.8 KiB
Java
68 lines
1.8 KiB
Java
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;
|
|
import org.mercury_im.messenger.di.component.DaggerAppComponent;
|
|
import org.mercury_im.messenger.di.module.AppModule;
|
|
import org.mercury_im.messenger.service.MercuryConnectionService;
|
|
|
|
|
|
public class MercuryImApplication extends Application {
|
|
|
|
static {
|
|
// Initialize Smack etc.
|
|
// new MercuryConfiguration();
|
|
}
|
|
|
|
private static MercuryImApplication INSTANCE;
|
|
private AppComponent appComponent;
|
|
private ClientStateHandler clientStateHandler = new ClientStateHandler();
|
|
|
|
public static MercuryImApplication getApplication() {
|
|
return INSTANCE;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
INSTANCE = this;
|
|
appComponent = createAppComponent();
|
|
|
|
registerActivityLifecycleCallbacks(clientStateHandler);
|
|
Notifications.initializeNotificationChannels(this);
|
|
|
|
startForegroundService();
|
|
}
|
|
|
|
/**
|
|
* Create the Dependency Injection graph.
|
|
*/
|
|
public AppComponent createAppComponent() {
|
|
AppComponent appComponent = DaggerAppComponent.builder()
|
|
.appModule(new AppModule(this))
|
|
.build();
|
|
|
|
appComponent.inject(this);
|
|
|
|
return appComponent;
|
|
}
|
|
|
|
public AppComponent getAppComponent() {
|
|
return appComponent;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|