Skip to content

Commit

Permalink
[#7]Preparing to allow editing of error uploads.
Browse files Browse the repository at this point in the history
  • Loading branch information
ecc-weizhi committed Jun 24, 2014
1 parent bf7010c commit 7413f9b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Android/CRIMP/src/com/nusclimb/live/crimp/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,13 @@ public static List<String> primitiveToList(String[] primitive){
}

/**
* Helper method to convert InputStream to String. Does not close stream.
* Helper method to convert InputStream to String. Does *NOT* close stream.
* Credit goes to http://stackoverflow.com/a/5445161/3733616
*
* @param is InputStream to convert
* @return String of stream content.
*/
@SuppressWarnings("resource")
public static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
Expand Down
4 changes: 2 additions & 2 deletions Android/CRIMP/src/com/nusclimb/live/crimp/UploadStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public enum UploadStatus {
UPLOAD("Uploading score."),
UPLOAD_WAITING("U/L failed. Waiting to retry."),
FINISHED("Finished."),
ERROR_DOWNLOAD("Download error."),
ERROR_UPLOAD("Upload error."),
ERROR_DOWNLOAD("Download error. Click to remedy."),
ERROR_UPLOAD("Upload error. Click to remedy."),
ERROR_NO_NETWORK("No Network.");

private String string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class UploadListActivity extends ListActivity {
private static final String TAG = UploadListActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -59,4 +63,9 @@ public void setButtonState(boolean enabled){
public void resume(View view){
((CrimpApplication)getApplicationContext()).resumeUpload();
}

@Override
protected void onListItemClick (ListView l, View v, int position, long id){

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class ScoreRequest extends SpringAndroidSpiceRequest<Score> {
private static final String TAG = ScoreRequest.class.getSimpleName();
private static final String BASE_URL = "http://crimp-stage.herokuapp.com/judge/get/";
private String baseUrl = "http://crimp-stage.herokuapp.com/judge/get/";

private String climberId;
private String r_id;
Expand Down Expand Up @@ -51,7 +51,7 @@ public ScoreRequest(String climberId, String round, String route) {
@Override
public Score loadDataFromNetwork() throws Exception {
// Craft URL.
String address = BASE_URL + climberId + "/" + r_id +
String address = baseUrl + climberId + "/" + r_id +
"?q=" + Helper.nextAlphaNumeric(6);

// Actual network calls.
Expand All @@ -73,4 +73,12 @@ public String getR_id(){
public String createCacheKey() {
return climberId + r_id;
}

public String getBaseUrl(){
return baseUrl;
}

public void setBaseUrl(String url){
baseUrl = url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public class UploadScoreSubmit extends SpringAndroidSpiceRequest<Object>{
private static final String TAG = UploadScoreSubmit.class.getSimpleName();
private static final String BASE_URL_POST = "http://crimp-stage.herokuapp.com/judge/set";
private String baseUrl = "http://crimp-stage.herokuapp.com/judge/set";

private SessionUpload uploadContent;
private int id;
Expand All @@ -34,13 +34,21 @@ public UploadScoreSubmit(SessionUpload uploadContent, int requestId){
public Object loadDataFromNetwork() throws Exception {
Log.i(TAG, "Doing post: "+uploadContent.toString());

return getRestTemplate().postForObject(BASE_URL_POST, uploadContent, Object.class);
return getRestTemplate().postForObject(baseUrl, uploadContent, Object.class);
}

public void updateScoreWithOld(String oldScore){
uploadContent.updateScoreWithOld(oldScore);
}

public String getBaseUrl(){
return baseUrl;
}

public void setBaseUrl(String url){
baseUrl = url;
}

public String createCacheKey() {
return "["+id+"]" + uploadContent.toString();
}
Expand Down

0 comments on commit 7413f9b

Please sign in to comment.