App.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package eu.kanade.tachiyomi;
  2. import android.app.Application;
  3. import android.content.Context;
  4. import org.acra.ACRA;
  5. import org.acra.annotation.ReportsCrashes;
  6. import org.greenrobot.eventbus.EventBus;
  7. import eu.kanade.tachiyomi.data.preference.PreferencesHelper;
  8. import eu.kanade.tachiyomi.injection.ComponentReflectionInjector;
  9. import eu.kanade.tachiyomi.injection.component.AppComponent;
  10. import eu.kanade.tachiyomi.injection.component.DaggerAppComponent;
  11. import eu.kanade.tachiyomi.injection.module.AppModule;
  12. import timber.log.Timber;
  13. @ReportsCrashes(
  14. formUri = "http://tachiyomi.kanade.eu/crash_report",
  15. reportType = org.acra.sender.HttpSender.Type.JSON,
  16. httpMethod = org.acra.sender.HttpSender.Method.PUT,
  17. excludeMatchingSharedPreferencesKeys={".*username.*",".*password.*"}
  18. )
  19. public class App extends Application {
  20. AppComponent applicationComponent;
  21. ComponentReflectionInjector<AppComponent> componentInjector;
  22. private int theme = 0;
  23. public static App get(Context context) {
  24. return (App) context.getApplicationContext();
  25. }
  26. @Override
  27. public void onCreate() {
  28. super.onCreate();
  29. if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
  30. applicationComponent = prepareAppComponent().build();
  31. componentInjector =
  32. new ComponentReflectionInjector<>(AppComponent.class, applicationComponent);
  33. setupTheme();
  34. setupEventBus();
  35. setupAcra();
  36. }
  37. private void setupTheme() {
  38. theme = PreferencesHelper.getTheme(this);
  39. }
  40. protected DaggerAppComponent.Builder prepareAppComponent() {
  41. return DaggerAppComponent.builder()
  42. .appModule(new AppModule(this));
  43. }
  44. protected void setupEventBus() {
  45. EventBus.builder()
  46. .addIndex(new EventBusIndex())
  47. .logNoSubscriberMessages(false)
  48. .installDefaultEventBus();
  49. }
  50. protected void setupAcra() {
  51. ACRA.init(this);
  52. }
  53. public AppComponent getComponent() {
  54. return applicationComponent;
  55. }
  56. public ComponentReflectionInjector<AppComponent> getComponentReflection() {
  57. return componentInjector;
  58. }
  59. public int getAppTheme() {
  60. return theme;
  61. }
  62. public void setAppTheme(int theme) {
  63. this.theme = theme;
  64. }
  65. }