Search in sources :

Example 1 with CountryCode

use of com.neovisionaries.i18n.CountryCode in project steve by RWTH-i5-IDSG.

the class ControllerHelper method populateCountryCodes.

private static Map<String, String> populateCountryCodes() {
    CountryCode[] codes = CountryCode.values();
    Arrays.sort(codes, Comparator.comparing(CountryCode::getName));
    Map<String, String> map = new LinkedHashMap<>(codes.length + 1);
    map.put("", EMPTY_OPTION);
    for (CountryCode c : codes) {
        if (shouldInclude(c)) {
            map.put(c.getAlpha2(), c.getName());
        }
    }
    return map;
}
Also used : CountryCode(com.neovisionaries.i18n.CountryCode) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with CountryCode

use of com.neovisionaries.i18n.CountryCode in project spotifybot by NotEchoDE.

the class PlayCommand method exec.

@SneakyThrows
@Override
public void exec(String userName, String id, UserLevel userLevel, String[] args) {
    ModuleEntry sPlay = getModule().getEntry("sPlay");
    if (!userLevel.isHigherOrEquals(sPlay.getUserLevel())) {
        sendMessage(getModule(ModuleType.SYSTEM).getEntry("noPerms"), "$USER", userName, "$ROLE", sPlay.getUserLevel().getPrettyName());
        return;
    }
    if (args.length >= 1) {
        StringBuilder searchQuery = new StringBuilder();
        for (int i = 0; i < args.length; i++) if (i != 0)
            searchQuery.append(" ");
        else
            searchQuery.append(args[i]);
        Paging<Track> search = getRoot().getSpotifyApi().searchTracks(searchQuery.toString()).build().execute();
        if (search.getTotal() == 0) {
            sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notFound"), "$USER", userName);
            return;
        }
        String uri = search.getItems()[0].getUri();
        CountryCode country = getRoot().getSpotifyApi().getCurrentUsersProfile().build().execute().getCountry();
        Track track = getRoot().getSpotifyApi().getTrack(uri.replace("spotify:track:", "")).build().execute();
        if (Arrays.stream(track.getAvailableMarkets()).noneMatch(countryCode -> countryCode.equals(CountryCode.DE))) {
            sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notAvailable"), "$USER", userName, "$SONG", track.getName());
            return;
        }
        getRoot().getSpotifyApi().addItemToUsersPlaybackQueue(uri).build().execute();
        getRoot().getSpotifyApi().skipUsersPlaybackToNextTrack().build().execute();
        sendMessage(sPlay, "$USER", userName, "$SONG", track.getName());
        return;
    }
    getRoot().getSpotifyApi().startResumeUsersPlayback().build().execute();
    String uri = SpotifyUtils.getUriFromJson(getRoot().getSpotifyApi().getUsersCurrentlyPlayingTrack().build().getJson());
    Track track = getRoot().getSpotifyApi().getTrack(SpotifyUtils.getIdFromUri(uri)).build().execute();
    sendMessage(sPlay, "$USER", userName, "$SONG", track.getName(), "$ARTISTS", SpotifyUtils.getArtists(track));
}
Also used : ModuleEntry(de.notecho.spotify.database.user.entities.module.ModuleEntry) CountryCode(com.neovisionaries.i18n.CountryCode) Track(se.michaelthelin.spotify.model_objects.specification.Track) SneakyThrows(lombok.SneakyThrows)

Example 3 with CountryCode

use of com.neovisionaries.i18n.CountryCode in project downlords-faf-client by FAForever.

the class UserInfoWindowController method setPlayer.

