Skip to content

Commit

Permalink
Fix warnings and update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenluo committed Aug 22, 2018
1 parent 972e5ca commit 435a0e8
Show file tree
Hide file tree
Showing 25 changed files with 298 additions and 290 deletions.
@@ -1,4 +1,4 @@
#Fri Aug 17 16:02:18 EDT 2018
#Fri Aug 17 18:56:36 EDT 2018
/Users/ellen/Documents/minimaList/android-colorpicker/src/main/res/drawable/color_picker_swatch.xml=/Users/ellen/Documents/minimaList/android-colorpicker/build/intermediates/packaged_res/debug/drawable/color_picker_swatch.xml
/Users/ellen/Documents/minimaList/android-colorpicker/src/main/res/layout/color_picker_swatch.xml=/Users/ellen/Documents/minimaList/android-colorpicker/build/intermediates/packaged_res/debug/layout/color_picker_swatch.xml
/Users/ellen/Documents/minimaList/android-colorpicker/src/main/res/layout/color_picker_dialog.xml=/Users/ellen/Documents/minimaList/android-colorpicker/build/intermediates/packaged_res/debug/layout/color_picker_dialog.xml
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -60,7 +60,7 @@
android:label="@string/title_activity_intro" />

<service
android:name=".NotifService"
android:name=".NotificationService"
android:enabled="true" />

<service
Expand Down
47 changes: 23 additions & 24 deletions app/src/main/java/com/ellenluo/minimaList/AddTaskActivity.java
@@ -1,11 +1,5 @@
package com.ellenluo.minimaList;

/**
* AddTaskActivity
* Created by Ellen Luo
* Activity that allows users to create a new task with customizable name, due date, reminder, list and details.
*/

import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.content.Intent;
Expand Down Expand Up @@ -36,6 +30,11 @@
import java.util.Date;
import java.util.Locale;

/**
* AddTaskActivity
* Created by Ellen Luo
* Activity that allows users to create a new task with customizable name, due date, reminder, list and details.
*/
public class AddTaskActivity extends AppCompatActivity implements TimePickerFragment.OnTimeSetListener,
DatePickerFragment.OnDateSetListener {

Expand Down Expand Up @@ -83,7 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_add_task);

// set up toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Expand All @@ -97,27 +96,27 @@ protected void onCreate(Bundle savedInstanceState) {
militaryTime = prefSettings.getBoolean("24h", false);

// initialize due date/time
tvDueDate = (TextView) findViewById(R.id.due_date);
tvDueTime = (TextView) findViewById(R.id.due_time);
btnClearDue = (Button) findViewById(R.id.clear_due);
tvDueDate = findViewById(R.id.due_date);
tvDueTime = findViewById(R.id.due_time);
btnClearDue = findViewById(R.id.clear_due);

// initialize reminder date/time/repeat
tvRemindDate = (TextView) findViewById(R.id.remind_date);
tvRemindTime = (TextView) findViewById(R.id.remind_time);
final Button btnSetRemind = (Button) findViewById(R.id.set_remind);
btnClearRemind = (Button) findViewById(R.id.clear_remind);
tvRepeat = (TextView) findViewById(R.id.repeat);
repeatSpinner = (Spinner) findViewById(R.id.repeat_spinner);
tvRemindDate = findViewById(R.id.remind_date);
tvRemindTime = findViewById(R.id.remind_time);
final Button btnSetRemind = findViewById(R.id.set_remind);
btnClearRemind = findViewById(R.id.clear_remind);
tvRepeat = findViewById(R.id.repeat);
repeatSpinner = findViewById(R.id.repeat_spinner);
ArrayAdapter<CharSequence> repeatAdapter = ArrayAdapter.createFromResource(this, R.array.repeat_options,
android.R.layout.simple_spinner_dropdown_item);
repeatSpinner.setAdapter(repeatAdapter);

// initialize new list instructions/text field
tvAddList = (TextView) findViewById(R.id.new_list_instructions);
etAddList = (EditText) findViewById(R.id.list_name);
tvAddList = findViewById(R.id.new_list_instructions);
etAddList = findViewById(R.id.list_name);

// set up reminder switch
Switch remindSwitch = (Switch) findViewById(R.id.remind_switch);
Switch remindSwitch = findViewById(R.id.remind_switch);

remindSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
Expand Down Expand Up @@ -146,7 +145,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
});

// set up list spinner
Spinner listSpinner = (Spinner) findViewById(R.id.list_spinner);
Spinner listSpinner = findViewById(R.id.list_spinner);

