Merge widgets together, bump version

* Allows for seamless upgrade to scrollable widget
pull/46/merge
Alex Baker 12 years ago
parent b6d82c2689
commit 9d609986eb

@ -5,8 +5,8 @@
--> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.tasks" package="org.tasks"
android:versionName="4.6.10" android:versionName="4.6.11"
android:versionCode="321"> android:versionCode="322">
<!-- widgets, alarms, and services will break if Astrid is installed on SD card --> <!-- widgets, alarms, and services will break if Astrid is installed on SD card -->
<!-- android:installLocation="internalOnly"> --> <!-- android:installLocation="internalOnly"> -->
@ -174,12 +174,6 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".widget.ScrollableWidgetConfigActivity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity <activity
android:name="com.todoroo.astrid.service.UpdateScreenFlow" android:name="com.todoroo.astrid.service.UpdateScreenFlow"
android:screenOrientation="portrait" android:screenOrientation="portrait"
@ -202,7 +196,6 @@
<!-- widgets --> <!-- widgets -->
<receiver <receiver
android:name="com.todoroo.astrid.widget.TasksWidget" android:name="com.todoroo.astrid.widget.TasksWidget"
android:enabled="@bool/is_pre_api_14"
android:label="@string/widget_mini"> android:label="@string/widget_mini">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
@ -212,18 +205,6 @@
android:resource="@xml/widget_provider_info" /> android:resource="@xml/widget_provider_info" />
</receiver> </receiver>
<receiver
android:name=".widget.ScrollableTasksWidget"
android:enabled="@bool/is_post_api_14"
android:label="@string/widget_mini">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/scrollable_widget_provider_info" />
</receiver>
<receiver android:name="com.todoroo.astrid.service.GlobalEventReceiver"> <receiver android:name="com.todoroo.astrid.service.GlobalEventReceiver">
<intent-filter> <intent-filter>
<action android:name="org.tasks.FLUSH_DETAILS" /> <action android:name="org.tasks.FLUSH_DETAILS" />

@ -89,9 +89,9 @@ import com.todoroo.astrid.timers.TimerPlugin;
import com.todoroo.astrid.ui.QuickAddBar; import com.todoroo.astrid.ui.QuickAddBar;
import com.todoroo.astrid.utility.AstridPreferences; import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.utility.Flags;
import com.todoroo.astrid.widget.TasksWidget;
import org.tasks.R; import org.tasks.R;
import org.tasks.widget.WidgetHelper;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
@ -719,7 +719,7 @@ public class TaskListFragment extends ListFragment implements OnSortSelectedList
if (resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED || resultCode == EditPreferences.RESULT_CODE_PERFORMANCE_PREF_CHANGED) { if (resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED || resultCode == EditPreferences.RESULT_CODE_PERFORMANCE_PREF_CHANGED) {
getActivity().finish(); getActivity().finish();
getActivity().startActivity(getActivity().getIntent()); getActivity().startActivity(getActivity().getIntent());
WidgetHelper.updateWidgets(getActivity()); TasksWidget.updateWidgets(getActivity());
return; return;
} else if (resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) { } else if (resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) {
Preferences.setLong(SyncActionHelper.PREF_LAST_AUTO_SYNC, 0); // Forces autosync to occur after login Preferences.setLong(SyncActionHelper.PREF_LAST_AUTO_SYNC, 0); // Forces autosync to occur after login
@ -1166,7 +1166,7 @@ public class TaskListFragment extends ListFragment implements OnSortSelectedList
editor.putInt(SortHelper.PREF_SORT_FLAGS, flags); editor.putInt(SortHelper.PREF_SORT_FLAGS, flags);
editor.putInt(SortHelper.PREF_SORT_SORT, sort); editor.putInt(SortHelper.PREF_SORT_SORT, sort);
editor.commit(); editor.commit();
WidgetHelper.updateWidgets(ContextManager.getContext()); TasksWidget.updateWidgets(ContextManager.getContext());
} }
} }
} }

