Browse files

Implement the put method for the ubuntu synchronizer, make some cosme…

…tic changes
  • Loading branch information...
1 parent c8dc072 commit 5b9096a952b66d2acc95feed29f83e30cac5b173 @matburt committed May 24, 2012
View
1 src/com/matburt/mobileorg/Dropbox/DropboxLoginListener.java
@@ -1,5 +1,6 @@
package com.matburt.mobileorg.Dropbox;
+//NOTE: Refactor out of Dropbox/
public abstract class DropboxLoginListener {
public abstract void loginSuccessfull();
public abstract void loginFailed(String message);
View
2 src/com/matburt/mobileorg/Dropbox/LoginAsyncTask.java
@@ -51,7 +51,7 @@
DropboxLoginListener mLoginListener;
Context mContext;
- // Will just log in
+ //NOTE: Rename and refactor
public LoginAsyncTask(Context context, DropboxLoginListener loginListener, Dropbox api, String user, String password) {
super();
mContext = context;
View
15 src/com/matburt/mobileorg/Settings/WizardActivity.java
@@ -427,24 +427,26 @@ void loginDropbox() {
}
void loginUbuntuOne() {
- UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer((Context)this, (MobileOrgApplication)getApplication());
+ final UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer((Context)this, (MobileOrgApplication)getApplication());
uos.username = ubuntuoneEmail.getText().toString();
uos.password = ubuntuonePass.getText().toString();
//move this into another thread, so we don't get an ANR if the network is unavailable
+ Thread uiThread = new HandlerThread("UIHandler");
+ uiThread.start();
+ uiHandler = new UIHandler(((HandlerThread)uiThread).getLooper());
+ showToast("Logging in, please wait");
if (uos.login()) {
- showToast("Login Successfull");
+ showToastRemote("Login Successfull");
loginButton.setEnabled(false);
- //createDropboxList();
- //allow scrolling to next page
wizard.enablePage( 1 );
uos.getBaseUser();
createUbuntuOneList();
- //display account info
}
else {
- showToast("Login Failed");
+ showToastRemote("Login Failed");
}
+
}
void showToast(String msg) {
@@ -495,6 +497,7 @@ public void loginSuccessfull() {
}
};
+
void storeKeys(String key, String secret) {
// Save the access key for later
View
43 src/com/matburt/mobileorg/Synchronizers/UbuntuOneSynchronizer.java
@@ -40,6 +40,7 @@
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
+import org.apache.http.message.BasicHeader;
import org.apache.http.client.ClientProtocolException;
import android.os.Build;
@@ -144,6 +145,48 @@ public void signRequest(HttpRequest request) {
}
protected void putRemoteFile(String filename, String contents) throws IOException {
+ try {
+ buildConsumer();
+ String latterPart = remoteIndexPath + filename;
+ latterPart = latterPart.replaceAll("/{2,}", "/");
+ String files_url = FILES_URL + root_path + latterPart;
+
+ URL url = new URL(files_url);
+ URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
+ url.getPort(), url.getPath(), url.getQuery(), url.getRef());
+ url = uri.toURL();
+
+ HttpPut request = new HttpPut(url.toString());
+ JSONObject createFile = new JSONObject();
+ createFile.put("kind", "file");
+ StringEntity se = new StringEntity(createFile.toString());
+ //se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
+ request.setEntity(se);
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ signRequest(request);
+ HttpResponse response = httpClient.execute(request);
+ verifyResponse(response);
+ JSONObject fileData = responseToJson(response);
+
+ String content_path = fileData.getString("content_path");
+ String content_url = FILES_BASE + content_path;
+
+ url = new URL(content_url);
+ uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
+ url.getPort(), url.getPath(), url.getQuery(), url.getRef());
+ url = uri.toURL();
+
+ request = new HttpPut(url.toString());
+ request.setEntity(new StringEntity(contents));
+ httpClient = new DefaultHttpClient();
+
+ signRequest(request);
+ response = httpClient.execute(request);
+ verifyResponse(response);
+
+ } catch (Exception e) {
+ Log.e("MobileOrg", "Exception in Ubuntu One Put File: " + e.toString());
+ }
}
protected BufferedReader getRemoteFile(String filename) {

0 comments on commit 5b9096a

Please sign in to comment.