<commit_before>package co.ello.ElloApp;

import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.WindowManager;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;

// Using a 3rd party Snackbar because we can't extend
// AppCompatActivity, thanks a lot XWalkActivity
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.enums.SnackbarType;
import com.nispok.snackbar.listeners.ActionClickListener;

import org.xwalk.core.JavascriptInterface;
import org.xwalk.core.XWalkActivity;
import org.xwalk.core.XWalkPreferences;
import org.xwalk.core.XWalkResourceClient;
import org.xwalk.core.XWalkView;

import javax.inject.Inject;

import co.ello.ElloApp.Dagger.ElloApp;
import co.ello.ElloApp.PushNotifications.RegistrationIntentService;


public class MainActivity
        extends XWalkActivity
        implements SwipeRefreshLayout.OnRefreshListener
{
    private final static String TAG = MainActivity.class.getSimpleName();

    @Inject
    protected Reachability reachability;

    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
    public static Boolean inBackground = true;
    public XWalkView xWalkView;
    private SwipeRefreshLayout swipeLayout;
    public String path = "https://ello.co";
    private ProgressDialog progress;
    private Boolean shouldReload = false;
    private Boolean isDeepLink = false;
    private BroadcastReceiver registerDeviceReceiver;
    private BroadcastReceiver pushReceivedReceiver;
    private Boolean isXWalkReady = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ((ElloApp) getApplication()).getNetComponent().inject(this);
        setContentView(R.layout.activity_main);
        swipeLayout = (SwipeRefreshLayout) findViewById(R.id.container);
        swipeLayout.setOnRefreshListener(this);

        setupWebView();
        // don't register the device for the initial release
        // coming soon to a theatre near you
//        setupRegisterDeviceReceiver();
//        setupPushReceivedReceiver();
    }

    protected void onXWalkReady() {
        isXWalkReady = true;
        xWalkView.getSettings().setUserAgentString(userAgentString());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)){
                XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
            }
        }

        xWalkView.addJavascriptInterface(this, "AndroidInterface");
        displayScreenContent();
        deepLinkWhenPresent();
    }

    @Override
    public void onRefresh() {
        if(!reachability.isNetworkConnected()) {
            displayScreenContent();
        }
        if(isXWalkReady) {
            xWalkView.reload(XWalkView.RELOAD_IGNORE_CACHE);
            progress.show();
        }
        swipeLayout.setRefreshing(false);
    }

    @Override
    protected void onStop() {
        super.onStop();
        inBackground = true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        inBackground = false;
        if(isXWalkReady) {
            xWalkView.resumeTimers();
            xWalkView.onShow();
        }

        if(!reachability.isNetworkConnected() || xWalkView == null) {
            displayScreenContent();
        }
        else if(shouldReload && isXWalkReady) {
            shouldReload = false;
            xWalkView.reload(XWalkView.RELOAD_IGNORE_CACHE);
        }
        deepLinkWhenPresent();
    }

    @Override
    protected void onPause() {
        if (isXWalkReady) {
            xWalkView.pauseTimers();
            xWalkView.onHide();
        }
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        xWalkView.onDestroy();
        if (registerDeviceReceiver != null) {
            unregisterReceiver(registerDeviceReceiver);
        }
        if (pushReceivedReceiver != null) {
            unregisterReceiver(pushReceivedReceiver);
        }
        super.onDestroy();
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
            shouldReload = true;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        xWalkView.onActivityResult(requestCode, resultCode, intent);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        Uri data = intent.getData();
        if (data != null) {
            path = data.toString();
            isDeepLink = true;
        }

        if (isXWalkReady) {
            xWalkView.onNewIntent(intent);
        }
    }

    @JavascriptInterface
    public void webAppLoaded() {
        if (progress != null) {
            progress.dismiss();
        }
        // uncomment for GCM when we go live with it !!
//        registerForGCM();
    }

    private void setupRegisterDeviceReceiver() {
        registerDeviceReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String reg_id = intent.getExtras().getString("GCM_REG_ID");
                String registerFunctionCall =
                        "javascript:registerAndroidNotifications(\"" +
                                reg_id + "\", \"" +
                                packageName() + "\", \"" +
                                versionName() + "\", \"" +
                                versionCode() + "\")";
                if(reg_id != null) {
                    xWalkView.load(registerFunctionCall, null);
                }
            }
        };

        registerReceiver(registerDeviceReceiver, new IntentFilter(ElloPreferences.REGISTRATION_COMPLETE));
    }<commit_msg>Reenable push registration<commit_after>package co.ello.ElloApp;

