This file contains hidden or 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
public void onResponse(User user, Retrofit retrofit) { | |
//200 | |
String data = "Github Name :" + user.getName() + | |
"\nBlog :"+user.getฺBlog() + | |
"\nCompany Name :" + user.getCompany(); | |
tvResult.setText(data); | |
//แสดง layout result | |
layoutForm.setVisibility(View.GONE); | |
layoutResult.setVisibility(View.VISIBLE); | |
layoutProgress.setVisibility(View.GONE); |
This file contains hidden or 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
Call call = git.getUser(username); |
This file contains hidden or 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
call.enqueue(new Callback<User>() { | |
@Override | |
public void onResponse(Response<User> response, Retrofit retrofit) { | |
} | |
@Override | |
public void onFailure(Throwable t) { | |
} | |
This file contains hidden or 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
@Override | |
public void onResponse(Response<User> response, Retrofit retrofit) { | |
User user = response.body(); | |
if (user == null) { | |
//404 or the response cannot be converted to User. | |
ResponseBody responseBody = response.errorBody(); | |
if (responseBody != null) { | |
listener.onBodyError(responseBody); | |
} else { |
This file contains hidden or 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
Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl("https://api.github.com") | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); |
This file contains hidden or 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
public class NetworkConnectionManager { | |
public NetworkConnectionManager() { | |
} | |
public void callServer(final OnNetworkCallbackListener listener,String username){ | |
Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl("https://api.github.com") |
This file contains hidden or 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
public interface OnNetworkCallbackListener{ | |
public void onResponse(User user, Retrofit retrofit); | |
public void onBodyError(ResponseBody responseBodyError); | |
public void onBodyErrorIsNull(); | |
public void onFailure(Throwable t); | |
} |
This file contains hidden or 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
<uses-permission android:name="android.permission.INTERNET" /> |
This file contains hidden or 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
public class User { | |
@Expose | |
String name; | |
@Expose | |
String blog; | |
@Expose | |
String company; | |
public String getName() { |
This file contains hidden or 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
public class MainActivity extends AppCompatActivity { | |
static { | |
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); | |
} | |
... | |
} |