From 613516e06a37b36c193c55d443c85481c5becc9e Mon Sep 17 00:00:00 2001 From: Tim Su Date: Fri, 13 Aug 2010 03:22:14 -0700 Subject: [PATCH] Updates to metadata control sets to touch task last modified so they will be sync'd, fixed a NPE in PDV --- astrid/AndroidManifest.xml | 4 +- astrid/astrid.launch | 4 +- astrid/default.properties | 2 +- .../producteev/ProducteevControlSet.java | 71 +++++++------------ .../producteev/sync/ProducteevDashboard.java | 1 + .../sync/ProducteevSyncProvider.java | 14 ++-- .../todoroo/astrid/tags/TagsControlSet.java | 25 +++++-- .../astrid/activity/TaskListActivity.java | 36 ++-------- 8 files changed, 68 insertions(+), 89 deletions(-) diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 5847ce2c2..5bc6d7daf 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -2,9 +2,9 @@ - + @@ -53,7 +53,7 @@ + android:label="@string/app_name"> diff --git a/astrid/astrid.launch b/astrid/astrid.launch index 7ce8fc659..19f7df00c 100644 --- a/astrid/astrid.launch +++ b/astrid/astrid.launch @@ -6,11 +6,13 @@ + + - + diff --git a/astrid/default.properties b/astrid/default.properties index dab739e94..c5d5335ee 100644 --- a/astrid/default.properties +++ b/astrid/default.properties @@ -10,5 +10,5 @@ # Indicates whether an apk should be generated for each density. split.density=false # Project target. -target=Motorola, Inc.:MILESTONE:7 +target=android-8 apk-configurations= diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java index aa852321c..ea5adde07 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java @@ -4,18 +4,15 @@ import java.util.ArrayList; import android.app.Activity; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.TextView; -import android.widget.AdapterView.OnItemSelectedListener; import com.timsu.astrid.R; import com.todoroo.andlib.service.Autowired; 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.model.Metadata; 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.ProducteevTask; import com.todoroo.astrid.producteev.sync.ProducteevUser; +import com.todoroo.astrid.service.MetadataService; /** * Control Set for managing task/dashboard assignments in Producteev @@ -35,9 +33,6 @@ public class ProducteevControlSet implements TaskEditControlSet { // --- instance variables - @Autowired - private ExceptionService exceptionService; - private final Activity activity; private Task myTask; @@ -47,6 +42,9 @@ public class ProducteevControlSet implements TaskEditControlSet { private ArrayList users = null; private ArrayList dashboards = null; + @Autowired + MetadataService metadataService; + public ProducteevControlSet(final Activity activity, ViewGroup parent) { DependencyInjectionService.getInstance().inject(this); @@ -54,36 +52,7 @@ public class ProducteevControlSet implements TaskEditControlSet { LayoutInflater.from(activity).inflate(R.layout.producteev_control, parent, true); 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.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 @@ -95,7 +64,7 @@ public class ProducteevControlSet implements TaskEditControlSet { long dashboardId = metadata.getValue(ProducteevTask.DASHBOARD_ID); StoreObject[] dashboardsData = ProducteevDataService.getInstance().getDashboards(); - dashboards = new ArrayList(dashboardsData.length); + dashboards = new ArrayList(dashboardsData.length); ProducteevDashboard ownerDashboard = null; int dashboardSpinnerIndex = 0; //dashboard to not sync as first spinner-entry @@ -109,7 +78,7 @@ public class ProducteevControlSet implements TaskEditControlSet { } } - ArrayAdapter dashAdapter = new ArrayAdapter(activity, + ArrayAdapter dashAdapter = new ArrayAdapter(activity, android.R.layout.simple_spinner_item, dashboards); dashAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dashboardSelector.setAdapter(dashAdapter); @@ -134,23 +103,33 @@ public class ProducteevControlSet implements TaskEditControlSet { } userSpinnerIndex++; } - ArrayAdapter usersAdapter = new ArrayAdapter(activity, + ArrayAdapter usersAdapter = new ArrayAdapter(activity, android.R.layout.simple_spinner_item, users); + usersAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); responsibleSelector.setAdapter(usersAdapter); responsibleSelector.setSelection(userSpinnerIndex); } } - @SuppressWarnings("nls") @Override public void writeToModel(Task task) { Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(task.getId()); - if (metadata != null) { - ProducteevDashboard dashboard = (ProducteevDashboard) dashboardSelector.getSelectedItem(); - metadata.setValue(ProducteevTask.DASHBOARD_ID, dashboard.getId()); + if (metadata == null) { + metadata = new Metadata(); + 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(); - metadata.setValue(ProducteevTask.RESPONSIBLE_ID, responsibleUser.getId()); + ProducteevUser responsibleUser = (ProducteevUser) responsibleSelector.getSelectedItem(); + metadata.setValue(ProducteevTask.RESPONSIBLE_ID, responsibleUser.getId()); + + if(metadata.getSetValues().size() > 0 ) { + metadataService.save(metadata); + task.setValue(Task.MODIFICATION_DATE, DateUtilities.now()); } - } + } } \ No newline at end of file diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDashboard.java b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDashboard.java index 63cca91d4..2deefe8cf 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDashboard.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDashboard.java @@ -48,6 +48,7 @@ public class ProducteevDashboard { * @param name name of the remote dashboard * @param usercsv csv-userstring as returned by a StoreObject-dashboard with property ProducteevDashboard.USERS */ + @SuppressWarnings("nls") public ProducteevDashboard(long id, String name, String usercsv) { this.id = id; this.name = name; diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java index 919f2aa23..4c22a5607 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java @@ -477,19 +477,25 @@ public class ProducteevSyncProvider extends SyncProvider 0) { 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"); putLabelIntoCache(result); } - invoker.tasksSetLabel(idTask, labelMap.get(label)); + invoker.tasksSetLabel(idTask, labelMap.get(pdvLabel)); } } if(toRemove.size() > 0) { for(String label : toRemove) { - if(!labelMap.containsKey(label)) + ProducteevLabel pdvLabel = new ProducteevLabel(); + pdvLabel.name = label; + pdvLabel.dashboard = idDashboard; + if(!labelMap.containsKey(pdvLabel)) continue; - invoker.tasksUnsetLabel(idTask, labelMap.get(label)); + invoker.tasksUnsetLabel(idTask, labelMap.get(pdvLabel)); } } } diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java index a4efc1299..6b699168f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java @@ -15,6 +15,7 @@ import android.widget.TextView; import com.timsu.astrid.R; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.sql.Criterion; +import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet; import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Task; @@ -32,6 +33,7 @@ public final class TagsControlSet implements TaskEditControlSet { private final TagService tagService = TagService.getInstance(); private final Tag[] allTags; + private String[] loadedTags; private final LinearLayout tagsContainer; private final Activity activity; @@ -47,8 +49,13 @@ public final class TagsControlSet implements TaskEditControlSet { TodorooCursor cursor = tagService.getTags(task.getId()); try { - for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) - addTag(cursor.get(TagService.TAG)); + loadedTags = new String[cursor.getCount()]; + for(int i = 0; i < loadedTags.length; i++) { + cursor.moveToNext(); + String tag = cursor.get(TagService.TAG); + addTag(tag); + loadedTags[i] = tag; + } } finally { cursor.close(); } @@ -63,15 +70,25 @@ public final class TagsControlSet implements TaskEditControlSet { return; LinkedHashSet tags = new LinkedHashSet(); + boolean identical = true; for(int i = 0; i < tagsContainer.getChildCount(); i++) { TextView tagName = (TextView)tagsContainer.getChildAt(i).findViewById(R.id.text1); if(tagName.getText().length() == 0) 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 */ diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index fb516461e..ee8b1f841 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -8,42 +8,39 @@ import java.util.concurrent.atomic.AtomicReference; import android.app.AlertDialog; import android.app.ListActivity; import android.content.BroadcastReceiver; -import android.content.ComponentName; import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; -import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.os.IBinder; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.ContextMenu; -import android.view.ContextMenu.ContextMenuInfo; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.Window; +import android.view.ContextMenu.ContextMenuInfo; import android.view.View.OnClickListener; import android.view.View.OnKeyListener; -import android.view.Window; import android.view.inputmethod.EditorInfo; import android.widget.AbsListView; -import android.widget.AbsListView.OnScrollListener; -import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; -import android.widget.TextView.OnEditorActionListener; 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.timsu.astrid.R; @@ -71,11 +68,9 @@ import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Task; -import com.todoroo.astrid.producteev.ProducteevBackgroundService; import com.todoroo.astrid.reminders.Notifications; import com.todoroo.astrid.reminders.ReminderService; import com.todoroo.astrid.reminders.ReminderService.AlarmScheduler; -import com.todoroo.astrid.rmilk.MilkBackgroundService; import com.todoroo.astrid.rmilk.MilkPreferences; import com.todoroo.astrid.service.AddOnService; import com.todoroo.astrid.service.MetadataService; @@ -199,9 +194,6 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, loadContextMenuIntents(); } }).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); } - 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 * ====================================================================== */