dashboards can now be created and assigned from within astrid. setting responsible person is now sent to server, too (fixin missing parameter in invoker.tasksCreate)

pull/14/head
Arne Jans 14 years ago committed by Tim Su
parent f9eb247ef6
commit ed8efb1e22

@ -2,27 +2,35 @@ package com.todoroo.astrid.producteev;
import java.util.ArrayList;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
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.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.StoreObject;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.producteev.sync.ProducteevDashboard;
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.ProducteevUser;
import com.todoroo.astrid.service.MetadataService;
@ -38,6 +46,7 @@ public class ProducteevControlSet implements TaskEditControlSet {
// --- instance variables
private final Activity activity;
private final DialogUtilities dialogUtilites;
private final View view;
private Task myTask;
@ -54,6 +63,8 @@ public class ProducteevControlSet implements TaskEditControlSet {
DependencyInjectionService.getInstance().inject(this);
this.activity = activity;
this.dialogUtilites = new DialogUtilities();
view = LayoutInflater.from(activity).inflate(R.layout.producteev_control, parent, true);
this.responsibleSelector = (Spinner) activity.findViewById(R.id.producteev_TEA_task_assign);
@ -67,9 +78,65 @@ public class ProducteevControlSet implements TaskEditControlSet {
@Override
public void onItemSelected(AdapterView<?> spinnerParent, View spinnerView,
int position, long id) {
Spinner dashSelector = (Spinner) spinnerParent;
final Spinner dashSelector = (Spinner) spinnerParent;
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
@ -140,8 +207,8 @@ public class ProducteevControlSet implements TaskEditControlSet {
ProducteevDashboard ownerDashboard = null;
int dashboardSpinnerIndex = -1;
//dashboard to not sync as first spinner-entry
for (int i=0;i<dashboardsData.length;i++) {
int i = 0;
for (i=0;i<dashboardsData.length;i++) {
ProducteevDashboard dashboard = new ProducteevDashboard(dashboardsData[i]);
dashboards.add(dashboard);
if(dashboard.getId() == dashboardId) {
@ -149,7 +216,11 @@ public class ProducteevControlSet implements TaskEditControlSet {
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));
// 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,
android.R.layout.simple_spinner_item, dashboards);
@ -157,7 +228,8 @@ public class ProducteevControlSet implements TaskEditControlSet {
dashboardSelector.setAdapter(dashAdapter);
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.setAdapter(null);
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();
/** setting for dashboard to getting created */
public static final int DASHBOARD_CREATE = -2;
/** setting for dashboard to not synchronize */
public static final int DASHBOARD_NO_SYNC = -1;

@ -389,6 +389,18 @@ public class ProducteevInvoker {
"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
*
@ -396,7 +408,7 @@ public class ProducteevInvoker {
* @param dashboard array-information about the dashboard, if this ...
*/
public JSONArray dashboardsAccess(long idDashboard, String dashboard) throws ApiServiceException, IOException {
return getResponse(callAuthenticated("dashboards/access",
return getResponse(callAuthenticated("dashboards/access.json",
"token", token,
"id_dashboard", idDashboard,
"dashboard", dashboard),"dashboard");

@ -38,7 +38,7 @@ public class ProducteevDashboard {
private ArrayList<ProducteevUser> users = null;
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();
for(int i = 0; i < changedDashboards.length(); i++) {
JSONObject remote = changedDashboards.getJSONObject(i).getJSONObject("dashboard");
long id = remote.getLong("id_dashboard");
StoreObject local = null;
for(StoreObject dashboard : dashboards) {
if(dashboard.getValue(ProducteevDashboard.REMOTE_ID).equals(id)) {
local = dashboard;
break;
}
}
updateDashboards(remote, false);
}
if(remote.getInt("deleted") != 0) {
if(local != null)
storeObjectDao.delete(local.getId());
continue;
}
// clear dashboard cache
dashboards = null;
}
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(';');
public StoreObject updateDashboards(JSONObject remote, boolean reinitCache) throws JSONException {
if (reinitCache)
readDashboards();
long id = remote.getLong("id_dashboard");
StoreObject local = null;
for(StoreObject dashboard : dashboards) {
if(dashboard.getValue(ProducteevDashboard.REMOTE_ID).equals(id)) {
local = dashboard;
break;
}
local.setValue(ProducteevDashboard.USERS, users.toString());
storeObjectDao.persist(local);
}
// clear dashboard cache
dashboards = null;
if(remote.getInt("deleted") != 0) {
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;
}
}

@ -255,6 +255,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
}
}
// ----------------------------------------------------------------------
// ------------------------------------------------------------ sync data
// ----------------------------------------------------------------------
@ -303,6 +304,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
long dashboard = ProducteevUtilities.INSTANCE.getDefaultDashboard();
if(local.pdvTask.containsNonNullValue(ProducteevTask.DASHBOARD_ID))
dashboard = local.pdvTask.getValue(ProducteevTask.DASHBOARD_ID);
long responsibleId = local.pdvTask.getValue(ProducteevTask.RESPONSIBLE_ID);
if(dashboard == ProducteevUtilities.DASHBOARD_NO_SYNC) {
// set a bogus task id, then return without creating
@ -311,7 +313,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
}
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));
ProducteevTaskContainer newRemoteTask;
try {

@ -27,6 +27,15 @@
<!-- dashboard title for tasks that are not synchronized -->
<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 -->
<string name="producteev_PPr_defaultdash_title">Default Workspace</string>

Loading…
Cancel
Save