Skip to content

Commit

Permalink
Merge pull request #7 from blanyal/database
Browse files Browse the repository at this point in the history
Working Database
  • Loading branch information
blanyal committed Apr 14, 2015
2 parents 5273bee + 4d40d07 commit e26b59d
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AddReminder"
<activity android:name=".AddReminderActivity"
android:label="@string/title_activity_add_reminder"/>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
package com.blanyal.remindme;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -37,23 +42,30 @@
import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;


public class AddReminder extends ActionBarActivity implements
public class AddReminderActivity extends ActionBarActivity implements
TimePickerDialog.OnTimeSetListener,
DatePickerDialog.OnDateSetListener{

private Toolbar mToolbar;
private EditText mReminderText;
private TextView mDateText, mTimeText, mRepeatText;
private TextView mDateText, mTimeText, mRepeatText, mRepeatNoText, mRepeatTypeText;
private FloatingActionButton mFAB1;
private FloatingActionButton mFAB2;
private Calendar mCalendar;
private int mYear, mMonth, mHour, mMinute, mDay;
private String mTitle;
private String mTime;
private String mDate;
private String mRepeatNo;
private String mRepeatType;
private String mActive;
private String mRepeat;


@Override
Expand All @@ -63,12 +75,12 @@ protected void onCreate(Bundle savedInstanceState) {


mToolbar = (Toolbar) findViewById(R.id.toolbar);
mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
mReminderText = (EditText) findViewById(R.id.reminder_title);
mDateText = (TextView) findViewById(R.id.set_date);
mTimeText = (TextView) findViewById(R.id.set_time);
mRepeatText = (TextView) findViewById(R.id.set_repeat);
mRepeatNoText = (TextView) findViewById(R.id.set_repeat_no);
mRepeatTypeText = (TextView) findViewById(R.id.set_repeat_type);


setSupportActionBar(mToolbar);
Expand All @@ -77,6 +89,12 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setHomeButtonEnabled(true);


mActive = "true";
mRepeat = "true";
mRepeatNo = Integer.toString(1);
mRepeatType = "Hour";


mCalendar = Calendar.getInstance();
mHour = mCalendar.get(Calendar.HOUR_OF_DAY);
mMinute = mCalendar.get(Calendar.MINUTE);
Expand Down Expand Up @@ -109,6 +127,9 @@ public void afterTextChanged(Editable s) {

mDateText.setText(mDate);
mTimeText.setText(mTime);
mRepeatNoText.setText(mRepeatNo);
mRepeatTypeText.setText(mRepeatType);
mRepeatText.setText("Every " + mRepeatNo + " " + mRepeatType + "(s)");

}

Expand All @@ -125,6 +146,7 @@ public void setTime(View v){
tpd.show(getFragmentManager(), "Timepickerdialog");
}


public void setDate(View v){
Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
Expand All @@ -136,6 +158,7 @@ public void setDate(View v){
dpd.show(getFragmentManager(), "Datepickerdialog");
}


@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
mTime = hourOfDay + ":" + minute;
Expand All @@ -149,18 +172,130 @@ public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayO
}


public void selectFab1(View v) {
mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
mFAB1.setVisibility(View.GONE);
mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
mFAB2.setVisibility(View.VISIBLE);
mActive = "true";
Log.d("Active", mActive);
}


public void selectFab2(View v) {
mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
mFAB2.setVisibility(View.GONE);
mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
mFAB1.setVisibility(View.VISIBLE);
mActive = "false";
Log.d("Active", mActive);
}


public void onSwitchRepeat(View view) {
boolean on = ((Switch) view).isChecked();

if (on) {
mRepeat = "true";
mRepeatText.setText("Every " + mRepeatNo + " " + mRepeatType + "(s)");
} else {
mRepeat = "false";
mRepeatText.setText(R.string.repeat_off);
}
}


public void selectRepeatType(View v){

final String[] items = new String[5];

items[0] = "Minute";
items[1] = "Hour";
items[2] = "Day";
items[3] = "Week";
items[4] = "Month";

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Type");
builder.setItems(items, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int item) {

mRepeatType = items[item];
mRepeatTypeText.setText(mRepeatType);
mRepeatText.setText("Every " + mRepeatNo + " " + mRepeatType + "(s)");
}
});
AlertDialog alert = builder.create();
alert.show();

}


