package org.pcc.repeatinglocalnotifications;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ToggleButton;

import org.pcc.repeatinglocalnotifications.notification.NotificationHelper;

// https://github.com/ptyagicodecamp/RepeatingLocalNotifications
// https://ptyagicodecamp.github.io/scheduling-repeating-local-notifications-using-alarm-manager.html

// http://www.singhajit.com/schedule-local-notification-in-android/

// https://www.techrepublic.com/blog/software-engineer/use-androids-alarmmanager-to-schedule-an-event/

// http://androidideasblog.blogspot.fr/2011/07/alarmmanager-and-notificationmanager.html

// https://www.c-sharpcorner.com/article/creating-and-scheduling-alarms-in-android/

// https://nnish.com/2014/12/16/scheduled-notifications-in-android-using-alarm-manager/

// https://www.journaldev.com/10463/android-notification-pendingintent

// https://github.com/google-developer-training/android-fundamentals/tree/master/StandUp

public class MainActivity extends AppCompatActivity {

    private Context mContext;

    private EditText hours;
    private EditText minutes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = getApplicationContext();

        hours = (EditText)findViewById(R.id.editTextHH);
        minutes = (EditText) findViewById(R.id.editTextMM);
    }

    public void clickToggleButtonRTC(View view) {
        boolean isEnabled = ((ToggleButton)view).isEnabled();

        if (isEnabled) {
            NotificationHelper.scheduleRepeatingRTCNotification(mContext, hours.getText().toString(), minutes.getText().toString());
            NotificationHelper.enableBootReceiver(mContext);
        } else {
            NotificationHelper.cancelAlarmRTC();
            NotificationHelper.disableBootReceiver(mContext);
        }
    }

    public void clickToggleButtonElapsed(View view) {
        boolean isEnabled = ((ToggleButton)view).isEnabled();

        if (isEnabled) {
            NotificationHelper.scheduleRepeatingElapsedNotification(mContext);
            NotificationHelper.enableBootReceiver(mContext);
        } else {
            NotificationHelper.cancelAlarmElapsed();
            NotificationHelper.disableBootReceiver(mContext);
        }
    }

    public void cancelAlarms(View view) {
        NotificationHelper.cancelAlarmRTC();
        NotificationHelper.cancelAlarmElapsed();
        NotificationHelper.disableBootReceiver(mContext);
    }
}
