@ -1,136 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.alarms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.todoroo.andlib.data.Callback;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.astrid.activity.TaskEditFragment;
|
||||
import com.todoroo.astrid.data.Metadata;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.helper.TaskEditControlSetBase;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.tasks.R;
|
||||
import org.tasks.dialogs.DateAndTimePickerDialog;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import static org.tasks.date.DateTimeUtils.newDate;
|
||||
import static org.tasks.date.DateTimeUtils.newDateTime;
|
||||
|
||||
/**
|
||||
* Control set to manage adding and removing tags
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public final class AlarmControlSet extends TaskEditControlSetBase {
|
||||
|
||||
private final AlarmService alarmService;
|
||||
private TaskEditFragment taskEditFragment;
|
||||
|
||||
private LinearLayout alertsContainer;
|
||||
|
||||
public AlarmControlSet(AlarmService alarmService, TaskEditFragment taskEditFragment) {
|
||||
super(taskEditFragment.getActivity(), R.layout.control_set_alarms);
|
||||
this.alarmService = alarmService;
|
||||
this.taskEditFragment = taskEditFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromTaskOnInitialize() {
|
||||
alertsContainer.removeAllViews();
|
||||
alarmService.getAlarms(model.getId(), new Callback<Metadata>() {
|
||||
@Override
|
||||
public void apply(Metadata entry) {
|
||||
addAlarm(newDate(entry.getValue(AlarmFields.TIME)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterInflate() {
|
||||
this.alertsContainer = (LinearLayout) getView().findViewById(R.id.alert_container);
|
||||
View.OnClickListener addAlarmListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
addAlarm(newDate());
|
||||
}
|
||||
};
|
||||
getView().findViewById(R.id.alarms_add).setOnClickListener(addAlarmListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToModelAfterInitialized(Task task) {
|
||||
LinkedHashSet<Long> alarms = new LinkedHashSet<>();
|
||||
for(int i = 0; i < alertsContainer.getChildCount(); i++) {
|
||||
Long dateValue = (Long) alertsContainer.getChildAt(i).getTag();
|
||||
if(dateValue == null) {
|
||||
continue;
|
||||
}
|
||||
alarms.add(dateValue);
|
||||
}
|
||||
|
||||
if(alarmService.synchronizeAlarms(task.getId(), alarms)) {
|
||||
task.setModificationDate(DateUtilities.now());
|
||||
}
|
||||
}
|
||||
|
||||
private void addAlarm(Date alert) {
|
||||
final View alertItem = LayoutInflater.from(activity).inflate(R.layout.alarm_edit_row, null);
|
||||
alertsContainer.addView(alertItem);
|
||||
|
||||
alertItem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
DateAndTimePickerDialog.dateAndTimePickerDialog(taskEditFragment.getFragmentManager(), taskEditFragment.getActivity(), newDateTime((Long) alertItem.getTag()), new DateAndTimePickerDialog.OnDateTimePicked() {
|
||||
@Override
|
||||
public void onDateTimePicked(DateTime dateTime) {
|
||||
v.setTag(dateTime.getMillis());
|
||||
TextView label = (TextView) v.findViewById(R.id.alarm_string);
|
||||
label.setText(getDisplayString(activity, dateTime.getMillis()));
|
||||
}
|
||||
}, new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
alertItem.setTag(alert.getTime());
|
||||
TextView display = (TextView) alertItem.findViewById(R.id.alarm_string);
|
||||
display.setText(getDisplayString(activity, alert.getTime()));
|
||||
|
||||
ImageButton reminderRemoveButton;
|
||||
reminderRemoveButton = (ImageButton)alertItem.findViewById(R.id.button1);
|
||||
reminderRemoveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
alertsContainer.removeView(alertItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getDisplayString(Context context, long forDate) {
|
||||
DateTime dateTime = newDateTime(forDate);
|
||||
Date d = dateTime.toDate();
|
||||
return (dateTime.getYear() == newDateTime().getYear()
|
||||
? DateUtilities.getDateStringHideYear(d)
|
||||
: DateUtilities.getDateString(d)) +
|
||||
", " + DateUtilities.getTimeString(context, d);
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 941 B |
|
Before Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 422 B |
|
Before Width: | Height: | Size: 807 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 588 B |
|
After Width: | Height: | Size: 830 B |
@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:state_pressed="true"
|
||||
android:drawable="@drawable/btn_dismiss_pressed" />
|
||||
<item android:drawable="@drawable/btn_dismiss_normal" />
|
||||
|
||||
</selector>
|
||||
|
Before Width: | Height: | Size: 567 B |
|
Before Width: | Height: | Size: 697 B |
|
After Width: | Height: | Size: 374 B |
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/alert_container"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
style="@android:style/TextAppearance"
|
||||
android:id="@+id/alarms_add"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_a_reminder"
|
||||
android:textColor="?attr/asTextColorHint"
|
||||
android:layout_marginBottom="@dimen/task_edit_padding_top_bottom"
|
||||
android:paddingBottom="@dimen/task_edit_padding_top_bottom" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -1,101 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="5dip"
|
||||
android:paddingRight="5dip">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/reminders_body"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<!-- reminders -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dip"
|
||||
android:text="@string/TEA_reminder_label"
|
||||
android:paddingTop="10dip"
|
||||
style="@style/TextAppearance" />
|
||||
|
||||
<CheckBox
|
||||
style="@style/TextAppearance"
|
||||
android:id="@+id/reminder_due"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:text="@string/TEA_reminder_due" />
|
||||
|
||||
<CheckBox
|
||||
style="@style/TextAppearance"
|
||||
android:id="@+id/reminder_overdue"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:text="@string/TEA_reminder_overdue" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<CheckBox
|
||||
style="@style/TextAppearance"
|
||||
android:id="@+id/reminder_random"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:text="@string/TEA_reminder_randomly" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/reminder_random_interval"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="1px"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/reminder_alarm_container"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="50dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/TEA_reminder_alarm_label"
|
||||
style="@style/TextAppearance" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_alarm_display"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:paddingLeft="10dip"
|
||||
android:textColor="?attr/asThemeTextColor" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/reminder_alarm"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/control_dialog_ok" />
|
||||
</LinearLayout>
|
||||