package com.kickstarter;

import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;

import com.facebook.FacebookSdk;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import net.danlew.android.joda.JodaTimeAndroid;
import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;

import java.net.CookieHandler;
import java.net.CookieManager;

import javax.inject.Inject;

import timber.log.Timber;

public class KSApplication extends Application {
  private ApplicationComponent component;
  private RefWatcher refWatcher;
  @Inject CookieManager cookieManager;

  @Override
  public void onCreate() {
    super.onCreate();

    // Log in debug mode, send to Hockey in production
    if (BuildConfig.DEBUG || isInUnitTests()) {
      Timber.plant(new Timber.DebugTree());
    } else {
      CrashManager.register(this, getString(R.string.hockey_app_id), new CrashManagerListener() {
        public boolean shouldAutoUploadCrashes() {
          return true;
        }
      });
    }

    if (!isInUnitTests()) {
      refWatcher = LeakCanary.install(this);
    }

    JodaTimeAndroid.init(this);

    component = DaggerApplicationComponent.builder()
      .applicationModule(new ApplicationModule(this))
      .build();
    component().inject(this);

    CookieHandler.setDefault(cookieManager);

    FacebookSdk.sdkInitialize(this);
  }

  public ApplicationComponent component() {
    return component;
  }

  public static RefWatcher getRefWatcher(@NonNull final Context context) {
    final KSApplication application = (KSApplication) context.getApplicationContext();
    return application.refWatcher;
  }

  protected boolean isInUnitTests() {
    return false;
  }
}

@@ -746,350 +746,253 @@
  // 
-Log in debug mode, send to Hockey in production%0A    if (BuildConfig.DEBUG %7C%7C isInUnitTests()) %7B%0A      Timber.plant(new Timber.DebugTree());%0A    %7D else %7B%0A      CrashManager.register(this, getString(R.string.hockey_app_id), new CrashManagerListener() %7B%0A        public boolean shouldAutoUploadCrashes() %7B%0A          return true;%0A        %7D%0A      %7D
+Only log for internal builds%0A    if (BuildConfig.FLAVOR.equals(%22internal%22)) %7B%0A      Timber.plant(new Timber.DebugTree());%0A    %7D%0A%0A    // Send crash reports in release builds%0A    if (!BuildConfig.DEBUG && !isInUnitTests()) %7B%0A      checkForCrashes(
 );%0A 
@@ -1684,11 +1684,233 @@
 lse;%0A  %7D
+%0A%0A  private void checkForCrashes() %7B%0A    CrashManager.register(this, getString(R.string.hockey_app_id), new CrashManagerListener() %7B%0A      public boolean shouldAutoUploadCrashes() %7B%0A        return true;%0A      %7D%0A    %7D);%0A  %7D
 %0A%7D%0A

Add crash reporting for any release build