-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tom Rosier
committed
Apr 18, 2015
1 parent
93a757d
commit 032b491
Showing
10 changed files
with
189 additions
and
23 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
app/src/main/java/uk/co/tomrosier/xetk/losesono/prototype/prototype/ActionEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package uk.co.tomrosier.xetk.losesono.prototype.prototype; | ||
|
||
/** | ||
* Created by xetk on 18/04/15. | ||
*/ | ||
public enum ActionEffect { | ||
positive, | ||
negative; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 50 additions & 3 deletions
53
...ain/java/uk/co/tomrosier/xetk/losesono/prototype/prototype/RestClient/VoteRestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,68 @@ | ||
package uk.co.tomrosier.xetk.losesono.prototype.prototype.RestClient; | ||
|
||
import android.content.Context; | ||
|
||
import com.loopj.android.http.JsonHttpResponseHandler; | ||
|
||
import org.apache.http.Header; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import uk.co.tomrosier.xetk.losesono.prototype.prototype.VoteType; | ||
import uk.co.tomrosier.xetk.losesono.prototype.prototype.entities.Vote; | ||
import uk.co.tomrosier.xetk.losesono.prototype.prototype.utils.AjaxCompleteHandler; | ||
|
||
/** | ||
* Created by xetk on 05/03/15. | ||
*/ | ||
public class VoteRestClient { | ||
|
||
public VoteRestClient() {} | ||
private RestClient restClient; | ||
|
||
public VoteRestClient(Context context) { | ||
restClient = new RestClient(context); | ||
} | ||
|
||
// TODO: | ||
public static Object getVoteByID(Integer voteID, VoteType voteType) { | ||
return null; | ||
public void getVoteByID(Integer voteID, VoteType voteType, final AjaxCompleteHandler handler) { | ||
|
||
String url = "vote/" + voteType(voteType) + "/" + voteID; | ||
|
||
restClient.get( | ||
url, | ||
null, | ||
new JsonHttpResponseHandler() { | ||
@Override | ||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) { | ||
if (statusCode == 200) { | ||
try { | ||
Vote vote = new Vote(response); | ||
|
||
handler.handleAction(vote); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} else { | ||
System.err.println("Getting Comments failed with status code of " + statusCode); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
// TODO: | ||
public static Object addVote() { | ||
return null; | ||
} | ||
|
||
|
||
private String voteType(VoteType vt) { | ||
if (vt == VoteType.comment) { | ||
return "comment"; | ||
} else if (vt == VoteType.message) { | ||
return "message"; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/uk/co/tomrosier/xetk/losesono/prototype/prototype/entities/Vote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package uk.co.tomrosier.xetk.losesono.prototype.prototype.entities; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Created by xetk on 18/04/15. | ||
*/ | ||
public class Vote { | ||
|
||
private int positive; | ||
private int negative; | ||
|
||
public Vote(JSONObject jsonObj) throws JSONException { | ||
this.positive = jsonObj.getInt("positive"); | ||
this.negative = jsonObj.getInt("negative"); | ||
} | ||
|
||
public Vote(int positive, int negative) { | ||
this.positive = positive; | ||
this.negative = negative; | ||
} | ||
|
||
|
||
public int getPositive() { | ||
return positive; | ||
} | ||
|
||
public int getNegative() { | ||
return negative; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.