Merge remote branch 'origin/master'

pull/14/head
Tim Su 14 years ago
commit 4751815fcc

@ -2,27 +2,35 @@ package com.todoroo.astrid.producteev;
import java.util.ArrayList; import java.util.ArrayList;
import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText;
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.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
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;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.producteev.sync.ProducteevDashboard; 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.ProducteevSyncProvider;
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; import com.todoroo.astrid.service.MetadataService;
@ -38,6 +46,7 @@ public class ProducteevControlSet implements TaskEditControlSet {
// --- instance variables // --- instance variables
private final Activity activity; private final Activity activity;
private final DialogUtilities dialogUtilites;
private final View view; private final View view;
private Task myTask; private Task myTask;
@ -54,6 +63,8 @@ public class ProducteevControlSet implements TaskEditControlSet {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
this.activity = activity; this.activity = activity;
this.dialogUtilites = new DialogUtilities();
view = LayoutInflater.from(activity).inflate(R.layout.producteev_control, parent, true); view = 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);
@ -67,9 +78,65 @@ public class ProducteevControlSet implements TaskEditControlSet {
@Override @Override
public void onItemSelected(AdapterView<?> spinnerParent, View spinnerView, public void onItemSelected(AdapterView<?> spinnerParent, View spinnerView,
int position, long id) { int position, long id) {
Spinner dashSelector = (Spinner) spinnerParent; final Spinner dashSelector = (Spinner) spinnerParent;
ProducteevDashboard dashboard = (ProducteevDashboard) dashSelector.getSelectedItem(); ProducteevDashboard dashboard = (ProducteevDashboard) dashSelector.getSelectedItem();
refreshResponsibleSpinner(dashboard.getUsers()); if (dashboard.getId() == ProducteevUtilities.DASHBOARD_CREATE) {
// let the user create a new dashboard
final EditText editor = new EditText(ProducteevControlSet.this.activity);
OnClickListener okListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Activity context = ProducteevControlSet.this.activity;
String newDashboardName = editor.getText().toString();
if (newDashboardName == null || newDashboardName.length() == 0) {
dialog.cancel();
} else {
// create the real dashboard, select it in the spinner and refresh responsiblespinner
ProgressDialog progressDialog = null;
try {
progressDialog = dialogUtilites.progressDialog(context,
context.getString(R.string.DLG_wait));
JSONObject newDashJSON = ProducteevSyncProvider.getInvoker().dashboardsCreate(newDashboardName).getJSONObject("dashboard");
StoreObject local = ProducteevDataService.getInstance().updateDashboards(newDashJSON, true);
if (local != null) {
ProducteevDashboard newDashboard = new ProducteevDashboard(local);
ArrayAdapter adapter = (ArrayAdapter) dashSelector.getAdapter();
adapter.insert(newDashboard, adapter.getCount()-1);
dashSelector.setSelection(adapter.getCount()-2);
refreshResponsibleSpinner(newDashboard.getUsers());
dialogUtilites.dismissDialog(context, progressDialog);
}
} catch (Exception e) {
dialogUtilites.dismissDialog(context, progressDialog);
dialogUtilites.okDialog(context,
context.getString(R.string.DLG_error, e.getMessage()),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
e.printStackTrace();
dashSelector.setSelection(0);
}
}
}
};
OnClickListener cancelListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
};
dialogUtilites.viewDialog(ProducteevControlSet.this.activity,
ProducteevControlSet.this.activity.getString(R.string.producteev_create_dashboard_name),
editor,
okListener,
cancelListener);
} else {
refreshResponsibleSpinner(dashboard.getUsers());
}
} }
@Override @Override
@ -140,8 +207,8 @@ public class ProducteevControlSet implements TaskEditControlSet {
ProducteevDashboard ownerDashboard = null; ProducteevDashboard ownerDashboard = null;
int dashboardSpinnerIndex = -1; int dashboardSpinnerIndex = -1;
//dashboard to not sync as first spinner-entry int i = 0;
for (int i=0;i<dashboardsData.length;i++) { for (i=0;i<dashboardsData.length;i++) {
ProducteevDashboard dashboard = new ProducteevDashboard(dashboardsData[i]); ProducteevDashboard dashboard = new ProducteevDashboard(dashboardsData[i]);
dashboards.add(dashboard); dashboards.add(dashboard);
if(dashboard.getId() == dashboardId) { if(dashboard.getId() == dashboardId) {
@ -149,7 +216,11 @@ public class ProducteevControlSet implements TaskEditControlSet {
dashboardSpinnerIndex = i; dashboardSpinnerIndex = i;
} }
} }
//dashboard to not sync as first spinner-entry
dashboards.add(0, new ProducteevDashboard(ProducteevUtilities.DASHBOARD_NO_SYNC, activity.getString(R.string.producteev_no_dashboard),null)); dashboards.add(0, new ProducteevDashboard(ProducteevUtilities.DASHBOARD_NO_SYNC, activity.getString(R.string.producteev_no_dashboard),null));
// dummyentry for adding a new dashboard
dashboards.add(new ProducteevDashboard(ProducteevUtilities.DASHBOARD_CREATE, activity.getString(R.string.producteev_create_dashboard),null));
ArrayAdapter<ProducteevDashboard> dashAdapter = new ArrayAdapter<ProducteevDashboard>(activity, ArrayAdapter<ProducteevDashboard> dashAdapter = new ArrayAdapter<ProducteevDashboard>(activity,
android.R.layout.simple_spinner_item, dashboards); android.R.layout.simple_spinner_item, dashboards);
@ -157,7 +228,8 @@ public class ProducteevControlSet implements TaskEditControlSet {
dashboardSelector.setAdapter(dashAdapter); dashboardSelector.setAdapter(dashAdapter);
dashboardSelector.setSelection(dashboardSpinnerIndex+1); dashboardSelector.setSelection(dashboardSpinnerIndex+1);
if (ownerDashboard == null || ownerDashboard.getId() == ProducteevUtilities.DASHBOARD_NO_SYNC) { if (ownerDashboard == null || ownerDashboard.getId() == ProducteevUtilities.DASHBOARD_NO_SYNC
|| ownerDashboard.getId() == ProducteevUtilities.DASHBOARD_CREATE) {
responsibleSelector.setEnabled(false); responsibleSelector.setEnabled(false);
responsibleSelector.setAdapter(null); responsibleSelector.setAdapter(null);
view.findViewById(R.id.producteev_TEA_task_assign_label).setVisibility(View.GONE); view.findViewById(R.id.producteev_TEA_task_assign_label).setVisibility(View.GONE);

@ -18,6 +18,9 @@ public class ProducteevUtilities extends SyncProviderUtilities {
public static final ProducteevUtilities INSTANCE = new ProducteevUtilities(); public static final ProducteevUtilities INSTANCE = new ProducteevUtilities();
/** setting for dashboard to getting created */
public static final int DASHBOARD_CREATE = -2;
/** setting for dashboard to not synchronize */ /** setting for dashboard to not synchronize */
public static final int DASHBOARD_NO_SYNC = -1; public static final int DASHBOARD_NO_SYNC = -1;

@ -389,6 +389,18 @@ public class ProducteevInvoker {
"id_colleague", idColleague); "id_colleague", idColleague);
} }
/**
* create a dasbhoard
*
* @param name
* @return the new created dashboard as JSONObject
*/
public JSONObject dashboardsCreate(String name) throws ApiServiceException, IOException {
return callAuthenticated("dashboards/create.json",
"token", token,
"title", name);
}
/** /**
* return the list of users who can access a specific dashboard * return the list of users who can access a specific dashboard
* *
@ -396,7 +408,7 @@ public class ProducteevInvoker {
* @param dashboard array-information about the dashboard, if this ... * @param dashboard array-information about the dashboard, if this ...
*/ */
public JSONArray dashboardsAccess(long idDashboard, String dashboard) throws ApiServiceException, IOException { public JSONArray dashboardsAccess(long idDashboard, String dashboard) throws ApiServiceException, IOException {
return getResponse(callAuthenticated("dashboards/access", return getResponse(callAuthenticated("dashboards/access.json",
"token", token, "token", token,
"id_dashboard", idDashboard, "id_dashboard", idDashboard,
"dashboard", dashboard),"dashboard"); "dashboard", dashboard),"dashboard");

@ -38,7 +38,7 @@ public class ProducteevDashboard {
private ArrayList<ProducteevUser> users = null; private ArrayList<ProducteevUser> users = null;
public ProducteevDashboard (StoreObject dashboardData) { public ProducteevDashboard (StoreObject dashboardData) {
this(dashboardData.getValue(REMOTE_ID),dashboardData.getValue(NAME),dashboardData.getValue(USERS)); this(dashboardData.getValue(REMOTE_ID),dashboardData.getValue(NAME),(dashboardData.containsValue(USERS)?dashboardData.getValue(USERS):null));
} }
/** /**

@ -243,41 +243,49 @@ public final class ProducteevDataService {
readDashboards(); readDashboards();
for(int i = 0; i < changedDashboards.length(); i++) { for(int i = 0; i < changedDashboards.length(); i++) {
JSONObject remote = changedDashboards.getJSONObject(i).getJSONObject("dashboard"); JSONObject remote = changedDashboards.getJSONObject(i).getJSONObject("dashboard");
long id = remote.getLong("id_dashboard"); updateDashboards(remote, false);
StoreObject local = null; }
for(StoreObject dashboard : dashboards) {
if(dashboard.getValue(ProducteevDashboard.REMOTE_ID).equals(id)) {
local = dashboard;
break;
}
}
if(remote.getInt("deleted") != 0) { // clear dashboard cache
if(local != null) dashboards = null;
storeObjectDao.delete(local.getId()); }
continue;
}
if(local == null) public StoreObject updateDashboards(JSONObject remote, boolean reinitCache) throws JSONException {
local = new StoreObject(); if (reinitCache)
local.setValue(StoreObject.TYPE, ProducteevDashboard.TYPE); readDashboards();
local.setValue(ProducteevDashboard.REMOTE_ID, id); long id = remote.getLong("id_dashboard");
local.setValue(ProducteevDashboard.NAME, remote.getString("title")); StoreObject local = null;
for(StoreObject dashboard : dashboards) {
StringBuilder users = new StringBuilder(); if(dashboard.getValue(ProducteevDashboard.REMOTE_ID).equals(id)) {
JSONArray accessList = remote.getJSONArray("accesslist"); local = dashboard;
for(int j = 0; j < accessList.length(); j++) { break;
JSONObject user = accessList.getJSONObject(j).getJSONObject("user");
users.append(user.getLong("id_user")).append(',');
String name = user.optString("firstname", "") + ' ' +
user.optString("lastname", "");
users.append(name.trim()).append(';');
} }
local.setValue(ProducteevDashboard.USERS, users.toString());
storeObjectDao.persist(local);
} }
// clear dashboard cache if(remote.getInt("deleted") != 0) {
dashboards = null; if(local != null)
storeObjectDao.delete(local.getId());
}
if(local == null)
local = new StoreObject();
local.setValue(StoreObject.TYPE, ProducteevDashboard.TYPE);
local.setValue(ProducteevDashboard.REMOTE_ID, id);
local.setValue(ProducteevDashboard.NAME, remote.getString("title"));
StringBuilder users = new StringBuilder();
JSONArray accessList = remote.getJSONArray("accesslist");
for(int j = 0; j < accessList.length(); j++) {
JSONObject user = accessList.getJSONObject(j).getJSONObject("user");
users.append(user.getLong("id_user")).append(',');
String name = user.optString("firstname", "") + ' ' +
user.optString("lastname", "");
users.append(name.trim()).append(';');
}
local.setValue(ProducteevDashboard.USERS, users.toString());
storeObjectDao.persist(local);
if (reinitCache)
dashboards = null;
return local;
} }
} }

@ -258,6 +258,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
} }
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// ------------------------------------------------------------ sync data // ------------------------------------------------------------ sync data
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -312,6 +313,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
long dashboard = ProducteevUtilities.INSTANCE.getDefaultDashboard(); long dashboard = ProducteevUtilities.INSTANCE.getDefaultDashboard();
if(local.pdvTask.containsNonNullValue(ProducteevTask.DASHBOARD_ID)) if(local.pdvTask.containsNonNullValue(ProducteevTask.DASHBOARD_ID))
dashboard = local.pdvTask.getValue(ProducteevTask.DASHBOARD_ID); dashboard = local.pdvTask.getValue(ProducteevTask.DASHBOARD_ID);
long responsibleId = local.pdvTask.getValue(ProducteevTask.RESPONSIBLE_ID);
if(dashboard == ProducteevUtilities.DASHBOARD_NO_SYNC) { if(dashboard == ProducteevUtilities.DASHBOARD_NO_SYNC) {
// set a bogus task id, then return without creating // set a bogus task id, then return without creating
@ -320,7 +322,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
} }
JSONObject response = invoker.tasksCreate(localTask.getValue(Task.TITLE), JSONObject response = invoker.tasksCreate(localTask.getValue(Task.TITLE),
null, dashboard, createDeadline(localTask), createReminder(localTask), responsibleId, dashboard, createDeadline(localTask), createReminder(localTask),
localTask.isCompleted() ? 2 : 1, createStars(localTask)); localTask.isCompleted() ? 2 : 1, createStars(localTask));
ProducteevTaskContainer newRemoteTask; ProducteevTaskContainer newRemoteTask;
try { try {

@ -30,6 +30,15 @@
<!-- dashboard title for tasks that are not synchronized --> <!-- dashboard title for tasks that are not synchronized -->
<string name="producteev_no_dashboard">Do Not Synchronize</string> <string name="producteev_no_dashboard">Do Not Synchronize</string>
<!-- dashboard spinner entry on TEA for adding a new dashboard -->
<string name="producteev_create_dashboard">Add new Workspace...</string>
<!-- dashboard spinner entry on TEA for adding a new dashboard -->
<string name="producteev_create_dashboard_name">Name for new Workspace</string>
<!-- dashboard sufffix for local new unsynced dashboards -->
<string name="producteev_create_dashboard_name_suffix">new</string>
<!-- preference title for default dashboard --> <!-- preference title for default dashboard -->
<string name="producteev_PPr_defaultdash_title">Default Workspace</string> <string name="producteev_PPr_defaultdash_title">Default Workspace</string>

Loading…
Cancel
Save