<commit_before>package net.opencurlybraces.android.projects.wifitoggler.ui;

import android.app.LoaderManager;
import android.content.ContentValues;
import android.content.Intent;
import android.content.IntentSender;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsResult;
import com.google.android.gms.location.LocationSettingsStatusCodes;

import net.opencurlybraces.android.projects.wifitoggler.Config;
import net.opencurlybraces.android.projects.wifitoggler.R;
import net.opencurlybraces.android.projects.wifitoggler.WifiToggler;
import net.opencurlybraces.android.projects.wifitoggler.data.DataAsyncQueryHandler;
import net.opencurlybraces.android.projects.wifitoggler.data.table.SavedWifi;
import net.opencurlybraces.android.projects.wifitoggler.ui.SwipeDismissListViewTouchListener
        .DismissCallbacks;
import net.opencurlybraces.android.projects.wifitoggler.util.NetworkUtils;
import net.opencurlybraces.android.projects.wifitoggler.util.PrefUtils;
import net.opencurlybraces.android.projects.wifitoggler.util.SavedWifiDBUtils;
import net.opencurlybraces.android.projects.wifitoggler.util.SnackBarUndoActionDataHandler;
import net.opencurlybraces.android.projects.wifitoggler.util.StartupUtils;


public abstract class SavedWifiListActivityAbstract extends AppCompatActivity implements
        LoaderManager.LoaderCallbacks<Cursor>, DismissCallbacks, View.OnClickListener,
        GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
        ResultCallback<LocationSettingsResult> {

    private static final String TAG = "BaseListActivity";
    private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 1002;

    protected static final String INSTANCE_KEY_FIRST_VISIBLE_POSITION = "firstVisiblePosition";
    protected static final String INSTANCE_KEY_OFFSET_FROM_TOP = "offsetFromTop";

    protected SavedWifiListAdapter mSavedWifiCursorAdapter = null;
    protected ListView mWifiTogglerWifiList = null;
    protected TextView mEmptyView = null;

    private int REQUEST_CHECK_SETTINGS = 1003;
    private Bundle mSavedInstanceState = null;
    private SwipeDismissListViewTouchListener mTouchListener = null;
    private GoogleApiClient mGoogleApiClient = null;
    private LocationRequest mLocationRequest = null;

    DataAsyncQueryHandler mDataAsyncQueryHandler = null;

    protected abstract void bindViews();

    protected abstract void handleSnackBar(int dismissedObjectPosition);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (Config.DEBUG_MODE) {
            StartupUtils.startStrictMode();
        }
        super.onCreate(savedInstanceState);

        initCursorLoader();
        initCursorAdapter();
        initDataAsyncQueryHandler();
        handlePostLollipopRequirements();
    }


    @Override
    protected void onStart() {
        super.onStart();
        if (mGoogleApiClient != null) {
            mGoogleApiClient.connect();

            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                    .addLocationRequest(mLocationRequest);

            PendingResult<LocationSettingsResult> mLocationSettingsResult = LocationServices
                    .SettingsApi.checkLocationSettings
                            (mGoogleApiClient, builder
                                    .build());

            mLocationSettingsResult.setResultCallback(this);

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        setAdapter();
        restoreListViewState();
        if (NetworkUtils.isWifiEnabled(this)) {
            WifiToggler.removeDeletedSavedWifiFromDB(this);<commit_msg>Fix for issue #7 : SavedWifiListActivityAbstract is leaking<commit_after>package net.opencurlybraces.android.projects.wifitoggler.ui;

import android.app.LoaderManager;
import android.content.ContentValues;
import android.content.Intent;
import android.content.IntentSender;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsResult;
import com.google.android.gms.location.LocationSettingsStatusCodes;

import net.opencurlybraces.android.projects.wifitoggler.Config;
import net.opencurlybraces.android.projects.wifitoggler.R;
import net.opencurlybraces.android.projects.wifitoggler.WifiToggler;
import net.opencurlybraces.android.projects.wifitoggler.data.DataAsyncQueryHandler;
import net.opencurlybraces.android.projects.wifitoggler.data.table.SavedWifi;
import net.opencurlybraces.android.projects.wifitoggler.ui.SwipeDismissListViewTouchListener
        .DismissCallbacks;
import net.opencurlybraces.android.projects.wifitoggler.util.NetworkUtils;
import net.opencurlybraces.android.projects.wifitoggler.util.PrefUtils;
import net.opencurlybraces.android.projects.wifitoggler.util.SavedWifiDBUtils;
import net.opencurlybraces.android.projects.wifitoggler.util.SnackBarUndoActionDataHandler;
import net.opencurlybraces.android.projects.wifitoggler.util.StartupUtils;


public abstract class SavedWifiListActivityAbstract extends AppCompatActivity implements
        LoaderManager.LoaderCallbacks<Cursor>, DismissCallbacks, View.OnClickListener,
        GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
        ResultCallback<LocationSettingsResult> {

    private static final String TAG = "BaseListActivity";
    private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 1002;

    protected static final String INSTANCE_KEY_FIRST_VISIBLE_POSITION = "firstVisiblePosition";
    protected static final String INSTANCE_KEY_OFFSET_FROM_TOP = "offsetFromTop";

    protected SavedWifiListAdapter mSavedWifiCursorAdapter = null;
    protected ListView mWifiTogglerWifiList = null;
    protected TextView mEmptyView = null;

    private int REQUEST_CHECK_SETTINGS = 1003;
    private Bundle mSavedInstanceState = null;
    private SwipeDismissListViewTouchListener mTouchListener = null;
    private GoogleApiClient mGoogleApiClient = null;
    private LocationRequest mLocationRequest = null;

    DataAsyncQueryHandler mDataAsyncQueryHandler = null;

    protected abstract void bindViews();

    protected abstract void handleSnackBar(int dismissedObjectPosition);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (Config.DEBUG_MODE) {
            StartupUtils.startStrictMode();
        }
        super.onCreate(savedInstanceState);

        initCursorLoader();
        initCursorAdapter();
        initDataAsyncQueryHandler();
        handlePostLollipopRequirements();
    }


    @Override
    protected void onStart() {
        super.onStart();
        if (mGoogleApiClient != null) {
            mGoogleApiClient.connect();

            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                    .addLocationRequest(mLocationRequest);

            PendingResult<LocationSettingsResult> mLocationSettingsResult = LocationServices
                    .SettingsApi.checkLocationSettings
                            (mGoogleApiClient, builder
                                    .build());

            mLocationSettingsResult.setResultCallback(this);

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        setAdapter();
        restoreListViewState();
        if (NetworkUtils.isWifiEnabled(this)) {
            WifiToggler.removeDeletedSavedWifiFromDB(this);
        }
    }


    @Override
    protected void onPause() {
        super.onPause();
        //Fix for issue #7
        if (mGoogleApiClient != null) {
            mGoogleApiClient.unregisterConnectionCallbacks(this);
            mGoogleApiClient.unregisterConnectionFailedListener(this);
            mGoogleApiClient.disconnect();
{'fraction_non_alphanumeric': 0.07870608838982178, 'fraction_numerical': 0.0022664056866179044, 'mean_word_length': 4.2933478735005455, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3529135', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2643, 'n_words': 438}