use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScoreItem in project RSAndroidApp by RailwayStations.
the class HighScoreActivity method loadHighScore.
private void loadHighScore(final BaseApplication baseApplication, final Country selectedCountry) {
final RSAPIClient rsapi = baseApplication.getRsapiClient();
final Call<HighScore> highScoreCall = selectedCountry.getCode().isEmpty() ? rsapi.getHighScore() : rsapi.getHighScore(selectedCountry.getCode());
highScoreCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull final Call<HighScore> call, @NonNull final Response<HighScore> response) {
if (response.isSuccessful()) {
adapter = new HighScoreAdapter(HighScoreActivity.this, response.body().getItems());
binding.highscoreList.setAdapter(adapter);
binding.highscoreList.setOnItemClickListener((adapter, v, position, arg3) -> {
final HighScoreItem highScoreItem = (HighScoreItem) adapter.getItemAtPosition(position);
final StationFilter stationFilter = baseApplication.getStationFilter();
stationFilter.setNickname(highScoreItem.getName());
baseApplication.setStationFilter(stationFilter);
final Intent intent = new Intent(HighScoreActivity.this, MapsActivity.class);
startActivity(intent);
});
}
}
@Override
public void onFailure(@NonNull final Call<HighScore> call, @NonNull final Throwable t) {
Log.e(TAG, "Error loading highscore", t);
Toast.makeText(getBaseContext(), getString(R.string.error_loading_highscore) + t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
Aggregations