@ -25,8 +25,7 @@ import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.provider.Astrid2TaskProvider; import com.todoroo.astrid.provider.Astrid2TaskProvider;
import com.todoroo.astrid.provider.Astrid3ContentProvider; import com.todoroo.astrid.provider.Astrid3ContentProvider;
import com.todoroo.astrid.widget.TasksWidget;
import org.tasks.widget.WidgetHelper;
/** /**
* Database wrapper * Database wrapper
@ -74,7 +73,7 @@ public class Database extends AbstractDatabase {
public void onDatabaseUpdated() { public void onDatabaseUpdated() {
Astrid2TaskProvider.notifyDatabaseModification(); Astrid2TaskProvider.notifyDatabaseModification();
Astrid3ContentProvider.notifyDatabaseModification(); Astrid3ContentProvider.notifyDatabaseModification();
WidgetHelper.updateWidgets(ContextManager.getContext()); TasksWidget.updateWidgets(ContextManager.getContext());
} }
}); });
} }

@ -3,8 +3,7 @@ package com.todoroo.astrid.service;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.sync.SyncResultCallback; import com.todoroo.astrid.sync.SyncResultCallback;
import com.todoroo.astrid.widget.TasksWidget;
import org.tasks.widget.WidgetHelper;
public class SyncResultCallbackWrapper implements SyncResultCallback { public class SyncResultCallbackWrapper implements SyncResultCallback {
private final SyncResultCallback wrapped; private final SyncResultCallback wrapped;
@ -37,14 +36,14 @@ public class SyncResultCallbackWrapper implements SyncResultCallback {
@Override @Override
public void started() { public void started() {
super.started(); super.started();
WidgetHelper.suppressUpdateFlag = DateUtilities.now(); TasksWidget.suppressUpdateFlag = DateUtilities.now();
} }
@Override @Override
public void finished() { public void finished() {
super.finished(); super.finished();
WidgetHelper.suppressUpdateFlag = 0L; TasksWidget.suppressUpdateFlag = 0L;
WidgetHelper.updateWidgets(ContextManager.getContext()); TasksWidget.updateWidgets(ContextManager.getContext());
} }
} }

@ -5,42 +5,80 @@
*/ */
package com.todoroo.astrid.widget; package com.todoroo.astrid.widget;
import android.annotation.TargetApi;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.util.Log; import android.util.Log;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities;
import org.tasks.R;
import org.tasks.widget.WidgetHelper;
public class TasksWidget extends AppWidgetProvider { public class TasksWidget extends AppWidgetProvider {
public static long suppressUpdateFlag = 0; // Timestamp--don't update widgets if this flag is non-zero and now() is within 5 minutes
private static final long SUPPRESS_TIME = DateUtilities.ONE_MINUTE * 5;
private static final WidgetHelper widgetHelper = new WidgetHelper();
@Override @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
try { try {
ContextManager.setContext(context); ContextManager.setContext(context);
super.onUpdate(context, appWidgetManager, appWidgetIds); super.onUpdate(context, appWidgetManager, appWidgetIds);
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// Start in service to prevent Application Not Responding timeout // Start in service to prevent Application Not Responding timeout
updateWidgets(context); updateWidgets(context);
} else {
ComponentName thisWidget = new ComponentName(context, TasksWidget.class);
int[] ids = appWidgetManager.getAppWidgetIds(thisWidget);
for (int id : ids) {
appWidgetManager.updateAppWidget(id, widgetHelper.createScrollableWidget(context, id));
}
}
} catch (Exception e) { } catch (Exception e) {
Log.e("astrid-update-widget", "widget update error", e); //$NON-NLS-1$ //$NON-NLS-2$ Log.e("astrid-update-widget", "widget update error", e); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
/**
* Update all widgets
*/
public static void updateWidgets(Context context) { public static void updateWidgets(Context context) {
if (suppressUpdateFlag > 0 && DateUtilities.now() - suppressUpdateFlag < SUPPRESS_TIME) {
return;
}
suppressUpdateFlag = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
context.startService(new Intent(context, WidgetUpdateService.class)); context.startService(new Intent(context, WidgetUpdateService.class));
} else {
updateScrollableWidgets(context, null);
}
} }
/** public static void applyConfigSelection(Context context, int id) {
* Update widget with the given id if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
*/
public static void updateWidget(Context context, int id) {
Intent intent = new Intent(ContextManager.getContext(), WidgetUpdateService.class); Intent intent = new Intent(ContextManager.getContext(), WidgetUpdateService.class);
intent.putExtra(WidgetUpdateService.EXTRA_WIDGET_ID, id); intent.putExtra(WidgetUpdateService.EXTRA_WIDGET_ID, id);
context.startService(intent); context.startService(intent);
} else {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
appWidgetManager.updateAppWidget(id, widgetHelper.createScrollableWidget(context, id));
updateScrollableWidgets(context, new int[]{id});
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void updateScrollableWidgets(Context context, int[] widgetIds) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
if (widgetIds == null) {
widgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, TasksWidget.class));
}
appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.list_view);
} }
} }

