Wire up call later button to create tasks with the appropriate due time

pull/14/head
Sam Bosley 12 years ago
parent b772c79bf9
commit 0e613f9017

@ -1,7 +1,5 @@
package com.todoroo.astrid.calls;
import java.util.Date;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
@ -15,19 +13,26 @@ import android.view.View.OnClickListener;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment.SnoozeDialog;
import com.todoroo.astrid.reminders.SnoozeCallback;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.ThemeService;
public class MissedCallActivity extends Activity {
public static final String EXTRA_NUMBER = "number"; //$NON-NLS-1$
public static final String EXTRA_NAME = "name"; //$NON-NLS-1$
public static final String EXTRA_TIME = "time"; //$NON-NLS-1$
private static final String PREF_IGNORE_PRESSES = "missedCallsIgnored"; //$NON-NLS-1$
private static final String PREF_IGNORE_PRESSES = "missedCallsIgnored";
@Autowired private TaskService taskService;
private final OnClickListener dismissListener = new OnClickListener() {
@Override
@ -72,6 +77,7 @@ public class MissedCallActivity extends Activity {
private String name;
private String number;
private String timeString;
private TextView returnCallButton;
private TextView callLaterButton;
@ -81,6 +87,7 @@ public class MissedCallActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DependencyInjectionService.getInstance().inject(this);
setContentView(R.layout.missed_call_activity);
@ -88,6 +95,7 @@ public class MissedCallActivity extends Activity {
name = intent.getStringExtra(EXTRA_NAME);
number = intent.getStringExtra(EXTRA_NUMBER);
timeString = intent.getStringExtra(EXTRA_TIME);
int color = ThemeService.getThemeColor();
@ -95,6 +103,7 @@ public class MissedCallActivity extends Activity {
callLaterButton = (TextView) findViewById(R.id.call_later);
ignoreButton = (TextView) findViewById(R.id.call_ignore);
dismissButton = findViewById(R.id.dismiss);
((TextView) findViewById(R.id.reminder_title)).setText(getString(R.string.MCA_title, timeString));
Resources r = getResources();
returnCallButton.setBackgroundColor(r.getColor(color));
@ -135,8 +144,17 @@ public class MissedCallActivity extends Activity {
SnoozeDialog sd = new SnoozeDialog(MissedCallActivity.this, new SnoozeCallback() {
@Override
public void snoozeForTime(long time) {
// Create task with due time 'time'
System.err.println("Should create a task for: " + new Date(time));
String title;
if (TextUtils.isEmpty(name))
title = getString(R.string.MCA_task_title_no_name, number);
else
title = getString(R.string.MCA_task_title_name, name, number);
Task newTask = new Task();
newTask.setValue(Task.TITLE, title);
newTask.setValue(Task.DUE_DATE, time);
taskService.save(newTask);
finish();
}
});

@ -1,5 +1,7 @@
package com.todoroo.astrid.calls;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -9,6 +11,7 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
@SuppressWarnings("nls")
@ -50,12 +53,16 @@ public class PhoneStateChangedReceiver extends BroadcastReceiver {
if (calls.getCount() > 0) {
calls.moveToFirst();
int nameIndex = calls.getColumnIndex(Calls.CACHED_NAME);
String name = "";
if (nameIndex > -1)
name = calls.getString(nameIndex);
String name = calls.getString(nameIndex);
int timeIndex = calls.getColumnIndex(Calls.DATE);
long time = calls.getLong(timeIndex);
String timeString = DateUtilities.getTimeString(context, new Date(time));
Intent missedCallIntent = new Intent(context, MissedCallActivity.class);
missedCallIntent.putExtra(MissedCallActivity.EXTRA_NUMBER, lastNumber);
missedCallIntent.putExtra(MissedCallActivity.EXTRA_NAME, name);
missedCallIntent.putExtra(MissedCallActivity.EXTRA_TIME, timeString);
missedCallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(missedCallIntent);
}

@ -465,8 +465,8 @@
<!-- ===================================================== MissedCallActivity == -->
<!-- Missed call: return call -->
<string name="MCA_title">Missed call!</string>
<!-- Missed call: return call (%s -> time of call)-->
<string name="MCA_title">Missed call at %s</string>
<!-- Missed call: return call -->
<string name="MCA_return_call">Call now</string>
@ -478,10 +478,10 @@
<string name="MCA_ignore">Ignore</string>
<!-- Missed call: dialog with name. %s->caller name -->
<string name="MCA_dialog_with_name">%s just called you!</string>
<string name="MCA_dialog_with_name">%s just called. What do you want to do?</string>
<!-- Missed call: dialog without name. %s->phone number -->
<string name="MCA_dialog_without_name">Someone just called you from %s.</string>
<string name="MCA_dialog_without_name">Someone just called you from %s. What do you want to do?</string>
<!-- Missed call: dialog to ignore all missed calls title -->
<string name="MCA_ignore_title">Ignore all missed calls?</string>
@ -500,6 +500,14 @@
<!-- Missed call: preference description -->
<string name="MCA_missed_calls_pref_desc">Astrid will notify you about missed calls and offer to remind you to call back</string>
<!-- Missed call: task title with name (%1$s -> name, %2$s -> number)-->
<string name="MCA_task_title_name">Call %1$s back at %2$s</string>
<!-- Missed call: task title no name (%s -> number)-->
<string name="MCA_task_title_no_name">Call %s back</string>
<!-- ===================================================== HelpActivity == -->

Loading…
Cancel
Save