Permalink
Browse files

Updated Dropbox API client

* No longer uses modified beta API client or Sandbox keys
* Can now authorize with any set of API keys and get full Dropbox access from multiple devices
* Removed old code, added constant for path to todo.txt (now located in Dropbox root by default)
* Authenticating before syncing, step 1 (still no store of auth keys)
* Login+Store Auth. Bug; does dual login + dual fetch (both user/pass and auth)
* Closes #27, Closes #24
  • Loading branch information...
tormodh authored and ginatrapani committed Aug 31, 2010
1 parent aca0891 commit 55a73f46c08009f3cb8ee8d196af67bb5cb1e71e
View
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="libs/apache-mime4j-0.4.jar"/>
- <classpathentry kind="lib" path="libs/dropbox-api-1.0-SNAPSHOT.jar"/>
- <classpathentry kind="lib" path="libs/httpmime-4.0-beta1.jar"/>
- <classpathentry kind="lib" path="libs/signpost-commonshttp4-1.2-SNAPSHOT.jar"/>
- <classpathentry kind="lib" path="libs/signpost-core-1.2-SNAPSHOT.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="lib" path="libs/dropbox-client-1.0-SNAPSHOT.jar"/>
+ <classpathentry kind="lib" path="libs/signpost-commonshttp4-1.2.1.1.jar"/>
+ <classpathentry kind="lib" path="libs/signpost-core-1.2.1.1.jar"/>
+ <classpathentry kind="lib" path="libs/json_simple-1.1.jar"/>
+ <classpathentry kind="lib" path="libs/apache-mime4j-0.6.jar"/>
+ <classpathentry kind="lib" path="libs/httpmime-4.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
@@ -4,7 +4,7 @@
.settings/
build.properties
build.xml
-#default.properties
+default.properties
local.properties
bin/
gen/
View
@@ -23,5 +23,5 @@
<activity android:name=".Filter" android:label="Filter" />
<activity android:name=".Preferences" android:label="@string/set_preferences" />
<activity android:name=".AddTask" android:label="@string/addtask" />
- </application>
+</application>
</manifest>
View
@@ -6,7 +6,7 @@ An Android application by [Gina Trapani](http://ginatrapani.org) and [the Todo.t
![Todo.Txt Touch](https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=https://github.com/downloads/ginatrapani/todo.txt-touch/todo.txt-touch.apk)
-Right now, when you install the app, log into Dropbox and it creates a Dropbox/Todo.txt/todo.txt file. To get started, choose "Add Task" from the menu and add your todo item. If you've already got a todo.txt file, just copy and paste it into your Dropbox/Todo.txt/ folder, then choose "Sync" from the menu in the Android app to load your tasks.
+Right now, when you install the app, log into Dropbox and it creates a Dropbox/todo.txt file. To get started, choose "Add Task" from the menu and add your todo item. If you've already got a todo.txt file, just copy and paste it into your Dropbox/ folder, then choose "Sync" from the menu in the Android app to load your tasks.
When you edit, complete, prioritize, or delete a task, the app makes the changes to your todo.txt file and syncs those changes back to Dropbox. You can filter by project, context, or priority, search, and sort by todo ID, priority, or alphabetically.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -6,11 +6,11 @@
<string name="add_task_failed">Could not add task</string>
<string name="updated_task">Updated task</string>
<string name="update_task_failed">Could not update task</string>
- <string name="initialized_dropbox">Initialized Dropbox support! Check Dropbox/Todo.txt/todo.txt.</string>
+ <string name="initialized_dropbox">Initialized Dropbox support! Check Dropbox/todo.txt.</string>
<string name="sort">Sort</string>
<string name="filter">Filter</string>
<string name="app_name">Todo.txt Touch</string>
- <string name="main_no_items">No tasks located in your Dropbox/Todo.txt/todo.txt file. Tap "Add Task" from the menu or copy your existing todo.txt file into Dropbox to get started.</string>
+ <string name="main_no_items">No tasks to display.</string>
<string name="set_preferences">Todo.txt Preferences</string>
<string name="preferences">Preferences</string>
<string name="sync">Sync</string>
@@ -16,7 +16,7 @@
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
-import com.dropbox.client.DropboxClient;
+import com.dropbox.client.DropboxAPI;
public class AddTask extends Activity {
@@ -153,15 +153,15 @@ protected void onPreExecute() {
protected Boolean doInBackground(Void... params) {
try {
TodoApplication app = (TodoApplication) getApplication();
- DropboxClient client = app.getClient(AddTask.this);
- if (client != null) {
+ DropboxAPI api = app.getAPI();
+ if (api != null) {
if (m_backup != null) {
Task updatedTask = TaskHelper.createTask(
m_backup.id, input);
- return DropboxUtil.updateTask(client,
+ return DropboxUtil.updateTask(api,
updatedTask.prio, input, m_backup);
} else {
- return DropboxUtil.addTask(client, input);
+ return DropboxUtil.addTask(api, input);
}
}
} catch (Exception e) {
@@ -189,4 +189,4 @@ protected void onPostExecute(Boolean result) {
});
}
-}
+}
@@ -9,6 +9,8 @@
public static final String PREF_FIRSTRUN = "firstrun";
public static final String PREF_ACCESSTOKEN_KEY = "accesstokenkey";
public static final String PREF_ACCESSTOKEN_SECRET = "accesstokensecret";
+ public static final String DROPBOX_MODUS = "dropbox";
+ public static final String PATH_TO_TODO_TXT = "/";
public static final String REMOTE_FILE = "/todo.txt";
@@ -0,0 +1,82 @@
+package com.todotxt.todotxttouch;
+
+import android.app.ProgressDialog;
+import android.os.AsyncTask;
+import android.util.Log;
+
+import com.dropbox.client.DropboxAPI;
+import com.dropbox.client.DropboxAPI.FileDownload;
+
+public class DropboxFetchAsyncTask extends AsyncTask<Void, Void, Boolean> {
+ /**
+ *
+ */
+ private TodoTxtTouch m_act;
+
+ /**
+ * @param todoTxtTouch
+ */
+ DropboxFetchAsyncTask(TodoTxtTouch todoTxtTouch) {
+ m_act = todoTxtTouch;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ m_act.m_ProgressDialog = ProgressDialog.show(m_act, "Please wait...",
+ "Retrieving todo.txt ...", true);
+ }
+
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ try {
+ TodoApplication app = (TodoApplication) m_act.getApplication();
+ DropboxAPI api = app.getAPI();
+ if (api.isAuthenticated()) {
+ try {
+ FileDownload file = api.getFileStream(
+ Constants.DROPBOX_MODUS, Constants.REMOTE_FILE,
+ null);
+ m_act.m_tasks = TodoUtil.loadTasksFromStream(file.is);
+ } catch (Exception e) {
+ Log.w(TodoTxtTouch.TAG,
+ "Failed to fetch todo file! Initializing dropbox support!"
+ + e.getMessage());
+ if (!Constants.TODOFILE.exists()) {
+ Util.createParentDirectory(Constants.TODOFILE);
+ Constants.TODOFILE.createNewFile();
+ }
+ api.putFile(Constants.DROPBOX_MODUS,
+ Constants.PATH_TO_TODO_TXT, Constants.TODOFILE);
+ m_act.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Util.showToastLong(m_act,
+ R.string.initialized_dropbox);
+ }
+ });
+ }
+ } else {
+ Log.w(TodoTxtTouch.TAG, "Could not get tasks!");
+ return false;
+ }
+ TodoUtil.writeToFile(m_act.m_tasks, Constants.TODOFILE);
+ return true;
+ } catch (Exception e) {
+ Log.e(TodoTxtTouch.TAG, e.getMessage(), e);
+ return false;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ m_act.m_ProgressDialog.dismiss();
+ m_act.clearFilter();
+ m_act.setFilteredTasks(false);
+ Log.d(TodoTxtTouch.TAG, "populateFromUrl size=" + m_act.m_tasks.size());
+ if (!result) {
+ Util.showToastLong(m_act, "Sync failed");
+ } else {
+ Util.showToastShort(m_act, m_act.m_tasks.size() + " items");
+ }
+ }
+}
@@ -0,0 +1,67 @@
+package com.todotxt.todotxttouch;
+
+import com.dropbox.client.DropboxAPI;
+import com.dropbox.client.DropboxAPI.Config;
+
+import android.os.AsyncTask;
+
+public class DropboxLoginAsyncTask extends AsyncTask<Void, Void, Integer> {
+
+ private TodoTxtTouch m_act;
+ private Config m_config;
+ private String m_username;
+ private String m_password;
+
+ public DropboxLoginAsyncTask(TodoTxtTouch act, Config config) {
+ m_act = act;
+ m_config = config;
+ }
+
+ public DropboxLoginAsyncTask(TodoTxtTouch act, String username,
+ String password, Config config) {
+ m_act = act;
+ m_config = config;
+ m_username = username;
+ m_password = password;
+ }
+
+ @Override
+ protected Integer doInBackground(Void... params) {
+ DropboxAPI api = m_act.getAPI();
+
+ if (!api.isAuthenticated()) {
+ m_config = api.authenticate(m_config, m_username, m_password);
+ m_act.setConfig(m_config);
+
+ if (m_config.authStatus != DropboxAPI.STATUS_SUCCESS)
+ return m_config.authStatus;
+ }
+
+ if (!api.accountInfo().isError()) {
+ return DropboxAPI.STATUS_SUCCESS;
+ } else {
+ return DropboxAPI.STATUS_FAILURE;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Integer result) {
+ super.onPostExecute(result);
+
+ if (result == DropboxAPI.STATUS_SUCCESS) {
+ if (m_config != null
+ && m_config.authStatus == DropboxAPI.STATUS_SUCCESS) {
+ m_act.storeKeys(m_config.accessTokenKey,
+ m_config.accessTokenSecret);
+ m_act.setLoggedIn(true);
+ m_act.showToast("Logged into Dropbox");
+ }
+ } else {
+ if (result == DropboxAPI.STATUS_NETWORK_ERROR) {
+ m_act.showToast("Network error: " + m_config.authDetail);
+ } else {
+ m_act.showToast("Unsuccessful login.");
+ }
+ }
+ }
+}
@@ -1,26 +1,30 @@
package com.todotxt.todotxttouch;
-import java.io.InputStream;
import java.util.ArrayList;
import android.util.Log;
-import com.dropbox.client.DropboxClient;
-import com.dropbox.client.DropboxClientHelper;
+import com.dropbox.client.DropboxAPI;
+import com.dropbox.client.DropboxAPI.FileDownload;
+import com.todotxt.todotxttouch.Constants;
+import com.todotxt.todotxttouch.Task;
+import com.todotxt.todotxttouch.TaskHelper;
+import com.todotxt.todotxttouch.TodoUtil;
public class DropboxUtil {
private final static String TAG = DropboxUtil.class.getSimpleName();
- public static boolean addTask(DropboxClient client, String input) {
- if (client != null) {
+ public static boolean addTask(DropboxAPI api, String input) {
+ if (api != null) {
ArrayList<Task> tasks = null;
try {
- tasks = fetchTasks(client);
+ tasks = fetchTasks(api);
Task task = TaskHelper.createTask(tasks.size(), input);
tasks.add(task);
TodoUtil.writeToFile(tasks, Constants.TODOFILETMP);
- DropboxClientHelper.putFile(client, "/", Constants.TODOFILETMP);
+ api.putFile(Constants.DROPBOX_MODUS,
+ Constants.PATH_TO_TODO_TXT, Constants.TODOFILETMP);
TodoUtil.writeToFile(tasks, Constants.TODOFILE);
return true;
} catch (Exception e) {
@@ -30,21 +34,21 @@ public static boolean addTask(DropboxClient client, String input) {
return false;
}
- public static boolean updateTask(DropboxClient client, char prio,
- String input, Task backup) {
- if (client != null) {
+ public static boolean updateTask(DropboxAPI api, char prio, String input,
+ Task backup) {
+ if (api != null) {
Task t = TaskHelper.createTask(backup.id, backup.text);
t.prio = prio;
t.text = input;
try {
- ArrayList<Task> tasks = fetchTasks(client);
+ ArrayList<Task> tasks = fetchTasks(api);
Task found = TaskHelper.find(tasks, backup);
if (found != null) {
t.id = found.id;
TaskHelper.updateById(tasks, t);
TodoUtil.writeToFile(tasks, Constants.TODOFILETMP);
- DropboxClientHelper.putFile(client, "/",
- Constants.TODOFILETMP);
+ api.putFile(Constants.DROPBOX_MODUS,
+ Constants.PATH_TO_TODO_TXT, Constants.TODOFILETMP);
TodoUtil.writeToFile(tasks, Constants.TODOFILE);
return true;
} else {
@@ -59,11 +63,10 @@ public static boolean updateTask(DropboxClient client, char prio,
return false;
}
- public static ArrayList<Task> fetchTasks(DropboxClient client)
- throws Exception {
- InputStream is = DropboxClientHelper.getFileStream(client,
- Constants.REMOTE_FILE);
- return TodoUtil.loadTasksFromStream(is);
+ public static ArrayList<Task> fetchTasks(DropboxAPI api) throws Exception {
+ FileDownload file = api.getFileStream(Constants.DROPBOX_MODUS,
+ Constants.REMOTE_FILE, null);
+ return TodoUtil.loadTasksFromStream(file.is);
}
-}
+}
Oops, something went wrong.

0 comments on commit 55a73f4

Please sign in to comment.