Last active
November 3, 2018 17:03
-
-
Save kyodgorbek/145a10f6bac9f9c9abc87fc3e3d4e3e4 to your computer and use it in GitHub Desktop.
CVApp
This file contains 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 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