@ -27,12 +27,12 @@ import org.tasks.R;
public class WidgetConfigActivity extends ListActivity { public class WidgetConfigActivity extends ListActivity {
static final String PREF_TITLE = "widget-title-"; public static final String PREF_TITLE = "widget-title-";
static final String PREF_SQL = "widget-sql-"; public static final String PREF_SQL = "widget-sql-";
static final String PREF_VALUES = "widget-values-"; public static final String PREF_VALUES = "widget-values-";
public static final String PREF_CUSTOM_INTENT = "widget-intent-"; public static final String PREF_CUSTOM_INTENT = "widget-intent-";
public static final String PREF_CUSTOM_EXTRAS = "widget-extras-"; public static final String PREF_CUSTOM_EXTRAS = "widget-extras-";
static final String PREF_TAG_ID = "widget-tag-id-"; public static final String PREF_TAG_ID = "widget-tag-id-";
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
@ -43,7 +43,7 @@ public class WidgetConfigActivity extends ListActivity {
} }
public void updateWidget() { public void updateWidget() {
TasksWidget.updateWidget(this, mAppWidgetId); TasksWidget.applyConfigSelection(this, mAppWidgetId);
} }
@Override @Override

@ -1,46 +0,0 @@
package org.tasks.widget;
import android.annotation.TargetApi;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import com.todoroo.andlib.service.ContextManager;
import org.tasks.R;
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class ScrollableTasksWidget extends AppWidgetProvider {
private final WidgetHelper widgetHelper = new WidgetHelper();
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
ContextManager.setContext(context);
super.onUpdate(context, appWidgetManager, appWidgetIds);
ComponentName thisWidget = new ComponentName(context, ScrollableTasksWidget.class);
int[] ids = appWidgetManager.getAppWidgetIds(thisWidget);
for (int id : ids) {
appWidgetManager.updateAppWidget(id, widgetHelper.createScrollableWidget(context, id));
}
}
public static void updateWidgets(Context context) {
updateWidgets(context, null);
}
public static void updateWidget(Context context, int id) {
updateWidgets(context, new int[]{id});
}
private static void updateWidgets(Context context, int[] widgetIds) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
if (widgetIds == null) {
widgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, ScrollableTasksWidget.class));
}
appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.list_view);
}
}

