Skip to content

Commit

Permalink
Merge pull request EventFahrplan#635 from EventFahrplan/session-kotli…
Browse files Browse the repository at this point in the history
…n-migration-part4

Migrate Session class from Java to Kotlin (part 4)
  • Loading branch information
johnjohndoe authored Apr 1, 2024
2 parents fe6e084 + 98b7540 commit 0dddd42
Show file tree
Hide file tree
Showing 37 changed files with 1,639 additions and 1,666 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import info.metadude.android.eventfahrplan.network.models.Session as SessionNetw

fun Session.shiftRoomIndexOnDays(dayIndices: Set<Int>) =
if (dayIndex in dayIndices) {
Session(this).apply { roomIndex += 1 }
copy(roomIndex = roomIndex + 1)
} else {
this
}
Expand Down Expand Up @@ -73,95 +73,93 @@ fun Session.toSessionDatabaseModel() = SessionDatabaseModel(
)

fun SessionDatabaseModel.toSessionAppModel(): Session {
val session = Session(sessionId)

session.abstractt = abstractt
session.dateText = date
session.dateUTC = dateUTC
session.dayIndex = dayIndex
session.description = description
session.duration = duration // minutes
session.feedbackUrl = feedbackUrl
session.hasAlarm = hasAlarm
session.language = language
session.links = links
session.highlight = isHighlight
session.recordingLicense = recordingLicense
session.recordingOptOut = recordingOptOut
session.relStartTime = relativeStartTime
session.roomName = roomName
session.roomIdentifier = roomIdentifier
session.roomIndex = roomIndex
session.slug = slug
session.speakers = createSpeakersList(speakers)
session.startTime = startTime // minutes since day start
session.subtitle = subtitle
session.timeZoneOffset = timeZoneOffset?.let { ZoneOffset.ofTotalSeconds(it) } // seconds
session.title = title
session.track = track
session.type = type
session.url = url

session.changedDayIndex = changedDay
session.changedDuration = changedDuration
session.changedIsCanceled = changedIsCanceled
session.changedIsNew = changedIsNew
session.changedLanguage = changedLanguage
session.changedRecordingOptOut = changedRecordingOptOut
session.changedRoomName = changedRoomName
session.changedSpeakers = changedSpeakers
session.changedSubtitle = changedSubtitle
session.changedStartTime = changedTime
session.changedTitle = changedTitle
session.changedTrack = changedTrack

return session
return Session(
sessionId = sessionId,
abstractt = abstractt,
dateText = date,
dateUTC = dateUTC,
dayIndex = dayIndex,
description = description,
duration = duration, // minutes
feedbackUrl = feedbackUrl,
hasAlarm = hasAlarm,
language = language,
links = links,
highlight = isHighlight,
recordingLicense = recordingLicense,
recordingOptOut = recordingOptOut,
relStartTime = relativeStartTime,
roomName = roomName,
roomIdentifier = roomIdentifier,
roomIndex = roomIndex,
slug = slug,
speakers = createSpeakersList(speakers),
startTime = startTime, // minutes since day start
subtitle = subtitle,
timeZoneOffset = timeZoneOffset?.let { ZoneOffset.ofTotalSeconds(it) }, // seconds
title = title,
track = track,
type = type,
url = url,

changedDayIndex = changedDay,
changedDuration = changedDuration,
changedIsCanceled = changedIsCanceled,
changedIsNew = changedIsNew,
changedLanguage = changedLanguage,
changedRecordingOptOut = changedRecordingOptOut,
changedRoomName = changedRoomName,
changedSpeakers = changedSpeakers,
changedSubtitle = changedSubtitle,
changedStartTime = changedTime,
changedTitle = changedTitle,
changedTrack = changedTrack,
)
}

