mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-19 12:24:12 +00:00
Merge pull request #576 from TheHollidayInn/todo-notification-updates
Todo notification updates
This commit is contained in:
commit
afc8787f6b
9 changed files with 258 additions and 51 deletions
73
Habitica/google-services.json
Normal file
73
Habitica/google-services.json
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
{
|
||||
"project_info": {
|
||||
"project_number": "726830572661",
|
||||
"firebase_url": "https://habitica-android.firebaseio.com",
|
||||
"project_id": "habitica-android",
|
||||
"storage_bucket": "habitica-android.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:726830572661:android:d2e86a80d3b5f4f7",
|
||||
"android_client_info": {
|
||||
"package_name": "com.habitrpg.android.habitica"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "726830572661-e0bp1cplmf3v2sfl7e7goog768b7dv7b.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyDbtO8iErLD14Gk42Gg48fijX1mzfPKzS8"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"analytics_service": {
|
||||
"status": 1
|
||||
},
|
||||
"appinvite_service": {
|
||||
"status": 1,
|
||||
"other_platform_oauth_client": []
|
||||
},
|
||||
"ads_service": {
|
||||
"status": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:726830572661:android:ffd6914ad1a696e4",
|
||||
"android_client_info": {
|
||||
"package_name": "com.habitrpg.android.habitica.debug"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "726830572661-e0bp1cplmf3v2sfl7e7goog768b7dv7b.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyDbtO8iErLD14Gk42Gg48fijX1mzfPKzS8"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"analytics_service": {
|
||||
"status": 1
|
||||
},
|
||||
"appinvite_service": {
|
||||
"status": 1,
|
||||
"other_platform_oauth_client": []
|
||||
},
|
||||
"ads_service": {
|
||||
"status": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
24
Habitica/res/layout/custom_date_time_dialogue.xml
Normal file
24
Habitica/res/layout/custom_date_time_dialogue.xml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<DatePicker
|
||||
android:id="@+id/datePicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
</DatePicker>
|
||||
|
||||
<TimePicker
|
||||
android:id="@+id/timePicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
</TimePicker>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Confirm"
|
||||
android:id="@+id/customDialogConfirmButton"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package com.habitrpg.android.habitica.helpers;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.RemindersItem;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 7/12/16.
|
||||
*/
|
||||
public class RemindersManager {
|
||||
|
||||
DateFormat dateFormater = new SimpleDateFormat("dd MMMM yyyy HH:mm:ss");
|
||||
|
||||
public RemindersItem createReminderFromDateString(String dateString) {
|
||||
try {
|
||||
Date date = dateFormater.parse(dateString);
|
||||
RemindersItem item = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
item.setId(randomUUID.toString());
|
||||
item.setStartDate(date);
|
||||
item.setTime(date);
|
||||
return item;
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String reminderTimeToString (Date time) {
|
||||
return dateFormater.format(time);
|
||||
}
|
||||
|
||||
public void createDialogeForEditText(EditText editText, String taskType, Context context) {
|
||||
Calendar currentTime = Calendar.getInstance();
|
||||
int hour = currentTime.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = currentTime.get(Calendar.MINUTE);
|
||||
|
||||
if (taskType.equals("todo")) {
|
||||
Dialog dialog = new Dialog(context);
|
||||
dialog.setContentView(R.layout.custom_date_time_dialogue);
|
||||
dialog.setTitle("Select Date and Time");
|
||||
|
||||
Button dialogConfirmButton = (Button) dialog.findViewById(R.id.customDialogConfirmButton);
|
||||
TimePicker dialogTimePicker = (TimePicker) dialog.findViewById(R.id.timePicker);
|
||||
DatePicker dialogDatePicker = (DatePicker) dialog.findViewById(R.id.datePicker);
|
||||
|
||||
dialogConfirmButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int day = dialogDatePicker.getDayOfMonth();
|
||||
int month = dialogDatePicker.getMonth();
|
||||
int year = dialogDatePicker.getYear();
|
||||
int hour = dialogTimePicker.getCurrentHour();
|
||||
int minute = dialogTimePicker.getCurrentMinute();
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(year, month, day, hour, minute, 0);
|
||||
|
||||
editText.setText(dateFormater.format(calendar.getTime()));
|
||||
dialog.hide();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
} else {
|
||||
TimePickerDialog timePickerDialog;
|
||||
timePickerDialog = new TimePickerDialog(context, (timePicker, selectedHour, selectedMinute) -> {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), selectedHour, selectedMinute, 0);
|
||||
editText.setText(dateFormater.format(calendar.getTime()));
|
||||
}, hour, minute, true);
|
||||
timePickerDialog.setTitle("Select Time");
|
||||
timePickerDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.habitrpg.android.habitica.ui.helpers;
|
||||
package com.habitrpg.android.habitica.helpers;
|
||||
|
||||
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||
import com.habitrpg.android.habitica.receivers.TaskReceiver;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.habitrpg.android.habitica.receivers;
|
||||
|
||||
import com.habitrpg.android.habitica.ui.helpers.TaskAlarmManager;
|
||||
import com.habitrpg.android.habitica.helpers.TaskAlarmManager;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
|
|
|
|||
|
|
@ -2,15 +2,17 @@ package com.habitrpg.android.habitica.receivers;
|
|||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.habitrpg.android.habitica.ui.helpers.TaskAlarmManager;
|
||||
import com.habitrpg.android.habitica.helpers.TaskAlarmManager;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 5/29/16.
|
||||
|
|
@ -42,15 +44,17 @@ public class TaskReceiver extends BroadcastReceiver {
|
|||
public void createNotification() {
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, 0);
|
||||
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
|
||||
Notification notification = new Notification.Builder(context)
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.ic_gryphon)
|
||||
.setContentTitle(taskTitle)
|
||||
.setContentText(taskTitle).setSmallIcon(R.drawable.ic_gryphon)
|
||||
.setContentIntent(pendingIntent)
|
||||
.build();
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
.setContentText(taskTitle)
|
||||
.setSound(soundUri)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(pendingIntent);
|
||||
|
||||
notificationManager.notify((int) System.currentTimeMillis(), notification);
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
|
|
@ -4,12 +4,13 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteTaskCommand;
|
||||
import com.habitrpg.android.habitica.helpers.RemindersManager;
|
||||
import com.habitrpg.android.habitica.ui.WrapContentRecyclerViewLayoutManager;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.CheckListAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.RemindersAdapter;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser;
|
||||
import com.habitrpg.android.habitica.ui.helpers.SimpleItemTouchHelperCallback;
|
||||
import com.habitrpg.android.habitica.ui.helpers.TaskAlarmManager;
|
||||
import com.habitrpg.android.habitica.helpers.TaskAlarmManager;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem;
|
||||
|
|
@ -26,6 +27,7 @@ import net.pherth.android.emoji_library.EmojiPopup;
|
|||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
|
@ -56,11 +58,13 @@ import android.widget.NumberPicker;
|
|||
import android.widget.Spinner;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
|
@ -168,6 +172,8 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
private TaskAlarmManager taskAlarmManager;
|
||||
private List<Tag> selectedTags;
|
||||
|
||||
private RemindersManager remindersManager;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_task_form;
|
||||
|
|
@ -189,6 +195,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
return;
|
||||
}
|
||||
|
||||
remindersManager = new RemindersManager();
|
||||
taskAlarmManager = TaskAlarmManager.getInstance(this);
|
||||
|
||||
dueDateListener = new DateEditTextListener(dueDatePickerText);
|
||||
|
|
@ -429,6 +436,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
if (task != null && task.getReminders() != null) {
|
||||
reminders = task.getReminders();
|
||||
}
|
||||
|
||||
remindersAdapter = new RemindersAdapter(reminders);
|
||||
|
||||
LinearLayoutManager llm = new LinearLayoutManager(this);
|
||||
|
|
@ -446,37 +454,15 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
|
||||
@OnClick(R.id.add_reminder_button)
|
||||
public void addReminder() {
|
||||
Date startDate = new Date(startDateListener.getCalendar().getTimeInMillis());
|
||||
|
||||
Date time = startDate;
|
||||
String reminderTimeString = newRemindersEditText.getText().toString();
|
||||
if (reminderTimeString.isEmpty()) return;
|
||||
String[] reminderTimeSplit = reminderTimeString.split(":");
|
||||
time.setHours(Integer.parseInt(reminderTimeSplit[0]));
|
||||
time.setMinutes(Integer.parseInt(reminderTimeSplit[1]));
|
||||
time.setSeconds(0);
|
||||
|
||||
RemindersItem item = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
item.setId(randomUUID.toString());
|
||||
item.setStartDate(startDate);
|
||||
item.setTime(time);
|
||||
|
||||
RemindersItem item = remindersManager.createReminderFromDateString(newRemindersEditText.getText().toString());
|
||||
item.setType(taskType);
|
||||
remindersAdapter.addItem(item);
|
||||
newRemindersEditText.setText("");
|
||||
}
|
||||
|
||||
@OnClick(R.id.new_reminder_edittext)
|
||||
public void changeNewReminderTime() {
|
||||
Calendar mcurrentTime = Calendar.getInstance();
|
||||
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = mcurrentTime.get(Calendar.MINUTE);
|
||||
TimePickerDialog mTimePicker;
|
||||
mTimePicker = new TimePickerDialog(TaskFormActivity.this, (timePicker, selectedHour, selectedMinute) -> {
|
||||
newRemindersEditText.setText(String.format("%d:%02d", selectedHour, selectedMinute));
|
||||
}, hour, minute, true);
|
||||
mTimePicker.setTitle("Select Time");
|
||||
mTimePicker.show();
|
||||
remindersManager.createDialogeForEditText(newRemindersEditText, taskType, this);
|
||||
}
|
||||
|
||||
private void createTagsCheckBoxes() {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,28 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.tasks;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.helpers.RemindersManager;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperAdapter;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperViewHolder;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.RemindersItem;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
|
@ -27,10 +35,13 @@ import butterknife.ButterKnife;
|
|||
*/
|
||||
public class RemindersAdapter extends RecyclerView.Adapter<RemindersAdapter.ItemViewHolder>
|
||||
implements ItemTouchHelperAdapter {
|
||||
|
||||
private final List<RemindersItem> reminders = new ArrayList<>();
|
||||
private RemindersManager remindersManager;
|
||||
|
||||
public RemindersAdapter(List<RemindersItem> remindersInc) {
|
||||
reminders.addAll(remindersInc);
|
||||
remindersManager = new RemindersManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -42,7 +53,7 @@ public class RemindersAdapter extends RecyclerView.Adapter<RemindersAdapter.Item
|
|||
@Override
|
||||
public void onBindViewHolder(final ItemViewHolder holder, int position) {
|
||||
Date time = reminders.get(position).getTime();
|
||||
holder.reminderItemTextView.setText(String.format("%d:%02d", time.getHours(), time.getMinutes()));
|
||||
holder.reminderItemTextView.setText(remindersManager.reminderTimeToString(time));
|
||||
holder.hour = time.getHours();
|
||||
holder.minute = time.getMinutes();
|
||||
}
|
||||
|
|
@ -94,19 +105,17 @@ public class RemindersAdapter extends RecyclerView.Adapter<RemindersAdapter.Item
|
|||
deleteButton.setOnClickListener(this);
|
||||
|
||||
reminderItemTextView.setOnClickListener(v -> {
|
||||
TimePickerDialog timePicker;
|
||||
timePicker = new TimePickerDialog(v.getContext(), (timePicker1, selectedHour, selectedMinute) -> {
|
||||
reminderItemTextView.setText(String.format("%d:%02d", selectedHour, selectedMinute));
|
||||
RemindersItem reminder = reminders.get(getAdapterPosition());
|
||||
|
||||
RemindersItem reminder = reminders.get(getAdapterPosition());
|
||||
Date time = reminder.getTime();
|
||||
time.setHours(selectedHour);
|
||||
time.setMinutes(selectedMinute);
|
||||
time.setSeconds(0);
|
||||
reminder.setTime(time);
|
||||
}, hour, minute, true);
|
||||
timePicker.setTitle("Select Time");
|
||||
timePicker.show();
|
||||
String taskType;
|
||||
|
||||
if (reminder.getTask() == null) {
|
||||
taskType = reminder.getType();
|
||||
} else {
|
||||
taskType = reminder.getTask().getType();
|
||||
}
|
||||
|
||||
remindersManager.createDialogeForEditText(reminderItemTextView, taskType, v.getContext());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,13 @@ import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
|||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
import com.raizlabs.android.dbflow.structure.container.ForeignKeyContainer;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 5/31/16.
|
||||
|
|
@ -35,6 +38,9 @@ public class RemindersItem extends BaseModel {
|
|||
@Column
|
||||
private Integer alarmId;
|
||||
|
||||
//Use to store task type before a task is created
|
||||
private String type;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -69,7 +75,13 @@ public class RemindersItem extends BaseModel {
|
|||
|
||||
public Task getTask() {
|
||||
if (task != null) {
|
||||
return task.toModel();
|
||||
//This will get all the task info
|
||||
Task taskModel = task.toModel();
|
||||
List<Task> task = new Select()
|
||||
.from(Task.class)
|
||||
.where(Condition.column("id").eq(taskModel.getId()))
|
||||
.queryList();
|
||||
return task.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -81,6 +93,14 @@ public class RemindersItem extends BaseModel {
|
|||
this.task.put("id", task.getId());
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (this.getId() == null) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue