Updates to metadata control sets to touch task last modified so they will be sync'd, fixed a NPE in PDV

pull/14/head
Tim Su 16 years ago
parent d507084ddc
commit 613516e06a

@ -2,9 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timsu.astrid" package="com.timsu.astrid"
android:versionName="3.1.0" android:versionCode="146"> android:versionName="3.1.0" android:versionCode="146">
<!-- android:installLocation="internalOnly"> -->
<!-- widgets, alarms, and services will break if Astrid is installed on SD card --> <!-- widgets, alarms, and services will break if Astrid is installed on SD card -->
<!-- android:installLocation="internalOnly"> -->
<!-- ================================================== Used Permissions = --> <!-- ================================================== Used Permissions = -->
@ -53,7 +53,7 @@
<supports-screens /> <supports-screens />
<application android:icon="@drawable/icon" <application android:icon="@drawable/icon"
android:label="@string/app_name" android:debuggable="true"> android:label="@string/app_name">
<!-- ====================================================== Activities = --> <!-- ====================================================== Activities = -->

@ -6,11 +6,13 @@
<intAttribute key="ch.zork.quicklaunch.index" value="0"/> <intAttribute key="ch.zork.quicklaunch.index" value="0"/>
<stringAttribute key="ch.zork.quicklaunch.mode" value="run"/> <stringAttribute key="ch.zork.quicklaunch.mode" value="run"/>
<intAttribute key="com.android.ide.eclipse.adt.action" value="0"/> <intAttribute key="com.android.ide.eclipse.adt.action" value="0"/>
<stringAttribute key="com.android.ide.eclipse.adt.activity" value="com.todoroo.astrid.core.CustomFilterActivity"/>
<stringAttribute key="com.android.ide.eclipse.adt.avd" value="android-22"/>
<stringAttribute key="com.android.ide.eclipse.adt.commandline" value="-scale 0.7"/> <stringAttribute key="com.android.ide.eclipse.adt.commandline" value="-scale 0.7"/>
<intAttribute key="com.android.ide.eclipse.adt.delay" value="0"/> <intAttribute key="com.android.ide.eclipse.adt.delay" value="0"/>
<booleanAttribute key="com.android.ide.eclipse.adt.nobootanim" value="true"/> <booleanAttribute key="com.android.ide.eclipse.adt.nobootanim" value="true"/>
<intAttribute key="com.android.ide.eclipse.adt.speed" value="0"/> <intAttribute key="com.android.ide.eclipse.adt.speed" value="0"/>
<booleanAttribute key="com.android.ide.eclipse.adt.target" value="false"/> <booleanAttribute key="com.android.ide.eclipse.adt.target" value="true"/>
<booleanAttribute key="com.android.ide.eclipse.adt.wipedata" value="false"/> <booleanAttribute key="com.android.ide.eclipse.adt.wipedata" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/astrid"/> <listEntry value="/astrid"/>

@ -10,5 +10,5 @@
# Indicates whether an apk should be generated for each density. # Indicates whether an apk should be generated for each density.
split.density=false split.density=false
# Project target. # Project target.
target=Motorola, Inc.:MILESTONE:7 target=android-8
apk-configurations= apk-configurations=

@ -4,18 +4,15 @@ import java.util.ArrayList;
import android.app.Activity; import android.app.Activity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet; import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.StoreObject; import com.todoroo.astrid.model.StoreObject;
@ -24,6 +21,7 @@ import com.todoroo.astrid.producteev.sync.ProducteevDashboard;
import com.todoroo.astrid.producteev.sync.ProducteevDataService; import com.todoroo.astrid.producteev.sync.ProducteevDataService;
import com.todoroo.astrid.producteev.sync.ProducteevTask; import com.todoroo.astrid.producteev.sync.ProducteevTask;
import com.todoroo.astrid.producteev.sync.ProducteevUser; import com.todoroo.astrid.producteev.sync.ProducteevUser;
import com.todoroo.astrid.service.MetadataService;
/** /**
* Control Set for managing task/dashboard assignments in Producteev * Control Set for managing task/dashboard assignments in Producteev
@ -35,9 +33,6 @@ public class ProducteevControlSet implements TaskEditControlSet {
// --- instance variables // --- instance variables
@Autowired
private ExceptionService exceptionService;
private final Activity activity; private final Activity activity;
private Task myTask; private Task myTask;
@ -47,6 +42,9 @@ public class ProducteevControlSet implements TaskEditControlSet {
private ArrayList<ProducteevUser> users = null; private ArrayList<ProducteevUser> users = null;
private ArrayList<ProducteevDashboard> dashboards = null; private ArrayList<ProducteevDashboard> dashboards = null;
@Autowired
MetadataService metadataService;
public ProducteevControlSet(final Activity activity, ViewGroup parent) { public ProducteevControlSet(final Activity activity, ViewGroup parent) {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
@ -54,36 +52,7 @@ public class ProducteevControlSet implements TaskEditControlSet {
LayoutInflater.from(activity).inflate(R.layout.producteev_control, parent, true); LayoutInflater.from(activity).inflate(R.layout.producteev_control, parent, true);
this.responsibleSelector = (Spinner) activity.findViewById(R.id.producteev_TEA_task_assign); this.responsibleSelector = (Spinner) activity.findViewById(R.id.producteev_TEA_task_assign);
this.responsibleSelector.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO tim, please set a flag here somewhere, so that producteevinvoker knows
// it has to invoke tasks/set_responsible, or otherwise do it your way...
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
this.dashboardSelector = (Spinner) activity.findViewById(R.id.producteev_TEA_dashboard_assign); this.dashboardSelector = (Spinner) activity.findViewById(R.id.producteev_TEA_dashboard_assign);
this.dashboardSelector.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO tim, please set a flag here somewhere, so that producteevinvoker knows
// it has to invoke tasks/set_dashboard, or otherwise do it your way...
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
} }
@Override @Override
@ -95,7 +64,7 @@ public class ProducteevControlSet implements TaskEditControlSet {
long dashboardId = metadata.getValue(ProducteevTask.DASHBOARD_ID); long dashboardId = metadata.getValue(ProducteevTask.DASHBOARD_ID);
StoreObject[] dashboardsData = ProducteevDataService.getInstance().getDashboards(); StoreObject[] dashboardsData = ProducteevDataService.getInstance().getDashboards();
dashboards = new ArrayList(dashboardsData.length); dashboards = new ArrayList<ProducteevDashboard>(dashboardsData.length);
ProducteevDashboard ownerDashboard = null; ProducteevDashboard ownerDashboard = null;
int dashboardSpinnerIndex = 0; int dashboardSpinnerIndex = 0;
//dashboard to not sync as first spinner-entry //dashboard to not sync as first spinner-entry
@ -109,7 +78,7 @@ public class ProducteevControlSet implements TaskEditControlSet {
} }
} }
ArrayAdapter<String> dashAdapter = new ArrayAdapter(activity, ArrayAdapter<ProducteevDashboard> dashAdapter = new ArrayAdapter<ProducteevDashboard>(activity,
android.R.layout.simple_spinner_item, dashboards); android.R.layout.simple_spinner_item, dashboards);
dashAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dashAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dashboardSelector.setAdapter(dashAdapter); dashboardSelector.setAdapter(dashAdapter);
@ -134,23 +103,33 @@ public class ProducteevControlSet implements TaskEditControlSet {
} }
userSpinnerIndex++; userSpinnerIndex++;
} }
ArrayAdapter<String> usersAdapter = new ArrayAdapter(activity, ArrayAdapter<ProducteevUser> usersAdapter = new ArrayAdapter<ProducteevUser>(activity,
android.R.layout.simple_spinner_item, users); android.R.layout.simple_spinner_item, users);
usersAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
responsibleSelector.setAdapter(usersAdapter); responsibleSelector.setAdapter(usersAdapter);
responsibleSelector.setSelection(userSpinnerIndex); responsibleSelector.setSelection(userSpinnerIndex);
} }
} }
@SuppressWarnings("nls")
@Override @Override
public void writeToModel(Task task) { public void writeToModel(Task task) {
Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(task.getId()); Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(task.getId());
if (metadata != null) { if (metadata == null) {
ProducteevDashboard dashboard = (ProducteevDashboard) dashboardSelector.getSelectedItem(); metadata = new Metadata();
metadata.setValue(ProducteevTask.DASHBOARD_ID, dashboard.getId()); metadata.setValue(Metadata.KEY, ProducteevTask.METADATA_KEY);
metadata.setValue(Metadata.TASK, task.getId());
metadata.setValue(ProducteevTask.ID, 0L);
}
ProducteevDashboard dashboard = (ProducteevDashboard) dashboardSelector.getSelectedItem();
metadata.setValue(ProducteevTask.DASHBOARD_ID, dashboard.getId());
ProducteevUser responsibleUser = (ProducteevUser) responsibleSelector.getSelectedItem(); ProducteevUser responsibleUser = (ProducteevUser) responsibleSelector.getSelectedItem();
metadata.setValue(ProducteevTask.RESPONSIBLE_ID, responsibleUser.getId()); metadata.setValue(ProducteevTask.RESPONSIBLE_ID, responsibleUser.getId());
if(metadata.getSetValues().size() > 0 ) {
metadataService.save(metadata);
task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
} }
} }
} }

@ -48,6 +48,7 @@ public class ProducteevDashboard {
* @param name name of the remote dashboard * @param name name of the remote dashboard
* @param usercsv csv-userstring as returned by a StoreObject-dashboard with property ProducteevDashboard.USERS * @param usercsv csv-userstring as returned by a StoreObject-dashboard with property ProducteevDashboard.USERS
*/ */
@SuppressWarnings("nls")
public ProducteevDashboard(long id, String name, String usercsv) { public ProducteevDashboard(long id, String name, String usercsv) {
this.id = id; this.id = id;
this.name = name; this.name = name;

@ -477,19 +477,25 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
if(toAdd.size() > 0) { if(toAdd.size() > 0) {
for(String label : toAdd) { for(String label : toAdd) {
if(!labelMap.containsKey(label)) { ProducteevLabel pdvLabel = new ProducteevLabel();
pdvLabel.name = label;
pdvLabel.dashboard = idDashboard;
if(!labelMap.containsKey(pdvLabel)) {
JSONObject result = invoker.labelsCreate(idDashboard, label).getJSONObject("label"); JSONObject result = invoker.labelsCreate(idDashboard, label).getJSONObject("label");
putLabelIntoCache(result); putLabelIntoCache(result);
} }
invoker.tasksSetLabel(idTask, labelMap.get(label)); invoker.tasksSetLabel(idTask, labelMap.get(pdvLabel));
} }
} }
if(toRemove.size() > 0) { if(toRemove.size() > 0) {
for(String label : toRemove) { for(String label : toRemove) {
if(!labelMap.containsKey(label)) ProducteevLabel pdvLabel = new ProducteevLabel();
pdvLabel.name = label;
pdvLabel.dashboard = idDashboard;
if(!labelMap.containsKey(pdvLabel))
continue; continue;
invoker.tasksUnsetLabel(idTask, labelMap.get(label)); invoker.tasksUnsetLabel(idTask, labelMap.get(pdvLabel));
} }
} }
} }

