Skip to content

Commit

Permalink
🚸 show language of the session closes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Mar 31, 2024
1 parent af2b60a commit 5ca3c18
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 17 deletions.
25 changes: 19 additions & 6 deletions frontend/themes/apus/views/session-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
font-size: 16px;
}

.session-view h3 {
font-size: 18px;
margin-bottom: 10px;
}

.running-session {
background-color: #9bf4ff;
}
Expand All @@ -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;
}
53 changes: 53 additions & 0 deletions src/main/java/swiss/fihlon/apus/conference/Language.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
3 changes: 2 additions & 1 deletion src/main/java/swiss/fihlon/apus/conference/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Speaker> speakers)
@NotNull String room, @NotNull String title, @NotNull List<Speaker> speakers,
@NotNull Language language)
implements Comparable<Session> {
@Override
public int compareTo(@NotNull final Session other) {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -83,8 +87,8 @@ public List<Session> 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");
Expand All @@ -100,7 +104,8 @@ public List<Session> 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);
}
}
Expand All @@ -111,12 +116,15 @@ public List<Session> 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 {
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/swiss/fihlon/apus/ui/view/SessionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,9 +44,10 @@ public final class SessionView extends Div {
private final transient List<Speaker> 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) {
Expand All @@ -53,20 +56,23 @@ public SessionView(@NotNull final Session session) {
session.title(),
session.speakers(),
session.startDate().toLocalTime(),
session.endDate().toLocalTime()
session.endDate().toLocalTime(),
session.language()
);
}

public SessionView(@NotNull final String room,
@Nullable final String title,
@NotNull final List<Speaker> 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
Expand All @@ -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();
Expand Down

0 comments on commit 5ca3c18

Please sign in to comment.