@ -1,157 +0,0 @@
package org.tasks.widget;
import android.app.ListActivity;
import android.appwidget.AppWidgetManager;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.service.ThemeService;
import org.tasks.R;
public class ScrollableWidgetConfigActivity extends ListActivity {
static final String PREF_TITLE = "widget-title-";
static final String PREF_SQL = "widget-sql-";
static final String PREF_VALUES = "widget-values-";
static final String PREF_CUSTOM_INTENT = "widget-intent-";
static final String PREF_CUSTOM_EXTRAS = "widget-extras-";
static final String PREF_TAG_ID = "widget-tag-id-";
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
FilterAdapter adapter = null;
private final WidgetHelper widgetHelper = new WidgetHelper();
public void updateWidget() {
// setup view for new widget
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
appWidgetManager.updateAppWidget(mAppWidgetId, widgetHelper.createScrollableWidget(getApplicationContext(), mAppWidgetId));
ScrollableTasksWidget.updateWidget(this, mAppWidgetId);
}
@Override
public void onCreate(Bundle icicle) {
ThemeService.applyTheme(this);
ThemeService.setForceFilterInvert(true);
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if they press the back button.
setResult(RESULT_CANCELED);
// Set the view layout resource to use.
setContentView(R.layout.widget_config_activity);
setTitle(R.string.WCA_title);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
// set up ui
adapter = new FilterAdapter(this, getListView(),
R.layout.filter_adapter_row, true, true);
adapter.filterStyle = R.style.TextAppearance_FLA_Filter_Widget;
setListAdapter(adapter);
Button button = (Button)findViewById(R.id.ok);
button.setOnClickListener(mOnClickListener);
}
View.OnClickListener mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// Save configuration options
saveConfiguration(adapter.getSelection());
updateWidget();
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
};
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Filter item = adapter.getItem(position);
adapter.setSelection(item);
}
@Override
protected void onResume() {
super.onResume();
adapter.registerRecevier();
}
@Override
protected void onPause() {
super.onPause();
adapter.unregisterRecevier();
}
@Override
protected void onStop() {
super.onStop();
ThemeService.setForceFilterInvert(false);
}
private void saveConfiguration(FilterListItem filterListItem){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
String sql = null, contentValuesString = null, title = null;
if(filterListItem != null && filterListItem instanceof Filter) {
sql = ((Filter)filterListItem).getSqlQuery();
ContentValues values = ((Filter)filterListItem).valuesForNewTasks;
if(values != null) {
contentValuesString = AndroidUtilities.contentValuesToSerializedString(values);
}
title = ((Filter)filterListItem).title;
}
Preferences.setString(ScrollableWidgetConfigActivity.PREF_TITLE + mAppWidgetId, title);
Preferences.setString(ScrollableWidgetConfigActivity.PREF_SQL + mAppWidgetId, sql);
Preferences.setString(ScrollableWidgetConfigActivity.PREF_VALUES + mAppWidgetId, contentValuesString);
if(filterListItem instanceof FilterWithCustomIntent) {
String flattenedName = ((FilterWithCustomIntent)filterListItem).customTaskList.flattenToString();
Preferences.setString(ScrollableWidgetConfigActivity.PREF_CUSTOM_INTENT + mAppWidgetId,
flattenedName);
String flattenedExtras = AndroidUtilities.bundleToSerializedString(((FilterWithCustomIntent)filterListItem).customExtras);
if (flattenedExtras != null) {
Preferences.setString(ScrollableWidgetConfigActivity.PREF_CUSTOM_EXTRAS + mAppWidgetId,
flattenedExtras);
}
}
}
}