db = new DBHandler(this);
listList = db.getAllLists();
Expand Down Expand Up @@ -234,12 +233,12 @@ public void onDateSet(DatePicker view, int year, int month, int day) {
if (picker == 0) {
due = Calendar.getInstance();
due.set(year, month, day, 0, 0, 0);
tvDueDate.setText(monthArray[month] + " " + day + ", " + year);
tvDueDate.setText(getString(R.string.add_task_due_date, monthArray[month], day, year));
btnClearDue.setVisibility(View.VISIBLE);
} else {
remind = Calendar.getInstance();
remind.set(year, month, day, 0, 0, 0);
tvRemindDate.setText(monthArray[month] + " " + day + ", " + year);
tvRemindDate.setText(getString(R.string.add_task_due_date, monthArray[month], day, year));
btnClearRemind.setVisibility(View.VISIBLE);
}

Expand Down Expand Up @@ -281,8 +280,8 @@ public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// add task to database
@SuppressWarnings("ConstantConditions")
private void addTask() {
EditText etName = (EditText) findViewById(R.id.task_name);
EditText etDetails = (EditText) findViewById(R.id.task_details);
EditText etName = findViewById(R.id.task_name);
EditText etDetails = findViewById(R.id.task_details);
String taskName = etName.getText().toString().trim();
String details = etDetails.getText().toString();

Expand Down
@@ -1,26 +1,31 @@
package com.ellenluo.minimaList;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.content.WakefulBroadcastReceiver;

/**
* AlarmManagerReceiver
* Created by Ellen Luo
* BroadcastReceiver that calls a notification service when a task reminder fires.
*/

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

public class AlarmManagerReceiver extends WakefulBroadcastReceiver {

public void onReceive(Context context, Intent intent) {
long id = intent.getExtras().getLong("id");
String text = intent.getExtras().getString("text");

// start notification service
Intent service = new Intent(context, NotifService.class);
Intent service = new Intent(context, NotificationService.class);
service.putExtra("id", id);
service.putExtra("text", text);
context.startService(service);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(service);
} else {
context.startService(service);
}
}

}
@@ -1,38 +1,39 @@
package com.ellenluo.minimaList;

/**
* BootCompletedReceiver
* Created by Ellen Luo
* BroadcastReceiver that resets all reminders after device reboot (powering off device cancels notifications).
*/

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import java.util.ArrayList;

/**
* BootCompletedReceiver
* Created by Ellen Luo
* BroadcastReceiver that resets all reminders after device reboot (powering off device cancels notifications).
*/
public class BootCompletedReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent incomingIntent) {
// get task list
DBHandler db = new DBHandler(context);
ArrayList<Task> taskList = db.getAllTasks();

// set new reminders
for (int i = 0; i < taskList.size(); i++) {
Task curTask = taskList.get(i);

if (curTask.getRemind() != -1 && curTask.getRemind() > System.currentTimeMillis()) {
Helper h = new Helper(context);
h.setReminder(curTask.getName(), curTask.getId(), curTask.getRemind());
if (incomingIntent.getAction() != null && incomingIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
// get task list
DBHandler db = new DBHandler(context);
ArrayList<Task> taskList = db.getAllTasks();

// set new reminders
for (int i = 0; i < taskList.size(); i++) {
Task curTask = taskList.get(i);

if (curTask.getRemind() != -1 && curTask.getRemind() > System.currentTimeMillis()) {
Helper h = new Helper(context);
h.setReminder(curTask.getName(), curTask.getId(), curTask.getRemind());
}
}
}

// schedules widget update at midnight
Helper h = new Helper(context);
h.scheduleUpdate();
// schedules widget update at midnight
Helper h = new Helper(context);
h.scheduleUpdate();
}
}

}
20 changes: 9 additions & 11 deletions app/src/main/java/com/ellenluo/minimaList/DBHandler.java
@@ -1,11 +1,5 @@
package com.ellenluo.minimaList;

/**
* DBHandler
* Created by Ellen Luo
* SQLiteOpenHelper that creates SQLite tables to store tasks and lists and allows various database operations.
*/

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
Expand All @@ -15,6 +9,11 @@
import java.util.ArrayList;
import java.util.Locale;

/**
* DBHandler
* Created by Ellen Luo
* SQLiteOpenHelper that creates SQLite tables to store tasks and lists and allows various database operations.
*/
public class DBHandler extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;
Expand Down Expand Up @@ -155,7 +154,7 @@ ArrayList<Task> getAllTasks() {
}

// update task in table
int updateTask(Task task) {
void updateTask(Task task) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_TASK_NAME, task.getName());
Expand All @@ -165,7 +164,7 @@ int updateTask(Task task) {
values.put(KEY_TASK_REPEAT, task.getRepeat());
values.put(KEY_TASK_NEXT_REMIND, task.getNextRemind());
values.put(KEY_TASK_LIST, task.getList());
return db.update(TABLE_TASKS, values, KEY_TASK_ID + " = ?", new String[]{String.valueOf(task.getId())});
db.update(TABLE_TASKS, values, KEY_TASK_ID + " = ?", new String[]{String.valueOf(task.getId())});
}

// delete task from table
Expand Down Expand Up @@ -243,12 +242,11 @@ ArrayList<List> getAllLists() {
}

// update list in table
int updateList(List list) {
void updateList(List list) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_LIST_NAME, list.getName());

return db.update(TABLE_LISTS, values, KEY_LIST_ID + " = ?", new String[]{String.valueOf(list.getId())});
db.update(TABLE_LISTS, values, KEY_LIST_ID + " = ?", new String[]{String.valueOf(list.getId())});
}

// delete list from table
Expand Down
20 changes: 11 additions & 9 deletions app/src/main/java/com/ellenluo/minimaList/DatePickerFragment.java
@@ -1,21 +1,21 @@
package com.ellenluo.minimaList;

/**
* DatePickerFragment
* Created by Ellen Luo
* DialogFragment that displays a calendar date picker.
*/

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;

import java.util.Calendar;

/**
* DatePickerFragment
* Created by Ellen Luo
* DialogFragment that displays a calendar date picker.
*/
public class DatePickerFragment extends DialogFragment {

OnDateSetListener listener;
Expand All @@ -38,9 +38,11 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = (OnDateSetListener) activity;
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof Activity){
listener = (OnDateSetListener) context;
}
}

}

0 comments on commit 435a0e8

Please sign in to comment.