mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
Java
69 lines
2.2 KiB
Java
package com.todoroo.astrid.gtasks;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.widget.Toast;
|
|
|
|
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.AstridApiConstants;
|
|
import com.todoroo.astrid.core.PluginServices;
|
|
import com.todoroo.astrid.data.Metadata;
|
|
import com.todoroo.astrid.utility.Flags;
|
|
|
|
/**
|
|
* Context Menu actions for changing indent level of a task
|
|
* @author Tim Su <tim@todoroo.com>
|
|
*
|
|
*/
|
|
abstract public class GtasksIndentAction extends BroadcastReceiver {
|
|
|
|
@Autowired private GtasksMetadataService gtasksMetadataService;
|
|
@Autowired private GtasksTaskListUpdater gtasksTaskListUpdater;
|
|
|
|
abstract int getDelta();
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
ContextManager.setContext(context);
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
|
if(taskId == -1)
|
|
return;
|
|
|
|
Metadata metadata = gtasksMetadataService.getTaskMetadata(taskId);
|
|
if(metadata == null) {
|
|
metadata = GtasksMetadata.createEmptyMetadata(taskId);
|
|
}
|
|
|
|
int newIndent = Math.max(0, metadata.getValue(GtasksMetadata.INDENT) + getDelta());
|
|
metadata.setValue(GtasksMetadata.INDENT, newIndent);
|
|
PluginServices.getMetadataService().save(metadata);
|
|
|
|
gtasksTaskListUpdater.updateMetadataForList(metadata.getValue(GtasksMetadata.LIST_ID));
|
|
|
|
Flags.set(Flags.REFRESH);
|
|
Toast.makeText(context, context.getString(R.string.gtasks_indent_toast, newIndent),
|
|
Toast.LENGTH_SHORT).show();
|
|
}
|
|
|
|
public static class GtasksIncreaseIndentAction extends GtasksIndentAction {
|
|
@Override
|
|
public int getDelta() {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
public static class GtasksDecreaseIndentAction extends GtasksIndentAction {
|
|
@Override
|
|
public int getDelta() {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
}
|