@ -17,7 +17,6 @@ import android.widget.RemoteViews;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.activity.TaskEditActivity; import com.todoroo.astrid.activity.TaskEditActivity;
@ -49,21 +48,6 @@ public class WidgetHelper {
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
public static long suppressUpdateFlag = 0; // Timestamp--don't update widgets if this flag is non-zero and now() is within 5 minutes
private static final long SUPPRESS_TIME = DateUtilities.ONE_MINUTE * 5;
public static void updateWidgets(Context context) {
if (suppressUpdateFlag > 0 && DateUtilities.now() - suppressUpdateFlag < SUPPRESS_TIME) {
return;
}
suppressUpdateFlag = 0;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
TasksWidget.updateWidgets(context);
} else {
ScrollableTasksWidget.updateWidgets(context);
}
}
public static void startWidgetService(Context context) { public static void startWidgetService(Context context) {
Class widgetServiceClass = android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH Class widgetServiceClass = android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH
? WidgetUpdateService.class ? WidgetUpdateService.class
@ -77,12 +61,9 @@ public class WidgetHelper {
} }
public static void triggerUpdate(Context context) { public static void triggerUpdate(Context context) {
Class widgetClass = android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH
? TasksWidget.class
: ScrollableTasksWidget.class;
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
ComponentName thisWidget = new ComponentName(context, widgetClass); ComponentName thisWidget = new ComponentName(context, TasksWidget.class);
Intent intent = new Intent(context, widgetClass); Intent intent = new Intent(context, TasksWidget.class);
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetManager.getAppWidgetIds(thisWidget)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetManager.getAppWidgetIds(thisWidget));
context.sendBroadcast(intent); context.sendBroadcast(intent);
@ -183,49 +164,49 @@ public class WidgetHelper {
// base our filter off the inbox filter, replace stuff if we have it // base our filter off the inbox filter, replace stuff if we have it
Filter filter = CoreFilterExposer.buildInboxFilter(context.getResources()); Filter filter = CoreFilterExposer.buildInboxFilter(context.getResources());
String sql = Preferences.getStringValue(ScrollableWidgetConfigActivity.PREF_SQL + widgetId); String sql = Preferences.getStringValue(WidgetConfigActivity.PREF_SQL + widgetId);
if(sql != null) { if(sql != null) {
filter.setSqlQuery(sql); filter.setSqlQuery(sql);
} }
String title = Preferences.getStringValue(ScrollableWidgetConfigActivity.PREF_TITLE + widgetId); String title = Preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId);
if(title != null) { if(title != null) {
filter.title = title; filter.title = title;
} }
String contentValues = Preferences.getStringValue(ScrollableWidgetConfigActivity.PREF_VALUES + widgetId); String contentValues = Preferences.getStringValue(WidgetConfigActivity.PREF_VALUES + widgetId);
if(contentValues != null) { if(contentValues != null) {
filter.valuesForNewTasks = AndroidUtilities.contentValuesFromSerializedString(contentValues); filter.valuesForNewTasks = AndroidUtilities.contentValuesFromSerializedString(contentValues);
} }
String customComponent = Preferences.getStringValue(ScrollableWidgetConfigActivity.PREF_CUSTOM_INTENT String customComponent = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT
+ widgetId); + widgetId);
if (customComponent != null) { if (customComponent != null) {
ComponentName component = ComponentName.unflattenFromString(customComponent); ComponentName component = ComponentName.unflattenFromString(customComponent);
filter = new FilterWithCustomIntent(filter.title, filter.title, filter.getSqlQuery(), filter.valuesForNewTasks); filter = new FilterWithCustomIntent(filter.title, filter.title, filter.getSqlQuery(), filter.valuesForNewTasks);
((FilterWithCustomIntent) filter).customTaskList = component; ((FilterWithCustomIntent) filter).customTaskList = component;
String serializedExtras = Preferences.getStringValue(ScrollableWidgetConfigActivity.PREF_CUSTOM_EXTRAS String serializedExtras = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS
+ widgetId); + widgetId);
((FilterWithCustomIntent) filter).customExtras = AndroidUtilities.bundleFromSerializedString(serializedExtras); ((FilterWithCustomIntent) filter).customExtras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
} }
// Validate tagData // Validate tagData
long id = Preferences.getLong(ScrollableWidgetConfigActivity.PREF_TAG_ID + widgetId, 0); long id = Preferences.getLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, 0);
TagData tagData; TagData tagData;
if (id > 0) { if (id > 0) {
tagData = tagDataService.fetchById(id, TagData.ID, TagData.NAME, TagData.TASK_COUNT, TagData.UUID, TagData.PICTURE, TagData.USER_ID, TagData.MEMBER_COUNT); tagData = tagDataService.fetchById(id, TagData.ID, TagData.NAME, TagData.TASK_COUNT, TagData.UUID, TagData.PICTURE, TagData.USER_ID, TagData.MEMBER_COUNT);
if (tagData != null && !tagData.getValue(TagData.NAME).equals(filter.title)) { // Tag has been renamed; rebuild filter if (tagData != null && !tagData.getValue(TagData.NAME).equals(filter.title)) { // Tag has been renamed; rebuild filter
filter = TagFilterExposer.filterFromTagData(context, tagData); filter = TagFilterExposer.filterFromTagData(context, tagData);
Preferences.setString(ScrollableWidgetConfigActivity.PREF_SQL + widgetId, filter.getSqlQuery()); Preferences.setString(WidgetConfigActivity.PREF_SQL + widgetId, filter.getSqlQuery());
Preferences.setString(ScrollableWidgetConfigActivity.PREF_TITLE + widgetId, filter.title); Preferences.setString(WidgetConfigActivity.PREF_TITLE + widgetId, filter.title);
ContentValues newTaskValues = filter.valuesForNewTasks; ContentValues newTaskValues = filter.valuesForNewTasks;
String contentValuesString = null; String contentValuesString = null;
if(newTaskValues != null) { if(newTaskValues != null) {
contentValuesString = AndroidUtilities.contentValuesToSerializedString(newTaskValues); contentValuesString = AndroidUtilities.contentValuesToSerializedString(newTaskValues);
} }
Preferences.setString(ScrollableWidgetConfigActivity.PREF_VALUES + widgetId, contentValuesString); Preferences.setString(WidgetConfigActivity.PREF_VALUES + widgetId, contentValuesString);
if (filter instanceof FilterWithCustomIntent) { if (filter instanceof FilterWithCustomIntent) {
String flattenedExtras = AndroidUtilities.bundleToSerializedString(((FilterWithCustomIntent) filter).customExtras); String flattenedExtras = AndroidUtilities.bundleToSerializedString(((FilterWithCustomIntent) filter).customExtras);
if (flattenedExtras != null) { if (flattenedExtras != null) {
Preferences.setString(ScrollableWidgetConfigActivity.PREF_CUSTOM_EXTRAS + widgetId, Preferences.setString(WidgetConfigActivity.PREF_CUSTOM_EXTRAS + widgetId,
flattenedExtras); flattenedExtras);
} }
} }
@ -233,7 +214,7 @@ public class WidgetHelper {
} else { } else {
tagData = tagDataService.getTagByName(filter.title, TagData.ID); tagData = tagDataService.getTagByName(filter.title, TagData.ID);
if (tagData != null) { if (tagData != null) {
Preferences.setLong(ScrollableWidgetConfigActivity.PREF_TAG_ID + widgetId, tagData.getId()); Preferences.setLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, tagData.getId());
} }
} }
@ -252,7 +233,7 @@ public class WidgetHelper {
String query = SortHelper.adjustQueryForFlagsAndSort( String query = SortHelper.adjustQueryForFlagsAndSort(
filter.getSqlQuery(), flags, sort).replaceAll("LIMIT \\d+", ""); filter.getSqlQuery(), flags, sort).replaceAll("LIMIT \\d+", "");
String tagName = Preferences.getStringValue(ScrollableWidgetConfigActivity.PREF_TITLE + widgetId); String tagName = Preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId);
return SubtasksHelper.applySubtasksToWidgetFilter(filter, query, tagName, 0); return SubtasksHelper.applySubtasksToWidgetFilter(filter, query, tagName, 0);
} }

