Create, rename, and delete Google Task Lists

pull/467/head
Alex Baker 8 years ago
parent 73ae880cbd
commit 5a38c807bc

@ -0,0 +1,4 @@
package org.tasks.activities;
public class GoogleTaskListSettingsActivity {
}

@ -18,6 +18,7 @@ import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.DatePickerActivity;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.activities.FilterSettingsActivity;
import org.tasks.activities.GoogleTaskListSettingsActivity;
import org.tasks.activities.TagSettingsActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dashclock.DashClockSettings;
@ -120,4 +121,6 @@ public interface ActivityComponent {
void inject(ColorPickerActivity colorPickerActivity);
void inject(BasicPreferences basicPreferences);
void inject(GoogleTaskListSettingsActivity googleTaskListSettingsActivity);
}

@ -5,12 +5,15 @@ import android.support.test.runner.AndroidJUnit4;
import com.google.api.client.util.DateTime;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.service.TaskDeleter;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.Broadcaster;
import org.tasks.data.TaskListDataProvider;
import org.tasks.injection.TestComponent;
import org.tasks.makers.RemoteGtaskListMaker;
@ -35,6 +38,9 @@ import static org.tasks.time.DateTimeUtils.currentTimeMillis;
public class GtasksListServiceTest extends DatabaseTestCase {
@Inject Database database;
@Inject TaskListDataProvider taskListDataProvider;
@Inject TaskDeleter taskDeleter;
@Inject MetadataDao metadataDao;
@Inject Broadcaster broadcaster;
private StoreObjectDao storeObjectDao;
@ -44,7 +50,7 @@ public class GtasksListServiceTest extends DatabaseTestCase {
public void setUp() {
super.setUp();
storeObjectDao = spy(new StoreObjectDao(database));
gtasksListService = new GtasksListService(storeObjectDao, broadcaster);
gtasksListService = new GtasksListService(storeObjectDao, taskListDataProvider, taskDeleter, metadataDao, broadcaster);
}
@Override

@ -0,0 +1,4 @@
package org.tasks.activities;
public class GoogleTaskListSettingsActivity {
}

@ -18,6 +18,7 @@ import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.DatePickerActivity;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.activities.FilterSettingsActivity;
import org.tasks.activities.GoogleTaskListSettingsActivity;
import org.tasks.activities.TagSettingsActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dashclock.DashClockSettings;
@ -120,4 +121,6 @@ public interface ActivityComponent {
void inject(ColorPickerActivity colorPickerActivity);
void inject(BasicPreferences basicPreferences);
void inject(GoogleTaskListSettingsActivity googleTaskListSettingsActivity);
}

@ -46,6 +46,8 @@
<service android:name=".location.GeofenceTransitionsIntentService"/>
<activity android:name=".activities.GoogleTaskListSettingsActivity" />
<activity
android:name="com.todoroo.astrid.gtasks.auth.GtasksLoginActivity"
android:theme="@style/TranslucentDialog" />

@ -6,10 +6,14 @@
package com.todoroo.astrid.gtasks;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskDeleter;
import org.tasks.Broadcaster;
import org.tasks.data.TaskListDataProvider;
import java.util.HashSet;
import java.util.List;
@ -26,20 +30,23 @@ import static org.tasks.time.DateTimeUtils.printTimestamp;
public class GtasksListService {
private final StoreObjectDao storeObjectDao;
private final TaskListDataProvider taskListDataProvider;
private final TaskDeleter taskDeleter;
private final MetadataDao metadataDao;
private final Broadcaster broadcaster;
@Inject
public GtasksListService(StoreObjectDao storeObjectDao, Broadcaster broadcaster) {
public GtasksListService(StoreObjectDao storeObjectDao, TaskListDataProvider taskListDataProvider,
TaskDeleter taskDeleter, MetadataDao metadataDao, Broadcaster broadcaster) {
this.storeObjectDao = storeObjectDao;
this.taskListDataProvider = taskListDataProvider;
this.taskDeleter = taskDeleter;
this.metadataDao = metadataDao;
this.broadcaster = broadcaster;
}
public List<GtasksList> getLists() {
return toGtasksList(storeObjectDao.getGtasksLists());
}
private static List<GtasksList> toGtasksList(List<StoreObject> storeObjects) {
return transform(storeObjects, GtasksList::new);
return transform(storeObjectDao.getGtasksLists(), GtasksList::new);
}
public GtasksList getList(long id) {
@ -85,12 +92,23 @@ public class GtasksListService {
// check for lists that aren't on remote server
for(Long listId : previousLists) {
storeObjectDao.delete(listId);
deleteList(storeObjectDao.getGtasksList(listId));
}
broadcaster.refreshLists();
}
public void deleteList(GtasksList gtasksList) {
taskListDataProvider
.constructCursor(new GtasksFilter(gtasksList), Task.PROPERTIES)
.forEach(task -> {
metadataDao.deleteWhere(MetadataDao.MetadataCriteria
.byTaskAndwithKey(task.getId(), GtasksMetadata.METADATA_KEY));
taskDeleter.delete(task);
});
storeObjectDao.delete(gtasksList.getId());
}
public List<GtasksList> getListsToUpdate(List<TaskList> remoteLists) {
List<GtasksList> listsToUpdate = newArrayList();
for (TaskList remoteList : remoteLists) {

@ -102,6 +102,24 @@ public class GtasksInvoker {
.setPrevious(previousId));
}
public void deleteGtaskList(String listId) throws IOException {
execute(service
.tasklists()
.delete(listId));
}
public TaskList renameGtaskList(String listId, String title) throws IOException {
return execute(service
.tasklists()
.patch(listId, new TaskList().setTitle(title)));
}
public TaskList createGtaskList(String title) throws IOException {
return execute(service
.tasklists()
.insert(new TaskList().setTitle(title)));
}
public void clearCompleted(String listId) throws IOException {
execute(service
.tasks()

@ -0,0 +1,218 @@
package org.tasks.activities;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.gtasks.GtasksList;
import com.todoroo.astrid.gtasks.GtasksListService;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.gtasks.CreateListDialog;
import org.tasks.gtasks.DeleteListDialog;
import org.tasks.gtasks.RenameListDialog;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
import org.tasks.preferences.Preferences;
import org.tasks.ui.MenuColorizer;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import static android.text.TextUtils.isEmpty;
import static org.tasks.gtasks.CreateListDialog.newCreateListDialog;
import static org.tasks.gtasks.DeleteListDialog.newDeleteListDialog;
import static org.tasks.gtasks.RenameListDialog.newRenameListDialog;
public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActivity
implements Toolbar.OnMenuItemClickListener, CreateListDialog.CreateListDialogCallback,
DeleteListDialog.DeleteListDialogCallback, RenameListDialog.RenameListDialogCallback {
private static final String FRAG_TAG_CREATE_LIST_DIALOG = "frag_tag_create_list_dialog";
private static final String FRAG_TAG_DELETE_LIST_DIALOG = "frag_tag_delete_list_dialog";
private static final String FRAG_TAG_RENAME_LIST_DIALOG = "frag_tag_rename_list_dialog";
public static final String EXTRA_STORE_DATA = "extra_store_data";
public static final String ACTION_DELETED = "action_deleted";
public static final String ACTION_RENAMED = "action_renamed";
private GtasksList gtasksList;
private boolean isNewList;
@Inject StoreObjectDao storeObjectDao;
@Inject DialogBuilder dialogBuilder;
@Inject Preferences preferences;
@Inject GtasksListService gtasksListService;
@BindView(R.id.tag_name) EditText listName;
@BindView(R.id.toolbar) Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.filter_settings_activity);
ButterKnife.bind(this);
StoreObject storeObject = getIntent().getParcelableExtra(EXTRA_STORE_DATA);
if (storeObject == null) {
isNewList = true;
storeObject = new StoreObject();
storeObject.setType(GtasksList.TYPE);
}
gtasksList = new GtasksList(storeObject);
final boolean backButtonSavesTask = preferences.backButtonSavesTask();
toolbar.setTitle(isNewList ? getString(R.string.new_list) : gtasksList.getName());
toolbar.setNavigationIcon(ContextCompat.getDrawable(this,
backButtonSavesTask ? R.drawable.ic_close_24dp : R.drawable.ic_save_24dp));
toolbar.setNavigationOnClickListener(v -> {
if (backButtonSavesTask) {
discard();
} else {
save();
}
});
toolbar.inflateMenu(R.menu.tag_settings_activity);
toolbar.setOnMenuItemClickListener(this);
toolbar.showOverflowMenu();
MenuColorizer.colorToolbar(this, toolbar);
if (isNewList) {
toolbar.getMenu().findItem(R.id.delete).setVisible(false);
listName.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(listName, InputMethodManager.SHOW_IMPLICIT);
} else {
listName.setText(gtasksList.getName());
}
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
private void save() {
String newName = getNewName();
if (isEmpty(newName)) {
Toast.makeText(this, R.string.name_cannot_be_empty, Toast.LENGTH_LONG).show();
return;
}
if (isNewList) {
newCreateListDialog(newName)
.show(getSupportFragmentManager(), FRAG_TAG_CREATE_LIST_DIALOG);
} else if (nameChanged()) {
newRenameListDialog(gtasksList.getRemoteId(), newName)
.show(getSupportFragmentManager(), FRAG_TAG_RENAME_LIST_DIALOG);
} else {
finish();
}
}
@Override
public void finish() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(listName.getWindowToken(), 0);
super.finish();
}
@Override
public void onBackPressed() {
if (preferences.backButtonSavesTask()) {
save();
} else {
discard();
}
}
private void deleteTag() {
dialogBuilder.newMessageDialog(R.string.delete_tag_confirmation, gtasksList.getName())
.setPositiveButton(R.string.delete, (dialog, which) -> newDeleteListDialog(gtasksList.getRemoteId())
.show(getSupportFragmentManager(), FRAG_TAG_DELETE_LIST_DIALOG))
.setNegativeButton(android.R.string.cancel, null)
.show();
}
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.delete:
deleteTag();
break;
}
return super.onOptionsItemSelected(item);
}
private void discard() {
if (hasChanges()) {
dialogBuilder.newMessageDialog(R.string.discard_changes)
.setPositiveButton(R.string.keep_editing, null)
.setNegativeButton(R.string.discard, (dialog, which) -> finish())
.show();
} else {
finish();
}
}
private String getNewName() {
return listName.getText().toString().trim();
}
private boolean hasChanges() {
if (isNewList) {
return !isEmpty(getNewName());
}
return nameChanged();
}
private boolean nameChanged() {
return !getNewName().equals(gtasksList.getName());
}
@Override
public void onListCreated(TaskList taskList) {
GtasksList list = new GtasksList(taskList.getId());
list.setName(taskList.getTitle());
storeObjectDao.persist(list);
setResult(RESULT_OK, new Intent().putExtra(TaskListActivity.OPEN_FILTER, new GtasksFilter(list)));
finish();
}
@Override
public void onListDeleted() {
gtasksListService.deleteList(gtasksList);
setResult(RESULT_OK, new Intent(ACTION_DELETED));
finish();
}
@Override
public void onListRenamed(TaskList taskList) {
gtasksList.setName(taskList.getTitle());
storeObjectDao.persist(gtasksList);
setResult(RESULT_OK, new Intent(ACTION_RENAMED).putExtra(TaskListActivity.OPEN_FILTER, new GtasksFilter(gtasksList)));
finish();
}
@Override
public void requestFailed() {
Toast.makeText(this, R.string.gtasks_GLA_errorIOAuth, Toast.LENGTH_LONG).show();
}
}

@ -0,0 +1,104 @@
package org.tasks.gtasks;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.DialogFragmentComponent;
import org.tasks.injection.InjectingDialogFragment;
import java.io.IOException;
import javax.inject.Inject;
import timber.log.Timber;
public class CreateListDialog extends InjectingDialogFragment {
public static CreateListDialog newCreateListDialog(String name) {
CreateListDialog dialog = new CreateListDialog();
Bundle args = new Bundle();
args.putString(EXTRA_NAME, name);
dialog.setArguments(args);
return dialog;
}
public interface CreateListDialogCallback {
void onListCreated(TaskList taskList);
void requestFailed();
}
private static final String EXTRA_NAME = "extra_name";
@Inject DialogBuilder dialogBuilder;
@Inject GtasksInvoker gtasksInvoker;
private CreateListDialogCallback callback;
private ProgressDialog dialog;
private String name;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
Bundle arguments = getArguments();
name = arguments.getString(EXTRA_NAME);
dialog = dialogBuilder.newProgressDialog(R.string.creating_new_list);
execute();
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return dialog;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
callback = (CreateListDialogCallback) activity;
}
@Override
protected void inject(DialogFragmentComponent component) {
component.inject(this);
}
private void execute() {
new AsyncTask<Void, Void, TaskList>() {
@Override
protected TaskList doInBackground(Void... voids) {
try {
return gtasksInvoker.createGtaskList(name);
} catch (IOException e) {
Timber.e(e, e.getMessage());
return null;
}
}
@Override
protected void onPostExecute(TaskList taskList) {
if (dialog.isShowing()) {
dialog.dismiss();
}
if (taskList == null) {
callback.requestFailed();
} else {
callback.onListCreated(taskList);
}
}
}.execute();
}
}

@ -0,0 +1,104 @@
package org.tasks.gtasks;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.DialogFragmentComponent;
import org.tasks.injection.InjectingDialogFragment;
import java.io.IOException;
import javax.inject.Inject;
import timber.log.Timber;
public class DeleteListDialog extends InjectingDialogFragment {
public static DeleteListDialog newDeleteListDialog(String id) {
DeleteListDialog dialog = new DeleteListDialog();
Bundle args = new Bundle();
args.putString(EXTRA_ID, id);
dialog.setArguments(args);
return dialog;
}
public interface DeleteListDialogCallback {
void onListDeleted();
void requestFailed();
}
private static final String EXTRA_ID = "extra_id";
@Inject DialogBuilder dialogBuilder;
@Inject GtasksInvoker gtasksInvoker;
private DeleteListDialogCallback callback;
private String id;
private ProgressDialog dialog;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
Bundle arguments = getArguments();
id = arguments.getString(EXTRA_ID);
dialog = dialogBuilder.newProgressDialog(R.string.deleting_list);
execute();
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return dialog;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
callback = (DeleteListDialogCallback) activity;
}
@Override
protected void inject(DialogFragmentComponent component) {
component.inject(this);
}
private void execute() {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... voids) {
try {
gtasksInvoker.deleteGtaskList(id);
return true;
} catch (IOException e) {
Timber.e(e, e.getMessage());
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (dialog.isShowing()) {
dialog.dismiss();
}
if (result) {
callback.onListDeleted();
} else {
callback.requestFailed();
}
}
}.execute();
}
}

@ -0,0 +1,108 @@
package org.tasks.gtasks;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.DialogFragmentComponent;
import org.tasks.injection.InjectingDialogFragment;
import java.io.IOException;
import javax.inject.Inject;
import timber.log.Timber;
public class RenameListDialog extends InjectingDialogFragment {
public static RenameListDialog newRenameListDialog(String id, String name) {
RenameListDialog dialog = new RenameListDialog();
Bundle args = new Bundle();
args.putString(EXTRA_ID, id);
args.putString(EXTRA_NAME, name);
dialog.setArguments(args);
return dialog;
}
public interface RenameListDialogCallback {
void onListRenamed(TaskList taskList);
void requestFailed();
}
private static final String EXTRA_NAME = "extra_name";
private static final String EXTRA_ID = "extra_id";
@Inject DialogBuilder dialogBuilder;
@Inject GtasksInvoker gtasksInvoker;
private RenameListDialogCallback callback;
private ProgressDialog dialog;
private String id;
private String name;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
Bundle arguments = getArguments();
id = arguments.getString(EXTRA_ID);
name = arguments.getString(EXTRA_NAME);
dialog = dialogBuilder.newProgressDialog(R.string.renaming_list);
execute();
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return dialog;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
callback = (RenameListDialogCallback) activity;
}
@Override
protected void inject(DialogFragmentComponent component) {
component.inject(this);
}
private void execute() {
new AsyncTask<Void, Void, TaskList>() {
@Override
protected TaskList doInBackground(Void... voids) {
try {
return gtasksInvoker.renameGtaskList(id, name);
} catch (IOException e) {
Timber.e(e, e.getMessage());
return null;
}
}
@Override
protected void onPostExecute(TaskList taskList) {
if (dialog.isShowing()) {
dialog.dismiss();
}
if (taskList == null) {
callback.requestFailed();
} else {
callback.onListRenamed(taskList);
}
}
}.execute();
}
}

