Skip to content

Commit

Permalink
Fix bug, forgot to add api key
Browse files Browse the repository at this point in the history
  • Loading branch information
mariogrip committed Oct 29, 2014
1 parent ced8eb8 commit 0853ee5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions app/src/main/java/com/mariogrip/octodroid/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Activity extends ActionBarActivity {
protected SharedPreferences prefs;
private get get_class;
protected String ip;
protected String key;
private Timer timer = new Timer();
private TimerTask timerTask;
public static boolean server_status = false;
Expand All @@ -44,6 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.status_tab);
prefs = PreferenceManager.getDefaultSharedPreferences(Activity.this);
ip = prefs.getString("ip", "localhost");
key = prefs.getString("api", "0");
get_class = new get();
Log.d("OctoPrint","test");
runner();
Expand Down Expand Up @@ -73,8 +75,8 @@ public void run() {

Activity.this.runOnUiThread(new Runnable() {
public void run() {
get.refreshJson(ip, "job");
get.refreshJson(ip, "printer");
get.refreshJson(ip, "job", key);
get.refreshJson(ip, "printer", key);

if (server_status) {
ProgressBar progress = (ProgressBar) findViewById(R.id.progressBar);
Expand Down Expand Up @@ -150,6 +152,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
case RESULT_SETTINGS:
prefs = PreferenceManager.getDefaultSharedPreferences(Activity.this);
ip = prefs.getString("ip", "localhost");
key = prefs.getString("api", "0");
break;

}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/mariogrip/octodroid/get.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ public static int getProgress(){
return returnData;
}

public static void refreshJson(String ip, String api){
public static void refreshJson(String ip, String api, String key){
if (ip == null || ip.equals("")){

}else {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet;
if (ip.startsWith("http://")){
httpGet = new HttpGet(ip + "/api/"+api);
httpGet = new HttpGet(ip + "/api/"+api + "?apikey=" + key);
}else{
httpGet = new HttpGet("http://"+ ip + "/api/"+api);
httpGet = new HttpGet("http://"+ ip + "/api/"+api + "?apikey=" + key);
}
try {
HttpResponse response = client.execute(httpGet);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/status_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="dsfds"
android:text=""
android:id="@+id/textView10_maci"
android:layout_below="@id/textView39"
android:layout_toEndOf="@id/textView"
Expand Down

0 comments on commit 0853ee5

Please sign in to comment.