@ -15,6 +15,7 @@ import android.widget.TextView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet; import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
@ -32,6 +33,7 @@ public final class TagsControlSet implements TaskEditControlSet {
private final TagService tagService = TagService.getInstance(); private final TagService tagService = TagService.getInstance();
private final Tag[] allTags; private final Tag[] allTags;
private String[] loadedTags;
private final LinearLayout tagsContainer; private final LinearLayout tagsContainer;
private final Activity activity; private final Activity activity;
@ -47,8 +49,13 @@ public final class TagsControlSet implements TaskEditControlSet {
TodorooCursor<Metadata> cursor = tagService.getTags(task.getId()); TodorooCursor<Metadata> cursor = tagService.getTags(task.getId());
try { try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) loadedTags = new String[cursor.getCount()];
addTag(cursor.get(TagService.TAG)); for(int i = 0; i < loadedTags.length; i++) {
cursor.moveToNext();
String tag = cursor.get(TagService.TAG);
addTag(tag);
loadedTags[i] = tag;
}
} finally { } finally {
cursor.close(); cursor.close();
} }
@ -63,15 +70,25 @@ public final class TagsControlSet implements TaskEditControlSet {
return; return;
LinkedHashSet<String> tags = new LinkedHashSet<String>(); LinkedHashSet<String> tags = new LinkedHashSet<String>();
boolean identical = true;
for(int i = 0; i < tagsContainer.getChildCount(); i++) { for(int i = 0; i < tagsContainer.getChildCount(); i++) {
TextView tagName = (TextView)tagsContainer.getChildAt(i).findViewById(R.id.text1); TextView tagName = (TextView)tagsContainer.getChildAt(i).findViewById(R.id.text1);
if(tagName.getText().length() == 0) if(tagName.getText().length() == 0)
continue; continue;
tags.add(tagName.getText().toString()); String tag = tagName.getText().toString();
tags.add(tag);
if(loadedTags.length <= i || !loadedTags[i].equals(tag))
identical = false;
} }
if(identical && tags.size() != loadedTags.length)
identical = false;
tagService.synchronizeTags(task.getId(), tags); if(!identical) {
tagService.synchronizeTags(task.getId(), tags);
task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
}
} }
/** Adds a tag to the tag field */ /** Adds a tag to the tag field */