@ -20,6 +20,7 @@ import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.DatePickerActivity;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.activities.FilterSettingsActivity;
import org.tasks.activities.GoogleTaskListSettingsActivity;
import org.tasks.activities.TagSettingsActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dashclock.DashClockSettings;
@ -127,4 +128,6 @@ public interface ActivityComponent {
void inject(ColorPickerActivity colorPickerActivity);
void inject(BasicPreferences basicPreferences);
void inject(GoogleTaskListSettingsActivity googleTaskListSettingsActivity);
}

@ -7,6 +7,9 @@ import org.tasks.dialogs.AddAttachmentDialog;
import org.tasks.dialogs.ColorPickerDialog;
import org.tasks.dialogs.RecordAudioDialog;
import org.tasks.dialogs.SortDialog;
import org.tasks.gtasks.CreateListDialog;
import org.tasks.gtasks.DeleteListDialog;
import org.tasks.gtasks.RenameListDialog;
import org.tasks.reminders.MissedCallDialog;
import org.tasks.reminders.NotificationDialog;
import org.tasks.reminders.SnoozeDialog;
@ -35,4 +38,10 @@ public interface DialogFragmentComponent {
void inject(ColorPickerDialog colorPickerDialog);
void inject(RecordAudioDialog recordAudioDialog);
void inject(CreateListDialog createListDialog);
void inject(DeleteListDialog deleteListDialog);
void inject(RenameListDialog renameListDialog);
}

@ -1,9 +1,11 @@
package org.tasks.tasklist;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.data.StoreObject;
@ -12,10 +14,13 @@ import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.sync.SyncResultCallback;
import org.tasks.R;
import org.tasks.activities.GoogleTaskListSettingsActivity;
import org.tasks.injection.FragmentComponent;
import javax.inject.Inject;
import static android.app.Activity.RESULT_OK;
public class GtasksListFragment extends TaskListFragment {
public static TaskListFragment newGtasksListFragment(GtasksFilter filter, GtasksList list) {
@ -26,6 +31,7 @@ public class GtasksListFragment extends TaskListFragment {
}
private static final String EXTRA_STORE_OBJECT = "extra_store_object";
private static final int REQUEST_LIST_SETTINGS = 10101;
@Inject SyncV2Service syncService;
@ -53,11 +59,32 @@ public class GtasksListFragment extends TaskListFragment {
case R.id.menu_clear_completed:
clearCompletedTasks();
return true;
case R.id.menu_gtasks_list_settings:
Intent intent = new Intent(getActivity(), GoogleTaskListSettingsActivity.class);
intent.putExtra(GoogleTaskListSettingsActivity.EXTRA_STORE_DATA, list.getStoreObject());
startActivityForResult(intent, REQUEST_LIST_SETTINGS);
return true;
default:
return super.onMenuItemClick(item);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LIST_SETTINGS) {
if (resultCode == RESULT_OK) {
TaskListActivity activity = (TaskListActivity) getActivity();
if (GoogleTaskListSettingsActivity.ACTION_DELETED.equals(data.getAction())) {
activity.onFilterItemClicked(null);
} else if (GoogleTaskListSettingsActivity.ACTION_RENAMED.equals(data.getAction())) {
activity.onFilterItemClicked(data.getParcelableExtra(TaskListActivity.OPEN_FILTER));
}
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
private void clearCompletedTasks() {
syncService.clearCompleted(list, new SyncResultCallback() {
@Override

@ -25,6 +25,7 @@ import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.CustomFilterActivity;
import org.tasks.R;
import org.tasks.activities.GoogleTaskListSettingsActivity;
import org.tasks.activities.TagSettingsActivity;
import org.tasks.filters.FilterCounter;
import org.tasks.filters.FilterProvider;
@ -236,6 +237,14 @@ public class FilterAdapter extends ArrayAdapter<FilterListItem> {
addSubMenu(R.string.gtasks_GPr_header, filterProvider.getGoogleTaskFilters(), true);
if (navigationDrawer) {
add(new NavigationDrawerAction(
activity.getResources().getString(R.string.new_list),
R.drawable.ic_add_24dp,
new Intent(activity, GoogleTaskListSettingsActivity.class),
NavigationDrawerFragment.REQUEST_NEW_GTASK_LIST));
}
if (navigationDrawer) {
add(new NavigationDrawerSeparator());

@ -23,7 +23,7 @@ import android.widget.ListView;
import com.todoroo.andlib.data.Property.CountProperty;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.sql.UnaryCriterion;
import org.tasks.activities.TagSettingsActivity;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.api.CustomFilter;
import com.todoroo.astrid.api.CustomFilterCriterion;
import com.todoroo.astrid.api.Filter;
@ -272,7 +272,7 @@ public class CustomFilterActivity extends ThemedInjectingAppCompatActivity imple
StoreObject storeObject = SavedFilter.persist(storeObjectDao, adapter, title, sql.toString(), values);
Filter filter = new CustomFilter(title, sql.toString(), values, storeObject.getId());
setResult(RESULT_OK, new Intent().putExtra(TagSettingsActivity.TOKEN_NEW_FILTER, filter));
setResult(RESULT_OK, new Intent().putExtra(TaskListActivity.OPEN_FILTER, filter));
finish();
}

@ -18,6 +18,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.data.Metadata;
@ -52,7 +53,6 @@ public class TagSettingsActivity extends ThemedInjectingAppCompatActivity implem
private static final int REQUEST_COLOR_PICKER = 10109;
public static final String TOKEN_NEW_FILTER = "newFilter"; //$NON-NLS-1$
public static final String TOKEN_AUTOPOPULATE_NAME = "autopopulateName"; //$NON-NLS-1$
public static final String EXTRA_TAG_DATA = "tagData"; //$NON-NLS-1$
public static final String EXTRA_TAG_UUID = "uuid"; //$NON-NLS-1$
@ -179,7 +179,7 @@ public class TagSettingsActivity extends ThemedInjectingAppCompatActivity implem
tagData.setName(newName);
tagData.setColor(selectedTheme);
tagDataDao.persist(tagData);
setResult(RESULT_OK, new Intent().putExtra(TOKEN_NEW_FILTER, TagFilterExposer.filterFromTag(tagData)));
setResult(RESULT_OK, new Intent().putExtra(TaskListActivity.OPEN_FILTER, TagFilterExposer.filterFromTag(tagData)));
} else if (hasChanges()) {
tagData.setName(newName);
tagData.setColor(selectedTheme);

@ -20,7 +20,6 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem;
import org.tasks.R;
import org.tasks.activities.TagSettingsActivity;
import org.tasks.filters.FilterCounter;
import org.tasks.filters.FilterProvider;
import org.tasks.filters.NavigationDrawerAction;
@ -35,6 +34,7 @@ import javax.inject.Inject;
import timber.log.Timber;
import static android.app.Activity.RESULT_OK;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
public class NavigationDrawerFragment extends InjectingFragment {
@ -45,6 +45,7 @@ public class NavigationDrawerFragment extends InjectingFragment {
public static final int REQUEST_NEW_LIST = 4;
public static final int ACTIVITY_REQUEST_NEW_FILTER = 5;
public static final int REQUEST_NEW_GTASK_LIST = 6;
private FilterAdapter adapter = null;
@ -93,9 +94,10 @@ public class NavigationDrawerFragment extends InjectingFragment {
activity.restart();
}
} else if (requestCode == REQUEST_NEW_LIST ||
requestCode == ACTIVITY_REQUEST_NEW_FILTER) {
if (resultCode == Activity.RESULT_OK && data != null) {
Filter newList = data.getParcelableExtra(TagSettingsActivity.TOKEN_NEW_FILTER);
requestCode == ACTIVITY_REQUEST_NEW_FILTER ||
requestCode == REQUEST_NEW_GTASK_LIST) {
if (resultCode == RESULT_OK && data != null) {
Filter newList = data.getParcelableExtra(TaskListActivity.OPEN_FILTER);
if (newList != null) {
mCallbacks.onFilterItemClicked(newList);
}

@ -5,4 +5,8 @@
android:id="@+id/menu_clear_completed"
android:title="@string/gtasks_GTA_clear_completed"
app:showAsAction="never" />
<item
android:id="@+id/menu_gtasks_list_settings"
android:title="@string/list_settings"
app:showAsAction="never" />
</menu>

@ -720,6 +720,7 @@ File %1$s contained %2$s.\n\n
<string name="discard_changes">Discard changes?</string>
<string name="discard">Discard</string>
<string name="tag_settings">Tag Settings</string>
<string name="list_settings">List settings</string>
<string name="delete">Delete</string>
<string name="filter_settings">Filter Settings</string>
<string name="show_hidden">Show hidden</string>
@ -824,5 +825,8 @@ File %1$s contained %2$s.\n\n
<string name="notification_shade">Notification shade</string>
<string name="notification_description">Show task description</string>
<string name="sync_error_permissions">Tasks requires permission</string>
<string name="creating_new_list">Creating new list</string>
<string name="deleting_list">Deleting list</string>
<string name="renaming_list">Renaming list</string>
</resources>

Loading…
Cancel
Save