Started rebuilding list creation activity, stubs for some things

pull/14/head
Sam Bosley 12 years ago
parent 5416dc044c
commit 741909cc13

@ -3,41 +3,29 @@ 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.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
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.DialogUtilities;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.FilterWithCustomIntent;
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.TagDataService;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.utility.Constants;
public class CalendarAlarmListCreator extends Activity {
public static final String TOKEN_LIST_NAME = "listName"; //$NON-NLS-1$
public static final String TOKEN_LIST_ID = "listId"; //$NON-NLS-1$
@Autowired
private UserDao userDao;
@ -52,34 +40,38 @@ public class CalendarAlarmListCreator extends Activity {
private ArrayList<String> emails;
private HashMap<String, User> emailsToUsers;
private boolean loggedIn;
private TagData tagData;
private TextView inviteAll;
private TextView moreOptions;
private TextView ignoreButton;
private View dismissButton;
private View ignoreSettingsButton;
private Button saveButton;
private Button cancelButton;
private ListView membersList;
private EditText tagName;
private final OnClickListener dismissListener = new OnClickListener() {
@Override
public void onClick(View v) {
finish();
AndroidUtilities.callOverridePendingTransition(CalendarAlarmListCreator.this, 0, android.R.anim.fade_out);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DependencyInjectionService.getInstance().inject(this);
setContentView(R.layout.create_event_list_activity);
saveButton = (Button) findViewById(R.id.save);
cancelButton = (Button) findViewById(R.id.cancel);
tagName = (EditText) findViewById(R.id.list_name);
membersList = (ListView) findViewById(R.id.members_list);
setContentView(R.layout.calendar_alarm_list_creator);
Intent intent = getIntent();
names = intent.getStringArrayListExtra(CalendarReminderActivity.TOKEN_NAMES);
emails = intent.getStringArrayListExtra(CalendarReminderActivity.TOKEN_EMAILS);
tagName.setText(intent.getStringExtra(TOKEN_LIST_NAME));
loggedIn = actFmPreferenceService.isLoggedIn();
tagData = tagDataService.fetchById(intent.getLongExtra(TOKEN_LIST_ID, -1), TagData.PROPERTIES);
inviteAll = (TextView) findViewById(R.id.invite_all);
moreOptions = (TextView) findViewById(R.id.list_settings);
ignoreButton = (TextView) findViewById(R.id.ignore);
ignoreSettingsButton = findViewById(R.id.ignore_settings);
initializeUserMap();
initializeListView();
setupUi();
addListeners();
}
@ -97,88 +89,22 @@ public class CalendarAlarmListCreator extends Activity {
}
}
private void addListeners() {
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
private void setupUi() {
TextView dialogView = (TextView) findViewById(R.id.reminder_message);
dialogView.setText("Stuff here");
}
});
saveButton.setOnClickListener(new OnClickListener() {
private void addListeners() {
ignoreButton.setOnClickListener(dismissListener);
dismissButton.setOnClickListener(dismissListener);
ignoreSettingsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
save();
}
});
}
private void save() {
String name = tagName.getText().toString();
TagData checkName = tagDataService.getTag(name, TagData.PROPERTIES);
if (checkName != null) {
DialogUtilities.okDialog(this, getString(R.string.CRA_list_exists_title), null);
return;
}
TagData newTag = new TagData();
newTag.setValue(TagData.NAME, name);
if (loggedIn) { // include members
JSONArray membersArray = getMembersArray();
if (Constants.DEBUG)
Log.w(CalendarAlarmScheduler.TAG, "Creating tag with members: " + membersArray.toString()); //$NON-NLS-1$
newTag.setValue(TagData.MEMBERS, membersArray.toString());
newTag.setValue(TagData.MEMBER_COUNT, membersArray.length());
}
tagDataService.save(newTag);
FilterWithCustomIntent filter = TagFilterExposer.filterFromTagData(this, newTag);
Intent listIntent = new Intent(this, TaskListActivity.class);
listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
listIntent.putExtras(filter.customExtras);
startActivity(listIntent);
Intent editPreferences = new Intent(CalendarAlarmListCreator.this, EditPreferences.class);
startActivity(editPreferences);
finish();
}
private void initializeListView() {
if (loggedIn) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, android.R.id.text1);
membersList.setAdapter(adapter);
membersList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
emails.remove(ActFmPreferenceService.thisUser().optString("email", null)); //$NON-NLS-1$
for (int i = 0; i < emails.size(); i++) {
String email = emails.get(i);
adapter.add(email);
membersList.setItemChecked(i, true);
}
if (adapter.getCount() == 0)
membersList.setVisibility(View.GONE);
} else {
membersList.setVisibility(View.GONE);
}
}
private JSONArray getMembersArray() {
JSONArray array = new JSONArray();
for (int i = 0; i < membersList.getCount(); i++) {
if (membersList.isItemChecked(i)) {
try {
JSONObject member = new JSONObject();
member.put("email", (String) membersList.getItemAtPosition(i)); //$NON-NLS-1$
array.put(member);
} catch (JSONException e) {
// ignored
}
}
}
return array;
});
}
}

@ -87,7 +87,7 @@ public class CalendarReminderActivity extends Activity {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Preferences.setBoolean(R.string.p_field_missed_calls, false);
Preferences.setBoolean(R.string.p_calendar_reminders, false);
dismissListener.onClick(v);
}
},
@ -213,11 +213,15 @@ public class CalendarReminderActivity extends Activity {
});
}
private void createNewList(String defaultName) {
private void createNewList(String name) {
TagData newTagData = new TagData();
newTagData.setValue(TagData.NAME, name);
tagDataService.save(newTagData);
Intent newListIntent = new Intent(this, CalendarAlarmListCreator.class);
newListIntent.putStringArrayListExtra(TOKEN_NAMES, getIntent().getStringArrayListExtra(TOKEN_NAMES));
newListIntent.putStringArrayListExtra(TOKEN_EMAILS, getIntent().getStringArrayListExtra(TOKEN_EMAILS));
newListIntent.putExtra(CalendarAlarmListCreator.TOKEN_LIST_NAME, defaultName);
newListIntent.putExtra(CalendarAlarmListCreator.TOKEN_LIST_ID, newTagData.getId());
startActivity(newListIntent);
dismissButton.performClick(); // finish with animation

@ -0,0 +1,104 @@
<?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_share_list_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/invite_all"
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"/>
<TextView
android:id="@+id/list_settings"
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:background="#707070"
android:text="@string/CRA_postpone"/>
<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:padding="4dip"
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_list_creator_view"/>
</LinearLayout>

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/list_name"
android:layout_width="250dip"
android:layout_height="50dip"
android:hint="@string/CRA_list_name_hint"/>
<ListView
android:id="@+id/members_list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/cancel"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_weight="1"
android:text="@string/DLG_cancel"/>
<Button
android:id="@+id/save"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_weight="1"
android:text="@string/DLG_save"/>
</LinearLayout>
</LinearLayout>

@ -573,6 +573,9 @@
<!-- 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>
<!-- ===================================================== HelpActivity == -->
<!-- Help: Button to get support from our website -->

Loading…
Cancel
Save