mirror of https://github.com/tasks/tasks
Further fleshing out gtasks - added decoration exposer and rewrote metadata service to use commons version
parent
9d829cfada
commit
a87cb96a8d
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||
import com.todoroo.astrid.api.Filter;
|
||||
import com.todoroo.astrid.api.TaskDecoration;
|
||||
import com.todoroo.astrid.api.TaskDecorationExposer;
|
||||
import com.todoroo.astrid.data.Metadata;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
|
||||
/**
|
||||
* Exposes {@link TaskDecoration} for GTasks indentation
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public class GtasksDecorationExposer implements TaskDecorationExposer {
|
||||
|
||||
@Autowired private GtasksMetadataService gtasksMetadataService;
|
||||
|
||||
public GtasksDecorationExposer() {
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskDecoration expose(Filter activeFilter, Task task) {
|
||||
if(!GtasksUtilities.INSTANCE.isLoggedIn())
|
||||
return null;
|
||||
|
||||
if(!activeFilter.sqlQuery.contains(GtasksMetadata.METADATA_KEY))
|
||||
return null;
|
||||
|
||||
return createDecoration(task);
|
||||
}
|
||||
|
||||
private TaskDecoration createDecoration(Task task) {
|
||||
Metadata metadata = gtasksMetadataService.getTaskMetadata(task.getId());
|
||||
if(metadata == null)
|
||||
return null;
|
||||
|
||||
int indentation = metadata.getValue(GtasksMetadata.INDENTATION);
|
||||
if(indentation <= 0)
|
||||
return null;
|
||||
|
||||
RemoteViews decoration = new RemoteViews(ContextManager.getContext().getPackageName(),
|
||||
R.layout.gtasks_decoration);
|
||||
decoration.setInt(R.id.indent, "setWidth", indentation * 20); //$NON-NLS-1$
|
||||
return new TaskDecoration(decoration, TaskDecoration.POSITION_LEFT, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.todoroo.astrid.gtasks.sync;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.todoroo.astrid.data.Metadata;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.gtasks.GtasksMetadata;
|
||||
import com.todoroo.astrid.producteev.sync.ProducteevTask;
|
||||
import com.todoroo.astrid.sync.SyncContainer;
|
||||
|
||||
/**
|
||||
* RTM Task Container
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public class GtasksTaskContainer extends SyncContainer {
|
||||
|
||||
public Metadata gtaskMetadata;
|
||||
|
||||
public GtasksTaskContainer(Task task, ArrayList<Metadata> metadata, Metadata gtaskMetadata) {
|
||||
this.task = task;
|
||||
this.metadata = metadata;
|
||||
this.gtaskMetadata = gtaskMetadata;
|
||||
if(this.gtaskMetadata == null) {
|
||||
this.gtaskMetadata = GtasksMetadata.createEmptyMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
public GtasksTaskContainer(Task task, ArrayList<Metadata> metadata) {
|
||||
this.task = task;
|
||||
this.metadata = metadata;
|
||||
|
||||
for(Iterator<Metadata> iterator = metadata.iterator(); iterator.hasNext(); ) {
|
||||
Metadata item = iterator.next();
|
||||
if(ProducteevTask.METADATA_KEY.equals(item.getValue(Metadata.KEY))) {
|
||||
gtaskMetadata = item;
|
||||
iterator.remove();
|
||||
// don't break, could be multiple
|
||||
}
|
||||
}
|
||||
if(this.gtaskMetadata == null) {
|
||||
this.gtaskMetadata = GtasksMetadata.createEmptyMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareForSaving() {
|
||||
super.prepareForSaving();
|
||||
metadata.add(gtaskMetadata);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- See the file "LICENSE" for the full license governing this code. -->
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/indent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"/>
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package com.todoroo.astrid.api;
|
||||
|
||||
import com.todoroo.astrid.data.Task;
|
||||
|
||||
/**
|
||||
* Internal API for exposing task decorations
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public interface TaskDecorationExposer {
|
||||
|
||||
/**
|
||||
* Expose task decorations for the given task
|
||||
*
|
||||
* @param task
|
||||
* @return null if no decorations, or decoration
|
||||
*/
|
||||
public TaskDecoration expose(Filter activeFilter, Task task);
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue