Olá Alguem saberia me a com app que coleta os dados de um usuario do github? Segue o status atual do meu codigo:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button searchButton = (Button) findViewById(R.id.search_button);
final EditText searchProfile = (EditText) findViewById(R.id.search_profile);
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fillProfileInfo(searchProfile.getText().toString());
}
});
}
void fillProfileInfo(String profile) {
String requestUrl = "https://api.github.com/users/" + profile;
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.get()
.url(requestUrl)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.i("getProfileInfo", "FAIL");
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String jsonData = response.body().string();
Log.i("getProfileInfo", jsonData);
if (response.isSuccessful()) {
CardView userCard = (CardView) findViewById(R.id.card_user_info);
try {
JSONObject rootObj = new JSONObject(jsonData);
TextView userName = (TextView) findViewById(R.id.user_name);
TextView userBio = (TextView) findViewById(R.id.user_bio);
TextView userFollowers = (TextView) findViewById(R.id.user_folowers);
TextView userRepos = (TextView) findViewById(R.id.user_repos);
ImageView userAvatar = (ImageView) findViewById((R.id.user_avatar));
userName.setText(rootObj.getString("login"));
userBio.setText(rootObj.getString("bio"));
userFollowers.setText(rootObj.getInt("followers") + " Seguidores");
userRepos.setText(rootObj.getInt("public_repos") + " Repositórios");
try {
Glide.with(MainActivity.this).load(rootObj.getString("avatar_url"))
.asBitmap()
.fitCenter()
.into(userAvatar);
} catch (Exception e) {
e.printStackTrace();
}
userCard.setVisibility(View.VISIBLE);
fillRepoInfo();
} catch (JSONException e) {
userCard.setVisibility(View.GONE);
}
}
}
});
}
void fillRepoInfo() {
return;
}
}