Localized strings and added progress dialog to cloning process

pull/14/head
Sam Bosley 14 years ago
parent 0050f1caff
commit ff853e0ce0

@ -1,8 +1,11 @@
package com.todoroo.astrid.tags.reusable;
import android.app.Activity;
import android.app.ProgressDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
@ -47,44 +50,57 @@ public class FeaturedTaskListFragment extends TagViewFragment {
protected void setUpMembersGallery() {
// Repurposed this method to set up listener for clone list button
View clone = getView().findViewById(R.id.clone_list);
if (taskAdapter == null || taskAdapter.getCount() == 0) {
clone.setOnClickListener(null);
} else {
clone.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Clone list
String localName = tagData.getValue(TagData.NAME) + " (Copy)";
long remoteId = 0;
TodorooCursor<TagData> existing = tagDataService.query(Query.select(TagData.REMOTE_ID)
.where(TagData.NAME.eqCaseInsensitive(localName)));
try {
if (existing.getCount() > 0) {
existing.moveToFirst();
TagData match = new TagData(existing);
remoteId = match.getValue(TagData.REMOTE_ID);
}
} finally {
existing.close();
clone.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Clone list
if (taskAdapter == null || taskAdapter.getCount() == 0) {
Toast.makeText(getActivity(), R.string.actfm_feat_list_clone_empty, Toast.LENGTH_LONG);
return;
}
final String localName = tagData.getValue(TagData.NAME) + " " + getString(R.string.actfm_feat_list_suffix); //$NON-NLS-1$
long remoteId = 0;
TodorooCursor<TagData> existing = tagDataService.query(Query.select(TagData.REMOTE_ID)
.where(TagData.NAME.eqCaseInsensitive(localName)));
try {
if (existing.getCount() > 0) {
existing.moveToFirst();
TagData match = new TagData(existing);
remoteId = match.getValue(TagData.REMOTE_ID);
}
TodorooCursor<Task> tasks = taskService.fetchFiltered(taskAdapter.getQuery(), null, Task.PROPERTIES);
try {
Task t = new Task();
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
t.readFromCursor(tasks);
taskService.cloneReusableTask(t,
localName, remoteId);
} finally {
existing.close();
}
final ProgressDialog pd = DialogUtilities.progressDialog(getActivity(), getString(R.string.actfm_feat_list_cloning));
final long finalRemoteId = remoteId;
new Thread(new Runnable() {
@Override
public void run() {
TodorooCursor<Task> tasks = taskService.fetchFiltered(taskAdapter.getQuery(), null, Task.PROPERTIES);
try {
Task t = new Task();
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
t.readFromCursor(tasks);
taskService.cloneReusableTask(t,
localName, finalRemoteId);
}
Activity activity = getActivity();
if (activity != null) {
DialogUtilities.dismissDialog(activity, pd);
DialogUtilities.okDialog(activity, getString(R.string.actfm_feat_list_clone_success), null);
}
Flags.set(Flags.REFRESH);
} finally {
tasks.close();
}
Flags.set(Flags.REFRESH);
DialogUtilities.okDialog(getActivity(), "Success!", null);
} finally {
tasks.close();
}
}
});
}
}).start();
}
});
}
@Override

@ -9,6 +9,7 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
@ -49,6 +50,7 @@ public class ReusableTaskAdapter extends TaskAdapter {
public void onClick(View v) {
ReusableTaskViewHolder holder = (ReusableTaskViewHolder) v.getTag();
taskService.cloneReusableTask(holder.task, null, 0);
Toast.makeText(fragment.getActivity(), R.string.actfm_feat_list_task_clone_success, Toast.LENGTH_LONG);
Flags.set(Flags.REFRESH);
}
});

@ -274,6 +274,16 @@
<string name="actfm_feat_list_clone">Copy this list</string>
<string name="actfm_feat_list_suffix">(Copy)</string>
<string name="actfm_feat_list_cloning">Copying...</string>
<string name="actfm_feat_list_clone_success">Success!</string>
<string name="actfm_feat_list_task_clone_success">Task copied</string>
<string name="actfm_feat_list_clone_empty">No tasks to copy</string>
<!-- ================================================ Synchronization == -->
<string name="actfm_status_title_logged_in">Status - Logged in as %s</string>

Loading…
Cancel
Save