public void setRepeatNo(View v){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Enter Number");
//alert.setMessage("Enter Number");

final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
alert.setView(input);
alert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

mRepeatNo = input.getText().toString().trim();
mRepeatNoText.setText(mRepeatNo);
mRepeatText.setText("Every " + mRepeatNo + " " + mRepeatType + "(s)");
}
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
alert.show();
}


public void saveReminder(){

ReminderDatabase rb = new ReminderDatabase(this);

// Inserting Reminder
rb.addReminder(new Reminder(mTitle, mDate, mTime, mRepeat, mRepeatNo, mRepeatType, mActive));

List<Reminder> reminders = rb.getAllReminders();

for (Reminder rm : reminders) {
String log = "Id: " + rm.getID() + " ,Title: " + rm.getTitle() + " ,Date: " + rm.getDate()
+ " ,Time: " + rm.getTime() + " ,Repeat: " + rm.getRepeat() + " ,RepeatNo: " + rm.getRepeatNo()
+ " ,RepeatType: " + rm.getRepeatType() + " ,Active: " + rm.getActive();

Log.d("Name: ", log);
}

Toast.makeText(getApplicationContext(), "Saved",
Toast.LENGTH_SHORT).show();

onBackPressed();
}


@Override
public void onBackPressed() {
super.onBackPressed();
}


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


@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
Expand All @@ -176,9 +311,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
mReminderText.setError("Reminder Title cannot be blank!");

else {
Toast.makeText(getApplicationContext(), "Saved",
Toast.LENGTH_SHORT).show();
onBackPressed();
saveReminder();
}
return true;

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/blanyal/remindme/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void onCreate(Bundle savedInstanceState) {
mAddReminderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), AddReminder.class);
Intent intent = new Intent(v.getContext(), AddReminderActivity.class);
startActivity(intent);
}
});
Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/com/blanyal/remindme/Reminder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class Reminder {
private String mTitle;
private String mDate;
private String mTime;
private Boolean mRepeat;
private String mRepeat;
private String mRepeatNo;
private String mRepeatType;
private Boolean mActive;
private String mActive;


public Reminder(int ID, String Title, String Date, String Time, Boolean Repeat, String RepeatNo, String RepeatType, Boolean Active){
public Reminder(int ID, String Title, String Date, String Time, String Repeat, String RepeatNo, String RepeatType, String Active){
mID = ID;
mTitle = Title;
mDate = Date;
Expand All @@ -41,7 +41,7 @@ public Reminder(int ID, String Title, String Date, String Time, Boolean Repeat,
mActive = Active;
}

public Reminder(String Title, String Date, String Time, Boolean Repeat, String RepeatNo, String RepeatType, Boolean Active){
public Reminder(String Title, String Date, String Time, String Repeat, String RepeatNo, String RepeatType, String Active){
mTitle = Title;
mDate = Date;
mTime = Time;
Expand Down Expand Up @@ -85,14 +85,6 @@ public void setTime(String time) {
mTime = time;
}

public Boolean isRepeat() {
return mRepeat;
}

public void setRepeat(Boolean repeat) {
mRepeat = repeat;
}

public String getRepeatType() {
return mRepeatType;
}
Expand All @@ -109,11 +101,19 @@ public void setRepeatNo(String repeatNo) {
mRepeatNo = repeatNo;
}

public Boolean isActive() {
public String getRepeat() {
return mRepeat;
}

public void setRepeat(String repeat) {
mRepeat = repeat;
}

public String getActive() {
return mActive;
}

public void setActive(Boolean active) {
public void setActive(String active) {
mActive = active;
}
}
Loading

0 comments on commit e26b59d

Please sign in to comment.