mirror of https://github.com/tasks/tasks
parent
65f990f927
commit
e8b1eff7d7
@ -1,423 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.opencrx;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.AutoCompleteTextView;
|
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.Property.LongProperty;
|
|
||||||
import com.todoroo.andlib.data.Property.StringProperty;
|
|
||||||
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.DateUtilities;
|
|
||||||
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
|
|
||||||
import com.todoroo.astrid.dao.StoreObjectDao;
|
|
||||||
import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria;
|
|
||||||
import com.todoroo.astrid.data.Metadata;
|
|
||||||
import com.todoroo.astrid.data.StoreObject;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
|
||||||
import com.todoroo.astrid.service.MetadataService;
|
|
||||||
import com.todoroo.astrid.ui.PopupControlSet;
|
|
||||||
|
|
||||||
import org.tasks.R;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Control Set for managing contact/creator assignments in OpenCRX
|
|
||||||
*
|
|
||||||
* @author Andrey Marchenko <igendou@gmail.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class OpencrxControlSet extends PopupControlSet {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that represents OpenCRX ActivityCreator. Duplicates some functionality of OpenCRX plugin.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static class OpencrxActivityCreator {
|
|
||||||
/** type*/
|
|
||||||
public static final String TYPE = "opencrx-creator"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
/** hashed creator id in opencrx */
|
|
||||||
public static final LongProperty REMOTE_ID = new LongProperty(StoreObject.TABLE,
|
|
||||||
StoreObject.ITEM.name);
|
|
||||||
|
|
||||||
/** creator name */
|
|
||||||
public static final StringProperty NAME = new StringProperty(StoreObject.TABLE,
|
|
||||||
StoreObject.VALUE1.name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* String ID in OpenCRX system (ActivityCreator)
|
|
||||||
*/
|
|
||||||
public static final StringProperty CRX_ID = new StringProperty(StoreObject.TABLE,
|
|
||||||
StoreObject.VALUE3.name);
|
|
||||||
|
|
||||||
// data class-part
|
|
||||||
private final long id;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private final String crxId;
|
|
||||||
|
|
||||||
public OpencrxActivityCreator (StoreObject creatorData) {
|
|
||||||
this(creatorData.getValue(REMOTE_ID),creatorData.getValue(NAME),
|
|
||||||
creatorData.containsValue(CRX_ID) ? creatorData.getValue(CRX_ID) : ""); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public OpencrxActivityCreator(long id, String name, String crxId) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.crxId = crxId;
|
|
||||||
}
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCrxId() {
|
|
||||||
return crxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that represents OpenCRX Contact. Duplicates some functionality of OpenCRX plugin.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static class OpencrxContact {
|
|
||||||
public static final String TYPE = "opencrx-contacts"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
/** hash contact id in opencrx */
|
|
||||||
public static final LongProperty REMOTE_ID = new LongProperty(StoreObject.TABLE,
|
|
||||||
StoreObject.ITEM.name);
|
|
||||||
|
|
||||||
/** contact first name */
|
|
||||||
public static final StringProperty FIRST_NAME = new StringProperty(StoreObject.TABLE,
|
|
||||||
StoreObject.VALUE1.name);
|
|
||||||
|
|
||||||
/** contact last name */
|
|
||||||
public static final StringProperty LAST_NAME = new StringProperty(StoreObject.TABLE,
|
|
||||||
StoreObject.VALUE2.name);
|
|
||||||
|
|
||||||
/** id in OpenCRX as string */
|
|
||||||
public static final StringProperty CRX_ID = new StringProperty(StoreObject.TABLE,
|
|
||||||
StoreObject.VALUE3.name);
|
|
||||||
|
|
||||||
private final long id;
|
|
||||||
|
|
||||||
private final String email;
|
|
||||||
|
|
||||||
private final String firstname;
|
|
||||||
|
|
||||||
private final String lastname;
|
|
||||||
|
|
||||||
private final String crxId;
|
|
||||||
|
|
||||||
public OpencrxContact(long id, String email, String firstname,
|
|
||||||
String lastname, String crxId) {
|
|
||||||
this.id = id;
|
|
||||||
this.email = email;
|
|
||||||
this.firstname = firstname;
|
|
||||||
this.lastname = lastname;
|
|
||||||
this.crxId = crxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OpencrxContact(StoreObject userData){
|
|
||||||
this(userData.getValue(REMOTE_ID), "", userData.getValue(FIRST_NAME), userData.getValue(LAST_NAME), userData.getValue(CRX_ID) ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
public String getFirstname() {
|
|
||||||
return firstname;
|
|
||||||
}
|
|
||||||
public String getLastname() {
|
|
||||||
return lastname;
|
|
||||||
}
|
|
||||||
public String getCrxId() {
|
|
||||||
return crxId;
|
|
||||||
}
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String displayString = ""; //$NON-NLS-1$
|
|
||||||
boolean hasFirstname = false;
|
|
||||||
boolean hasLastname = false;
|
|
||||||
if (firstname != null && firstname.length() > 0) {
|
|
||||||
displayString += firstname;
|
|
||||||
hasFirstname = true;
|
|
||||||
}
|
|
||||||
if (lastname != null && lastname.length() > 0) {
|
|
||||||
hasLastname = true;
|
|
||||||
}
|
|
||||||
if (hasFirstname && hasLastname) {
|
|
||||||
displayString += " "; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
if (hasLastname) {
|
|
||||||
displayString += lastname;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasFirstname && !hasLastname && email != null
|
|
||||||
&& email.length() > 0) {
|
|
||||||
displayString += email;
|
|
||||||
}
|
|
||||||
return displayString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// --- instance variables
|
|
||||||
|
|
||||||
private Spinner assignedToSelector;
|
|
||||||
private Spinner creatorSelector;
|
|
||||||
|
|
||||||
private AutoCompleteTextView assignedToTextInput;
|
|
||||||
private AutoCompleteTextView creatorTextInput;
|
|
||||||
|
|
||||||
private ArrayList<OpencrxContact> users = null;
|
|
||||||
private ArrayList<OpencrxActivityCreator> dashboards = null;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MetadataService metadataService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StoreObjectDao storeObjectDao;
|
|
||||||
|
|
||||||
public OpencrxControlSet(final Activity activity, int viewLayout, int displayViewLayout, int title) {
|
|
||||||
super(activity, viewLayout, displayViewLayout, title);
|
|
||||||
DependencyInjectionService.getInstance().inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void afterInflate() {
|
|
||||||
//View view = LayoutInflater.from(activity).inflate(R.layout.opencrx_control, parent, true);
|
|
||||||
|
|
||||||
this.assignedToSelector = (Spinner) getView().findViewById(R.id.opencrx_TEA_task_assign);
|
|
||||||
TextView emptyView = new TextView(activity);
|
|
||||||
emptyView.setText(activity.getText(R.string.opencrx_no_creator));
|
|
||||||
assignedToSelector.setEmptyView(emptyView);
|
|
||||||
|
|
||||||
this.creatorSelector = (Spinner) getView().findViewById(R.id.opencrx_TEA_dashboard_assign);
|
|
||||||
|
|
||||||
this.assignedToTextInput = (AutoCompleteTextView) getView().findViewById(R.id.opencrx_TEA_contact_textinput);
|
|
||||||
this.creatorTextInput = (AutoCompleteTextView) getView().findViewById(R.id.opencrx_TEA_creator_textinput);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void readFromTaskOnInitialize() {
|
|
||||||
|
|
||||||
|
|
||||||
Metadata metadata = getTaskMetadata(model.getId());
|
|
||||||
if(metadata == null) {
|
|
||||||
metadata = OpencrxCoreUtils.INSTANCE.newMetadata(model.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill the dashboard-spinner and set the current dashboard
|
|
||||||
long dashboardId = OpencrxCoreUtils.INSTANCE.getDefaultCreator();
|
|
||||||
if(metadata.containsNonNullValue(OpencrxCoreUtils.ACTIVITY_CREATOR_ID)) {
|
|
||||||
dashboardId = metadata.getValue(OpencrxCoreUtils.ACTIVITY_CREATOR_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
StoreObject[] dashboardsData = readStoreObjects(OpencrxActivityCreator.TYPE);
|
|
||||||
dashboards = new ArrayList<OpencrxActivityCreator>(dashboardsData.length);
|
|
||||||
int dashboardSpinnerIndex = -1;
|
|
||||||
|
|
||||||
for (int i=0;i<dashboardsData.length;i++) {
|
|
||||||
OpencrxActivityCreator dashboard = new OpencrxActivityCreator(dashboardsData[i]);
|
|
||||||
dashboards.add(dashboard);
|
|
||||||
if(dashboard.getId() == dashboardId) {
|
|
||||||
dashboardSpinnerIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//dashboard to not sync as first spinner-entry
|
|
||||||
dashboards.add(0, new OpencrxActivityCreator(OpencrxCoreUtils.CREATOR_NO_SYNC, activity.getString(R.string.opencrx_no_creator), "")); //$NON-NLS-1$
|
|
||||||
|
|
||||||
ArrayAdapter<OpencrxActivityCreator> dashAdapter = new ArrayAdapter<OpencrxActivityCreator>(activity,
|
|
||||||
android.R.layout.simple_spinner_item, dashboards);
|
|
||||||
dashAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
creatorSelector.setAdapter(dashAdapter);
|
|
||||||
creatorSelector.setSelection(dashboardSpinnerIndex+1);
|
|
||||||
|
|
||||||
ArrayAdapter<OpencrxActivityCreator> creatorAdapterTextInput = new ArrayAdapter<OpencrxActivityCreator>(activity,
|
|
||||||
android.R.layout.simple_spinner_item, dashboards);
|
|
||||||
creatorTextInput.setAdapter(creatorAdapterTextInput);
|
|
||||||
creatorTextInput.setOnItemClickListener(new OnItemClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapter, View view, int position,
|
|
||||||
long id) {
|
|
||||||
OpencrxActivityCreator creatorInput = (OpencrxActivityCreator) adapter.getItemAtPosition(position);
|
|
||||||
|
|
||||||
if (creatorInput == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int selectedIndex = creatorSelector.getSelectedItemPosition();
|
|
||||||
|
|
||||||
for (int i = 0; i < creatorSelector.getAdapter().getCount(); ++i){
|
|
||||||
OpencrxActivityCreator current = (OpencrxActivityCreator) creatorSelector.getAdapter().getItem(i);
|
|
||||||
if (current != null && current.getId() == creatorInput.getId()){
|
|
||||||
selectedIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
creatorSelector.setSelection(selectedIndex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assigned user
|
|
||||||
long responsibleId = OpencrxCoreUtils.INSTANCE.getDefaultAssignedUser();
|
|
||||||
if (metadata.containsNonNullValue(OpencrxCoreUtils.ACTIVITY_ASSIGNED_TO_ID)){
|
|
||||||
responsibleId = metadata.getValue(OpencrxCoreUtils.ACTIVITY_ASSIGNED_TO_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
StoreObject[] usersData = readStoreObjects(OpencrxContact.TYPE);
|
|
||||||
this.users = new ArrayList<OpencrxContact>();
|
|
||||||
for (StoreObject user : usersData){
|
|
||||||
this.users.add(new OpencrxContact(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayAdapter<OpencrxContact> usersAdapter = new ArrayAdapter<OpencrxContact>(activity,
|
|
||||||
android.R.layout.simple_spinner_item, this.users);
|
|
||||||
usersAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
assignedToSelector.setAdapter(usersAdapter);
|
|
||||||
|
|
||||||
int responsibleSpinnerIndex = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < this.users.size() ; i++) {
|
|
||||||
if (this.users.get(i).getId() == responsibleId ) {
|
|
||||||
responsibleSpinnerIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assignedToSelector.setSelection(responsibleSpinnerIndex);
|
|
||||||
|
|
||||||
ArrayAdapter<OpencrxContact> contactAdapterTextInput = new ArrayAdapter<OpencrxContact>(activity,
|
|
||||||
android.R.layout.simple_spinner_item, this.users);
|
|
||||||
|
|
||||||
assignedToTextInput.setAdapter(contactAdapterTextInput);
|
|
||||||
assignedToTextInput.setOnItemClickListener(new OnItemClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapter, View view, int position,
|
|
||||||
long id) {
|
|
||||||
|
|
||||||
OpencrxContact userInput = (OpencrxContact) adapter.getItemAtPosition(position);
|
|
||||||
|
|
||||||
if (userInput == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int selectedIndex = assignedToSelector.getSelectedItemPosition();
|
|
||||||
|
|
||||||
for (int i = 0; i < assignedToSelector.getAdapter().getCount(); ++i){
|
|
||||||
OpencrxContact current = (OpencrxContact) assignedToSelector.getAdapter().getItem(i);
|
|
||||||
if (current != null && current.getId() == userInput.getId()){
|
|
||||||
selectedIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assignedToSelector.setSelection(selectedIndex);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String writeToModelAfterInitialized(Task task) {
|
|
||||||
Metadata metadata = getTaskMetadata(task.getId());
|
|
||||||
try {
|
|
||||||
if (metadata == null) {
|
|
||||||
metadata = OpencrxCoreUtils.INSTANCE.newMetadata(task.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
OpencrxActivityCreator dashboard = (OpencrxActivityCreator) creatorSelector.getSelectedItem();
|
|
||||||
metadata.setValue(OpencrxCoreUtils.ACTIVITY_CREATOR_ID, dashboard.getId());
|
|
||||||
|
|
||||||
OpencrxContact responsibleUser = (OpencrxContact) assignedToSelector.getSelectedItem();
|
|
||||||
|
|
||||||
if(responsibleUser == null) {
|
|
||||||
metadata.setValue(OpencrxCoreUtils.ACTIVITY_ASSIGNED_TO_ID, 0L);
|
|
||||||
} else {
|
|
||||||
metadata.setValue(OpencrxCoreUtils.ACTIVITY_ASSIGNED_TO_ID, responsibleUser.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(metadata.getSetValues().size() > 0) {
|
|
||||||
metadataService.save(metadata);
|
|
||||||
task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("opencrx-error", "Error Saving Metadata", e); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads metadata out of a task
|
|
||||||
* @return null if no metadata found
|
|
||||||
*/
|
|
||||||
private Metadata getTaskMetadata(long taskId) {
|
|
||||||
TodorooCursor<Metadata> cursor = metadataService.query(Query.select(Metadata.PROPERTIES).where(
|
|
||||||
MetadataCriteria.byTaskAndwithKey(taskId, OpencrxCoreUtils.OPENCRX_ACTIVITY_METADATA_KEY))
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
if(cursor.getCount() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
cursor.moveToFirst();
|
|
||||||
return new Metadata(cursor);
|
|
||||||
} finally {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private StoreObject[] readStoreObjects(String type) {
|
|
||||||
StoreObject[] ret;
|
|
||||||
TodorooCursor<StoreObject> cursor = storeObjectDao.query(Query.select(StoreObject.PROPERTIES).
|
|
||||||
where(StoreObjectCriteria.byType(type)));
|
|
||||||
try {
|
|
||||||
ret = new StoreObject[cursor.getCount()];
|
|
||||||
for(int i = 0; i < ret.length; i++) {
|
|
||||||
cursor.moveToNext();
|
|
||||||
StoreObject dashboard = new StoreObject(cursor);
|
|
||||||
ret[i] = dashboard;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void refreshDisplayView() {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,134 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.opencrx;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.SharedPreferences.Editor;
|
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.Property.LongProperty;
|
|
||||||
import com.todoroo.andlib.data.Property.StringProperty;
|
|
||||||
import com.todoroo.andlib.service.ContextManager;
|
|
||||||
import com.todoroo.astrid.data.Metadata;
|
|
||||||
import com.todoroo.astrid.sync.SyncProviderUtilities;
|
|
||||||
|
|
||||||
public class OpencrxCoreUtils extends SyncProviderUtilities{
|
|
||||||
|
|
||||||
public static final String OPENCRX_ACTIVITY_METADATA_KEY = "opencrx"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
public static final String IDENTIFIER = "crx"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
public static final LongProperty ACTIVITY_ID = new LongProperty(Metadata.TABLE, Metadata.VALUE1.name);
|
|
||||||
public static final LongProperty ACTIVITY_CREATOR_ID = new LongProperty(Metadata.TABLE, Metadata.VALUE2.name);
|
|
||||||
public static final LongProperty ACTIVITY_USERCREATOR_ID = new LongProperty(Metadata.TABLE, Metadata.VALUE3.name);
|
|
||||||
public static final LongProperty ACTIVITY_ASSIGNED_TO_ID = new LongProperty(Metadata.TABLE, Metadata.VALUE4.name);
|
|
||||||
public static final StringProperty ACTIVITY_CRX_ID = new StringProperty(Metadata.TABLE, Metadata.VALUE5.name);
|
|
||||||
|
|
||||||
private static final String PREF_USER_ID = "crx_userid"; //$NON-NLS-1$
|
|
||||||
private static final String PREF_DEFAULT_CREATOR = "opencrx_defaultcreator"; //$NON-NLS-1$
|
|
||||||
private static final String PREFS_FILE = "crx-prefs"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
private static final String OPENCRX_PACKAGE = "ru.otdelit.astrid.opencrx"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
public static final long CREATOR_NO_SYNC = -1;
|
|
||||||
|
|
||||||
public static final OpencrxCoreUtils INSTANCE = new OpencrxCoreUtils();
|
|
||||||
|
|
||||||
private OpencrxCoreUtils(){
|
|
||||||
// prevent instantiation
|
|
||||||
}
|
|
||||||
|
|
||||||
public Metadata newMetadata(long forTask) {
|
|
||||||
Metadata metadata = new Metadata();
|
|
||||||
metadata.setValue(Metadata.KEY, OPENCRX_ACTIVITY_METADATA_KEY);
|
|
||||||
metadata.setValue(Metadata.TASK, forTask);
|
|
||||||
metadata.setValue(ACTIVITY_ID, 0L);
|
|
||||||
metadata.setValue(ACTIVITY_CREATOR_ID, getDefaultCreator());
|
|
||||||
metadata.setValue(ACTIVITY_USERCREATOR_ID, getDefaultAssignedUser());
|
|
||||||
metadata.setValue(ACTIVITY_ASSIGNED_TO_ID, getDefaultAssignedUser());
|
|
||||||
metadata.setValue(ACTIVITY_CRX_ID, ""); //$NON-NLS-1$
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopOngoing() {
|
|
||||||
SharedPreferences sharedPreferences = OpencrxCoreUtils.getPrefs();
|
|
||||||
|
|
||||||
if (sharedPreferences != null){
|
|
||||||
Editor editor = sharedPreferences.edit();
|
|
||||||
editor.putBoolean(getIdentifier() + PREF_ONGOING, false);
|
|
||||||
editor.commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets default creator from setting
|
|
||||||
* @return CREATOR_NO_SYNC if should not sync, otherwise remote id
|
|
||||||
*/
|
|
||||||
public long getDefaultCreator() {
|
|
||||||
long defaultCreatorId = CREATOR_NO_SYNC ;
|
|
||||||
SharedPreferences sharedPreferences = OpencrxCoreUtils.getPrefs();
|
|
||||||
|
|
||||||
if (sharedPreferences != null){
|
|
||||||
String defCreatorString = sharedPreferences.getString(PREF_DEFAULT_CREATOR, String.valueOf(CREATOR_NO_SYNC));
|
|
||||||
|
|
||||||
try{
|
|
||||||
defaultCreatorId = Long.parseLong(defCreatorString);
|
|
||||||
}catch(Exception ex){
|
|
||||||
defaultCreatorId = CREATOR_NO_SYNC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultCreatorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDefaultAssignedUser(){
|
|
||||||
SharedPreferences sharedPreferences = OpencrxCoreUtils.getPrefs();
|
|
||||||
|
|
||||||
if (sharedPreferences != null){
|
|
||||||
return sharedPreferences.getLong(PREF_USER_ID, -1);
|
|
||||||
}else{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static SharedPreferences getPrefs() {
|
|
||||||
try {
|
|
||||||
Context crxContext = ContextManager.getContext().createPackageContext(OPENCRX_PACKAGE, 0);
|
|
||||||
SharedPreferences sharedPreferences = crxContext.getSharedPreferences(PREFS_FILE,
|
|
||||||
Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
|
|
||||||
return sharedPreferences;
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isLoggedIn() {
|
|
||||||
SharedPreferences sharedPreferences = OpencrxCoreUtils.getPrefs();
|
|
||||||
|
|
||||||
if (sharedPreferences != null) {
|
|
||||||
return sharedPreferences.getString(getIdentifier() + PREF_TOKEN, null) != null;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIdentifier() {
|
|
||||||
return IDENTIFIER;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public int getSyncIntervalKey() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLoggedInUserName() {
|
|
||||||
return ""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
<?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="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<!-- opencrx task assignment controlset -->
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="100">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/opencrx_TEA_creator_assign_label"
|
|
||||||
style="@style/TextAppearance.GEN_EditLabel.DLG_EditLabel" />
|
|
||||||
|
|
||||||
<AutoCompleteTextView
|
|
||||||
android:id="@+id/opencrx_TEA_creator_textinput"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:hint="@string/opencrx_creator_input_hint"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Spinner
|
|
||||||
android:id="@+id/opencrx_TEA_dashboard_assign"
|
|
||||||
android:prompt="@string/opencrx_TEA_creator_assign_label"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/opencrx_TEA_task_assign_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/opencrx_TEA_task_assign_label"
|
|
||||||
style="@style/TextAppearance.GEN_EditLabel.DLG_EditLabel" />
|
|
||||||
|
|
||||||
<AutoCompleteTextView
|
|
||||||
android:id="@+id/opencrx_TEA_contact_textinput"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:hint="@string/opencrx_contact_input_hint"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Spinner
|
|
||||||
android:id="@+id/opencrx_TEA_task_assign"
|
|
||||||
android:prompt="@string/opencrx_TEA_task_assign_label"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="1px"
|
|
||||||
android:padding="5dip"
|
|
||||||
android:background="@android:drawable/divider_horizontal_dark" />
|
|
||||||
<include layout="@layout/control_dialog_ok"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
<?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:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
|
|
||||||
<!-- tags -->
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/opencrx_body"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="50dip"
|
|
||||||
android:paddingLeft="10dip"
|
|
||||||
android:paddingRight="10dip"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="15dip"
|
|
||||||
android:text="@string/opencrx_TEA_opencrx_title"
|
|
||||||
style="@style/TextAppearance.GEN_EditLabel" />
|
|
||||||
</LinearLayout>
|
|
||||||
<View
|
|
||||||
android:id="@+id/TEA_Separator"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="1px"
|
|
||||||
style="@style/TEA_Separator" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
This file contains preference keys and preference list values.
|
|
||||||
These should not be translated
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<string name="opencrx_PPr_interval_key">opencrx_sync_freq</string>
|
|
||||||
<string name="opencrx_PPr_defaultcreator_key">opencrx_defaultcreator</string>
|
|
||||||
<string name="opencrx_PPr_host_key">opencrx_host</string>
|
|
||||||
<string name="opencrx_PPr_segment_key">opencrx_segment</string>
|
|
||||||
<string name="opencrx_PPr_provider_key">opencrx_provider</string>
|
|
||||||
</resources>
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
|
|
||||||
<!-- ====================== Plugin Boilerplate ========================= -->
|
|
||||||
|
|
||||||
<!-- replacement string for task edit "Notes" when using OpenCRX -->
|
|
||||||
<string name="opencrx_TEA_notes">Add a Comment</string>
|
|
||||||
|
|
||||||
<string name="opencrx_creator_input_hint">Creator</string>
|
|
||||||
|
|
||||||
<string name="opencrx_contact_input_hint">Assigned to</string>
|
|
||||||
<!-- ==================================================== Preferences == -->
|
|
||||||
|
|
||||||
<!-- creator title for tasks that are not synchronized -->
|
|
||||||
<string name="opencrx_no_creator">(Do Not Synchronize)</string>
|
|
||||||
|
|
||||||
<!-- preference title for default creator -->
|
|
||||||
<string name="opencrx_PPr_defaultcreator_title">Default ActivityCreator</string>
|
|
||||||
|
|
||||||
<!-- OpenCRX host and segment group name -->
|
|
||||||
<string name="opencrx_group">OpenCRX server</string>
|
|
||||||
|
|
||||||
<!-- preference description for OpenCRX host -->
|
|
||||||
<string name="opencrx_host_title">Host</string>
|
|
||||||
|
|
||||||
<!-- dialog title for OpenCRX host -->
|
|
||||||
<string name="opencrx_host_dialog_title">OpenCRX host</string>
|
|
||||||
|
|
||||||
<!-- example for OpenCRX host -->
|
|
||||||
<string name="opencrx_host_summary">For example: <i>mydomain.com</i></string>
|
|
||||||
|
|
||||||
<!-- preference description for OpenCRX segment -->
|
|
||||||
<string name="opencrx_segment_title">Segment</string>
|
|
||||||
|
|
||||||
<!-- dialog title for OpenCRX segment -->
|
|
||||||
<string name="opencrx_segment_dialog_title">Synchronized segment</string>
|
|
||||||
|
|
||||||
<!-- example for OpenCRX segment -->
|
|
||||||
<string name="opencrx_segment_summary">For example: <i>Standard</i></string>
|
|
||||||
|
|
||||||
<!-- default value for OpenCRX segment -->
|
|
||||||
<string name="opencrx_segment_default">Standard</string>
|
|
||||||
|
|
||||||
<!-- preference description for OpenCRX provider -->
|
|
||||||
<string name="opencrx_provider_title">Provider</string>
|
|
||||||
|
|
||||||
<!-- dialog title for OpenCRX provider -->
|
|
||||||
<string name="opencrx_provider_dialog_title">OpenCRX data provider</string>
|
|
||||||
|
|
||||||
<!-- example for OpenCRX provider -->
|
|
||||||
<string name="opencrx_provider_summary">For example: <i>CRX</i></string>
|
|
||||||
|
|
||||||
<!-- default value for OpenCRX provider -->
|
|
||||||
<string name="opencrx_provider_default">CRX</string>
|
|
||||||
|
|
||||||
<!-- ================================================ labels for layout-elements == -->
|
|
||||||
|
|
||||||
<!-- label for task-assignment spinner on taskeditactivity -->
|
|
||||||
<string name="opencrx_TEA_task_assign_label">Assign this task to this person:</string>
|
|
||||||
|
|
||||||
<!-- label for dashboard-assignment spinner on taskeditactivity -->
|
|
||||||
<string name="opencrx_TEA_creator_assign_label">Assign this task to this creator:</string>
|
|
||||||
|
|
||||||
<string name="opencrx_TEA_opencrx_title">OpenCRX Controls</string>
|
|
||||||
|
|
||||||
</resources>
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
|
||||||
**
|
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
|
||||||
-->
|
|
||||||
<PreferenceScreen
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:title="@string/sync_SPr_group_status">
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
|
||||||
android:layout="@layout/status_preference"
|
|
||||||
android:key="@string/sync_SPr_status_key"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:gravity="center"/>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:title="@string/sync_SPr_group_options">
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilineListPreference
|
|
||||||
android:key="@string/opencrx_PPr_interval_key"
|
|
||||||
android:entries="@array/sync_SPr_interval_entries"
|
|
||||||
android:entryValues="@array/sync_SPr_interval_values"
|
|
||||||
android:title="@string/sync_SPr_interval_title" />
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilineListPreference
|
|
||||||
android:key="@string/opencrx_PPr_defaultcreator_key"
|
|
||||||
android:title="@string/opencrx_PPr_defaultcreator_title" />
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:title="@string/opencrx_group">
|
|
||||||
<EditTextPreference
|
|
||||||
android:key="@string/opencrx_PPr_host_key"
|
|
||||||
android:title="@string/opencrx_host_title"
|
|
||||||
android:dialogTitle="@string/opencrx_host_dialog_title"
|
|
||||||
android:summary="@string/opencrx_host_summary"
|
|
||||||
/>
|
|
||||||
<EditTextPreference
|
|
||||||
android:key="@string/opencrx_PPr_segment_key"
|
|
||||||
android:title="@string/opencrx_segment_title"
|
|
||||||
android:dialogTitle="@string/opencrx_segment_dialog_title"
|
|
||||||
android:summary="@string/opencrx_segment_summary"
|
|
||||||
android:defaultValue="@string/opencrx_segment_default"
|
|
||||||
/>
|
|
||||||
<EditTextPreference
|
|
||||||
android:key="@string/opencrx_PPr_provider_key"
|
|
||||||
android:title="@string/opencrx_provider_title"
|
|
||||||
android:dialogTitle="@string/opencrx_provider_dialog_title"
|
|
||||||
android:summary="@string/opencrx_provider_summary"
|
|
||||||
android:defaultValue="@string/opencrx_provider_default"
|
|
||||||
/>
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:title="@string/sync_SPr_group_actions">
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
|
||||||
android:key="@string/sync_SPr_sync_key"
|
|
||||||
android:title="@string/sync_SPr_sync" />
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
|
||||||
android:key="@string/sync_SPr_forget_key"
|
|
||||||
android:title="@string/sync_SPr_forget"
|
|
||||||
android:summary="@string/sync_SPr_forget_description" />
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
||||||
Loading…
Reference in New Issue