Skip to content

Instantly share code, notes, and snippets.

@kyodgorbek
Last active November 3, 2018 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyodgorbek/145a10f6bac9f9c9abc87fc3e3d4e3e4 to your computer and use it in GitHub Desktop.
Save kyodgorbek/145a10f6bac9f9c9abc87fc3e3d4e3e4 to your computer and use it in GitHub Desktop.
CVApp
public class IntroductionItem extends AppCompatActivity {
public RealmList<Introduction> introductionList;
Context context;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.introduction);
RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
recyclerView.setVisibility(View.VISIBLE);
//TODO move this initialization to App extends Application
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
final Realm realm = Realm.getInstance(realmConfiguration);
if (InternetConnection.checkConnection(context)) {
KitabInterface kitabInterface = ApiClient.getApiService();
Call<KitabSawti> call = kitabInterface.getIntroduction();
call.enqueue(new Callback<KitabSawti>() {
@Override
public void onResponse(Call<KitabSawti> call, Response<KitabSawti> response) {
introductionList = response.body().getIntroduction();
recyclerView.setAdapter(new IntroductionAdapter(IntroductionItem.this, introductionList));
realm.beginTransaction();
for (int i = 0; i < introductionList.size(); i++) {
Introduction introduction = realm.createObject(Introduction.class);
introduction.setImage(introductionList.get(0).getImage());
introduction.setIntroduction(introductionList.get(0).getIntroduction());
}
realm.commitTransaction();
}else{
@Override
public void onFailure (Call < KitabSawti > call, Throwable t){
List<Introduction> list = realm.where(Introduction.class).findAll();
if (list != null) {
recyclerView.setAdapter(new IntroductionAdapter(IntroductionItem.this, list));
}
}
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment