Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Creates remote todo.txt if it does not exist

Closes #46

Improves message when creating remote todo.txt
Saves local tasks when sync-ing after changing path, if no todo.txt remotely.
Still doesn't sync on startup (except first run)
  • Loading branch information...
commit 3c0ead292c947406e39c97ac20afe159db0c431b 1 parent 4a62e36
@tormodh tormodh authored ginatrapani committed
View
26 src/com/todotxt/todotxttouch/DropboxFetchAsyncTask.java
@@ -53,16 +53,19 @@ protected void onPreExecute() {
@Override
protected Boolean doInBackground(Void... params) {
try {
- DropboxAPI api = ((TodoApplication) m_act.getApplication()).getAPI();
- m_remoteFile = api.getFileStream(Constants.DROPBOX_MODUS, m_app.getRemoteFileAndPath(), null);
-
- if ( m_remoteFile.isError() ) {
- if ( 404 == m_remoteFile.httpCode ) {
- api.putFile(Constants.DROPBOX_MODUS, m_app.getRemotePath(), Constants.TODOFILE);
+ DropboxAPI api = ((TodoApplication) m_act.getApplication())
+ .getAPI();
+ m_remoteFile = api.getFileStream(Constants.DROPBOX_MODUS,
+ m_app.getRemoteFileAndPath(), null);
+
+ if (m_remoteFile.isError()) {
+ if (404 == m_remoteFile.httpCode) {
+ api.putFile(Constants.DROPBOX_MODUS, m_app.getRemotePath(),
+ Constants.TODOFILE);
}
return false;
}
-
+
m_act.m_tasks = TodoUtil.loadTasksFromStream(m_remoteFile.is);
TodoUtil.writeToFile(m_act.m_tasks, Constants.TODOFILE);
return true;
@@ -78,7 +81,14 @@ protected void onPostExecute(Boolean result) {
m_act.setFilteredTasks(false);
Log.d(TodoTxtTouch.TAG, "populateFromUrl size=" + m_act.m_tasks.size());
if (!result) {
- Util.showToastLong(m_act, "Sync failed: " + (null==m_remoteFile?"Null remote file":m_remoteFile.httpReason));
+ if (null != m_remoteFile && 404 == m_remoteFile.httpCode) {
+ Util.showToastLong(m_act,
+ "Added: " + m_app.getRemoteFileAndPath());
+ } else {
+ Util.showToastLong(m_act, "Sync failed: "
+ + (null == m_remoteFile ? "Null remote file"
+ : m_remoteFile.httpReason));
+ }
} else {
Util.showToastShort(m_act, m_act.m_tasks.size() + " items");
}
View
17 src/com/todotxt/todotxttouch/TodoApplication.java
@@ -76,13 +76,14 @@ private boolean authenticate() {
return true;
}
clearKeys();
- m_loggedIn = false;
return false;
}
private void clearKeys() {
- // TODO Auto-generated method stub
-
+ Editor editor = m_prefs.edit();
+ editor.clear();
+ editor.commit();
+ m_loggedIn = false;
}
private String[] getAuthKeys() {
@@ -99,11 +100,8 @@ public void onTerminate() {
public void unlinkDropbox() {
Log.i(TAG, "Clearing current user data!");
- Editor editor = m_prefs.edit();
- editor.clear();
- editor.commit();
getAPI().deauthenticate();
- m_loggedIn = false;
+ clearKeys();
Constants.TODOFILE.delete();
Constants.TODOFILETMP.delete();
}
@@ -135,9 +133,10 @@ public void setConfig(Config authenticate) {
}
public String getRemotePath() {
- return m_prefs.getString("todotxtpath", getResources().getString(R.string.TODOTXTPATH_defaultPath));
+ return m_prefs.getString("todotxtpath",
+ getResources().getString(R.string.TODOTXTPATH_defaultPath));
}
-
+
public String getRemoteFileAndPath() {
return getRemotePath() + "/" + Constants.REMOTE_FILE;
}
View
26 src/com/todotxt/todotxttouch/TodoTxtTouch.java
@@ -121,18 +121,28 @@ public void onCreate(Bundle savedInstanceState) {
getListView().setOnCreateContextMenuListener(this);
+ initializeTasks();
+ }
+
+ private void initializeTasks() {
boolean firstrun = m_app.m_prefs.getBoolean(Constants.PREF_FIRSTRUN,
true);
+
if (firstrun) {
Log.i(TAG, "Initializing app");
Editor editor = m_app.m_prefs.edit();
editor.putBoolean(Constants.PREF_FIRSTRUN, false);
editor.commit();
- if (getAPI().isAuthenticated()) {
- populateFromExternal();
- } else {
- login();
+ try {
+ if (!Constants.TODOFILE.exists()) {
+ Util.createParentDirectory(Constants.TODOFILE);
+ Constants.TODOFILE.createNewFile();
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Error creating local files", e);
}
+
+ populateFromExternal();
} else {
populateFromFile();
}
@@ -442,9 +452,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
m_search = data.getStringExtra(Constants.EXTRA_SEARCH);
setFilteredTasks(false);
}
- } else if ( requestCode == REQUEST_PREFERENCES) {
- if ( resultCode == Preferences.RESULT_SYNC_LIST) {
- populateFromExternal();
+ } else if (requestCode == REQUEST_PREFERENCES) {
+ if (resultCode == Preferences.RESULT_SYNC_LIST) {
+ initializeTasks();
}
}
}
@@ -619,7 +629,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
default:
holder.taskprio.setTextColor(res.getColor(R.color.black));
}
- // hide line numbers unless show preference is checked
+ // hide line numbers unless show preference is checked
if (!m_app.m_prefs.getBoolean("showlinenumberspref", false)) {
holder.taskid.setTextColor(res.getColor(R.color.white));
}
View
4 src/com/todotxt/todotxttouch/TodoUtil.java
@@ -77,7 +77,7 @@
BufferedReader in = null;
if (!Constants.TODOFILE.exists()) {
Log.w(TAG, Constants.TODOFILE.getAbsolutePath()
- + " does not exists!");
+ + " does not exist!");
} else {
InputStream is = new FileInputStream(Constants.TODOFILE);
try {
@@ -102,7 +102,7 @@
public static void writeToFile(List<Task> tasks, File file) {
try {
if (!Util.isDeviceWritable()) {
- throw new IOException("Device Not Writable!");
+ throw new IOException("Device is not writable!");
}
Util.createParentDirectory(file);
FileWriter fw = new FileWriter(file);
Please sign in to comment.
Something went wrong with that request. Please try again.