mirror of https://github.com/tasks/tasks
Lots of progress + stubs for the calendar reminder activity
parent
1d891a8c01
commit
c62c117b37
@ -0,0 +1,225 @@
|
|||||||
|
package com.todoroo.astrid.gcal;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.timsu.astrid.R;
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.andlib.service.Autowired;
|
||||||
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||||
|
import com.todoroo.andlib.sql.Query;
|
||||||
|
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||||
|
import com.todoroo.andlib.utility.DateUtilities;
|
||||||
|
import com.todoroo.andlib.utility.DialogUtilities;
|
||||||
|
import com.todoroo.andlib.utility.Preferences;
|
||||||
|
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
||||||
|
import com.todoroo.astrid.activity.EditPreferences;
|
||||||
|
import com.todoroo.astrid.dao.UserDao;
|
||||||
|
import com.todoroo.astrid.data.TagData;
|
||||||
|
import com.todoroo.astrid.data.User;
|
||||||
|
import com.todoroo.astrid.service.StartupService;
|
||||||
|
import com.todoroo.astrid.service.TagDataService;
|
||||||
|
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
public class CalendarReminderActivity extends Activity {
|
||||||
|
|
||||||
|
public static final String TOKEN_NAMES = "names";
|
||||||
|
public static final String TOKEN_EMAILS = "emails";
|
||||||
|
public static final String TOKEN_EVENT_NAME = "eventName";
|
||||||
|
public static final String TOKEN_EVENT_TIME = "eventTime";
|
||||||
|
|
||||||
|
private static final String PREF_IGNORE_PRESSES = "calEventsIgnored";
|
||||||
|
|
||||||
|
// Prompt user to ignore all missed calls after this many ignore presses
|
||||||
|
private static final int IGNORE_PROMPT_COUNT = 3;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TagDataService tagDataService;
|
||||||
|
|
||||||
|
private ArrayList<String> names;
|
||||||
|
private ArrayList<String> emails;
|
||||||
|
private HashMap<String, User> emailsToUsers;
|
||||||
|
private String eventName;
|
||||||
|
private long eventTime;
|
||||||
|
|
||||||
|
private TextView ignoreButton;
|
||||||
|
private TextView createListButton;
|
||||||
|
private View dismissButton;
|
||||||
|
private View ignoreSettingsButton;
|
||||||
|
|
||||||
|
private final OnClickListener dismissListener = new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
AndroidUtilities.callOverridePendingTransition(CalendarReminderActivity.this, 0, android.R.anim.fade_out);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final OnClickListener ignoreListener = new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(final View v) {
|
||||||
|
// Check for number of ignore presses
|
||||||
|
int ignorePresses = Preferences.getInt(PREF_IGNORE_PRESSES, 0);
|
||||||
|
ignorePresses++;
|
||||||
|
if (ignorePresses == IGNORE_PROMPT_COUNT) {
|
||||||
|
DialogUtilities.okCancelCustomDialog(CalendarReminderActivity.this,
|
||||||
|
getString(R.string.CRA_ignore_title),
|
||||||
|
getString(R.string.CRA_ignore_body),
|
||||||
|
R.string.CRA_ignore_all,
|
||||||
|
R.string.CRA_ignore_this,
|
||||||
|
0,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Preferences.setBoolean(R.string.p_field_missed_calls, false);
|
||||||
|
dismissListener.onClick(v);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dismissListener.onClick(v);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dismissListener.onClick(v);
|
||||||
|
}
|
||||||
|
Preferences.setInt(PREF_IGNORE_PRESSES, ignorePresses);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
new StartupService().onStartupApplication(this);
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
DependencyInjectionService.getInstance().inject(this);
|
||||||
|
|
||||||
|
setContentView(R.layout.calendar_reminder_activity);
|
||||||
|
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
names = intent.getStringArrayListExtra(TOKEN_NAMES);
|
||||||
|
emails = intent.getStringArrayListExtra(TOKEN_EMAILS);
|
||||||
|
eventName = intent.getStringExtra(TOKEN_EVENT_NAME);
|
||||||
|
eventTime = intent.getLongExtra(TOKEN_EVENT_TIME, DateUtilities.now());
|
||||||
|
|
||||||
|
createListButton = (TextView) findViewById(R.id.create_list);
|
||||||
|
ignoreButton = (TextView) findViewById(R.id.ignore);
|
||||||
|
ignoreSettingsButton = findViewById(R.id.ignore_settings);
|
||||||
|
dismissButton = findViewById(R.id.dismiss);
|
||||||
|
|
||||||
|
initializeUserMap();
|
||||||
|
|
||||||
|
setupUi();
|
||||||
|
|
||||||
|
addListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeUserMap() {
|
||||||
|
emailsToUsers = new HashMap<String, User>();
|
||||||
|
TodorooCursor<User> users = userDao.query(Query.select(User.PROPERTIES).where(User.EMAIL.in(emails.toArray(new String[emails.size()]))));
|
||||||
|
try {
|
||||||
|
for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) {
|
||||||
|
User u = new User(users);
|
||||||
|
emailsToUsers.put(u.getValue(User.EMAIL), u);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
users.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupUi() {
|
||||||
|
((TextView) findViewById(R.id.reminder_title))
|
||||||
|
.setText(getString(R.string.CRA_title, eventName));
|
||||||
|
|
||||||
|
LinearLayout root = (LinearLayout) findViewById(R.id.reminder_root);
|
||||||
|
|
||||||
|
for (int i = 0; i < emails.size(); i++) {
|
||||||
|
String email = emails.get(i);
|
||||||
|
if (email.equals(ActFmPreferenceService.thisUser().optString("email", null)))
|
||||||
|
continue;
|
||||||
|
String displayString = email;
|
||||||
|
if (!TextUtils.isEmpty(names.get(i))) {
|
||||||
|
displayString = names.get(i);
|
||||||
|
} else if (emailsToUsers.containsKey(email)) {
|
||||||
|
User u = emailsToUsers.get(email);
|
||||||
|
displayString = u.getDisplayName();
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView tv = new TextView(this);
|
||||||
|
tv.setText(displayString);
|
||||||
|
tv.setTextColor(getResources().getColor(android.R.color.white));
|
||||||
|
root.addView(tv);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView dialogView = (TextView) findViewById(R.id.reminder_message);
|
||||||
|
dialogView.setText(getString(R.string.CRA_speech_bubble));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addListeners() {
|
||||||
|
ignoreButton.setOnClickListener(ignoreListener);
|
||||||
|
dismissButton.setOnClickListener(dismissListener);
|
||||||
|
|
||||||
|
ignoreSettingsButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent editPreferences = new Intent(CalendarReminderActivity.this, EditPreferences.class);
|
||||||
|
startActivity(editPreferences);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
createListButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
TagData existing = tagDataService.getTag(eventName, TagData.PROPERTIES);
|
||||||
|
if (existing != null) {
|
||||||
|
listExists(existing);
|
||||||
|
} else {
|
||||||
|
createNewList(eventName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listExists(final TagData tag) {
|
||||||
|
DialogUtilities.okCancelCustomDialog(this,
|
||||||
|
getString(R.string.CRA_list_exists_title),
|
||||||
|
getString(R.string.CRA_list_exists_body, tag.getValue(TagData.NAME)),
|
||||||
|
R.string.CRA_create_new,
|
||||||
|
R.string.CRA_use_existing,
|
||||||
|
0,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
createNewList(tag.getValue(TagData.NAME) + " "
|
||||||
|
+ DateUtilities.getDateStringHideYear(CalendarReminderActivity.this, new Date(eventTime)));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
// use existing list
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createNewList(String defaultName) {
|
||||||
|
// Do something
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
<?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:id="@+id/reminder_root"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dip"
|
||||||
|
android:layout_marginRight="10dip"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="@drawable/reminder_dialog_background">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_marginTop="5dip"
|
||||||
|
android:layout_marginRight="5dip"
|
||||||
|
android:layout_marginBottom="15dip"
|
||||||
|
android:layout_marginLeft="10dip">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/reminder_title"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="1dip"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/CRA_title"/>
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/dismiss"
|
||||||
|
android:layout_width="25dip"
|
||||||
|
android:layout_height="25dip"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_menu_close"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/calendar_reminder_speech_bubble"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<include layout="@layout/astrid_speech_bubble" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/create_list"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="35dip"
|
||||||
|
android:layout_marginLeft="10dip"
|
||||||
|
android:layout_marginRight="10dip"
|
||||||
|
android:layout_marginBottom="10dip"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/CRA_create_list"/>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dip"
|
||||||
|
android:layout_marginRight="10dip"
|
||||||
|
android:layout_marginBottom="10dip">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ignore"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="35dip"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/CRA_ignore"
|
||||||
|
android:background="#707070"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ignore_settings"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_width="35dip"
|
||||||
|
android:layout_height="35dip"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/single_gear"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
<?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="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<include layout="@layout/astrid_calendar_reminder_view"/>
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Reference in New Issue