Skip to content

Instantly share code, notes, and snippets.

@nutchy
Created October 16, 2017 16:56
Show Gist options
  • Save nutchy/63289212b60c740c7466288bef134e92 to your computer and use it in GitHub Desktop.
Save nutchy/63289212b60c740c7466288bef134e92 to your computer and use it in GitHub Desktop.
[MyLazyInstagram] - MainActivity.java
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");
}
// Create Conenction
public void getConnection(){
// ..
}
private void getContentByName(String userName){
// ..
@Override
public void onResponse(Call<UserProfile> call, Response<UserProfile> response) {
if (response.isSuccessful()){
UserProfile userProfile = response.body();
display(userProfile);
}
}
//..
}
private void display(UserProfile userProfile){
// Each Layout has number of type recycler
List<Layout> layouts = new ArrayList<>();
layouts.add(new Layout(Layout.TYPE_USER_DETAIL));
layouts.add(new Layout(Layout.TYPE_POST_ITEM));
LazyInstagramAdapter lazyInstagramAdapter = new LazyInstagramAdapter(this, layouts);
lazyInstagramAdapter.setUserProfile(userProfile);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(lazyInstagramAdapter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment