Fixed bugs with Notification fragments in swipe between lists

pull/14/head
Sam Bosley 13 years ago
parent 7dd5833e30
commit 5f8e86d7bd

@ -37,15 +37,12 @@ import android.widget.Spinner;
import android.widget.TimePicker;
import com.timsu.astrid.R;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.repeats.RepeatControlSet;
import com.todoroo.astrid.service.StartupService;
@ -94,25 +91,10 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL
@Override
protected void onNewIntent(Intent intent) {
populateFilter(intent);
displayNotificationPopup();
super.onNewIntent(intent);
}
private void populateFilter(Intent intent) {
taskId = intent.getLongExtra(TOKEN_ID, -1);
if(taskId == -1)
return;
Filter itemFilter = new Filter(getString(R.string.rmd_NoA_filter),
getString(R.string.rmd_NoA_filter),
new QueryTemplate().where(TaskCriteria.byId(taskId)),
null);
intent.putExtra(TaskListFragment.TOKEN_FILTER, itemFilter);
if (getActivity() instanceof TaskListActivity) // Title was already set before this fragment took over; set it again
((TaskListActivity) getActivity()).setListsTitle(itemFilter.title);
}
/**
* Set up the UI for this activity
*/
@ -124,6 +106,16 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL
new ReminderDialog((AstridActivity) getActivity(), taskId, title).show();
}
@Override
public void onDetach() {
Activity activity = getActivity();
if (activity instanceof TaskListActivity) {
TaskListActivity tla = (TaskListActivity) activity;
tla.getFragmentPagerAdapter().remove(filter);
}
super.onDetach();
}
public static class SnoozeDialog extends FrameLayout implements DialogInterface.OnClickListener {
LinearLayout snoozePicker;

@ -5,12 +5,14 @@ import java.util.Date;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
@ -21,12 +23,16 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.service.NotificationManager;
import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.utility.Constants;
@ -176,9 +182,18 @@ public class Notifications extends BroadcastReceiver {
String text = reminder + " " + taskTitle; //$NON-NLS-1$
Intent notifyIntent = new Intent(context, TaskListActivity.class);
FilterWithCustomIntent itemFilter = new FilterWithCustomIntent(context.getString(R.string.rmd_NoA_filter),
context.getString(R.string.rmd_NoA_filter),
new QueryTemplate().where(TaskCriteria.byId(id)),
null);
Bundle customExtras = new Bundle();
customExtras.putLong(NotificationFragment.TOKEN_ID, id);
customExtras.putString(EXTRAS_TEXT, text);
itemFilter.customExtras = customExtras;
itemFilter.customTaskList = new ComponentName(context, NotificationFragment.class);
notifyIntent.setAction("NOTIFY" + id); //$NON-NLS-1$
notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id);
notifyIntent.putExtra(EXTRAS_TEXT, text);
notifyIntent.putExtra(TaskListFragment.TOKEN_FILTER, itemFilter);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_NOTIFICATION);

@ -38,7 +38,6 @@ import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.CoreFilterExposer;
import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.ThemeService;
@ -172,10 +171,6 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
tlfPager.setOnPageChangeListener(this);
}
if (getIntent().getIntExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT) ==
Constants.SOURCE_NOTIFICATION)
setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, extras, NotificationFragment.class);
else
setupTasklistFragmentWithFilter(savedFilter, extras);
if (savedFilter != null)
@ -396,6 +391,10 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
lists.setText(item.title);
}
public TaskListFragmentPagerAdapter getFragmentPagerAdapter() {
return tlfPagerAdapter;
}
@Override
public void onPageSelected(int position) {
if (tlfPagerAdapter != null) {

@ -69,6 +69,10 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
return filterAdapter.addOrLookup(filter);
}
public void remove(Filter filter) {
filterAdapter.remove(filter);
}
/**
* Get the filter at the specified position
* @param position

Loading…
Cancel
Save