<commit_before>package com.hastagqq.app;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.gson.Gson;
import com.hastagqq.app.api.BasicApiResponse;
import com.hastagqq.app.api.GetNewsApiResponse;
import com.hastagqq.app.api.NewsApiClient;
import com.hastagqq.app.db.NewsDal;
import com.hastagqq.app.model.DeviceInfo;
import com.hastagqq.app.model.News;
import com.hastagqq.app.util.Constants;
import com.hastagqq.app.util.GPSTracker;
import com.hastagqq.app.util.GsonUtil;
import com.hastagqq.app.util.HttpUtil;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class MainActivity extends FragmentActivity implements NewsApiClient.GetCallback,
        NewsApiClient.CreateCallback {
	private static final String TAG = MainActivity.class.getSimpleName();
    private static final String PROPERTY_APP_VERSION = "appVersion";
    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;

    public static final String EXTRA_MESSAGE = "message";
    public static final String PROPERTY_REG_ID = "registration_id";

    private String mRegId;
    private String mLocation;
    private GoogleCloudMessaging mGcm;
    private Context mContext;
    private NewsListFragment mNewsListFragment;
    private NewsDal mNewsDal;
    private List<News> mNewsItems;
    private String mCurrentFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mNewsDal = new NewsDal(this);

        if (!checkPlayServices()) {
            Toast.makeText(this, R.string.err_no_gcm, Toast.LENGTH_LONG).show();
            finish();

            return;
        } else {
            mGcm = GoogleCloudMessaging.getInstance(this);
            mContext = getApplicationContext();
            mRegId = getRegistrationId(mContext);

            if (mRegId.isEmpty()) {
                registerInBackground();
            }
        }

        showNewsListFragment();
        Log.d(TAG, "::onCreate() -- " + mLocation);
    }

    @Override
    protected void onResume() {
        super.onResume();

        GPSTracker gpsTracker = new GPSTracker(MainActivity.this);
        mLocation = gpsTracker.getCity();

        try {
            mNewsDal.open();
            mNewsDal.deleteAllNews();
            NewsApiClient.getNews(mLocation, this);
        } catch (SQLException e) {
            Log.e(TAG, "ERROR: " + e);
        }

        if (!checkPlayServices()) {
            Toast.makeText(this, R.string.err_no_gcm, Toast.LENGTH_LONG).show();
            finish();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        mNewsDal.close();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_create_news:
                showCreateNewsFragment();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onGetNewsComplete(GetNewsApiResponse apiResponse) {
        Log.d(TAG, "::onGetNewsComplete() -- START");
        Log.d(TAG, "::onGetNewsComplete() -- " + apiResponse);
        final List<News> newsItems = apiResponse.getNewsItems();
        Log.d(TAG, "::onGetNewsComplete() -- newsItems size = " + newsItems.size());

        mNewsItems = newsItems;
        mNewsListFragment.onNewsAvailable(newsItems);

        new Thread(new Runnable() {
            @Override
            public void run() {
                if (!newsItems.isEmpty()) {
                    for (News news : newsItems) {
                        Log.d(TAG, "::onGetNewsComplete() -- location = " + news.getLocation());
                        mNewsDal.createNews(news);
                    }
                }
            }
        });

        Log.d(TAG, "::onGetNewsComplete() -- END");
    }

    @Override
    public void onCreateNewsComplete(BasicApiResponse apiResponse) {
        Log.d(TAG, "::onCreateNewsComplete() -- START");
        Log.d(TAG, "::onCreateNewsComplete() -- " + apiResponse);<commit_msg>Nope.<commit_after>package com.hastagqq.app;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.gson.Gson;
import com.hastagqq.app.api.BasicApiResponse;
import com.hastagqq.app.api.GetNewsApiResponse;
import com.hastagqq.app.api.NewsApiClient;
import com.hastagqq.app.db.NewsDal;
import com.hastagqq.app.model.DeviceInfo;
import com.hastagqq.app.model.News;
import com.hastagqq.app.util.Constants;
import com.hastagqq.app.util.GPSTracker;
import com.hastagqq.app.util.GsonUtil;
import com.hastagqq.app.util.HttpUtil;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

public class MainActivity extends FragmentActivity implements NewsApiClient.GetCallback,
        NewsApiClient.CreateCallback {
	private static final String TAG = MainActivity.class.getSimpleName();
    private static final String PROPERTY_APP_VERSION = "appVersion";
    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;

    public static final String EXTRA_MESSAGE = "message";
    public static final String PROPERTY_REG_ID = "registration_id";

    private String mRegId;
    private String mLocation;
    private GoogleCloudMessaging mGcm;
    private Context mContext;
    private NewsListFragment mNewsListFragment;
    private NewsDal mNewsDal;
    private List<News> mNewsItems;
    private String mCurrentFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mNewsDal = new NewsDal(this);

        if (!checkPlayServices()) {
            Toast.makeText(this, R.string.err_no_gcm, Toast.LENGTH_LONG).show();
            finish();

            return;
        } else {
            mGcm = GoogleCloudMessaging.getInstance(this);
            mContext = getApplicationContext();
            mRegId = getRegistrationId(mContext);

            if (mRegId.isEmpty()) {
                registerInBackground();
            }
        }

        showNewsListFragment();
        Log.d(TAG, "::onCreate() -- " + mLocation);
    }

    @Override
    protected void onResume() {
        super.onResume();

        GPSTracker gpsTracker = new GPSTracker(MainActivity.this);
        mLocation = gpsTracker.getCity();

        try {
            mNewsDal.open();
            mNewsDal.deleteAllNews();
            NewsApiClient.getNews(mLocation, this);
        } catch (SQLException e) {
            Log.e(TAG, "ERROR: " + e);
        }

        if (!checkPlayServices()) {
            Toast.makeText(this, R.string.err_no_gcm, Toast.LENGTH_LONG).show();
            finish();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        mNewsDal.close();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_create_news:
                showCreateNewsFragment();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onGetNewsComplete(GetNewsApiResponse apiResponse) {
        Log.d(TAG, "::onGetNewsComplete() -- START");
        Log.d(TAG, "::onGetNewsComplete() -- " + apiResponse);
        final List<News> newsItems = apiResponse.getNewsItems();
        Log.d(TAG, "::onGetNewsComplete() -- newsItems size = " + newsItems.size());

        mNewsItems = newsItems;

        Collections.reverse(newsItems);

        if (mCurrentFragment != null && mCurrentFragment.equals("list"))
            mNewsListFragment.onNewsAvailable(newsItems);

        new Thread(new Runnable() {
            @Override
            public void run() {
                if (!newsItems.isEmpty()) {
                    for (News news : newsItems) {
                        Log.d(TAG, "::onGetNewsComplete() -- location = " + news.getLocation());
                        mNewsDal.createNews(news);
                    }
                }
            }
        });

        Log.d(TAG, "::onGetNewsComplete() -- END");
    }

    @Override
    public void onCreateNewsComplete(BasicApiResponse apiResponse) {
        Log.d(TAG, "::onCreateNewsComplete() -- START");
        Log.d(TAG, "::onCreateNewsComplete() -- " + apiResponse);
{'fraction_non_alphanumeric': 0.10785928869076461, 'fraction_numerical': 0.0011629033821106696, 'mean_word_length': 2.7269772481040087, 'pattern_counts': {'":': 16, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '2135007', 'n_tokens_mistral': 3055, 'n_tokens_neox': 2948, 'n_words': 558}