Search in sources :

Example 1 with StationFilter

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();
}
Also used : IntStream(java.util.stream.IntStream) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) LayoutInflater(android.view.LayoutInflater) StationFilter(de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter) Intent(android.content.Intent) BaseApplication(de.bahnhoefe.deutschlands.bahnhofsfotos.BaseApplication) AlertDialog(android.app.AlertDialog) Nullable(androidx.annotation.Nullable) AttributeSet(android.util.AttributeSet) R(de.bahnhoefe.deutschlands.bahnhofsfotos.R) Toast(android.widget.Toast) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) Button(android.widget.Button) CountryActivity(de.bahnhoefe.deutschlands.bahnhofsfotos.CountryActivity) ContextCompat(androidx.core.content.ContextCompat) ContextThemeWrapper(android.view.ContextThemeWrapper)

Example 2 with StationFilter

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();
        }
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) StationFilter(de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter) Intent(android.content.Intent) Response(retrofit2.Response) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Country(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Country) HighScoreAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.HighScoreAdapter) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) HighScoreItem(de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScoreItem) AdapterView(android.widget.AdapterView) Build(android.os.Build) TargetApi(android.annotation.TargetApi) Log(android.util.Log) HighScore(de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScore) SearchView(androidx.appcompat.widget.SearchView) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) Callback(retrofit2.Callback) ActivityHighScoreBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityHighScoreBinding) RSAPIClient(de.bahnhoefe.deutschlands.bahnhofsfotos.rsapi.RSAPIClient) SearchManager(android.app.SearchManager) Call(retrofit2.Call) HighScoreItem(de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScoreItem) HighScore(de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScore) RSAPIClient(de.bahnhoefe.deutschlands.bahnhofsfotos.rsapi.RSAPIClient) Intent(android.content.Intent) HighScoreAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.HighScoreAdapter) StationFilter(de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter)

Aggregations

Context (android.content.Context)2 Intent (android.content.Intent)2 View (android.view.View)2 Toast (android.widget.Toast)2 StationFilter (de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter)2 TargetApi (android.annotation.TargetApi)1 AlertDialog (android.app.AlertDialog)1 SearchManager (android.app.SearchManager)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 AttributeSet (android.util.AttributeSet)1 Log (android.util.Log)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 LinearLayout (android.widget.LinearLayout)1 NonNull (androidx.annotation.NonNull)1