fun SessionNetworkModel.toSessionAppModel(): Session {
val session = Session(sessionId)

session.abstractt = abstractt
session.dateText = date
session.dateUTC = dateUTC
session.dayIndex = dayIndex
session.description = description
session.duration = duration // minutes
session.feedbackUrl = feedbackUrl
session.hasAlarm = hasAlarm
session.language = language
session.links = links
session.highlight = isHighlight
session.recordingLicense = recordingLicense
session.recordingOptOut = recordingOptOut
session.relStartTime = relativeStartTime
session.roomName = roomName
session.roomIdentifier = roomGuid
session.roomIndex = roomIndex
session.slug = slug
session.speakers = createSpeakersList(speakers)
session.startTime = startTime // minutes since day start
session.subtitle = subtitle
session.timeZoneOffset = timeZoneOffset?.let { ZoneOffset.ofTotalSeconds(it) } // seconds
session.title = title
session.track = track
session.type = type
session.url = url

session.changedDayIndex = changedDayIndex
session.changedDuration = changedDuration
session.changedIsCanceled = changedIsCanceled
session.changedIsNew = changedIsNew
session.changedLanguage = changedLanguage
session.changedRecordingOptOut = changedRecordingOptOut
session.changedRoomName = changedRoomName
session.changedSpeakers = changedSpeakers
session.changedSubtitle = changedSubtitle
session.changedStartTime = changedStartTime
session.changedTitle = changedTitle
session.changedTrack = changedTrack

return session
return Session(
sessionId = sessionId,
abstractt = abstractt,
dateText = date,
dateUTC = dateUTC,
dayIndex = dayIndex,
description = description,
duration = duration, // minutes
feedbackUrl = feedbackUrl,
hasAlarm = hasAlarm,
language = language,
links = links,
highlight = isHighlight,
recordingLicense = recordingLicense,
recordingOptOut = recordingOptOut,
relStartTime = relativeStartTime,
roomName = roomName,
roomIdentifier = roomGuid,
roomIndex = roomIndex,
slug = slug,
speakers = createSpeakersList(speakers),
startTime = startTime, // minutes since day start
subtitle = subtitle,
timeZoneOffset = timeZoneOffset?.let { ZoneOffset.ofTotalSeconds(it) }, // seconds
title = title,
track = track,
type = type,
url = url,

changedDayIndex = changedDayIndex,
changedDuration = changedDuration,
changedIsCanceled = changedIsCanceled,
changedIsNew = changedIsNew,
changedLanguage = changedLanguage,
changedRecordingOptOut = changedRecordingOptOut,
changedRoomName = changedRoomName,
changedSpeakers = changedSpeakers,
changedSubtitle = changedSubtitle,
changedStartTime = changedStartTime,
changedTitle = changedTitle,
changedTrack = changedTrack,
)
}

/**
Expand Down Expand Up @@ -210,14 +208,14 @@ fun Session.sanitize(): Session {
if (tempTrack.isEmpty() && type.isNotEmpty()) {
tempTrack = type
}
return Session(this).apply {
title = tempTitle
subtitle = tempSubtitle
abstractt = tempAbstract
description = tempDescription
track = tempTrack
language = tempLanguage
}
return this.copy(
title = tempTitle,
subtitle = tempSubtitle,
abstractt = tempAbstract,
description = tempDescription,
track = tempTrack,
language = tempLanguage,
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ fun Shift.toSessionAppModel(
virtualRoomName: String,
dayRanges: List<DayRange>

) = Session("${SHIFT_ID_OFFSET + sID}").apply {
abstractt = ""
dateText = startsAtLocalDateString
dateUTC = dateUtcMs
dayIndex = oneBasedDayIndex(logging, dayRanges)
description = descriptionText
duration = shiftDuration // minutes
relStartTime = minuteOfDay
roomName = virtualRoomName
speakers = emptyList()
startTime = minuteOfDay // minutes since day start
title = talkTitle
subtitle = locationName
) = Session(
sessionId = "${SHIFT_ID_OFFSET + sID}",
abstractt = "",
dateText = startsAtLocalDateString,
dateUTC = dateUtcMs,
dayIndex = oneBasedDayIndex(logging, dayRanges),
description = descriptionText,
duration = shiftDuration, // minutes
relStartTime = minuteOfDay,
roomName = virtualRoomName,
speakers = emptyList(),
startTime = minuteOfDay, // minutes since day start
title = talkTitle,
subtitle = locationName,
// Shift.timeZoneName is not mapped here. Using Meta.timeZoneName instead.
track = typeName
url = talkUrl
}
track = typeName,
url = talkUrl,
)


/**
* Returns the day index (starting at 1) based on the start date and time of this shift.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ internal class SessionDetailsViewModel(

fun favorSession() {
loadSelectedSession { session ->
val favoredSession = Session(session).apply {
val favoredSession = session.copy(
highlight = true // Required: Update property because updateHighlight refers to its value!
}
)
repository.updateHighlight(favoredSession)
}
}

fun unfavorSession() {
loadSelectedSession { session ->
val unfavoredSession = Session(session).apply {
val unfavoredSession = session.copy (
highlight = false // Required: Update property because updateHighlight refers to its value!
}
)
repository.updateHighlight(unfavoredSession)
}
}
Expand Down
Loading

0 comments on commit 0dddd42

Please sign in to comment.