@ -63,10 +63,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:background="@color/widget_body_light" android:background="@color/widget_body_dark"
android:layout_marginTop="37dip"
android:padding="10dip"
android:text="@string/TWi_loading"
style="@style/TextAppearance.Widget" /> style="@style/TextAppearance.Widget" />
</LinearLayout> </LinearLayout>

@ -64,9 +64,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:background="@color/widget_body_light" android:background="@color/widget_body_light"
android:layout_marginTop="37dip"
android:padding="10dip"
android:text="@string/TWi_loading"
style="@style/TextAppearance.Widget" /> style="@style/TextAppearance.Widget" />
</LinearLayout> </LinearLayout>

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_pre_api_14">false</bool>
<bool name="is_post_api_14">true</bool>
</resources>

@ -43,7 +43,4 @@
<attr name="shortcutLabels" format="reference"/> <attr name="shortcutLabels" format="reference"/>
</declare-styleable> </declare-styleable>
<bool name="is_pre_api_14">true</bool>
<bool name="is_post_api_14">false</bool>
</resources> </resources>

@ -6,7 +6,7 @@
--> -->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:configure="org.tasks.widget.ScrollableWidgetConfigActivity" android:configure="com.todoroo.astrid.widget.WidgetConfigActivity"
android:minWidth="142dip" android:minWidth="142dip"
android:minHeight="142dip" android:minHeight="142dip"
android:minResizeWidth="142dip" android:minResizeWidth="142dip"

Loading…
Cancel
Save