Remove ShortcutActivity

pull/384/head
Alex Baker 8 years ago
parent 79c2850eb7
commit 1b348fb9f4

@ -150,16 +150,6 @@
</intent-filter>
</activity>
<!-- Activity launched from shortcut -->
<activity
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" />
</intent-filter>
</activity>
<!-- Activity for selecting Android shortcut -->
<activity
android:name="com.todoroo.astrid.activity.FilterShortcutActivity"

@ -17,7 +17,6 @@ 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,9 +25,9 @@ import org.tasks.filters.FilterProvider;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ForApplication;
import org.tasks.injection.InjectingListActivity;
import org.tasks.intents.TaskIntents;
import org.tasks.preferences.ActivityPreferences;
import java.util.Map;
import org.tasks.preferences.DefaultFilterProvider;
import javax.inject.Inject;
@ -39,6 +38,7 @@ public class FilterShortcutActivity extends InjectingListActivity {
@Inject FilterProvider filterProvider;
@Inject @ForApplication Context context;
@Inject DialogBuilder dialogBuilder;
@Inject DefaultFilterProvider defaultFilterProvider;
private FilterAdapter adapter = null;
@ -67,7 +67,9 @@ public class FilterShortcutActivity extends InjectingListActivity {
.show();
return;
}
Intent shortcutIntent = createShortcutIntent(context, filter);
String filterId = defaultFilterProvider.getFilterPreferenceValue(filter);
Intent shortcutIntent = TaskIntents.getTaskListByIdIntent(context, filterId);
Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap();
Intent intent = new Intent();
@ -80,46 +82,6 @@ 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);

@ -1,137 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.activity;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import java.util.Set;
/**
* This activity is launched when a user opens up a notification from the
* tray. It launches the appropriate activity based on the passed in parameters.
*
* @author timsu
*
*/
public class ShortcutActivity extends InjectingAppCompatActivity {
// --- constants
/** token for passing a {@link Filter}'s title through extras */
public static final String TOKEN_FILTER_TITLE = "title"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s sql through extras */
public static final String TOKEN_FILTER_SQL = "sql"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s values for new tasks through extras as exploded ContentValues */
public static final String TOKEN_FILTER_VALUES_ITEM = "v4ntp_"; //$NON-NLS-1$
/** token for passing a ComponentNameto launch */
public static final String TOKEN_CUSTOM_CLASS = "class"; //$NON-NLS-1$
/** List of the above constants for searching */
private static final String[] CUSTOM_EXTRAS = {
TOKEN_FILTER_TITLE,
TOKEN_FILTER_SQL,
TOKEN_FILTER_VALUES_ITEM,
TOKEN_CUSTOM_CLASS
};
// --- implementation
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
launchShortcut();
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
launchShortcut();
}
private void launchShortcut() {
Intent intent = getIntent();
Bundle extras = intent.getExtras();
Intent taskListIntent = new Intent(this, TaskListActivity.class);
if (extras != null) {
if(extras.containsKey(TOKEN_CUSTOM_CLASS)) {
taskListIntent.putExtras(intent.getExtras());
}
// launched from desktop shortcut, must create a fake filter
String title = extras.getString(TOKEN_FILTER_TITLE);
String sql = extras.getString(TOKEN_FILTER_SQL);
sql = sql.replace("tasks.userId=0", "1"); // TODO: replace dirty hack for missing column
ContentValues values = new ContentValues();
for(String key : extras.keySet()) {
if(!key.startsWith(TOKEN_FILTER_VALUES_ITEM)) {
continue;
}
Object value = extras.get(key);
key = key.substring(TOKEN_FILTER_VALUES_ITEM.length());
// assume one of the big 4...
if(value instanceof String) {
values.put(key, (String) value);
} else if(value instanceof Integer) {
values.put(key, (Integer) value);
} else if(value instanceof Double) {
values.put(key, (Double) value);
} else if(value instanceof Long) {
values.put(key, (Long) value);
} else {
throw new IllegalStateException("Unsupported bundle type " + value.getClass()); //$NON-NLS-1$
}
}
Filter filter;
if (extras.containsKey(TOKEN_CUSTOM_CLASS)) {
filter = new FilterWithCustomIntent(title, sql, values);
Bundle customExtras = new Bundle();
Set<String> keys = extras.keySet();
for (String key : keys) {
if (AndroidUtilities.indexOf(CUSTOM_EXTRAS, key) < 0) {
AndroidUtilities.putInto(customExtras, key, extras.get(key));
}
}
((FilterWithCustomIntent) filter).customExtras = customExtras; // Something
((FilterWithCustomIntent) filter).customTaskList = ComponentName.unflattenFromString(extras.getString(TOKEN_CUSTOM_CLASS));
} else {
filter = new Filter(title, sql, values);
}
taskListIntent.putExtra(TaskListActivity.OPEN_FILTER, filter);
}
startActivity(taskListIntent);
finish();
}
}

@ -17,8 +17,6 @@ import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.subtasks.SubtasksTagListFragment;
import org.tasks.BuildConfig;
public class FilterWithCustomIntent extends Filter {
/**
@ -39,10 +37,6 @@ public class FilterWithCustomIntent extends Filter {
super(listingTitle, sqlQuery, valuesForNewTasks);
}
public FilterWithCustomIntent(String listingTitle, String sqlQuery, ContentValues valuesForNewTasks) {
super(listingTitle, sqlQuery, valuesForNewTasks);
}
public Intent getCustomIntent() {
Intent intent = new Intent();
if(customExtras != null) {

@ -14,14 +14,13 @@ 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;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.utility.Constants;
import org.tasks.R;
import org.tasks.intents.TaskIntents;
import org.tasks.notifications.NotificationManager;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
@ -78,7 +77,7 @@ public class TimerPlugin {
notificationManager.cancel(Constants.NOTIFICATION_TIMER);
} else {
Filter filter = TimerFilterExposer.createFilter(context);
Intent notifyIntent = FilterShortcutActivity.createShortcutIntent(context, filter);
Intent notifyIntent = TaskIntents.getTaskListIntent(context, filter);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
Constants.NOTIFICATION_TIMER, notifyIntent, 0);

@ -5,7 +5,6 @@ import com.todoroo.astrid.actfm.TagSettingsActivity;
import com.todoroo.astrid.activity.BeastModePreferences;
import com.todoroo.astrid.activity.FilterShortcutActivity;
import com.todoroo.astrid.activity.ShareLinkActivity;
import com.todoroo.astrid.activity.ShortcutActivity;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.core.CustomFilterActivity;
import com.todoroo.astrid.core.DefaultsPreferences;
@ -67,8 +66,6 @@ public interface BaseActivityComponent {
void inject(TaskListActivity taskListActivity);
void inject(ShortcutActivity shortcutActivity);
void inject(BeastModePreferences beastModePreferences);
void inject(NotificationActivity notificationActivity);

Loading…
Cancel
Save