import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.WindowManager;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;

// Using a 3rd party Snackbar because we can't extend
// AppCompatActivity, thanks a lot XWalkActivity
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.enums.SnackbarType;
import com.nispok.snackbar.listeners.ActionClickListener;

import org.xwalk.core.JavascriptInterface;
import org.xwalk.core.XWalkActivity;
import org.xwalk.core.XWalkPreferences;
import org.xwalk.core.XWalkResourceClient;
import org.xwalk.core.XWalkView;

import javax.inject.Inject;

import co.ello.ElloApp.Dagger.ElloApp;
import co.ello.ElloApp.PushNotifications.RegistrationIntentService;


public class MainActivity
        extends XWalkActivity
        implements SwipeRefreshLayout.OnRefreshListener
{
    private final static String TAG = MainActivity.class.getSimpleName();

    @Inject
    protected Reachability reachability;

    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
    public static Boolean inBackground = true;
    public XWalkView xWalkView;
    private SwipeRefreshLayout swipeLayout;
    public String path = "https://ello.co";
    private ProgressDialog progress;
    private Boolean shouldReload = false;
    private Boolean isDeepLink = false;
    private BroadcastReceiver registerDeviceReceiver;
    private BroadcastReceiver pushReceivedReceiver;
    private Boolean isXWalkReady = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ((ElloApp) getApplication()).getNetComponent().inject(this);
        setContentView(R.layout.activity_main);
        swipeLayout = (SwipeRefreshLayout) findViewById(R.id.container);
        swipeLayout.setOnRefreshListener(this);

        setupWebView();
        setupRegisterDeviceReceiver();
        setupPushReceivedReceiver();
    }

    protected void onXWalkReady() {
        isXWalkReady = true;
        xWalkView.getSettings().setUserAgentString(userAgentString());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)){
                XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
            }
        }

        xWalkView.addJavascriptInterface(this, "AndroidInterface");
        displayScreenContent();
        deepLinkWhenPresent();
    }

    @Override
    public void onRefresh() {
        if(!reachability.isNetworkConnected()) {
            displayScreenContent();
        }
        if(isXWalkReady) {
            xWalkView.reload(XWalkView.RELOAD_IGNORE_CACHE);
            progress.show();
        }
        swipeLayout.setRefreshing(false);
    }

    @Override
    protected void onStop() {
        super.onStop();
        inBackground = true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        inBackground = false;
        if(isXWalkReady) {
            xWalkView.resumeTimers();
            xWalkView.onShow();
        }

        if(!reachability.isNetworkConnected() || xWalkView == null) {
            displayScreenContent();
        }
        else if(shouldReload && isXWalkReady) {
            shouldReload = false;
            xWalkView.reload(XWalkView.RELOAD_IGNORE_CACHE);
        }
        deepLinkWhenPresent();
    }

    @Override
    protected void onPause() {
        if (isXWalkReady) {
            xWalkView.pauseTimers();
            xWalkView.onHide();
        }
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        xWalkView.onDestroy();
        if (registerDeviceReceiver != null) {
            unregisterReceiver(registerDeviceReceiver);
        }
        if (pushReceivedReceiver != null) {
            unregisterReceiver(pushReceivedReceiver);
        }
        super.onDestroy();
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
            shouldReload = true;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        xWalkView.onActivityResult(requestCode, resultCode, intent);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        Uri data = intent.getData();
        if (data != null) {
            path = data.toString();
            isDeepLink = true;
        }

        if (isXWalkReady) {
            xWalkView.onNewIntent(intent);
        }
    }

    @JavascriptInterface
    public void webAppLoaded() {
        if (progress != null) {
            progress.dismiss();
        }
        registerForGCM();
    }

    private void setupRegisterDeviceReceiver() {
        registerDeviceReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String reg_id = intent.getExtras().getString("GCM_REG_ID");
                String registerFunctionCall =
                        "javascript:registerAndroidNotifications(\"" +
                                reg_id + "\", \"" +
                                packageName() + "\", \"" +
                                versionName() + "\", \"" +
                                versionCode() + "\")";
                if(reg_id != null) {
                    xWalkView.load(registerFunctionCall, null);
                }
            }
        };

        registerReceiver(registerDeviceReceiver, new IntentFilter(ElloPreferences.REGISTRATION_COMPLETE));
    }
{'fraction_non_alphanumeric': 0.09368874950999607, 'fraction_numerical': 0.0014112112896903176, 'mean_word_length': 2.5541933686263585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3828091', 'n_tokens_mistral': 3517, 'n_tokens_neox': 3408, 'n_words': 648}