Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. package com.example.retrofitgitexample.ui.adapter;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.widget.ListView;
  7. import android.widget.Toast;
  8.  
  9. import com.example.retrofitgitexample.R;
  10. import com.example.retrofitgitexample.api.model.GitHubRepo;
  11. import com.example.retrofitgitexample.service.GitHubClient;
  12.  
  13. import java.util.List;
  14.  
  15. import retrofit2.Call;
  16. import retrofit2.Callback;
  17. import retrofit2.Response;
  18. import retrofit2.Retrofit;
  19. import retrofit2.converter.gson.GsonConverterFactory;
  20.  
  21. public class MainActivity extends AppCompatActivity {
  22.  
  23. private ListView listview;
  24. public static final String TAG = "MainActivityLog";
  25.  
  26. @Override
  27. protected void onCreate(Bundle savedInstanceState) {
  28. super.onCreate(savedInstanceState);
  29. setContentView(R.layout.activity_main);
  30.  
  31. listview = findViewById(R.id.pagination_list);
  32.  
  33. Retrofit.Builder builder = new Retrofit.Builder()
  34. .baseUrl("https://api.github.com/")
  35. .addConverterFactory(GsonConverterFactory.create());
  36.  
  37. Retrofit retrofit = builder.build();
  38.  
  39. GitHubClient client = retrofit.create(GitHubClient.class);
  40. Call<List<GitHubRepo>> call = client.reposForUser("fs-opensource");
  41.  
  42. call.enqueue(new Callback<List<GitHubRepo>>() {
  43. @Override
  44. public void onResponse(Call<List<GitHubRepo>> call, Response<List<GitHubRepo>> response) {
  45. List<GitHubRepo> repos = response.body();
  46. Log.d(TAG, "onResponse: " + repos);
  47. // listview.setAdapter(new GitHubRepoAdapter(MainActivity.this, repos));
  48. }
  49.  
  50. @Override
  51. public void onFailure(Call<List<GitHubRepo>> call, Throwable t) {
  52. Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_SHORT).show();
  53. }
  54. });
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement