use of de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter in project RSAndroidApp by RailwayStations.
the class StationFilterBar method selectNicknameFilter.
public void selectNicknameFilter(final View view) {
final var nicknames = baseApplication.getDbAdapter().getPhotographerNicknames();
final var stationFilter = baseApplication.getStationFilter();
if (nicknames.length == 0) {
Toast.makeText(getContext(), getContext().getString(R.string.no_nicknames_found), Toast.LENGTH_LONG).show();
return;
}
final int selectedNickname = IntStream.range(0, nicknames.length).filter(i -> nicknames[i].equals(stationFilter.getNickname())).findFirst().orElse(-1);
new AlertDialog.Builder(new ContextThemeWrapper(getContext(), R.style.AlertDialogCustom)).setIcon(R.mipmap.ic_launcher).setTitle(R.string.select_nickname).setSingleChoiceItems(nicknames, selectedNickname, null).setPositiveButton(R.string.button_ok_text, (dialog, whichButton) -> {
dialog.dismiss();
final int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
if (selectedPosition >= 0 && nicknames.length > selectedPosition) {
stationFilter.setNickname(nicknames[selectedPosition]);
setFilterButton(nicknameFilter, stationFilter.getNicknameIcon(), R.string.filter_nickname, stationFilter.getNicknameColor());
updateStationFilter(stationFilter);
}
}).setNeutralButton(R.string.button_remove_text, (dialog, whichButton) -> {
dialog.dismiss();
stationFilter.setNickname(null);
setFilterButton(nicknameFilter, stationFilter.getNicknameIcon(), R.string.filter_nickname, stationFilter.getNicknameColor());
updateStationFilter(stationFilter);
}).setNegativeButton(R.string.button_myself_text, (dialog, whichButton) -> {
dialog.dismiss();
stationFilter.setNickname(baseApplication.getNickname());
setFilterButton(nicknameFilter, stationFilter.getNicknameIcon(), R.string.filter_nickname, stationFilter.getNicknameColor());
updateStationFilter(stationFilter);
}).create().show();
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter 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