Fix shortcut widget (again)

pull/384/head
Alex Baker 9 years ago
parent ca3dd8697a
commit 1b13ea7ac1

@ -144,7 +144,8 @@
<!-- Activity launched from shortcut -->
<activity
android:name="com.todoroo.astrid.activity.ShortcutActivity">
android:name="com.todoroo.astrid.activity.ShortcutActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />

@ -17,6 +17,7 @@ import android.widget.ListView;
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 org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
@ -26,6 +27,8 @@ import org.tasks.injection.ForApplication;
import org.tasks.injection.InjectingListActivity;
import org.tasks.preferences.ActivityPreferences;
import java.util.Map;
import javax.inject.Inject;
public class FilterShortcutActivity extends InjectingListActivity {
@ -63,7 +66,7 @@ public class FilterShortcutActivity extends InjectingListActivity {
.show();
return;
}
Intent shortcutIntent = ShortcutActivity.createIntent(context, filter);
Intent shortcutIntent = createShortcutIntent(context, filter);
Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap();
Intent intent = new Intent();
@ -76,6 +79,46 @@ public class FilterShortcutActivity extends InjectingListActivity {
}
};
public static Intent createShortcutIntent(Context context, Filter filter) {
Intent shortcutIntent = new Intent(context, ShortcutActivity.class);
if(filter instanceof FilterWithCustomIntent) {
FilterWithCustomIntent customFilter = ((FilterWithCustomIntent)filter);
if(customFilter.customExtras != null) {
shortcutIntent.putExtras(customFilter.customExtras);
}
shortcutIntent.putExtra(ShortcutActivity.TOKEN_CUSTOM_CLASS, customFilter.customTaskList.flattenToString());
}
shortcutIntent.setAction(Intent.ACTION_VIEW);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_TITLE, filter.listingTitle);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_SQL, filter.getSqlQuery());
if (filter.valuesForNewTasks != null) {
for (Map.Entry<String, Object> item : filter.valuesForNewTasks.valueSet()) {
String key = ShortcutActivity.TOKEN_FILTER_VALUES_ITEM + item.getKey();
Object value = item.getValue();
putExtra(shortcutIntent, key, value);
}
}
return shortcutIntent;
}
private static void putExtra(Intent intent, String key, Object value) {
// assume one of the big 4...
if (value instanceof String) {
intent.putExtra(key, (String) value);
} else if (value instanceof Integer) {
intent.putExtra(key, (Integer) value);
} else if (value instanceof Double) {
intent.putExtra(key, (Double) value);
} else if (value instanceof Long) {
intent.putExtra(key, (Long) value);
} else {
throw new IllegalStateException(
"Unsupported bundle type " + value.getClass()); //$NON-NLS-1$
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);

@ -7,7 +7,6 @@ package com.todoroo.astrid.activity;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@ -17,7 +16,6 @@ import com.todoroo.astrid.api.FilterWithCustomIntent;
import org.tasks.injection.InjectingAppCompatActivity;
import java.util.Map.Entry;
import java.util.Set;
/**
@ -57,7 +55,7 @@ public class ShortcutActivity extends InjectingAppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
launchTaskList();
launchShortcut();
}
@Override
@ -66,22 +64,21 @@ public class ShortcutActivity extends InjectingAppCompatActivity {
setIntent(intent);
launchTaskList();
launchShortcut();
}
private void launchTaskList() {
private void launchShortcut() {
Intent intent = getIntent();
Bundle extras = intent.getExtras();
Intent taskListIntent = new Intent(this, TaskListActivity.class);
taskListIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) {
taskListIntent.putExtras(intent.getExtras());
}
if (extras != null) {
if(extras.containsKey(TOKEN_CUSTOM_CLASS)) {
taskListIntent.putExtras(intent.getExtras());
}
if(extras != null && extras.containsKey(TOKEN_FILTER_SQL)) {
// launched from desktop shortcut, must create a fake filter
String title = extras.getString(TOKEN_FILTER_TITLE);
String sql = extras.getString(TOKEN_FILTER_SQL);
@ -131,46 +128,4 @@ public class ShortcutActivity extends InjectingAppCompatActivity {
startActivity(taskListIntent);
finish();
}
public static Intent createIntent(Context context, Filter filter) {
Intent shortcutIntent = new Intent(context, ShortcutActivity.class);
if(filter instanceof FilterWithCustomIntent) {
FilterWithCustomIntent customFilter = ((FilterWithCustomIntent)filter);
if(customFilter.customExtras != null) {
shortcutIntent.putExtras(customFilter.customExtras);
}
shortcutIntent.putExtra(TOKEN_CUSTOM_CLASS, customFilter.customTaskList.flattenToString());
}
shortcutIntent.setAction(Intent.ACTION_VIEW);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_TITLE,
filter.listingTitle);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_SQL,
filter.getSqlQuery());
if (filter.valuesForNewTasks != null) {
for (Entry<String, Object> item : filter.valuesForNewTasks.valueSet()) {
String key = TOKEN_FILTER_VALUES_ITEM + item.getKey();
Object value = item.getValue();
putExtra(shortcutIntent, key, value);
}
}
return shortcutIntent;
}
private static void putExtra(Intent intent, String key, Object value) {
// assume one of the big 4...
if (value instanceof String) {
intent.putExtra(key, (String) value);
} else if (value instanceof Integer) {
intent.putExtra(key, (Integer) value);
} else if (value instanceof Double) {
intent.putExtra(key, (Double) value);
} else if (value instanceof Long) {
intent.putExtra(key, (Long) value);
} else {
throw new IllegalStateException(
"Unsupported bundle type " + value.getClass()); //$NON-NLS-1$
}
}
}

@ -14,6 +14,7 @@ import android.support.v7.app.NotificationCompat;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.FilterShortcutActivity;
import com.todoroo.astrid.activity.ShortcutActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.data.Task;
@ -77,7 +78,7 @@ public class TimerPlugin {
notificationManager.cancel(Constants.NOTIFICATION_TIMER);
} else {
Filter filter = TimerFilterExposer.createFilter(context);
Intent notifyIntent = ShortcutActivity.createIntent(context, filter);
Intent notifyIntent = FilterShortcutActivity.createShortcutIntent(context, filter);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
Constants.NOTIFICATION_TIMER, notifyIntent, 0);

Loading…
Cancel
Save