last day (14 days later) » 

9:35 AM
1
A: Picasso image not displaying

Wana AntTake a look at this example which uses OkHttpClient: https://github.com/toaderandrei/loadcart/blob/master/app/src/main/java/com/android/cartloading/httpclient/HttpClient.java Here you can find the Picasso part: https://github.com/toaderandrei/loadcart/blob/master/app/src/main/java/com/android/ca...

 
thank you I will look at it
I have some questions about your github code can we go to a chat?
 
In 4h yes, we (s)can.
 
in 4 hrs ill be sleeping . anyway ill post my questions here maybe you can answer them when you come back.
hello you there
 
Yes, I am right now, but at work. If it is fast we can try a chat.
 
I used to get json array objects using DefaultHttpClient. can you tell me a simple example how to read with okhttp ? I read your code but I didnt understand this ProductsDTO response = null; how to initilaise response in my side. I know you are using other activities and interface and i understand the quue request of okhttp but for sake of helping me can you tell me a simple example with okhttp how to connect read json objects ? @wana Ant
 
9:35 AM
You can try to import the github in your code and take a look directly. Basically all the magic that OkHttpClient does is there. It returns an InputStream and that I parse. That's it
as it seems we can talk here
 
yes here is good
I want to understand how it works ok http in your code involved many things
private static void request(String url,String json,Callback callback,boolean isPost){
MediaType JSON=MediaType.parse("application/json");
OkHttpClient client=new OkHttpClient();
Request.Builder requestBuilder=new Request.Builder();
if (isPost == true) {
RequestBody requestBody=RequestBody.create(JSON,json);
requestBuilder.post(requestBody);
}
else requestBuilder.get();
Request request=requestBuilder.url(url).addHeader("Authorization",UserData.getInstance().getBaseAuth()).addHeader("Accept","application/json").build();
 
if it is post then I do a post else a get
 
this simple code from the net
it should be get right ?
 
so
Request request = new Request.Builder().url(getProductsCartUrl()).get().build();

Response resp = okHttpClient.newCall(request).execute();
if (resp != null) {
switch (resp.code()) {
case 200:
final ResponseBody responseBody = resp.body();
final InputStream stream = responseBody.byteStream();
if (stream != null) {
response = getContentParser().parseProductsCart(stream);
}
break;
default:
response = null;
Log.w(TAG, "Message is:" + resp.code());
break;
}
looking at this code of mine
it does like that
assembles the Request
from the URL
the method getProductsCartUrl is a method that returns the base url for the request
for example
www.cartapi.com/products
it can be that
then you add the rest of the stuff - if there is something
once you have the right url, the get appears and build
and you have a request
then okhttpClient will try to execute the call, you have a responseBody
next you take the stream and parse it, that's it
nothing more nothing less
 
yes its simple once you understand it
 
9:43 AM
(I also say the same - it is simple if u know it)
 
in this code response = getContentParser().parseProductsCart(stream);
 
I use my parser
you can take a look there inside
the git project is free
 
can you send me the link of the parseaer
 
when do we use
Call call=client.newCall(request);
call.enqueue(callback);
 
9:48 AM
this is for asynchronous call right?
because I use my threading mechanism
 
this is full code from the net
 
u can take a look here
 
private static void request(String url,String json,Callback callback,boolean isPost){
MediaType JSON=MediaType.parse("application/json");
OkHttpClient client=new OkHttpClient();
Request.Builder requestBuilder=new Request.Builder();
if (isPost == true) {
RequestBody requestBody=RequestBody.create(JSON,json);
requestBuilder.post(requestBody);
}
else requestBuilder.get();
Request request=requestBuilder.url(url).addHeader("Authorization",UserData.getInstance().getBaseAuth()).addHeader("Accept","application/json").build();
they user alot call back
 
yes I read it
its seems you got alot of experience
 
9:51 AM
in general in android, but okhttp, not so much
 
yes in android I mean becasue you orgenize everything in correct way
anyway
I want to write a simple code from my side
 
yes, I try as much as possible
 
that read from php file adn store the value
 
to write organised and simple, not so big classes, structured, encapsulated, etc
yeah, I understand, but you can just reuse all the stuff I did, they are all reusable
copy-paste the httpclient, the parser, modify according to ur needs
it is simple as well
 
I am new to android so i need time till I able to orgenise and simplfy everythig
honestly my aim here is to try to understand okhttp i dont want to copy and paste thats why I am talking to you
if i copy them i will not understand
ok this code I fully understand
Response resp = okHttpClient.newCall(request).execute();
if (resp != null) {
switch (resp.code()) {
case 200:
final ResponseBody responseBody = resp.body();
final InputStream stream = responseBody.byteStream();
if (stream != null) {
response = getContentParser().parseProductsCart(stream);
}
but If I want to parse in the same code
            response = gson.fromJson(inputStreamReader, ProductsDTO.class);
such way is correct ?
but I dont know what is productDTO.class
 
9:59 AM
so, the ProductDTO is actually the class that comes out of the son.fromGson parsing
because if u use Gson u need the mapping class
 
Ah i dont use Gson .. yet
 

last day (14 days later) »