public void setPlayer(Player player) {
    this.player = player;
    usernameLabel.setText(player.getUsername());
    countryFlagService.loadCountryFlag(player.getCountry()).ifPresent(image -> countryImageView.setImage(image));
    avatarImageView.setImage(IdenticonUtil.createIdenticon(player.getId()));
    gamesPlayedLabel.setText(i18n.number(player.getNumberOfGames()));
    ratingLabelGlobal.setText(i18n.number(RatingUtil.getGlobalRating(player)));
    ratingLabel1v1.setText(i18n.number(RatingUtil.getLeaderboardRating(player)));
    updateNameHistory(player);
    CountryCode countryCode = CountryCode.getByCode(player.getCountry());
    if (countryCode != null) {
        // Country code is unknown to CountryCode, like A1 or A2 (from GeoIP)
        countryLabel.setText(countryCode.getName());
    } else {
        countryLabel.setText(player.getCountry());
    }
    globalButton.fire();
    globalButton.setSelected(true);
    loadAchievements();
    eventService.getPlayerEvents(player.getId()).thenAccept(events -> {
        plotFactionsChart(events);
        plotUnitsByCategoriesChart(events);
        plotTechBuiltChart(events);
        plotGamesPlayedChart();
    }).exceptionally(throwable -> {
        notificationService.addImmediateErrorNotification(throwable, "userInfo.statistics.errorLoading");
        log.warn("Could not load player events", throwable);
        return null;
    });
}
Also used : StageStyle(javafx.stage.StageStyle) UiService(com.faforever.client.theme.UiService) AchievementDefinition(com.faforever.client.api.dto.AchievementDefinition) EVENT_BUILT_AIR_UNITS(com.faforever.client.events.EventService.EVENT_BUILT_AIR_UNITS) XYChart(javafx.scene.chart.XYChart) AchievementState(com.faforever.client.achievements.AchievementService.AchievementState) PlayerEvent(com.faforever.client.api.dto.PlayerEvent) InvalidationListener(javafx.beans.InvalidationListener) EVENT_BUILT_NAVAL_UNITS(com.faforever.client.events.EventService.EVENT_BUILT_NAVAL_UNITS) FXCollections.observableList(javafx.collections.FXCollections.observableList) WindowController(com.faforever.client.fx.WindowController) TimeService(com.faforever.client.util.TimeService) ScrollPane(javafx.scene.control.ScrollPane) EVENT_AEON_PLAYS(com.faforever.client.events.EventService.EVENT_AEON_PLAYS) LeaderboardService(com.faforever.client.leaderboard.LeaderboardService) EVENT_UEF_WINS(com.faforever.client.events.EventService.EVENT_UEF_WINS) Map(java.util.Map) TableView(javafx.scene.control.TableView) PlayerService(com.faforever.client.player.PlayerService) Pane(javafx.scene.layout.Pane) Data(javafx.scene.chart.XYChart.Data) Collectors(java.util.stream.Collectors) StatisticsService(com.faforever.client.stats.StatisticsService) AchievementService(com.faforever.client.achievements.AchievementService) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) PieChart(javafx.scene.chart.PieChart) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Region(javafx.scene.layout.Region) OffsetDateTime(java.time.OffsetDateTime) ToggleButton(javafx.scene.control.ToggleButton) EVENT_BUILT_TECH_3_UNITS(com.faforever.client.events.EventService.EVENT_BUILT_TECH_3_UNITS) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) NotNull(org.jetbrains.annotations.NotNull) EventService(com.faforever.client.events.EventService) PlayerAchievement(com.faforever.client.api.dto.PlayerAchievement) EVENT_AEON_WINS(com.faforever.client.events.EventService.EVENT_AEON_WINS) StackedBarChart(javafx.scene.chart.StackedBarChart) EVENT_CYBRAN_PLAYS(com.faforever.client.events.EventService.EVENT_CYBRAN_PLAYS) FXCollections(javafx.collections.FXCollections) EVENT_BUILT_TECH_1_UNITS(com.faforever.client.events.EventService.EVENT_BUILT_TECH_1_UNITS) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) RatingHistoryDataPoint(com.faforever.client.domain.RatingHistoryDataPoint) NotificationService(com.faforever.client.notification.NotificationService) LineChart(javafx.scene.chart.LineChart) KnownFeaturedMod(com.faforever.client.game.KnownFeaturedMod) EVENT_CYBRAN_WINS(com.faforever.client.events.EventService.EVENT_CYBRAN_WINS) EVENT_UEF_PLAYS(com.faforever.client.events.EventService.EVENT_UEF_PLAYS) UNLOCKED(com.faforever.client.achievements.AchievementService.AchievementState.UNLOCKED) AchievementItemController(com.faforever.client.achievements.AchievementItemController) CountryCode(com.neovisionaries.i18n.CountryCode) OffsetDateTimeCell(com.faforever.client.fx.OffsetDateTimeCell) Modality(javafx.stage.Modality) RatingUtil(com.faforever.client.util.RatingUtil) Label(javafx.scene.control.Label) IdenticonUtil(com.faforever.client.util.IdenticonUtil) Controller(com.faforever.client.fx.Controller) Node(javafx.scene.Node) CLOSE(com.faforever.client.fx.WindowController.WindowButtonType.CLOSE) StringConverter(javafx.util.StringConverter) EVENT_SERAPHIM_WINS(com.faforever.client.events.EventService.EVENT_SERAPHIM_WINS) EVENT_SERAPHIM_PLAYS(com.faforever.client.events.EventService.EVENT_SERAPHIM_PLAYS) EVENT_BUILT_TECH_2_UNITS(com.faforever.client.events.EventService.EVENT_BUILT_TECH_2_UNITS) Assert(com.faforever.client.util.Assert) Component(org.springframework.stereotype.Component) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) EVENT_BUILT_LAND_UNITS(com.faforever.client.events.EventService.EVENT_BUILT_LAND_UNITS) DateTimeFormatter(java.time.format.DateTimeFormatter) NameRecord(com.faforever.client.player.NameRecord) Window(javafx.stage.Window) I18n(com.faforever.client.i18n.I18n) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Collections(java.util.Collections) CountryCode(com.neovisionaries.i18n.CountryCode)

Example 4 with CountryCode

use of com.neovisionaries.i18n.CountryCode in project downlords-faf-client by FAForever.

the class PrivateUserInfoController method setPlayer.

