package com.sfsu.controllers;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

import com.sfsu.receiver.ReminderReceiver;

/**
 * Created by Pavitra on 12/11/2015.
 */
public class ReminderController {

    private Context mContext;
    private long selectedInterval;

    /**
     * Initialize the Alarm Manager for the current Context.
     *
     * @param context
     */
    public ReminderController init(Context context) {
        this.mContext = context;
        return this;
    }

    /**
     * Build the ReminderController for the given context and interval.
     */
    public void schedule() {
        AlarmManager mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        Intent alarmIntent = new Intent(mContext, ReminderReceiver.class);
        PendingIntent mPendingIntent = PendingIntent.getBroadcast(mContext, 0, alarmIntent, 0);

        mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + selectedInterval,
                selectedInterval, mPendingIntent);

    }

    /**
     * Set the interval to trigger the alarm and also to set the interval for repeating the alarm on specific intervals.
     *
     * @param selectedInterval
     * @return
     */
    public ReminderController interval(long selectedInterval) {
        this.selectedInterval = selectedInterval;
        return this;
    }
}

@@ -184,16 +184,45 @@
 emClock;
+%0Aimport android.widget.Toast;
 %0A%0Aimport
@@ -403,16 +403,91 @@
 nterval;
+%0A    private PendingIntent mPendingIntent;%0A    private Intent mAlarmIntent;
 %0A%0A    /*
@@ -548,16 +548,76 @@
 Context.
+ Initialze the PendingIntent and Intent for current context.
 %0A     *%0A
@@ -729,24 +729,176 @@
  = context;%0A
+        mAlarmIntent = new Intent(mContext, ReminderReceiver.class);%0A        mPendingIntent = PendingIntent.getBroadcast(mContext, 0, mAlarmIntent, 0);%0A
         retu
@@ -1144,340 +1144,542 @@
     
-Intent alarmIntent = new Intent(mContext, ReminderReceiver.class);%0A        PendingIntent mPendingIntent = PendingIntent.getBroadcast(mContext, 0, alarmIntent, 0);%0A%0A        mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + selectedInterval,%0A                selectedInterval, mPendingIntent
+mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + selectedInterval,%0A                selectedInterval, mPendingIntent);%0A        Toast.makeText(mContext, %22Reminder started%22, Toast.LENGTH_SHORT).show();%0A    %7D%0A%0A    /**%0A     * Stops the reminder.%0A     */%0A    public void cancel() %7B%0A        AlarmManager manager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);%0A        manager.cancel(mPendingIntent);%0A        Toast.makeText(mContext, %22Reminder stopped%22, Toast.LENGTH_SHORT).show(
 );%0A
-%0A
     

Change the inint(0 method to initialize PendingIntent and Intent