@ -8,42 +8,39 @@ import java.util.concurrent.atomic.AtomicReference;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ListActivity; import android.app.ListActivity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnKeyListener; import android.view.View.OnKeyListener;
import android.view.Window;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast; import android.widget.Toast;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.TextView.OnEditorActionListener;
import com.flurry.android.FlurryAgent; import com.flurry.android.FlurryAgent;
import com.timsu.astrid.R; import com.timsu.astrid.R;
@ -71,11 +68,9 @@ import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.producteev.ProducteevBackgroundService;
import com.todoroo.astrid.reminders.Notifications; import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.reminders.ReminderService; import com.todoroo.astrid.reminders.ReminderService;
import com.todoroo.astrid.reminders.ReminderService.AlarmScheduler; import com.todoroo.astrid.reminders.ReminderService.AlarmScheduler;
import com.todoroo.astrid.rmilk.MilkBackgroundService;
import com.todoroo.astrid.rmilk.MilkPreferences; import com.todoroo.astrid.rmilk.MilkPreferences;
import com.todoroo.astrid.service.AddOnService; import com.todoroo.astrid.service.AddOnService;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
@ -199,9 +194,6 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
loadContextMenuIntents(); loadContextMenuIntents();
} }
}).start(); }).start();
// bind to services that require task list refreshing
bindServices();
} }
/** /**
@ -368,24 +360,6 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
sortSort= Preferences.getInt(SortSelectionActivity.PREF_SORT_SORT, 0); sortSort= Preferences.getInt(SortSelectionActivity.PREF_SORT_SORT, 0);
} }
public void bindServices() {
ServiceConnection refreshConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
System.err.println("connected to service " + name); //$NON-NLS-1$
//
}
@Override
public void onServiceDisconnected(ComponentName name) {
// service disconnected, let's refresh
System.err.println("your junk was done, refreshing"); //$NON-NLS-1$
loadTaskListContent(true);
}
};
bindService(new Intent(this, MilkBackgroundService.class), refreshConnection, 0);
bindService(new Intent(this, ProducteevBackgroundService.class), refreshConnection, 0);
}
/* ====================================================================== /* ======================================================================
* ============================================================ lifecycle * ============================================================ lifecycle
* ====================================================================== */ * ====================================================================== */

Loading…
Cancel
Save