From 5ca3c18db03ef982a7033ac1c7116e17588b03f0 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Sun, 31 Mar 2024 12:18:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20show=20language=20of=20the=20ses?= =?UTF-8?q?sion=20closes=20#60?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/themes/apus/views/session-view.css | 25 ++++++--- .../fihlon/apus/conference/Language.java | 53 +++++++++++++++++++ .../swiss/fihlon/apus/conference/Session.java | 3 +- .../apus/conference/doag/ConferenceAPI.java | 20 ++++--- .../fihlon/apus/ui/view/SessionView.java | 29 ++++++++-- 5 files changed, 113 insertions(+), 17 deletions(-) create mode 100644 src/main/java/swiss/fihlon/apus/conference/Language.java diff --git a/frontend/themes/apus/views/session-view.css b/frontend/themes/apus/views/session-view.css index 969bb81..9147a90 100644 --- a/frontend/themes/apus/views/session-view.css +++ b/frontend/themes/apus/views/session-view.css @@ -28,11 +28,6 @@ font-size: 16px; } -.session-view h3 { - font-size: 18px; - margin-bottom: 10px; -} - .running-session { background-color: #9bf4ff; } @@ -45,6 +40,24 @@ opacity: 0.5; } -.empty-session h3 { +.empty-session .title h3 { text-transform: uppercase; } + +.session-view .title { + content: ""; + clear: both; + display: table; + width: 400px; +} + +.session-view .title h3 { + font-size: 18px; + margin-bottom: 10px; + float: left; + width: 376px; +} + +.session-view .title .language { + float: right; +} diff --git a/src/main/java/swiss/fihlon/apus/conference/Language.java b/src/main/java/swiss/fihlon/apus/conference/Language.java new file mode 100644 index 0000000..760f205 --- /dev/null +++ b/src/main/java/swiss/fihlon/apus/conference/Language.java @@ -0,0 +1,53 @@ +/* + * Apus - A social wall for conferences with additional features. + * Copyright (C) Marcus Fihlon and the individual contributors to Apus. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package swiss.fihlon.apus.conference; + +import org.jetbrains.annotations.NotNull; + +public enum Language { + + DE("de", "\uD83C\uDDE9\uD83C\uDDEA"), + EN("en", "\uD83C\uDDEC\uD83C\uDDE7"); + + private final String languageCode; + private final String flagEmoji; + + public static Language languageWithCode(@NotNull final String languageCode) { + for (final Language language : values()) { + if (language.languageCode.equals(languageCode)) { + return language; + } + } + throw new IllegalArgumentException(String.format("No language constant with language code '%s'!", languageCode)); + } + + Language(@NotNull final String languageCode, @NotNull final String flagEmoji) { + this.languageCode = languageCode; + this.flagEmoji = flagEmoji; + } + + @NotNull + public String getLanguageCode() { + return languageCode; + } + + @NotNull + public String getFlagEmoji() { + return flagEmoji; + } +} diff --git a/src/main/java/swiss/fihlon/apus/conference/Session.java b/src/main/java/swiss/fihlon/apus/conference/Session.java index e3aae0e..b126756 100644 --- a/src/main/java/swiss/fihlon/apus/conference/Session.java +++ b/src/main/java/swiss/fihlon/apus/conference/Session.java @@ -23,7 +23,8 @@ import java.util.List; public record Session(@NotNull String id, @NotNull LocalDateTime startDate, @NotNull LocalDateTime endDate, - @NotNull String room, @NotNull String title, @NotNull List speakers) + @NotNull String room, @NotNull String title, @NotNull List speakers, + @NotNull Language language) implements Comparable { @Override public int compareTo(@NotNull final Session other) { diff --git a/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java b/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java index 1670b20..88e4e0a 100644 --- a/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java +++ b/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java @@ -21,6 +21,9 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import swiss.fihlon.apus.conference.Language; import swiss.fihlon.apus.conference.Session; import swiss.fihlon.apus.conference.SessionImportException; import swiss.fihlon.apus.conference.Speaker; @@ -43,6 +46,7 @@ public final class ConferenceAPI { + public static final Logger LOGGER = LoggerFactory.getLogger(ConferenceAPI.class); public static final String CONFERENCE_API_LOCATION = "https://meine.doag.org/api/event/action.getCPEventAgenda/eventId.%d/"; private final String location; @@ -83,8 +87,8 @@ public List getSessions() { if (!"lecture".equalsIgnoreCase(type)) { continue; } - final String language = getLanguage(slot); - final String title = getTitle(slot, language); + final Language language = getLanguage(slot); + final String title = getTitle(slot, language.getLanguageCode()); final LocalTime startTime = LocalTime.parse(slot.getString("start")); final Duration duration = parseDuration(slot.getString("duration")); final JSONArray persons = slot.getJSONArray("persons"); @@ -100,7 +104,8 @@ public List getSessions() { LocalDateTime.of(date, startTime).plus(duration), room, title, - speakers.stream().map(Speaker::new).toList()); + speakers.stream().map(Speaker::new).toList(), + language); sessions.add(session); } } @@ -111,12 +116,15 @@ public List getSessions() { return sessions; } - private String getLanguage(@NotNull final JSONObject slot) { + private Language getLanguage(@NotNull final JSONObject slot) { + String languageCode = "de"; try { - return slot.getJSONArray("language").getString(0); + languageCode = slot.getJSONArray("language").getString(0); } catch (final JSONException e) { - return "de"; + LOGGER.error("Error reading language from slot '{}': {}", + slot.getInt("id"), e.getMessage()); } + return Language.languageWithCode(languageCode); } private String getTitle(@NotNull final JSONObject slot, @NotNull final String defaultLanguage) throws JSONException { diff --git a/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java b/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java index 21c12b6..e36527e 100644 --- a/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java +++ b/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java @@ -24,8 +24,10 @@ import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.H3; +import com.vaadin.flow.component.html.Span; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import swiss.fihlon.apus.conference.Language; import swiss.fihlon.apus.conference.Session; import swiss.fihlon.apus.conference.Speaker; @@ -42,9 +44,10 @@ public final class SessionView extends Div { private final transient List speakers; private final LocalTime startTime; private final LocalTime endTime; + private final Language language; public SessionView(@NotNull final String room) { - this(room, null, List.of(), null, null); + this(room, null, List.of(), null, null, null); } public SessionView(@NotNull final Session session) { @@ -53,7 +56,8 @@ public SessionView(@NotNull final Session session) { session.title(), session.speakers(), session.startDate().toLocalTime(), - session.endDate().toLocalTime() + session.endDate().toLocalTime(), + session.language() ); } @@ -61,12 +65,14 @@ public SessionView(@NotNull final String room, @Nullable final String title, @NotNull final List speakers, @Nullable final LocalTime startTime, - @Nullable final LocalTime endTime) { + @Nullable final LocalTime endTime, + @Nullable final Language language) { this.room = room; this.title = title; this.speakers = speakers; this.startTime = startTime; this.endTime = endTime; + this.language = language; } @Override @@ -80,8 +86,23 @@ protected void onAttach(@NotNull final AttachEvent attachEvent) { @NotNull private Component createTitleComponent() { - return new H3(new Text(title == null ? getTranslation("conference.session.closed") : title)); + final var titleComponent = new Div(); + titleComponent.addClassName("title"); + titleComponent.add(new H3(new Text(title == null ? getTranslation("conference.session.closed") : title))); + titleComponent.add(createLanguageComponent()); + return titleComponent; } + + @NotNull + private Component createLanguageComponent() { + final var languageComponent = new Span(); + languageComponent.addClassName("language"); + if (language != null) { + languageComponent.add(language.getFlagEmoji()); + } + return languageComponent; + } + @NotNull private Component createSpeakersComponent() { final var speakersComponent = new Div();