First pass at everything except the more options button when creating a list

pull/14/head
Sam Bosley 13 years ago
parent 741909cc13
commit e1b4ecf257

@ -3,9 +3,14 @@ package com.todoroo.astrid.gcal;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
@ -22,6 +27,7 @@ import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.ThemeService;
public class CalendarAlarmListCreator extends Activity {
@ -77,6 +83,13 @@ public class CalendarAlarmListCreator extends Activity {
}
private void initializeUserMap() {
String thisUser = ActFmPreferenceService.thisUser().optString("email"); //$NON-NLS-1$
if (emails.contains(thisUser)) {
int index = emails.indexOf(thisUser);
emails.remove(index);
names.remove(index);
}
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 {
@ -91,7 +104,29 @@ public class CalendarAlarmListCreator extends Activity {
private void setupUi() {
TextView dialogView = (TextView) findViewById(R.id.reminder_message);
dialogView.setText("Stuff here");
StringBuilder builder = new StringBuilder(getString(R.string.CRA_created_list_dialog, tagData.getValue(TagData.NAME)));
String attendeesString = buildAttendeesString();
int color = ThemeService.getThemeColor();
String title;
if (!TextUtils.isEmpty(attendeesString)) {
builder.append(attendeesString)
.append(" ") //$NON-NLS-1$
.append(getString(R.string.CRA_invitation_prompt));
inviteAll.setBackgroundColor(getResources().getColor(color));
title = getString(R.string.CRA_share_list_title);
} else {
title = getString(R.string.CRA_list_created_title);
moreOptions.setBackgroundColor(getResources().getColor(color));
inviteAll.setVisibility(View.GONE);
ignoreButton.setVisibility(View.GONE);
ignoreSettingsButton.setVisibility(View.GONE);
}
((TextView) findViewById(R.id.reminder_title))
.setText(title);
dialogView.setText(builder.toString());
}
private void addListeners() {
@ -106,5 +141,75 @@ public class CalendarAlarmListCreator extends Activity {
finish();
}
});
inviteAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Set members json and save
if (!actFmPreferenceService.isLoggedIn()) {
moreOptions.performClick();
return;
} else {
JSONArray membersArray = buildMembersArray();
tagData.setValue(TagData.MEMBERS, membersArray.toString());
tagData.setValue(TagData.MEMBER_COUNT, membersArray.length());
tagDataService.save(tagData);
}
}
});
moreOptions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//
}
});
}
private String buildAttendeesString() {
if (emails.size() == 0) {
return ""; //$NON-NLS-1$
} else if (emails.size() == 1) {
String displayName = getDisplayName(0);
return getString(R.string.CRA_one_attendee, displayName);
} else { // emails.size() >= 2
String displayName1 = getDisplayName(0);
String displayName2 = getDisplayName(1);
int extras = emails.size() - 2;
if (extras > 0)
return getString(R.string.CRA_many_attendees, displayName1, displayName2, extras);
else
return getString(R.string.CRA_two_attendees, displayName1, displayName2);
}
}
private JSONArray buildMembersArray() {
JSONArray array = new JSONArray();
for (String email : emails) {
JSONObject member = new JSONObject();
try {
member.put("email", email); //$NON-NLS-1$
array.put(member);
} catch (JSONException e) {
//
}
}
return array;
}
private String getDisplayName(int index) {
String name = names.get(index);
if (!TextUtils.isEmpty(name))
return name;
String email = emails.get(index);
if (emailsToUsers.containsKey(email)) {
User u = emailsToUsers.get(email);
String userName = u.getValue(User.NAME);
if (!TextUtils.isEmpty(userName))
return userName;
}
return email;
}
}

@ -564,17 +564,29 @@
<!-- Calendar reminder: list exists dialog use existing button -->
<string name="CRA_use_existing">Use existing</string>
<!-- Calendar reminder: list title hint -->
<string name="CRA_list_name_hint">List name</string>
<!-- Calendar remindr: created list (%s -> list name) -->
<string name="CRA_created_list_dialog">I created a list %s.</string>
<!-- Calendar reminder: include event members -->
<string name="CRA_include_members">Share with event members</string>
<!-- Calendar reminder: one attendee (%s -> attendee name or email) -->
<string name="CRA_one_attendee">%s is attending.</string>
<!-- Calendar reminder: two attendees (%s -> attendee name or email) -->
<string name="CRA_two_attendees">%1$s and %2$s are attending.</string>
<!-- Calendar reminder: many attendees (%s -> attendee name or email, %3$i -> how many other people) -->
<string name="CRA_many_attendees">%1$s, %2$s, and %3$i others are attending.</string>
<!-- Calendar reminder: invitation prompt -->
<string name="CRA_invitation_prompt">Want to invite them?</string>
<!-- Calendar reminder: preference title -->
<string name="CRA_calendar_reminders_pref_title">Monitor calendar events</string>
<!-- Calendar reminder: share list title -->
<string name="CRA_share_list_title">Share the list?</string>
<!-- Calendar reminder: share list title when no other attendees exist-->
<string name="CRA_list_created_title">List created!</string>
<!-- ===================================================== HelpActivity == -->

Loading…
Cancel
Save