Tap task on widget to open task edit screen

pull/46/merge
Alex Baker 11 years ago
parent 9d609986eb
commit 7f2c03a430

@ -6,7 +6,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.tasks"
android:versionName="4.6.11"
android:versionCode="322">
android:versionCode="323">
<!-- widgets, alarms, and services will break if Astrid is installed on SD card -->
<!-- android:installLocation="internalOnly"> -->

@ -752,8 +752,11 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
}
if (activity instanceof TaskListActivity) {
if (title.getText().length() == 0 && isNewTask
&& model != null && model.isSaved()) {
if (title.getText().length() == 0 && isNewTask && model != null && model.isSaved()) {
taskService.delete(model);
}
} else if (activity instanceof TaskEditActivity) {
if (title.getText().length() == 0 && isNewTask && model != null && model.isSaved()) {
taskService.delete(model);
}
}
@ -783,8 +786,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
shouldSaveState = false;
// abandon editing in this case
if (title.getText().length() == 0
|| TextUtils.isEmpty(model.getValue(Task.TITLE))) {
if (title.getText().length() == 0 || TextUtils.isEmpty(model.getValue(Task.TITLE))) {
if (isNewTask) {
TimerPlugin.updateTimer(getActivity(), model, false);
taskService.delete(model);

@ -176,7 +176,7 @@ public class WidgetUpdateService extends Service {
views.setOnClickPendingIntent(R.id.taskbody, pListIntent);
}
PendingIntent pEditIntent = widgetHelper.getEditIntent(context, filter, widgetId);
PendingIntent pEditIntent = widgetHelper.getNewTaskIntent(context, filter, widgetId);
if (pEditIntent != null) {
views.setOnClickPendingIntent(R.id.widget_button, pEditIntent);
views.setOnClickPendingIntent(R.id.widget_title, pEditIntent);

@ -12,6 +12,9 @@ import android.widget.RemoteViewsService;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.activity.TaskEditActivity;
import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
@ -109,7 +112,10 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
row.setTextViewText(R.id.text, textContent);
row.setTextColor(R.id.text, textColor);
row.setOnClickFillInIntent(R.id.text, new Intent());
Intent intent = new Intent(context, TaskEditActivity.class);
intent.putExtra(TaskEditFragment.TOKEN_ID, task.getId());
intent.putExtra(TaskListActivity.OPEN_TASK, task.getId());
row.setOnClickFillInIntent(R.id.text, intent);
return row;
} catch (Exception e) {

@ -42,12 +42,21 @@ import com.todoroo.astrid.widget.WidgetUpdateService;
import org.tasks.R;
import static android.content.Intent.*;
public class WidgetHelper {
static {
AstridDependencyInjector.initialize();
}
private static int flags = FLAG_ACTIVITY_NEW_TASK
| FLAG_ACTIVITY_MULTIPLE_TASK
| FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
| FLAG_ACTIVITY_NO_HISTORY
| FLAG_ACTIVITY_PREVIOUS_IS_TOP;
public static void startWidgetService(Context context) {
Class widgetServiceClass = android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH
? WidgetUpdateService.class
@ -62,6 +71,9 @@ public class WidgetHelper {
public static void triggerUpdate(Context context) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
if (appWidgetManager == null) {
return;
}
ComponentName thisWidget = new ComponentName(context, TasksWidget.class);
Intent intent = new Intent(context, TasksWidget.class);
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
@ -91,11 +103,14 @@ public class WidgetHelper {
PendingIntent listIntent = getListIntent(context, filter, id);
if (listIntent != null) {
remoteViews.setOnClickPendingIntent(R.id.widget_title, listIntent);
remoteViews.setPendingIntentTemplate(R.id.list_view, listIntent);
}
PendingIntent editIntent = getEditIntent(context, filter, id);
if (editIntent != null) {
remoteViews.setOnClickPendingIntent(R.id.widget_button, editIntent);
PendingIntent newTaskIntent = getNewTaskIntent(context, filter, id);
if (newTaskIntent != null) {
remoteViews.setOnClickPendingIntent(R.id.widget_button, newTaskIntent);
}
PendingIntent editTaskIntent = getEditTaskIntent(context, filter, id);
if (editTaskIntent != null) {
remoteViews.setPendingIntentTemplate(R.id.list_view, editTaskIntent);
}
return remoteViews;
}
@ -126,38 +141,53 @@ public class WidgetHelper {
listIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}
public PendingIntent getEditIntent(Context context, Filter filter, int id) {
Intent editIntent;
private PendingIntent getEditTaskIntent(Context context, Filter filter, int widgetId) {
Intent intent;
if (AstridPreferences.useTabletLayout(context)) {
intent = new Intent(context, TaskListActivity.class);
if (filter != null && filter instanceof FilterWithCustomIntent) {
Bundle customExtras = ((FilterWithCustomIntent) filter).customExtras;
intent.putExtras(customExtras);
}
} else {
intent = new Intent(context, TaskEditActivity.class);
}
intent.setFlags(flags);
intent.putExtra(TaskEditFragment.OVERRIDE_FINISH_ANIM, false);
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
public PendingIntent getNewTaskIntent(Context context, Filter filter, int id) {
Intent intent;
boolean tablet = AstridPreferences.useTabletLayout(context);
if (tablet) {
editIntent = new Intent(context, TaskListActivity.class);
editIntent.putExtra(TaskListActivity.OPEN_TASK, 0L);
}
else {
editIntent = new Intent(context, TaskEditActivity.class);
intent = new Intent(context, TaskListActivity.class);
intent.putExtra(TaskListActivity.OPEN_TASK, 0L);
} else {
intent = new Intent(context, TaskEditActivity.class);
}
editIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
editIntent.putExtra(TaskEditFragment.OVERRIDE_FINISH_ANIM, false);
intent.setFlags(flags);
intent.putExtra(TaskEditFragment.OVERRIDE_FINISH_ANIM, false);
if (filter != null) {
editIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
intent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
if (filter.valuesForNewTasks != null) {
String values = AndroidUtilities.contentValuesToSerializedString(filter.valuesForNewTasks);
values = PermaSql.replacePlaceholders(values);
editIntent.putExtra(TaskEditFragment.TOKEN_VALUES, values);
editIntent.setAction("E" + id + values);
intent.putExtra(TaskEditFragment.TOKEN_VALUES, values);
intent.setAction("E" + id + values);
}
if (tablet) {
if (filter instanceof FilterWithCustomIntent) {
Bundle customExtras = ((FilterWithCustomIntent) filter).customExtras;
editIntent.putExtras(customExtras);
intent.putExtras(customExtras);
}
}
} else {
editIntent.setAction("E" + id);
intent.setAction("E" + id);
}
return PendingIntent.getActivity(context, -id, editIntent, 0);
return PendingIntent.getActivity(context, -id, intent, 0);
}
public Filter getFilter(Context context, int widgetId) {
@ -203,7 +233,7 @@ public class WidgetHelper {
contentValuesString = AndroidUtilities.contentValuesToSerializedString(newTaskValues);
}
Preferences.setString(WidgetConfigActivity.PREF_VALUES + widgetId, contentValuesString);
if (filter instanceof FilterWithCustomIntent) {
if (filter != null) {
String flattenedExtras = AndroidUtilities.bundleToSerializedString(((FilterWithCustomIntent) filter).customExtras);
if (flattenedExtras != null) {
Preferences.setString(WidgetConfigActivity.PREF_CUSTOM_EXTRAS + widgetId,

Loading…
Cancel
Save