Search in sources :

Example 1 with HighScoreItem

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();
        }
    });
}
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

TargetApi (android.annotation.TargetApi)1 SearchManager (android.app.SearchManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 Menu (android.view.Menu)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Toast (android.widget.Toast)1 NonNull (androidx.annotation.NonNull)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 SearchView (androidx.appcompat.widget.SearchView)1 ActivityHighScoreBinding (de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityHighScoreBinding)1 HighScoreAdapter (de.bahnhoefe.deutschlands.bahnhofsfotos.db.HighScoreAdapter)1 Country (de.bahnhoefe.deutschlands.bahnhofsfotos.model.Country)1 HighScore (de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScore)1 HighScoreItem (de.bahnhoefe.deutschlands.bahnhofsfotos.model.HighScoreItem)1