diff --git a/src/amazon/java/org/tasks/activities/GoogleTaskListSettingsActivity.java b/src/amazon/java/org/tasks/activities/GoogleTaskListSettingsActivity.java new file mode 100644 index 000000000..ef9b88577 --- /dev/null +++ b/src/amazon/java/org/tasks/activities/GoogleTaskListSettingsActivity.java @@ -0,0 +1,4 @@ +package org.tasks.activities; + +public class GoogleTaskListSettingsActivity { +} diff --git a/src/amazon/java/org/tasks/injection/ActivityComponent.java b/src/amazon/java/org/tasks/injection/ActivityComponent.java index 49cf15a7b..6da60dcc7 100644 --- a/src/amazon/java/org/tasks/injection/ActivityComponent.java +++ b/src/amazon/java/org/tasks/injection/ActivityComponent.java @@ -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); } diff --git a/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java b/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java index 92624eb40..183c347b6 100644 --- a/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java +++ b/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java @@ -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 diff --git a/src/generic/java/org/tasks/activities/GoogleTaskListSettingsActivity.java b/src/generic/java/org/tasks/activities/GoogleTaskListSettingsActivity.java new file mode 100644 index 000000000..ef9b88577 --- /dev/null +++ b/src/generic/java/org/tasks/activities/GoogleTaskListSettingsActivity.java @@ -0,0 +1,4 @@ +package org.tasks.activities; + +public class GoogleTaskListSettingsActivity { +} diff --git a/src/generic/java/org/tasks/injection/ActivityComponent.java b/src/generic/java/org/tasks/injection/ActivityComponent.java index 49cf15a7b..6da60dcc7 100644 --- a/src/generic/java/org/tasks/injection/ActivityComponent.java +++ b/src/generic/java/org/tasks/injection/ActivityComponent.java @@ -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); } diff --git a/src/googleplay/AndroidManifest.xml b/src/googleplay/AndroidManifest.xml index 047ba4a65..eece8f1d8 100644 --- a/src/googleplay/AndroidManifest.xml +++ b/src/googleplay/AndroidManifest.xml @@ -46,6 +46,8 @@ + + diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java index b0c71f915..d903f751d 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java @@ -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 getLists() { - return toGtasksList(storeObjectDao.getGtasksLists()); - } - - private static List toGtasksList(List 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 getListsToUpdate(List remoteLists) { List listsToUpdate = newArrayList(); for (TaskList remoteList : remoteLists) { diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java b/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java index 99d1f864b..6d487302c 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java @@ -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() diff --git a/src/googleplay/java/org/tasks/activities/GoogleTaskListSettingsActivity.java b/src/googleplay/java/org/tasks/activities/GoogleTaskListSettingsActivity.java new file mode 100644 index 000000000..90bd26ecb --- /dev/null +++ b/src/googleplay/java/org/tasks/activities/GoogleTaskListSettingsActivity.java @@ -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(); + } +} diff --git a/src/googleplay/java/org/tasks/gtasks/CreateListDialog.java b/src/googleplay/java/org/tasks/gtasks/CreateListDialog.java new file mode 100644 index 000000000..1a9059507 --- /dev/null +++ b/src/googleplay/java/org/tasks/gtasks/CreateListDialog.java @@ -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() { + @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(); + } +} diff --git a/src/googleplay/java/org/tasks/gtasks/DeleteListDialog.java b/src/googleplay/java/org/tasks/gtasks/DeleteListDialog.java new file mode 100644 index 000000000..39a73db6b --- /dev/null +++ b/src/googleplay/java/org/tasks/gtasks/DeleteListDialog.java @@ -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() { + @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(); + } +} diff --git a/src/googleplay/java/org/tasks/gtasks/RenameListDialog.java b/src/googleplay/java/org/tasks/gtasks/RenameListDialog.java new file mode 100644 index 000000000..6f720c149 --- /dev/null +++ b/src/googleplay/java/org/tasks/gtasks/RenameListDialog.java @@ -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() { + @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(); + } +} diff --git a/src/googleplay/java/org/tasks/injection/ActivityComponent.java b/src/googleplay/java/org/tasks/injection/ActivityComponent.java index 37fc35489..890ad1825 100644 --- a/src/googleplay/java/org/tasks/injection/ActivityComponent.java +++ b/src/googleplay/java/org/tasks/injection/ActivityComponent.java @@ -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); } diff --git a/src/googleplay/java/org/tasks/injection/DialogFragmentComponent.java b/src/googleplay/java/org/tasks/injection/DialogFragmentComponent.java index d6bc7ad5c..77f28a519 100644 --- a/src/googleplay/java/org/tasks/injection/DialogFragmentComponent.java +++ b/src/googleplay/java/org/tasks/injection/DialogFragmentComponent.java @@ -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); } diff --git a/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java b/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java index 5fa83bf29..976362f2d 100644 --- a/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java +++ b/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java @@ -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 diff --git a/src/main/java/com/todoroo/astrid/adapter/FilterAdapter.java b/src/main/java/com/todoroo/astrid/adapter/FilterAdapter.java index 2b4f025f8..22bcea2e8 100644 --- a/src/main/java/com/todoroo/astrid/adapter/FilterAdapter.java +++ b/src/main/java/com/todoroo/astrid/adapter/FilterAdapter.java @@ -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 { 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()); diff --git a/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java b/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java index 35e9ded07..fe716f6f0 100644 --- a/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java +++ b/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java @@ -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(); } diff --git a/src/main/java/org/tasks/activities/TagSettingsActivity.java b/src/main/java/org/tasks/activities/TagSettingsActivity.java index 8a809b844..83abb080d 100644 --- a/src/main/java/org/tasks/activities/TagSettingsActivity.java +++ b/src/main/java/org/tasks/activities/TagSettingsActivity.java @@ -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); diff --git a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java index 62da68c9b..559b37825 100644 --- a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java +++ b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java @@ -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); } diff --git a/src/main/res/menu/menu_gtasks_list_fragment.xml b/src/main/res/menu/menu_gtasks_list_fragment.xml index 8f3b25484..d758af992 100644 --- a/src/main/res/menu/menu_gtasks_list_fragment.xml +++ b/src/main/res/menu/menu_gtasks_list_fragment.xml @@ -5,4 +5,8 @@ android:id="@+id/menu_clear_completed" android:title="@string/gtasks_GTA_clear_completed" app:showAsAction="never" /> + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 8c13ecdaa..ce911efdb 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -720,6 +720,7 @@ File %1$s contained %2$s.\n\n Discard changes? Discard Tag Settings + List settings Delete Filter Settings Show hidden @@ -824,5 +825,8 @@ File %1$s contained %2$s.\n\n Notification shade Show task description Tasks requires permission + Creating new list + Deleting list + Renaming list