/*
Copyright 2009-2015 Urban Airship Inc. All rights reserved.


Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.urbanairship.sample;

import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;

import com.urbanairship.UAirship;
import com.urbanairship.push.notifications.DefaultNotificationFactory;

public class SampleApplication extends Application {

    private static final String FIRST_RUN_KEY = "first_run";

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

        // Optionally, customize your config at runtime:
        //
        // AirshipConfigOptions options = new AirshipConfigOptions();
        // options.inProduction = false;
        // options.developmentAppKey = "Your Development App Key";
        // options.developmentAppSecret "Your Development App Secret";
        //
        // UAirship.takeOff(this, options);

        UAirship.takeOff(this, new UAirship.OnReadyCallback() {
            @Override
            public void onAirshipReady(UAirship airship) {
                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                boolean isFirstRun = preferences.getBoolean(FIRST_RUN_KEY, true);
                if (isFirstRun) {
                    preferences.edit().putBoolean(FIRST_RUN_KEY, false).apply();
                }

                configureAirship(airship, isFirstRun);
            }
        });
    }

    /**
     * Called when UAirship is finished taking off.
     * @param airship The UAirship singleton.
     * @param isFirstRun Flag indicating if this is a first app run.
     */
    private void configureAirship(UAirship airship, boolean isFirstRun) {
        // Customize the notification factory with the
        DefaultNotificationFactory factory = new DefaultNotificationFactory(this);
        factory.setColor(ContextCompat.getColor(this, R.color.color_primary));
        factory.setSmallIconId(R.drawable.ic_notification);

        // Set the custom factory
        airship.getPushManager().setNotificationFactory(factory);

        // Enable user notifications by default on first run
        if (isFirstRun) {
            airship.getPushManager().setUserNotificationsEnabled(true);
        }
    }
}

@@ -1785,17 +1785,27 @@
        /
-/
+*%0A         
  Optiona
@@ -1843,26 +1843,16 @@
 untime:%0A
-        //
 %0A       
@@ -1852,18 +1852,17 @@
         
-//
+ 
  Airship
@@ -1909,19 +1909,26 @@
 gOptions
+.Builder
 ()
-;
 %0A       
@@ -1932,61 +1932,74 @@
     
-// options.inProduction = false;%0A        // options.d
+        .setInProduction(!BuildConfig.DEBUG)%0A                .setD
 evel
@@ -2010,19 +2010,17 @@
 ntAppKey
- = 
+(
 %22Your De
@@ -2037,17 +2037,17 @@
 App Key%22
-;
+)
 %0A       
@@ -2051,20 +2051,21 @@
     
-// options.d
+        .setD
 evel
@@ -2079,17 +2079,17 @@
 ppSecret
- 
+(
 %22Your De
@@ -2113,20 +2113,170 @@
 ret%22
-;%0A        //
+)%0A                .setProductionAppKey(%22Your Production App Key%22)%0A                .setProductionAppSecret(%22Your Production App Secret%22)%0A                .build();%0A
 %0A   
@@ -2280,18 +2280,17 @@
         
-//
+ 
  UAirshi
@@ -2314,16 +2314,28 @@
 ptions);
+%0A         */
 %0A%0A      

Update samples with new config