Last active
October 15, 2017 16:04
-
-
Save nutchy/261e963f6980c8ecff6f9a2413ab6462 to your computer and use it in GitHub Desktop.
[MyLazyInstagram] - MainActivity.java
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 { | |
public OkHttpClient client; | |
public Retrofit retrofit; | |
public LazyInstagramApi lazyInstagramApi; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.lazyinstagram_main); | |
getConnection(); | |
getContentByName("cartoon"); | |
} | |
public void getConnection(){ | |
client = new OkHttpClient.Builder().build(); | |
retrofit = new Retrofit | |
.Builder() | |
.baseUrl(LazyInstagramApi.BASE_URL) | |
.client(client) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); | |
lazyInstagramApi = retrofit.create(LazyInstagramApi.class); | |
} | |
private void getContentByName(String userName){ | |
Call<UserProfile> call = lazyInstagramApi.getProfile(userName); | |
call.enqueue(new Callback<UserProfile>() { | |
@Override | |
public void onResponse(Call<UserProfile> call, Response<UserProfile> response) { | |
if (response.isSuccessful()){ | |
// Mapping to Model | |
UserProfile userProfile = response.body(); | |
} | |
} | |
@Override | |
public void onFailure(Call<UserProfile> call, Throwable t) { | |
System.out.println("Connect API FAILED"); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment