Skip to content

Commit

Permalink
fixed bug, I guess 😅
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcodekiddie committed Jul 21, 2019
1 parent 01021af commit be220d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 58 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/com/kutt/it/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Kutt kutt=new KuttBuilder().setApi_key("j8v5d0DkIelYxcZRtwNy1BpSWKJezZolueS~Vev6").setDomain("https://kutt.it").build();
Kutt kutt=new KuttBuilder().setApi_key("Put API key here").setDomain("https://kutt.it").build();

String res="";
try
{
//res=kutt.submit("https://onezero.medium.com/what-will-happen-when-robots-store-all-our-memories-20ca1ddaf4d0","lllllll",null,null);
//res=kutt.deleteUrl("sWucZH","links.fossfreaks.com");
res=kutt.stats("uhhff",null); Log.v("llll",res);
//res=kutt.stats("lw6",null); Log.v("llll",res);

res=kutt.deleteUrl("l",null);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import retrofit2.Callback;
import retrofit2.Response;

class HTTPRequestSender extends AsyncTask<Call,Void,String>
class HTTPRequestSender extends AsyncTask<Call,Void,String>
{


Expand All @@ -29,34 +29,24 @@ protected String doInBackground(Call... args)

Boolean isResponseSuccess = responseMessage.isSuccessful();
String responseSuccess = responseMessage.body();
String responseFailed = responseMessage.errorBody().string();
Integer responseCode=responseMessage.code();

Log.v("response"," "+responseSuccess +" "+responseCode.toString());

if(responseCode==200)
{
result+=responseSuccess;

Log.v("watha", ""+isResponseSuccess.toString() + responseSuccess + responseFailed);
if (isResponseSuccess) {
result += responseSuccess;
} else {
result += responseFailed;
}

if(responseCode==400)
{
result+=responseMessage.errorBody().string();
}

response.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
Log.v("watha",response.body());
try {
Log.v("watha_err",response.errorBody().string());
} catch (IOException e) {
e.printStackTrace();
}

}

@Override
public void onFailure(Call<String> call, Throwable t) {

}
});
}
catch (IOException ex)
{
Expand Down
41 changes: 6 additions & 35 deletions kutt_android/src/main/java/com/kutt/it/kutt_android/Kutt.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public String deleteUrl(@NonNull String id,@Nullable String domain) throws Exce
postData.put("domain",domain);
}
deleteCall=api.deleteUrl("application/json",postData.toString());
return "";

String result=new HTTPRequestSender().execute(deleteCall).get();

return result;
}

public String stats(@NonNull String id,@Nullable String domain) throws Exception
Expand All @@ -107,44 +110,12 @@ public String stats(@NonNull String id,@Nullable String domain) throws Exceptio
statsCall=api.stats(id,domain);
}

final String[] result = {"."};


//new HTTPRequestSender().execute(deleteCall).get();

final CountDownLatch countDownLatch=new CountDownLatch(1);


statsCall.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
countDownLatch.countDown();
Log.v("peeda_latch_or", String.valueOf(countDownLatch.getCount()));

Log.v("peeda", String.valueOf(response.isSuccessful()));
Log.v("peeda_body",response.body());
try {
Log.v("peeda_error_body",response.errorBody().string());
} catch (IOException e) {
e.printStackTrace();
}
String result= new HTTPRequestSender().execute(statsCall).get();

result[0] +=response.body();
countDownLatch.countDown();
}

@Override
public void onFailure(Call<String> call, Throwable t) {
result[0]+=t.getMessage();
//countDownLatch.countDown();
}
});

Log.v("peeda_latch", String.valueOf(countDownLatch.getCount()));
countDownLatch.await();


return result[0];
return result;
}
}

0 comments on commit be220d8

Please sign in to comment.