// Path: app/src/main/java/com/YC2010/MyClass/model/Reminder_item.java
// public class Reminder_item {
//     // variables
//     String id;
//     String title;
//     String location;
//     GregorianCalendar mClaendar;
//     String type;
// 
//     // type:
//     // "c"      customized
//     // "e"      exams
//     // "fb"     facebook events
//     // "d"      important dates
// 
//     // constructor
//     public Reminder_item(){
//         // empty
//     }
// 
//     // Ctor for all
//     public Reminder_item(String id, String title, String location, int year, int month, int day, int hour, int minute, String type){
//         this.id = id;
//         this.title = title;
//         this.location = location;
//         this.mClaendar = new GregorianCalendar(year,month,day,hour,minute);
//         this.type = type;
//     }
// 
//     // ctor for no hout and minute
//     public Reminder_item(String id, String title, String location, int year, int month, int day, String type){
//         this.id = id;
//         this.title = title;
//         this.location = location;
//         this.mClaendar = new GregorianCalendar(year,month,day);
//         this.type = type;
//     }
// 
//     //Ctor for unix time
//     public Reminder_item(String id, String title, String location, long unix_time, String type){
//         this.id = id;
//         this.title = title;
//         this.location = location;
//         this.mClaendar = new GregorianCalendar();
//         this.mClaendar.setTimeInMillis(unix_time);
//         this.type = type;
//     }
// 
//     public String get_id(){
//         return this.id;
//     }
// 
//     public String get_title(){
//         return this.title;
//     }
// 
//     public String get_location(){
//         return this.location;
//     }
// 
//     public long get_unix_time(){
//         return this.mClaendar.getTimeInMillis();
//     }
// 
//     public String get_type(){ return this.type;}
// }


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;
import com.YC2010.MyClass.model.Reminder_item;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

    // get reminder count
    public int CountReminders(){
        SQLiteDatabase db = this.getReadableDatabase();

        long now_time = GregorianCalendar.getInstance().getTime().getTime();
        String selectQuery = "SELECT  COUNT(*) FROM " + TABLE_REMINDERS + " WHERE " +
                KEY_UNIX_TIME + " > " + now_time;
        SQLiteStatement s = db.compileStatement(selectQuery);
        long count = s.simpleQueryForLong();
        return (int)count;
    }

    // see if exam in 7 days
    public boolean closoToExam(Date mdate){
        SQLiteDatabase db = this.getReadableDatabase();
        long event_time = mdate.getTime();
        long weeks_time = 604800000;
        long time_in_a_week = event_time + weeks_time;
        String selectQuery = "SELECT  COUNT(*) FROM " + TABLE_REMINDERS + " WHERE " +
                KEY_UNIX_TIME + " > " + event_time + " and " +  KEY_UNIX_TIME + " < " +
                time_in_a_week + " and " + KEY_TYPE + " = 'e'";
        SQLiteStatement s = db.compileStatement(selectQuery);
        long count = s.simpleQueryForLong();
        //Log.d("getAllReminders", "long is " + count);
        return count > 0;
    }

    // Get All Reminder
    public List<Reminder_item> getAllReminders() {
// Path: app/src/main/java/com/YC2010/MyClass/model/Reminder_item.java
// public class Reminder_item {
//     // variables
//     String id;
//     String title;
//     String location;
//     GregorianCalendar mClaendar;
//     String type;
// 
//     // type:
//     // "c"      customized
//     // "e"      exams
//     // "fb"     facebook events
//     // "d"      important dates
// 
//     // constructor
//     public Reminder_item(){
//         // empty
//     }
// 
//     // Ctor for all
//     public Reminder_item(String id, String title, String location, int year, int month, int day, int hour, int minute, String type){
//         this.id = id;
//         this.title = title;
//         this.location = location;
//         this.mClaendar = new GregorianCalendar(year,month,day,hour,minute);
//         this.type = type;
//     }
// 
//     // ctor for no hout and minute
//     public Reminder_item(String id, String title, String location, int year, int month, int day, String type){
//         this.id = id;
//         this.title = title;
//         this.location = location;
//         this.mClaendar = new GregorianCalendar(year,month,day);
//         this.type = type;
//     }
// 
//     //Ctor for unix time
//     public Reminder_item(String id, String title, String location, long unix_time, String type){
//         this.id = id;
//         this.title = title;
//         this.location = location;
//         this.mClaendar = new GregorianCalendar();
//         this.mClaendar.setTimeInMillis(unix_time);
//         this.type = type;
//     }
// 
//     public String get_id(){
//         return this.id;
//     }
// 
//     public String get_title(){
//         return this.title;
//     }
// 
//     public String get_location(){
//         return this.location;
//     }
// 
//     public long get_unix_time(){
//         return this.mClaendar.getTimeInMillis();
//     }
// 
//     public String get_type(){ return this.type;}
// }


// Path: app/src/main/java/com/YC2010/MyClass/data/ReminderDBHandler.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;
import com.YC2010.MyClass.model.Reminder_item;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;


    // get reminder count
    public int CountReminders(){
        SQLiteDatabase db = this.getReadableDatabase();

        long now_time = GregorianCalendar.getInstance().getTime().getTime();
        String selectQuery = "SELECT  COUNT(*) FROM " + TABLE_REMINDERS + " WHERE " +
                KEY_UNIX_TIME + " > " + now_time;
        SQLiteStatement s = db.compileStatement(selectQuery);
        long count = s.simpleQueryForLong();
        return (int)count;
    }

    // see if exam in 7 days
    public boolean closoToExam(Date mdate){
        SQLiteDatabase db = this.getReadableDatabase();
        long event_time = mdate.getTime();
        long weeks_time = 604800000;
        long time_in_a_week = event_time + weeks_time;
        String selectQuery = "SELECT  COUNT(*) FROM " + TABLE_REMINDERS + " WHERE " +
                KEY_UNIX_TIME + " > " + event_time + " and " +  KEY_UNIX_TIME + " < " +
                time_in_a_week + " and " + KEY_TYPE + " = 'e'";
        SQLiteStatement s = db.compileStatement(selectQuery);
        long count = s.simpleQueryForLong();
        //Log.d("getAllReminders", "long is " + count);
        return count > 0;
    }

    // Get All Reminder
    public List<Reminder_item> getAllReminders() {
        List<Reminder_item> reminderList = new ArrayList<>();