public void setPlayer(Player player) {
    this.player = player;
    CountryCode countryCode = CountryCode.getByCode(player.getCountry());
    usernameLabel.setText(player.getUsername());
    userImageView.setImage(IdenticonUtil.createIdenticon(player.getId()));
    countryFlagService.loadCountryFlag(player.getCountry()).ifPresent(image -> countryImageView.setImage(image));
    countryLabel.setText(countryCode == null ? player.getCountry() : countryCode.getName());
    player.globalRatingMeanProperty().addListener((observable) -> loadReceiverGlobalRatingInformation(player));
    player.globalRatingDeviationProperty().addListener((observable) -> loadReceiverGlobalRatingInformation(player));
    loadReceiverGlobalRatingInformation(player);
    player.leaderboardRatingMeanProperty().addListener((observable) -> loadReceiverLadderRatingInformation(player));
    player.leaderboardRatingDeviationProperty().addListener((observable) -> loadReceiverLadderRatingInformation(player));
    loadReceiverLadderRatingInformation(player);
    player.gameProperty().addListener(new WeakInvalidationListener(gameInvalidationListener));
    gameInvalidationListener.invalidated(player.gameProperty());
    gamesPlayedLabel.textProperty().bind(player.numberOfGamesProperty().asString());
    populateUnlockedAchievementsLabel(player);
}
Also used : WeakInvalidationListener(javafx.beans.WeakInvalidationListener) CountryCode(com.neovisionaries.i18n.CountryCode)

Example 5 with CountryCode

use of com.neovisionaries.i18n.CountryCode in project commercetools-jvm-sdk by commercetools.

the class TaxCategoryUpdateCommandIntegrationTest method addTaxRate.

@Test
public void addTaxRate() {
    withUpdateableTaxCategory(client(), taxCategory -> {
        // add tax rate
        final String name = "ag7";
        final CountryCode countryCode = CountryCode.AG;
        final TaxRateDraft de7 = TaxRateDraftBuilder.of(name, 0.07, true, countryCode).build();
        final TaxCategory taxCategoryWithTaRate = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategory, AddTaxRate.of(de7)));
        final TaxRate actual = taxCategoryWithTaRate.getTaxRates().stream().filter(rate -> name.equals(rate.getName())).findFirst().get();
        assertThat(actual.getCountry()).isEqualTo(countryCode);
        assertThat(actual.getAmount()).isEqualTo(0.07);
        assertThat(actual.getId()).overridingErrorMessage("the tax rate fetched from API has an id").isNotNull();
        assertThat(actual.getName()).isEqualTo(de7.getName());
        // remove tax rate
        final TaxCategory updatedTaxCategory = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategoryWithTaRate, RemoveTaxRate.of(actual.getId())));
        assertThat(updatedTaxCategory.getTaxRates()).matches(rates -> !rates.stream().anyMatch(rate -> name.equals(rate.getName())));
        return updatedTaxCategory;
    });
}
Also used : TaxCategoryFixtures.withUpdateableTaxCategory(io.sphere.sdk.taxcategories.TaxCategoryFixtures.withUpdateableTaxCategory) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) TaxRate(io.sphere.sdk.taxcategories.TaxRate) TaxRateDraft(io.sphere.sdk.taxcategories.TaxRateDraft) CountryCode(com.neovisionaries.i18n.CountryCode) IntegrationTest(io.sphere.sdk.test.IntegrationTest) Test(org.junit.Test)

Aggregations

CountryCode (com.neovisionaries.i18n.CountryCode)11 Test (org.junit.Test)3 Set (java.util.Set)2 AchievementItemController (com.faforever.client.achievements.AchievementItemController)1 AchievementService (com.faforever.client.achievements.AchievementService)1 AchievementState (com.faforever.client.achievements.AchievementService.AchievementState)1 UNLOCKED (com.faforever.client.achievements.AchievementService.AchievementState.UNLOCKED)1 AchievementDefinition (com.faforever.client.api.dto.AchievementDefinition)1 PlayerAchievement (com.faforever.client.api.dto.PlayerAchievement)1 PlayerEvent (com.faforever.client.api.dto.PlayerEvent)1 RatingHistoryDataPoint (com.faforever.client.domain.RatingHistoryDataPoint)1 EventService (com.faforever.client.events.EventService)1 EVENT_AEON_PLAYS (com.faforever.client.events.EventService.EVENT_AEON_PLAYS)1 EVENT_AEON_WINS (com.faforever.client.events.EventService.EVENT_AEON_WINS)1 EVENT_BUILT_AIR_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_AIR_UNITS)1 EVENT_BUILT_LAND_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_LAND_UNITS)1 EVENT_BUILT_NAVAL_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_NAVAL_UNITS)1 EVENT_BUILT_TECH_1_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_TECH_1_UNITS)1 EVENT_BUILT_TECH_2_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_TECH_2_UNITS)1 EVENT_BUILT_TECH_3_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_TECH_3_UNITS)1