<commit_before>package com.example.deanna.dailyimdbquotes;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


public class MainActivity extends Activity {
    public static MainActivity instance = null;
    private static String LOG_TAG = "QuotesMain";
    CountDownTimer mCountDownTimer;
    TextView mTextView;
    Button mNewQuoteButton;
    ImageView mImageView;
    double prevVal_hoursBetweenQuotes;
    String prevVal_titleText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(LOG_TAG,"onCreate called");

        instance = this;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mTextView = (TextView) findViewById(R.id.timeTillNextQuote);
        mImageView = (ImageView) findViewById(R.id.imageView1);

        mNewQuoteButton = (Button)findViewById(R.id.getNotification);
        mNewQuoteButton.setOnClickListener(mCreateNotificationListener);

        mNewQuoteButton.setVisibility(View.INVISIBLE);
        mTextView.setVisibility(View.INVISIBLE);

        // FORCE THIS WHILE DEVELOPING
        //MyAlarmManager.cancelAlarm(this);
        //Utility.setCurrentTitleId(this, null);

        storeCurrentPreferenceValues();

        String currentTitleId = Utility.getCurrentTitleId(this);
        if(currentTitleId == null){
            getQuotes();
        }else{
            if(Utility.getCurrentTitleText(this).equalsIgnoreCase(getString(R.string.pref_titleText_default))){ //special case for when Office Space
                mImageView.setImageResource(R.drawable.milton);
                mImageView.setScaleType(ImageView.ScaleType.CENTER);
            }

            MyAlarmManager.rescheduleAlarm(this);
            displayTimeTillNextAlarm();
            getImageForTitleId();
        }
    }

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

    private void storeCurrentPreferenceValues(){
        prevVal_hoursBetweenQuotes = Utility.getHoursBetweenQuotes(this);
        prevVal_titleText = Utility.getCurrentTitleText(this);
    }

    public void checkIfPreferencesChanged() {
        // number of hours between quotes
        double currVal_hoursBetweenQuotes = Utility.getHoursBetweenQuotes(this);
        if (currVal_hoursBetweenQuotes != prevVal_hoursBetweenQuotes) {
            prevVal_hoursBetweenQuotes = currVal_hoursBetweenQuotes;
            if (currVal_hoursBetweenQuotes < 1.0) {
                Utility.setHoursBetweenQuotes(this, 1.0);
            }
            Log.d(LOG_TAG, "Updating alarm for hours_between_quotes change");
            MyAlarmManager.cancelAlarm(this);
            MyAlarmManager.scheduleNewAlarm(this);
            displayTimeTillNextAlarm();
        }

        //title to show quotes for
        String currVal_titleText = Utility.getCurrentTitleText(this);
        if (!currVal_titleText.equals(prevVal_titleText)) {
            prevVal_titleText = currVal_titleText;
            Log.d(LOG_TAG, "Getting new quotes for title since it changed");
            getQuotes();
        }
    }

    private View.OnClickListener mCreateNotificationListener = new View.OnClickListener() {
        public void onClick(View v) {
            startQuotes();
        }
    };

    private void startQuotes(){
        MyAlarmManager.createNotification(getBaseContext());
        displayNotificationWaiting();
        makeTextBoxVisible();
    }

    public void displayNotificationWaiting(){
        if(mCountDownTimer != null) {
            mCountDownTimer.cancel(); //cancel previous timer
        }

        makeTextBoxVisible();
        mTextView.setText("Quote is waiting for you in the notification bar!");

        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
        String ret = settings.getString("time_nextAlarm", null);
        if(ret == null ){ //no alarms scheduled, allow new requests<commit_msg>Allow new quote straight away when title is changed; don't make wait for previous alarm to expire<commit_after>package com.example.deanna.dailyimdbquotes;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


public class MainActivity extends Activity {
    public static MainActivity instance = null;
    private static String LOG_TAG = "QuotesMain";
    CountDownTimer mCountDownTimer;
    TextView mTextView;
    Button mNewQuoteButton;
    ImageView mImageView;
    double prevVal_hoursBetweenQuotes;
    String prevVal_titleText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(LOG_TAG,"onCreate called");

        instance = this;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mTextView = (TextView) findViewById(R.id.timeTillNextQuote);
        mImageView = (ImageView) findViewById(R.id.imageView1);

        mNewQuoteButton = (Button)findViewById(R.id.getNotification);
        mNewQuoteButton.setOnClickListener(mCreateNotificationListener);

        mNewQuoteButton.setVisibility(View.INVISIBLE);
        mTextView.setVisibility(View.INVISIBLE);

        // FORCE THIS WHILE DEVELOPING
        //MyAlarmManager.cancelAlarm(this);
        //Utility.setCurrentTitleId(this, null);

        storeCurrentPreferenceValues();

        String currentTitleId = Utility.getCurrentTitleId(this);
        if(currentTitleId == null){
            getQuotes();
        }else{
            if(Utility.getCurrentTitleText(this).equalsIgnoreCase(getString(R.string.pref_titleText_default))){ //special case for when Office Space
                mImageView.setImageResource(R.drawable.milton);
                mImageView.setScaleType(ImageView.ScaleType.CENTER);
            }

            MyAlarmManager.rescheduleAlarm(this);
            displayTimeTillNextAlarm();
            getImageForTitleId();
        }
    }

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

    private void storeCurrentPreferenceValues(){
        prevVal_hoursBetweenQuotes = Utility.getHoursBetweenQuotes(this);
        prevVal_titleText = Utility.getCurrentTitleText(this);
    }

    public void checkIfPreferencesChanged() {
        // number of hours between quotes
        double currVal_hoursBetweenQuotes = Utility.getHoursBetweenQuotes(this);
        if (currVal_hoursBetweenQuotes != prevVal_hoursBetweenQuotes) {
            prevVal_hoursBetweenQuotes = currVal_hoursBetweenQuotes;
            if (currVal_hoursBetweenQuotes < 1.0) {
                Utility.setHoursBetweenQuotes(this, 1.0);
            }
            Log.d(LOG_TAG, "Updating alarm for hours_between_quotes change");
            MyAlarmManager.cancelAlarm(this);
            MyAlarmManager.scheduleNewAlarm(this);
            displayTimeTillNextAlarm();
        }

        //title to show quotes for
        String currVal_titleText = Utility.getCurrentTitleText(this);
        if (!currVal_titleText.equals(prevVal_titleText)) {
            prevVal_titleText = currVal_titleText;
            Log.d(LOG_TAG, "Getting new quotes for title since it changed");
            MyAlarmManager.cancelAlarm(this); //allow new quotes straight away
            getQuotes();
        }
    }

    private View.OnClickListener mCreateNotificationListener = new View.OnClickListener() {
        public void onClick(View v) {
            startQuotes();
        }
    };

    private void startQuotes(){
        MyAlarmManager.createNotification(getBaseContext());
        displayNotificationWaiting();
        makeTextBoxVisible();
    }

    public void displayNotificationWaiting(){
        if(mCountDownTimer != null) {
            mCountDownTimer.cancel(); //cancel previous timer
        }

        makeTextBoxVisible();
        mTextView.setText("Quote is waiting for you in the notification bar!");

        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
        String ret = settings.getString("time_nextAlarm", null);
        if(ret == null ){ //no alarms scheduled, allow new requests
{'fraction_non_alphanumeric': 0.08571111357832796, 'fraction_numerical': 0.001110247585211502, 'mean_word_length': 3.0760180995475115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6648587', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2337, 'n_words': 471}