Commit 8338d4d9 authored by Alan McNatty's avatar Alan McNatty
Browse files

A round of recent changes for release 1.2

parent 4817ae61
......@@ -7,12 +7,16 @@
<string name="pref_upload_url_key">upload.uri</string>
<string name="pref_upload_url_title">Upload URI</string>
<string name="pref_upload_url_summary">Enter the URL to post files to Mahara</string>
<string name="pref_upload_url_default">http://www.mahara.org/artefact/file/mobileupload.php</string>
<string name="pref_upload_url_default">http://master.dev.mahara.org/artefact/file/mobileupload.php</string>
<string name="pref_upload_token_key">upload.token</string>
<string name="pref_upload_token_title">Token</string>
<string name="pref_upload_token_summary">Enter your Mahara upload token</string>
<string name="pref_upload_username_key">upload.username</string>
<string name="pref_upload_username_title">Username</string>
<string name="pref_upload_username_summary">Enter your Mahara username</string>
<string name="prefcat_advanced">Advanced</string>
<string name="pref_upload_folder_key">upload.folder</string>
......
......@@ -8,6 +8,10 @@
android:title="@string/pref_upload_url_title"
android:summary="@string/pref_upload_url_summary"
android:defaultValue="@string/pref_upload_url_default" />
<EditTextPreference
android:key="@string/pref_upload_username_key"
android:title="@string/pref_upload_username_title"
android:summary="@string/pref_upload_username_summary" />
<EditTextPreference
android:key="@string/pref_upload_token_key"
android:title="@string/pref_upload_token_title"
......@@ -25,6 +29,7 @@
android:key="@string/pref_upload_view_key"
android:title="@string/pref_upload_view_title"
android:summary="@string/pref_upload_view_summary"
android:defaultValue="false"
android:enabled="false"
/>
......
......@@ -57,9 +57,6 @@ public class ArtifactSettings extends Activity implements OnClickListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ensure we have default preferences (if none set by user)
//PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
//TODO: Add thumbnail of image to upload options screen.
setContentView(R.layout.artifact_settings);
......@@ -91,6 +88,7 @@ public class ArtifactSettings extends Activity implements OnClickListener {
String title = m_filepath.substring(m_filepath.lastIndexOf("/") + 1,
m_filepath.lastIndexOf("."));
((EditText)findViewById(R.id.txtArtifactTitle)).setText(title);
((EditText)findViewById(R.id.txtArtifactTitle)).selectAll();
}
}
}
......
......@@ -99,33 +99,47 @@ public class RestClient {
return sb.toString();
}
public static JSONObject UploadArtifact(String url, String token, String folder,
String filename, String title, Context context){
// TODO: change this to be a hash of post variables
public static JSONObject UploadArtifact(String url, String token, String username, Boolean view,
String foldername, String filename, String title,
Context context){
Vector<String> pNames = new Vector<String>();
Vector<String> pVals = new Vector<String>();
pNames.add("userfile");
pVals.add("");
if (!title.equals("")) {
pNames.add("title");
pVals.add(title);
}
if (!token.equals("")) {
pNames.add("token");
pVals.add(token);
}
if (!username.equals("")) {
pNames.add("username");
pVals.add(username);
}
if (!foldername.equals("")) {
pNames.add("foldername");
pVals.add(foldername);
}
if (!filename.equals("")) {
pNames.add("filename");
pVals.add(filename);
}
if (view) {
pNames.add("view");
pVals.add("true");
}
String [] paramNames, paramVals;
paramNames = paramVals = new String[]{};
paramNames = pNames.toArray(paramNames);
paramVals = pVals.toArray(paramVals);
if ( DEBUG ) Log.d(TAG, "String url: '" + url +
"', String token: '" + token +
"', String folder: '" + folder +
"', String filename: '" + filename + "'");
return CallFunction(url, token, folder, filename, paramNames, paramVals, context);
return CallFunction(url, paramNames, paramVals, context);
}
public static JSONObject CallFunction(String url, String token, String folder, String filename,
String[] paramNames, String[] paramVals,
Context context)
public static JSONObject CallFunction(String url, String[] paramNames, String[] paramVals, Context context)
{
JSONObject json = new JSONObject();
SchemeRegistry supportedSchemes = new SchemeRegistry();
......@@ -147,12 +161,7 @@ public class RestClient {
HttpConnectionParams.setSoTimeout(http_params, CONNECTION_TIMEOUT);
DefaultHttpClient httpclient = new DefaultHttpClient(ccm, http_params);
if ( DEBUG ) Log.d(TAG, "String url: '" + url +
"', String token: '" + token +
"', String folder: '" + folder +
"', String filename: '" + filename + "'");
if (paramNames == null) {
paramNames = new String[0];
}
......@@ -167,27 +176,24 @@ public class RestClient {
SortedMap<String,String> sig_params = new TreeMap<String,String>();
sig_params.put("token", token);
sig_params.put("foldername", folder);
HttpResponse response = null;
try {
File file = null;
// If this is a POST call, then it is a file upload. Check to see if a
// filename is given, and if so, open that file.
if (!filename.equals("")) {
file = new File(filename);
}
// Get the title of the photo being uploaded so we can pass it into the
// MultipartEntityMonitored class to be broadcast for progress updates.
String title = "";
for (int i = 0; i < paramNames.length; ++i) {
if (paramNames[i].equals("title")) {
title = paramVals[i];
break;
}
else if (paramNames[i].equals("filename")) {
file = new File(paramVals[i]);
continue;
}
sig_params.put(paramNames[i], paramVals[i]);
}
HttpPost httppost = new HttpPost(url);
......@@ -207,8 +213,9 @@ public class RestClient {
String content = convertStreamToString(resEntity.getContent());
if ( response.getStatusLine().getStatusCode() == 200 ) {
try {
json.put("success", content.toString());
Log.i(TAG, "success, updating token to : " + content.toString());
String new_token = content.toString().trim();
json.put("success", new_token);
Log.i(TAG, "success, updating token to : " + content.toString());
} catch (JSONException e) {
json = null;
}
......
......@@ -111,6 +111,8 @@ public class TransferService extends Service {
JSONObject result = RestClient.UploadArtifact(
getUploadURLPref(),
getUploadAuthTokenPref(),
getUploadUsernamePref(),
getUploadCreateViewPref(),
getUploadFolderPref(),
upload_info.getString("filename"),
upload_info.getString("title"),
......@@ -129,7 +131,7 @@ public class TransferService extends Service {
m_uploads.clear();
} else if ( result.has("success") ) {
try {
setUploadAuthTokenPref(result.getString("success").trim());
setUploadAuthTokenPref(result.getString("success"));
} catch (JSONException e) {
Log.e(TAG, "Failed to get success token from result.");
}
......@@ -284,14 +286,21 @@ public class TransferService extends Service {
private String getUploadURLPref() {
return mPrefs.getString(getString(R.string.pref_upload_url_key), null);
}
private Boolean getUploadCreateViewPref() {
return mPrefs.getBoolean(getString(R.string.pref_upload_view_key), false);
}
private String getUploadFolderPref() {
return mPrefs.getString(getString(R.string.pref_upload_folder_key), null);
}
public String getUploadAuthTokenPref() {
return mPrefs.getString(getString(R.string.pref_upload_token_key), null);
}
public String getUploadUsernamePref() {
return mPrefs.getString(getString(R.string.pref_upload_username_key), null);
}
public void setUploadAuthTokenPref(String newToken) {
if ( DEBUG ) Log.d(TAG, "New Token is '" + newToken + "'");
mPrefs.edit()
.putString(getString(R.string.pref_upload_token_key), newToken)
.commit()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment