diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatistic.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatistic.kt index 917ab8e8da..d62d9d2f3f 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatistic.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatistic.kt @@ -50,7 +50,7 @@ data class ChangeStatistic private constructor( * [changed][Session.isChanged] or [new][Session.changedIsNew]. */ fun getChangedFavoritesCount() = sessions - .count { it.highlight && (it.changedIsCanceled || it.isChanged || it.changedIsNew) } + .count { it.isHighlight && (it.changedIsCanceled || it.isChanged || it.changedIsNew) } .also { log("$it changed favorites") } private fun log(message: String) = logging.d(LOG_TAG, message) diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightExtensions.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightExtensions.kt deleted file mode 100644 index 733a0c3d07..0000000000 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightExtensions.kt +++ /dev/null @@ -1,9 +0,0 @@ -package nerd.tuxmobil.fahrplan.congress.dataconverters - -import nerd.tuxmobil.fahrplan.congress.models.Highlight -import info.metadude.android.eventfahrplan.database.models.Highlight as HighlightDatabaseModel - -fun HighlightDatabaseModel.toHighlightAppModel() = Highlight( - sessionId = sessionId, - isHighlight = isHighlight -) diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightsExtensions.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightsExtensions.kt deleted file mode 100644 index 059e142a51..0000000000 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightsExtensions.kt +++ /dev/null @@ -1,6 +0,0 @@ -package nerd.tuxmobil.fahrplan.congress.dataconverters - -import info.metadude.android.eventfahrplan.database.models.Highlight as HighlightDatabaseModel - - -fun List.toHighlightsAppModel() = map(HighlightDatabaseModel::toHighlightAppModel) diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensions.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensions.kt index 4001b1e26b..9e9a2118a6 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensions.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensions.kt @@ -6,33 +6,34 @@ import info.metadude.android.eventfahrplan.commons.temporal.Moment import info.metadude.android.eventfahrplan.network.serialization.FahrplanParser import nerd.tuxmobil.fahrplan.congress.models.DateInfo import nerd.tuxmobil.fahrplan.congress.models.Room -import nerd.tuxmobil.fahrplan.congress.models.Session import nerd.tuxmobil.fahrplan.congress.schedule.TrackBackgrounds import org.threeten.bp.ZoneOffset import info.metadude.android.eventfahrplan.database.models.Highlight as HighlightDatabaseModel import info.metadude.android.eventfahrplan.database.models.Session as SessionDatabaseModel import info.metadude.android.eventfahrplan.network.models.Session as SessionNetworkModel +import nerd.tuxmobil.fahrplan.congress.models.Session as SessionAppModel -fun Session.shiftRoomIndexOnDays(dayIndices: Set) = +fun SessionNetworkModel.shiftRoomIndexOnDays(dayIndices: Set) = if (dayIndex in dayIndices) { copy(roomIndex = roomIndex + 1) } else { this } -fun Session.toRoom() = Room(identifier = roomIdentifier, name = roomName) +fun SessionAppModel.toRoom() = Room(identifier = roomIdentifier, name = roomName) -fun Session.toDateInfo(): DateInfo = DateInfo(dayIndex, Moment.parseDate(dateText)) +fun SessionDatabaseModel.toDateInfo(): DateInfo = DateInfo(dayIndex, Moment.parseDate(dateText)) -fun Session.toHighlightDatabaseModel() = HighlightDatabaseModel( +fun SessionAppModel.toHighlightDatabaseModel() = HighlightDatabaseModel( sessionId = Integer.parseInt(sessionId), - isHighlight = highlight + isHighlight = isHighlight ) -fun Session.toSessionDatabaseModel() = SessionDatabaseModel( +fun SessionDatabaseModel.toSessionAppModel(): SessionAppModel { + return SessionAppModel( sessionId = sessionId, abstractt = abstractt, - date = dateText, + dateText = dateText, dateUTC = dateUTC, dayIndex = dayIndex, description = description, @@ -41,24 +42,24 @@ fun Session.toSessionDatabaseModel() = SessionDatabaseModel( hasAlarm = hasAlarm, language = language, links = links, - isHighlight = highlight, + isHighlight = isHighlight, recordingLicense = recordingLicense, recordingOptOut = recordingOptOut, - relativeStartTime = relStartTime, + relativeStartTime = relativeStartTime, roomName = roomName, roomIdentifier = roomIdentifier, roomIndex = roomIndex, slug = slug, - speakers = createSpeakersString(speakers), + speakers = createSpeakersList(speakers), startTime = startTime, // minutes since day start subtitle = subtitle, - timeZoneOffset = timeZoneOffset?.totalSeconds, // seconds + timeZoneOffset = timeZoneOffset?.let { ZoneOffset.ofTotalSeconds(it) }, title = title, track = track, type = type, url = url, - changedDay = changedDayIndex, + changedDayIndex = changedDayIndex, changedDuration = changedDuration, changedIsCanceled = changedIsCanceled, changedIsNew = changedIsNew, @@ -66,17 +67,18 @@ fun Session.toSessionDatabaseModel() = SessionDatabaseModel( changedRecordingOptOut = changedRecordingOptOut, changedRoomName = changedRoomName, changedSpeakers = changedSpeakers, + changedStartTime = changedStartTime, changedSubtitle = changedSubtitle, - changedTime = changedStartTime, changedTitle = changedTitle, - changedTrack = changedTrack -) + changedTrack = changedTrack, + ) +} -fun SessionDatabaseModel.toSessionAppModel(): Session { - return Session( +fun SessionDatabaseModel.toSessionNetworkModel(): SessionNetworkModel { + return SessionNetworkModel( sessionId = sessionId, abstractt = abstractt, - dateText = date, + dateText = dateText, dateUTC = dateUTC, dayIndex = dayIndex, description = description, @@ -85,24 +87,24 @@ fun SessionDatabaseModel.toSessionAppModel(): Session { hasAlarm = hasAlarm, language = language, links = links, - highlight = isHighlight, + isHighlight = isHighlight, recordingLicense = recordingLicense, recordingOptOut = recordingOptOut, - relStartTime = relativeStartTime, + relativeStartTime = relativeStartTime, roomName = roomName, - roomIdentifier = roomIdentifier, + roomGuid = roomIdentifier, roomIndex = roomIndex, slug = slug, - speakers = createSpeakersList(speakers), + speakers = speakers, startTime = startTime, // minutes since day start subtitle = subtitle, - timeZoneOffset = timeZoneOffset?.let { ZoneOffset.ofTotalSeconds(it) }, // seconds + timeZoneOffset = timeZoneOffset, title = title, track = track, type = type, url = url, - changedDayIndex = changedDay, + changedDayIndex = changedDayIndex, changedDuration = changedDuration, changedIsCanceled = changedIsCanceled, changedIsNew = changedIsNew, @@ -110,18 +112,18 @@ fun SessionDatabaseModel.toSessionAppModel(): Session { changedRecordingOptOut = changedRecordingOptOut, changedRoomName = changedRoomName, changedSpeakers = changedSpeakers, + changedStartTime = changedStartTime, changedSubtitle = changedSubtitle, - changedStartTime = changedTime, changedTitle = changedTitle, changedTrack = changedTrack, ) } -fun SessionNetworkModel.toSessionAppModel(): Session { - return Session( +fun SessionNetworkModel.toSessionDatabaseModel(): SessionDatabaseModel { + return SessionDatabaseModel( sessionId = sessionId, abstractt = abstractt, - dateText = date, + dateText = dateText, dateUTC = dateUTC, dayIndex = dayIndex, description = description, @@ -130,18 +132,18 @@ fun SessionNetworkModel.toSessionAppModel(): Session { hasAlarm = hasAlarm, language = language, links = links, - highlight = isHighlight, + isHighlight = isHighlight, recordingLicense = recordingLicense, recordingOptOut = recordingOptOut, - relStartTime = relativeStartTime, + relativeStartTime = relativeStartTime, roomName = roomName, roomIdentifier = roomGuid, roomIndex = roomIndex, slug = slug, - speakers = createSpeakersList(speakers), + speakers = speakers, startTime = startTime, // minutes since day start subtitle = subtitle, - timeZoneOffset = timeZoneOffset?.let { ZoneOffset.ofTotalSeconds(it) }, // seconds + timeZoneOffset = timeZoneOffset, title = title, track = track, type = type, @@ -155,8 +157,8 @@ fun SessionNetworkModel.toSessionAppModel(): Session { changedRecordingOptOut = changedRecordingOptOut, changedRoomName = changedRoomName, changedSpeakers = changedSpeakers, - changedSubtitle = changedSubtitle, changedStartTime = changedStartTime, + changedSubtitle = changedSubtitle, changedTitle = changedTitle, changedTrack = changedTrack, ) @@ -169,7 +171,7 @@ fun SessionNetworkModel.toSessionAppModel(): Session { * scheme is used for similar sessions. This is achieved by customizing related track names. Colors * are derived from track names, see [TrackBackgrounds]. */ -fun Session.sanitize(): Session { +fun SessionNetworkModel.sanitize(): SessionNetworkModel { var tempTitle = title var tempSubtitle = subtitle var tempAbstract = abstractt @@ -186,7 +188,7 @@ fun Session.sanitize(): Session { if (tempAbstract == tempDescription) { tempAbstract = "" } - if (createSpeakersString(speakers) == tempSubtitle) { + if (speakers == tempSubtitle) { tempSubtitle = "" } if (tempDescription.isEmpty()) { @@ -221,12 +223,8 @@ fun Session.sanitize(): Session { /** * Delimiter which is used in [FahrplanParser] to construct the speakers string. */ -private const val SPEAKERS_DELIMITER = ";" +private const val SPEAKERS_DELIMITER_FOR_SPLITTING = ";" private fun createSpeakersList(speakers: String): List { - return if (speakers.isEmpty()) emptyList() else speakers.split(SPEAKERS_DELIMITER) -} - -private fun createSpeakersString(speakers: List): String { - return speakers.joinToString(SPEAKERS_DELIMITER) + return if (speakers.isEmpty()) emptyList() else speakers.split(SPEAKERS_DELIMITER_FOR_SPLITTING).map { it.trim() } } diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionsExtensions.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionsExtensions.kt index a2d10781ca..4503c29e2f 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionsExtensions.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionsExtensions.kt @@ -2,16 +2,16 @@ package nerd.tuxmobil.fahrplan.congress.dataconverters import info.metadude.android.eventfahrplan.commons.temporal.DayRange import info.metadude.android.eventfahrplan.commons.temporal.Moment -import nerd.tuxmobil.fahrplan.congress.models.Session import nerd.tuxmobil.fahrplan.congress.models.VirtualDay import info.metadude.android.eventfahrplan.database.models.Session as SessionDatabaseModel import info.metadude.android.eventfahrplan.network.models.Session as SessionNetworkModel +import nerd.tuxmobil.fahrplan.congress.models.Session as SessionAppModel -fun List.shiftRoomIndicesOfMainSchedule(dayIndices: Set) = map { +fun List.shiftRoomIndicesOfMainSchedule(dayIndices: Set) = map { it.shiftRoomIndexOnDays(dayIndices) } -fun List.toDayIndices(): Set { +fun List.toDayIndices(): Set { val dayIndices = HashSet() forEach { dayIndices.add(it.dayIndex) @@ -20,10 +20,10 @@ fun List.toDayIndices(): Set { } /** - * Splits the given sessions into [VirtualDay]s. The [Session.dateText] field is used to separate them. + * Splits the given sessions into [VirtualDay]s. The [SessionAppModel.dateText] field is used to separate them. * This field is unique for a virtual day, even for sessions after midnight. */ -fun List.toVirtualDays(): List { +fun List.toVirtualDays(): List { var index = 0 return groupBy { it.dateText } .map { (_, sessions) -> @@ -32,11 +32,9 @@ fun List.toVirtualDays(): List { } } -fun List.toDateInfos() = map(Session::toDateInfo) +fun List.toDateInfos() = map(SessionDatabaseModel::toDateInfo) -fun List.toSessionsDatabaseModel() = map(Session::toSessionDatabaseModel) - -fun List.toDayRanges(): List { +fun List.toDayRanges(): List { val ranges = mutableSetOf() forEach { val day = Moment.parseDate(it.dateText) @@ -46,8 +44,10 @@ fun List.toDayRanges(): List { return ranges.sortedBy { it.startsAt }.toList() } -fun List.toSessionsAppModel2(): List = map(SessionNetworkModel::toSessionAppModel) +fun List.toSessionsNetworkModel() = map(SessionDatabaseModel::toSessionNetworkModel) + +fun List.toSessionsDatabaseModel() = map(SessionNetworkModel::toSessionDatabaseModel) fun List.toSessionsAppModel() = map(SessionDatabaseModel::toSessionAppModel) -fun List.sanitize(): List = map(Session::sanitize) +fun List.sanitize(): List = map(SessionNetworkModel::sanitize) diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensions.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensions.kt index b05bc80d7b..964f507a11 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensions.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensions.kt @@ -6,21 +6,21 @@ import info.metadude.android.eventfahrplan.commons.temporal.DayRange import info.metadude.android.eventfahrplan.commons.temporal.Moment.Companion.MILLISECONDS_OF_ONE_SECOND import info.metadude.android.eventfahrplan.commons.temporal.Moment.Companion.toMoment import info.metadude.kotlin.library.engelsystem.models.Shift -import nerd.tuxmobil.fahrplan.congress.models.Session import org.threeten.bp.Duration +import info.metadude.android.eventfahrplan.network.models.Session as SessionNetworkModel private const val LOG_TAG = "ShiftsExtensions" // Avoid conflicts with the IDs of the main schedule. private const val SHIFT_ID_OFFSET = 300000 -fun Shift.toSessionAppModel( +fun Shift.toSessionNetworkModel( logging: Logging, virtualRoomName: String, dayRanges: List -) = Session( +) = SessionNetworkModel( sessionId = "${SHIFT_ID_OFFSET + sID}", abstractt = "", dateText = startsAtLocalDateString, @@ -28,9 +28,9 @@ fun Shift.toSessionAppModel( dayIndex = oneBasedDayIndex(logging, dayRanges), description = descriptionText, duration = shiftDuration, // minutes - relStartTime = minuteOfDay, + relativeStartTime = minuteOfDay, roomName = virtualRoomName, - speakers = emptyList(), + speakers = "", startTime = minuteOfDay, // minutes since day start title = talkTitle, subtitle = locationName, diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftsExtensions.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftsExtensions.kt index a435938adc..649c709174 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftsExtensions.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftsExtensions.kt @@ -4,13 +4,13 @@ import info.metadude.android.eventfahrplan.commons.logging.Logging import info.metadude.android.eventfahrplan.commons.temporal.DayRange import info.metadude.kotlin.library.engelsystem.models.Shift -fun List.toSessionAppModels( +fun List.toSessionsNetworkModel( logging: Logging, virtualRoomName: String, dayRanges: List -) = map { it.toSessionAppModel(logging, virtualRoomName, dayRanges) } +) = map { it.toSessionNetworkModel(logging, virtualRoomName, dayRanges) } /** * Returns a list of shifts which only contains shifts which are within the given day ranges extent. diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModel.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModel.kt index 709a1cbfb8..bb21e21408 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModel.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModel.kt @@ -166,7 +166,7 @@ internal class SessionDetailsViewModel( hasWikiLinks = links.containsWikiLink(), sessionLink = sessionLink, // Options menu - isFlaggedAsFavorite = highlight, + isFlaggedAsFavorite = isHighlight, hasAlarm = hasAlarm, supportsFeedback = supportsFeedback, supportsIndoorNavigation = supportsIndoorNavigation, @@ -206,7 +206,7 @@ internal class SessionDetailsViewModel( fun favorSession() { loadSelectedSession { session -> val favoredSession = session.copy( - highlight = true // Required: Update property because updateHighlight refers to its value! + isHighlight = true // Required: Update property because updateHighlight refers to its value! ) repository.updateHighlight(favoredSession) } @@ -215,7 +215,7 @@ internal class SessionDetailsViewModel( fun unfavorSession() { loadSelectedSession { session -> val unfavoredSession = session.copy ( - highlight = false // Required: Update property because updateHighlight refers to its value! + isHighlight = false // Required: Update property because updateHighlight refers to its value! ) repository.updateHighlight(unfavoredSession) } diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/models/Highlight.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/models/Highlight.kt deleted file mode 100644 index cf27dcfbb5..0000000000 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/models/Highlight.kt +++ /dev/null @@ -1,8 +0,0 @@ -package nerd.tuxmobil.fahrplan.congress.models - -data class Highlight( - - val sessionId: Int, - val isHighlight: Boolean - -) diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/models/Session.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/models/Session.kt index eb1948c831..b22d496967 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/models/Session.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/models/Session.kt @@ -28,7 +28,7 @@ data class Session( val dateUTC: Long = 0, // milliseconds val timeZoneOffset: ZoneOffset? = null, val startTime: Int = 0, // minutes since day start - val relStartTime: Int = 0, // minutes since conference start + val relativeStartTime: Int = 0, // minutes since conference start val duration: Int = 0, // minutes val roomName: String = "", val roomIdentifier: String = "", // Unique identifier of a room, e.g. "bccb6a5b-b26b-4f17-90b9-b5966f5e34d8" @@ -40,7 +40,7 @@ data class Session( val slug: String = "", val recordingLicense: String = "", val recordingOptOut: Boolean = false, - val highlight: Boolean = false, + val isHighlight: Boolean = false, val hasAlarm: Boolean = false, val changedTitle: Boolean = false, @@ -71,7 +71,7 @@ data class Session( /** * Returns a moment based on the start time milliseconds. * - * Don't use in [Conference.ofSessions] as long as [relStartTime] is supported. + * Don't use in [Conference.ofSessions] as long as [relativeStartTime] is supported. * See: [5a402](https://github.com/EventFahrplan/EventFahrplan/commit/5a4022b00434700274a824cc63f6d54a18b06fac) */ val startsAt: Moment @@ -86,6 +86,9 @@ data class Session( val endsAt: Moment get() = Moment.ofEpochMilli(dateUTC + duration.toLong() * MILLISECONDS_OF_ONE_MINUTE) + /** + * Keep in sync with [info.metadude.android.eventfahrplan.database.models.Session.isChanged]. + */ val isChanged: Boolean get() = changedTitle || changedSubtitle || @@ -98,25 +101,6 @@ data class Session( changedRecordingOptOut || changedTrack - /** - * Returns a new session with [changedIsCanceled] set to `true` - * and all other change flags set to `false`. - */ - fun cancel() = copy( - changedIsCanceled = true, - changedIsNew = false, - changedTitle = false, - changedSubtitle = false, - changedRoomName = false, - changedDayIndex = false, - changedStartTime = false, - changedDuration = false, - changedSpeakers = false, - changedLanguage = false, - changedRecordingOptOut = false, - changedTrack = false, - ) - } private data class EssentialSession( diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepository.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepository.kt index cec1f54906..c4b0cf6564 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepository.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepository.kt @@ -38,22 +38,19 @@ import nerd.tuxmobil.fahrplan.congress.dataconverters.toDateInfos import nerd.tuxmobil.fahrplan.congress.dataconverters.toDayIndices import nerd.tuxmobil.fahrplan.congress.dataconverters.toDayRanges import nerd.tuxmobil.fahrplan.congress.dataconverters.toHighlightDatabaseModel -import nerd.tuxmobil.fahrplan.congress.dataconverters.toHighlightsAppModel import nerd.tuxmobil.fahrplan.congress.dataconverters.toMetaAppModel import nerd.tuxmobil.fahrplan.congress.dataconverters.toMetaDatabaseModel import nerd.tuxmobil.fahrplan.congress.dataconverters.toMetaNetworkModel import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionAppModel -import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionAppModels import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionsAppModel -import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionsAppModel2 import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionsDatabaseModel +import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionsNetworkModel import nerd.tuxmobil.fahrplan.congress.exceptions.AppExceptionHandler import nerd.tuxmobil.fahrplan.congress.models.Alarm import nerd.tuxmobil.fahrplan.congress.models.ConferenceTimeFrame import nerd.tuxmobil.fahrplan.congress.models.ConferenceTimeFrame.Known import nerd.tuxmobil.fahrplan.congress.models.ConferenceTimeFrame.Unknown import nerd.tuxmobil.fahrplan.congress.models.ScheduleData -import nerd.tuxmobil.fahrplan.congress.models.Session import nerd.tuxmobil.fahrplan.congress.net.CustomHttpClient import nerd.tuxmobil.fahrplan.congress.net.FetchScheduleResult import nerd.tuxmobil.fahrplan.congress.net.HttpStatus @@ -78,8 +75,11 @@ import nerd.tuxmobil.fahrplan.congress.serialization.ScheduleChanges.Companion.c import nerd.tuxmobil.fahrplan.congress.utils.AlarmToneConversion import nerd.tuxmobil.fahrplan.congress.validation.MetaValidation.validate import okhttp3.OkHttpClient +import info.metadude.android.eventfahrplan.database.models.Meta as MetaDatabaseModel +import info.metadude.android.eventfahrplan.database.models.Session as SessionDatabaseModel import info.metadude.android.eventfahrplan.network.models.Meta as MetaNetworkModel import nerd.tuxmobil.fahrplan.congress.models.Meta as MetaAppModel +import nerd.tuxmobil.fahrplan.congress.models.Session as SessionAppModel object AppRepository { @@ -158,10 +158,10 @@ object AppRepository { * The returned list might be empty. */ @OptIn(ExperimentalCoroutinesApi::class) - val starredSessions: Flow> by lazy { + val starredSessions: Flow> by lazy { refreshStarredSessionsSignal .onStart { emit(Unit) } - .mapLatest { loadStarredSessions() } + .mapLatest { loadStarredSessions().toSessionsAppModel() } .flowOn(executionContext.database) } @@ -180,10 +180,10 @@ object AppRepository { * The returned list might be empty. */ @OptIn(ExperimentalCoroutinesApi::class) - val sessionsWithoutShifts: Flow> by lazy { + val sessionsWithoutShifts: Flow> by lazy { refreshSessionsWithoutShiftsSignal .onStart { emit(Unit) } - .mapLatest { loadSessionsForAllDays(includeEngelsystemShifts = false) } + .mapLatest { loadSessionsForAllDays(includeEngelsystemShifts = false).toSessionsAppModel() } .flowOn(executionContext.database) } @@ -202,10 +202,10 @@ object AppRepository { * The returned list might be empty. */ @OptIn(ExperimentalCoroutinesApi::class) - val sessions: Flow> by lazy { + val sessions: Flow> by lazy { refreshSessionsSignal .onStart { emit(Unit) } - .mapLatest { loadSessionsForAllDays() } + .mapLatest { loadSessionsForAllDays().toSessionsAppModel() } .flowOn(executionContext.database) } @@ -224,10 +224,10 @@ object AppRepository { * The returned list might be empty. */ @OptIn(ExperimentalCoroutinesApi::class) - val changedSessions: Flow> by lazy { + val changedSessions: Flow> by lazy { refreshChangedSessionsSignal .onStart { emit(Unit) } - .mapLatest { loadChangedSessions() } + .mapLatest { loadChangedSessions().toSessionsAppModel() } .flowOn(executionContext.database) } @@ -269,7 +269,7 @@ object AppRepository { * Emits the session from the database which has been selected. */ @OptIn(ExperimentalCoroutinesApi::class) - val selectedSession: Flow by lazy { + val selectedSession: Flow by lazy { refreshSelectedSessionSignal .onStart { emit(Unit) } .mapLatest { loadSelectedSession() } @@ -374,7 +374,7 @@ object AppRepository { if (fetchResult.isSuccessful) { val validMeta = meta.copy(httpHeader = fetchScheduleResult.httpHeader).validate() - updateMeta(validMeta) + updateMeta(validMeta.toMetaDatabaseModel()) check(onParsingDone != {}) { "Nobody registered to receive ParseScheduleResult." } // Parsing val parsingStatus = if (meta.numDays == 0) InitialParsing else Parsing @@ -399,21 +399,24 @@ object AppRepository { onLoadingShiftsDone: (loadShiftsResult: LoadShiftsResult) -> Unit) { scheduleNetworkRepository.parseSchedule(scheduleXml, httpHeader, onUpdateSessions = { sessions -> - val oldSessions = loadSessionsForAllDays(true) - val newSessions = sessions.toSessionsAppModel2().sanitize() + val oldSessions = loadSessionsForAllDays(true).toSessionsNetworkModel() + val newSessions = sessions.sanitize() val scheduleChanges = computeSessionsWithChangeFlags(newSessions, oldSessions) if (scheduleChanges.foundNoteworthyChanges) { updateScheduleChangesSeen(false) } - updateSessions(scheduleChanges.sessionsWithChangeFlags, scheduleChanges.oldCanceledSessions) + updateSessions( + scheduleChanges.sessionsWithChangeFlags.toSessionsDatabaseModel(), + scheduleChanges.oldCanceledSessions.toSessionsDatabaseModel(), + ) }, onUpdateMeta = { meta -> val validMeta = meta.validate() - updateMeta(validMeta) + updateMeta(validMeta.toMetaDatabaseModel()) }, onParsingDone = { isSuccess: Boolean, version: String -> if (!isSuccess) { - updateMeta(oldMeta.copy(httpHeader = HttpHeader(eTag = "", lastModified = ""))) + updateMeta(oldMeta.copy(httpHeader = HttpHeader(eTag = "", lastModified = "")).toMetaDatabaseModel()) } val parseResult = ParseScheduleResult(isSuccess, version) val parseScheduleStatus = if (isSuccess) ParseSuccess else ParseFailure(parseResult) @@ -494,16 +497,17 @@ object AppRepository { } val dayRanges = loadSessionsForAllDays(includeEngelsystemShifts = false) .toDayRanges() - val oldShifts = loadEngelsystemShiftsForAllDays() + val oldShifts = loadEngelsystemShiftsForAllDays().toSessionsNetworkModel() val sessionizedShifts = shifts .also { logging.d(LOG_TAG, "Shifts unfiltered = ${it.size}") } .cropToDayRangesExtent(dayRanges) .also { logging.d(LOG_TAG, "Shifts filtered = ${it.size}") } - .toSessionAppModels(logging, ENGELSYSTEM_ROOM_NAME, dayRanges) + .toSessionsNetworkModel(logging, ENGELSYSTEM_ROOM_NAME, dayRanges) .sanitize() val shiftChanges = computeSessionsWithChangeFlags(sessionizedShifts, oldShifts) if (oldShifts.isEmpty() || shiftChanges.foundChanges) { val toBeUpdatedSessions = loadSessionsForAllDays(false) // Drop all shifts before ... + .toSessionsNetworkModel() .toMutableList() .let { when { @@ -518,7 +522,10 @@ object AppRepository { val toBeDeletedSessions = oldShifts .filter { persisted -> sessionizedShifts.none { newOrUpdated -> persisted.sessionId == newOrUpdated.sessionId } } .also { logging.d(LOG_TAG, "Shifts to be removed = ${it.size}") } - updateSessions(toBeUpdatedSessions, toBeDeletedSessions) + updateSessions( + toBeUpdatedSessions.toSessionsDatabaseModel(), + toBeDeletedSessions.toSessionsDatabaseModel(), + ) } } @@ -526,9 +533,9 @@ object AppRepository { * Loads the session which has been selected at last. */ @WorkerThread - fun loadSelectedSession(): Session { + fun loadSelectedSession(): SessionAppModel { val sessionId = readSelectedSessionId() - return readSessionBySessionId(sessionId) + return readSessionBySessionId(sessionId).toSessionAppModel() } /** @@ -538,7 +545,7 @@ object AppRepository { */ fun loadConferenceTimeFrame(): ConferenceTimeFrame { val sessions = loadSessionsForAllDays() - val timeFrame = if (sessions.isEmpty()) null else Conference.ofSessions(sessions).timeFrame + val timeFrame = if (sessions.isEmpty()) null else Conference.ofSessions(sessions.toSessionsAppModel()).timeFrame return if (timeFrame == null) Unknown else Known(timeFrame.start, timeFrame.endInclusive) } @@ -557,7 +564,7 @@ object AppRepository { @WorkerThread fun loadUncanceledSessionsForDayIndex(): ScheduleData { val dayIndex = readDisplayDayIndex() - val sessions = loadUncanceledSessionsForDayIndex(dayIndex) + val sessions = loadUncanceledSessionsForDayIndex(dayIndex).toSessionsAppModel() return sessionsTransformer.transformSessions(dayIndex, sessions) } @@ -575,15 +582,16 @@ object AppRepository { */ @WorkerThread private fun loadStarredSessions() = loadSessionsForAllDays(true) - .filter { it.highlight && !it.changedIsCanceled } + .filter { it.isHighlight && !it.changedIsCanceled } .also { logging.d(LOG_TAG, "${it.size} sessions starred.") } /** * Loads all sessions from the database which have been marked as changed, cancelled or new. * The returned list might be empty. */ + // TODO Stop exposing database layer model to the app layer. @WorkerThread - fun loadChangedSessions() = loadSessionsForAllDays(true) + fun loadChangedSessions(): List = loadSessionsForAllDays(true) .filter { it.isChanged || it.changedIsCanceled || it.changedIsNew } .also { logging.d(LOG_TAG, "${it.size} sessions changed.") } @@ -613,7 +621,7 @@ object AppRepository { * All days can be loaded if -1 is passed as the [day][dayIndex]. * To exclude Engelsystem shifts pass false to [includeEngelsystemShifts]. */ - private fun loadSessionsForDayIndex(dayIndex: Int, includeEngelsystemShifts: Boolean): List { + private fun loadSessionsForDayIndex(dayIndex: Int, includeEngelsystemShifts: Boolean): List { val sessions = if (dayIndex == ALL_DAYS) { logging.d(LOG_TAG, "Loading sessions for all days.") if (includeEngelsystemShifts) { @@ -635,7 +643,7 @@ object AppRepository { val highlightedSessions = sessions.map { session -> if (session.sessionId in highlightedSessionIds) { - session.copy(highlight = true) + session.copy(isHighlight = true) } else { session } @@ -694,10 +702,10 @@ object AppRepository { } private fun readHighlights() = - highlightsDatabaseRepository.query().toHighlightsAppModel() + highlightsDatabaseRepository.query() @WorkerThread - fun updateHighlight(session: Session) { + fun updateHighlight(session: SessionAppModel) { val highlightDatabaseModel = session.toHighlightDatabaseModel() val values = highlightDatabaseModel.toContentValues() highlightsDatabaseRepository.update(values, session.sessionId) @@ -722,10 +730,9 @@ object AppRepository { refreshUncanceledSessions() } - private fun readSessionBySessionId(sessionId: String): Session { + private fun readSessionBySessionId(sessionId: String): SessionDatabaseModel { val session = sessionsDatabaseRepository .querySessionBySessionId(sessionId) - .toSessionAppModel() val isHighlighted = highlightsDatabaseRepository .queryBySessionId(sessionId.toInt()) @@ -737,7 +744,7 @@ object AppRepository { return if (isHighlighted || hasAlarm) { session.copy( - highlight = isHighlighted, + isHighlight = isHighlighted, hasAlarm = hasAlarm, ) } else { @@ -746,16 +753,16 @@ object AppRepository { } private fun readSessionsForDayIndexOrderedByDateUtc(dayIndex: Int) = - sessionsDatabaseRepository.querySessionsForDayIndexOrderedByDateUtc(dayIndex).toSessionsAppModel() + sessionsDatabaseRepository.querySessionsForDayIndexOrderedByDateUtc(dayIndex) private fun readSessionsOrderedByDateUtc() = - sessionsDatabaseRepository.querySessionsOrderedByDateUtc().toSessionsAppModel() + sessionsDatabaseRepository.querySessionsOrderedByDateUtc() private fun readSessionsOrderedByDateUtcExcludingEngelsystemShifts() = - sessionsDatabaseRepository.querySessionsWithoutRoom(ENGELSYSTEM_ROOM_NAME).toSessionsAppModel() + sessionsDatabaseRepository.querySessionsWithoutRoom(ENGELSYSTEM_ROOM_NAME) private fun readEngelsystemShiftsOrderedByDateUtc() = - sessionsDatabaseRepository.querySessionsWithinRoom(ENGELSYSTEM_ROOM_NAME).toSessionsAppModel() + sessionsDatabaseRepository.querySessionsWithinRoom(ENGELSYSTEM_ROOM_NAME) private fun readSelectedSessionId(): String { val id = sharedPreferencesRepository.getSelectedSessionId() @@ -786,9 +793,8 @@ object AppRepository { fun readDateInfos() = readSessionsOrderedByDateUtc().toDateInfos() - private fun updateSessions(toBeUpdatedSessions: List, toBeDeletedSessions: List = emptyList()) { - val toBeUpdatedSessionsDatabaseModel = toBeUpdatedSessions.toSessionsDatabaseModel() - val toBeUpdated = toBeUpdatedSessionsDatabaseModel.map { it.sessionId to it.toContentValues() } + private fun updateSessions(toBeUpdatedSessions: List, toBeDeletedSessions: List = emptyList()) { + val toBeUpdated = toBeUpdatedSessions.map { it.sessionId to it.toContentValues() } val toBeDeleted = toBeDeletedSessions.map { it.sessionId } sessionsDatabaseRepository.updateSessions(toBeUpdated, toBeDeleted) refreshStarredSessions() @@ -831,9 +837,8 @@ object AppRepository { * See also: [HttpStatus.HTTP_OK] */ @VisibleForTesting - fun updateMeta(meta: MetaNetworkModel) { - val metaDatabaseModel = meta.toMetaDatabaseModel() - val values = metaDatabaseModel.toContentValues() + fun updateMeta(meta: MetaDatabaseModel) { + val values = meta.toContentValues() metaDatabaseRepository.insert(values) refreshMeta() } diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.kt index 47f0607e1f..6ea7091d85 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.kt @@ -516,10 +516,10 @@ class FahrplanFragment : Fragment(), SessionViewEventsHandler { val context = requireContext() when (menuItemIndex) { CONTEXT_MENU_ITEM_ID_FAVORITES -> { - val updatedSession = session.copy(highlight = !session.highlight) + val updatedSession = session.copy(isHighlight = !session.isHighlight) viewModel.updateFavorStatus(updatedSession) - sessionViewDrawer.setSessionBackground(updatedSession.highlight, updatedSession.track, contextMenuView) - SessionViewDrawer.setSessionTextColor(updatedSession.highlight, contextMenuView) + sessionViewDrawer.setSessionBackground(updatedSession.isHighlight, updatedSession.track, contextMenuView) + SessionViewDrawer.setSessionTextColor(updatedSession.isHighlight, contextMenuView) updateMenuItems() } CONTEXT_MENU_ITEM_ID_SET_ALARM -> { @@ -571,7 +571,7 @@ class FahrplanFragment : Fragment(), SessionViewEventsHandler { super.onCreateContextMenu(menu, view, menuInfo) contextMenuView = view val session = view.tag as Session - if (session.highlight) { + if (session.isHighlight) { menu.add(0, CONTEXT_MENU_ITEM_ID_FAVORITES, 0, getString(R.string.menu_item_title_unflag_as_favorite)) } else { menu.add(0, CONTEXT_MENU_ITEM_ID_FAVORITES, 0, getString(R.string.menu_item_title_flag_as_favorite)) diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculator.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculator.kt index c16cc52fe3..8ded499d41 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculator.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculator.kt @@ -84,7 +84,7 @@ data class LayoutCalculator( startTime += Duration.ofDays(1).toMinutes().toInt() } } else { - startTime = session.relStartTime + startTime = session.relativeStartTime } return startTime } diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModel.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModel.kt index 9a5530cf33..6e27ea6307 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModel.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModel.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch import nerd.tuxmobil.fahrplan.congress.changes.ChangeStatistic +import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionsAppModel import nerd.tuxmobil.fahrplan.congress.net.ParseResult import nerd.tuxmobil.fahrplan.congress.notifications.NotificationHelper import nerd.tuxmobil.fahrplan.congress.repositories.AppRepository @@ -109,7 +110,7 @@ internal class MainViewModel( private fun onParsingDone() { if (!repository.readScheduleChangesSeen()) { val scheduleVersion = repository.readMeta().version - val sessions = repository.loadChangedSessions() + val sessions = repository.loadChangedSessions().toSessionsAppModel() val statistic = ChangeStatistic.of(sessions, logging) val parameter = ScheduleChangesParameter(scheduleVersion, statistic) mutableScheduleChangesParameter.sendOneTimeEvent(parameter) diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/SessionViewDrawer.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/SessionViewDrawer.kt index 6eb299b1cb..493e3dbc40 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/SessionViewDrawer.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/SessionViewDrawer.kt @@ -71,8 +71,8 @@ internal class SessionViewDrawer( } ViewCompat.setStateDescription(sessionView, contentDescriptionFormatter .getStateContentDescription(session, useDeviceTimeZone)) - setSessionBackground(session.highlight, session.track, sessionView) - setSessionTextColor(session.highlight, sessionView) + setSessionBackground(session.isHighlight, session.track, sessionView) + setSessionTextColor(session.isHighlight, sessionView) sessionView.tag = session } diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChanges.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChanges.kt index c33b7e7fa1..810e9d867d 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChanges.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChanges.kt @@ -1,12 +1,12 @@ package nerd.tuxmobil.fahrplan.congress.serialization -import nerd.tuxmobil.fahrplan.congress.models.Session as SessionAppModel +import info.metadude.android.eventfahrplan.network.models.Session as SessionNetworkModel @Suppress("DataClassPrivateConstructor") data class ScheduleChanges private constructor( - val sessionsWithChangeFlags: List, - val oldCanceledSessions: List, + val sessionsWithChangeFlags: List, + val oldCanceledSessions: List, val foundNoteworthyChanges: Boolean, val foundChanges: Boolean, @@ -18,16 +18,16 @@ data class ScheduleChanges private constructor( * Returns a pair of a new list of sessions and two boolean flags indicating whether changes * have been found. [foundNoteworthyChanges] indicates generic changes which are relevant * for the schedule changes screen. [foundChanges] is based on the comparison of all - * session properties. Further, each session is flagged as ["new"][SessionAppModel.changedIsNew], - * ["canceled"][SessionAppModel.changedIsCanceled] or according to the changes detected when + * session properties. Further, each session is flagged as ["new"][SessionNetworkModel.changedIsNew], + * ["canceled"][SessionNetworkModel.changedIsCanceled] or according to the changes detected when * comparing it to its equivalent from the [oldSessions] list. * * This function does not modify the given lists nor any of its elements. */ fun computeSessionsWithChangeFlags( - newSessions: List, - oldSessions: List + newSessions: List, + oldSessions: List ): ScheduleChanges { @@ -40,7 +40,7 @@ data class ScheduleChanges private constructor( val oldNotCanceledSessions = oldSessions.filterNot { it.changedIsCanceled }.toMutableList() val oldCanceledSessions = oldSessions.filter { it.changedIsCanceled } - val sessionsWithChangeFlags = mutableListOf() + val sessionsWithChangeFlags = mutableListOf() var sessionIndex = 0 while (sessionIndex < newSessions.size) { @@ -151,7 +151,7 @@ data class ScheduleChanges private constructor( var changedDuration: Boolean = false ) - private fun SessionAppModel.equalsInNoteworthyProperties(session: SessionAppModel): Boolean { + private fun SessionNetworkModel.equalsInNoteworthyProperties(session: SessionNetworkModel): Boolean { return title == session.title && subtitle == session.subtitle && speakers == session.speakers && @@ -165,20 +165,20 @@ data class ScheduleChanges private constructor( } /** - * Intentionally omit volatile properties such as [SessionAppModel.hasAlarm], - * [SessionAppModel.highlight] which are only relevant for the UI layer. - * Also omit change flags such as [SessionAppModel.changedIsNew]. + * Intentionally omit volatile properties such as [SessionNetworkModel.hasAlarm], + * [SessionNetworkModel.isHighlight] which are only relevant for the UI layer. + * Also omit change flags such as [SessionNetworkModel.changedIsNew]. * - * Once [SessionAppModel] is converted into a Kotlin data class and its properties + * Once [SessionNetworkModel] is converted into a Kotlin data class and its properties * are separated this function can be replaced by an equals comparison. */ - private fun SessionAppModel.equalsContentWise(session: SessionAppModel): Boolean { + private fun SessionNetworkModel.equalsContentWise(session: SessionNetworkModel): Boolean { return equalsInNoteworthyProperties(session) && url == session.url && dateText == session.dateText && dateUTC == session.dateUTC && timeZoneOffset == session.timeZoneOffset && - relStartTime == session.relStartTime && + relativeStartTime == session.relativeStartTime && type == session.type && slug == session.slug && abstractt == session.abstractt && diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/utils/ContentDescriptionFormatter.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/utils/ContentDescriptionFormatter.kt index 7369ef4b0a..6a2f76480f 100644 --- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/utils/ContentDescriptionFormatter.kt +++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/utils/ContentDescriptionFormatter.kt @@ -78,7 +78,7 @@ class ContentDescriptionFormatter(val context: Context) { .newInstance(useDeviceTimeZone) .getFormattedTime(session.dateUTC, session.timeZoneOffset) val startsAtContentDescription = getStartTimeContentDescription(startsAtText) - val isHighlightContentDescription = getHighlightContentDescription(session.highlight) + val isHighlightContentDescription = getHighlightContentDescription(session.isHighlight) return "$isHighlightContentDescription, $startsAtContentDescription, $roomNameContentDescription" } diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatisticTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatisticTest.kt index d49a5b38da..e778c5844e 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatisticTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/changes/ChangeStatisticTest.kt @@ -12,12 +12,12 @@ class ChangeStatisticTest { private val unchangedSessions = listOf( Session( sessionId = "1001", - highlight = false, + isHighlight = false, changedTitle = false, ), Session( sessionId = "1002", - highlight = true, + isHighlight = true, changedTitle = false, ) ) @@ -25,12 +25,12 @@ class ChangeStatisticTest { private val changedSessions = listOf( Session( sessionId = "1003", - highlight = true, + isHighlight = true, changedTitle = true, ), Session( sessionId = "1004", - highlight = false, + isHighlight = false, changedTitle = true, ) ) @@ -38,12 +38,12 @@ class ChangeStatisticTest { private val oldSessions = listOf( Session( sessionId = "2001", - highlight = false, + isHighlight = false, changedIsNew = false, ), Session( sessionId = "2002", - highlight = true, + isHighlight = true, changedIsNew = false, ) ) @@ -51,12 +51,12 @@ class ChangeStatisticTest { private val newSessions = listOf( Session( sessionId = "2003", - highlight = true, + isHighlight = true, changedIsNew = true, ), Session( sessionId = "2004", - highlight = false, + isHighlight = false, changedIsNew = true, ) ) @@ -64,12 +64,12 @@ class ChangeStatisticTest { private val uncanceledSessions = listOf( Session( sessionId = "3001", - highlight = false, + isHighlight = false, changedIsCanceled = false, ), Session( sessionId = "3002", - highlight = true, + isHighlight = true, changedIsCanceled = false, ) ) @@ -77,12 +77,12 @@ class ChangeStatisticTest { private val canceledSessions = listOf( Session( sessionId = "3003", - highlight = true, + isHighlight = true, changedIsCanceled = true, ), Session( sessionId = "3004", - highlight = false, + isHighlight = false, changedIsCanceled = true, ) ) diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightExtensionsTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightExtensionsTest.kt deleted file mode 100644 index 250963829f..0000000000 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/HighlightExtensionsTest.kt +++ /dev/null @@ -1,23 +0,0 @@ -package nerd.tuxmobil.fahrplan.congress.dataconverters - -import com.google.common.truth.Truth.assertThat -import nerd.tuxmobil.fahrplan.congress.models.Highlight -import org.junit.jupiter.api.Test -import info.metadude.android.eventfahrplan.database.models.Highlight as HighlightDatabaseModel - -class HighlightExtensionsTest { - - @Test - fun toHighlightAppModel() { - val highlightDatabaseModel = HighlightDatabaseModel( - sessionId = 2342, - isHighlight = true - ) - val highlightAppModel = Highlight( - sessionId = 2342, - isHighlight = true - ) - assertThat(highlightDatabaseModel.toHighlightAppModel()).isEqualTo(highlightAppModel) - } - -} diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensionsTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensionsTest.kt index 9bef784baf..24b3d56f04 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensionsTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/SessionExtensionsTest.kt @@ -5,7 +5,7 @@ import info.metadude.android.eventfahrplan.commons.temporal.Moment import info.metadude.android.eventfahrplan.database.models.Highlight import info.metadude.android.eventfahrplan.database.models.Session.Companion.RECORDING_OPT_OUT_ON import nerd.tuxmobil.fahrplan.congress.models.DateInfo -import nerd.tuxmobil.fahrplan.congress.models.Session +import nerd.tuxmobil.fahrplan.congress.models.Room import org.junit.jupiter.api.Test import org.threeten.bp.ZoneOffset import info.metadude.android.eventfahrplan.database.models.Session as SessionDatabaseModel @@ -16,7 +16,7 @@ class SessionExtensionsTest { @Test fun `shiftRoomIndexOnDays shifts the room index by 1 if the day index is contained in the given set`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", dayIndex = 3, roomIndex = 17, @@ -29,7 +29,7 @@ class SessionExtensionsTest { @Test fun `shiftRoomIndexOnDays does not shift the room index if the day index is not contained in the given set`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", dayIndex = 3, roomIndex = 17, @@ -42,7 +42,7 @@ class SessionExtensionsTest { @Test fun `shiftRoomIndexOnDays does not shift the room index if the given set is empty`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", dayIndex = 3, roomIndex = 17, @@ -54,12 +54,12 @@ class SessionExtensionsTest { } @Test - fun `toSessionDatabaseModel returns a database session derived from an app session`() { - val session = SessionDatabaseModel( + fun `toSessionAppModel returns an app session derived from a database session`() { + val databaseModel = SessionDatabaseModel( sessionId = "7331", abstractt = "Lorem ipsum", dayIndex = 3, - date = "2015-08-13", + dateText = "2015-08-13", dateUTC = 1439478900000L, description = "Lorem ipsum dolor sit amet", duration = 45, @@ -84,7 +84,7 @@ class SessionExtensionsTest { type = "tutorial", url = "https://talks.mrmcd.net/2018/talk/V3FUNG", - changedDay = true, + changedDayIndex = true, changedDuration = true, changedIsCanceled = true, changedIsNew = true, @@ -92,21 +92,64 @@ class SessionExtensionsTest { changedRecordingOptOut = true, changedRoomName = true, changedSpeakers = true, + changedStartTime = true, changedSubtitle = true, - changedTime = true, changedTitle = true, changedTrack = true ) - assertThat(session.toSessionAppModel().toSessionDatabaseModel()).isEqualTo(session) + + val appModel = SessionAppModel( + sessionId = "7331", + abstractt = "Lorem ipsum", + dayIndex = 3, + dateText = "2015-08-13", + dateUTC = 1439478900000L, + description = "Lorem ipsum dolor sit amet", + duration = 45, + feedbackUrl = "https://talks.mrmcd.net/2018/talk/V3FUNG/feedback", + hasAlarm = true, + isHighlight = true, + language = "en", + links = "[Website](https://www.example.com/path)", + relativeStartTime = 1035, + recordingLicense = "CC 0", + recordingOptOut = RECORDING_OPT_OUT_ON, + roomName = "Simulacron-3", + roomIdentifier = "88888888-4444-4444-4444-121212121212", + roomIndex = 17, + speakers = listOf("John Doe", "Noah Doe"), + startTime = 1036, + slug = "lorem", + subtitle = "My subtitle", + timeZoneOffset = ZoneOffset.ofTotalSeconds(3600), + title = "My title", + track = "Security & Hacking", + type = "tutorial", + url = "https://talks.mrmcd.net/2018/talk/V3FUNG", + + changedDayIndex = true, + changedDuration = true, + changedIsCanceled = true, + changedIsNew = true, + changedLanguage = true, + changedRecordingOptOut = true, + changedRoomName = true, + changedSpeakers = true, + changedSubtitle = true, + changedStartTime = true, + changedTitle = true, + changedTrack = true, + ) + assertThat(databaseModel.toSessionAppModel()).isEqualTo(appModel) } @Test - fun `toSessionAppModel returns an app session derived from a network session`() { - val sessionNetworkModel = SessionNetworkModel( + fun `toSessionDatabaseModel and toSessionNetworkModel convert a network session forth and back`() { + val networkModel = SessionNetworkModel( sessionId = "7331", abstractt = "Lorem ipsum", dayIndex = 3, - date = "2015-08-13", + dateText = "2015-08-13", dateUTC = 1439478900000L, description = "Lorem ipsum dolor sit amet", duration = 45, @@ -121,7 +164,7 @@ class SessionExtensionsTest { roomName = "Simulacron-3", roomGuid = "88888888-4444-4444-4444-121212121212", roomIndex = 17, - speakers = "John Doe;Noah Doe", + speakers = "John Doe; Noah Doe", startTime = 1036, slug = "lorem", subtitle = "My subtitle", @@ -144,54 +187,23 @@ class SessionExtensionsTest { changedTitle = true, changedTrack = true ) - val sessionAppModel = SessionAppModel( - sessionId = "7331", - abstractt = "Lorem ipsum", - dayIndex = 3, - dateText = "2015-08-13", - dateUTC = 1439478900000L, - description = "Lorem ipsum dolor sit amet", - duration = 45, - feedbackUrl = "https://talks.mrmcd.net/2018/talk/V3FUNG/feedback", - hasAlarm = true, - highlight = true, - language = "en", - links = "[Website](https://www.example.com/path)", - relStartTime = 1035, - recordingLicense = "CC 0", - recordingOptOut = RECORDING_OPT_OUT_ON, - roomName = "Simulacron-3", - roomIdentifier = "88888888-4444-4444-4444-121212121212", - roomIndex = 17, - speakers = listOf("John Doe", "Noah Doe"), - startTime = 1036, - slug = "lorem", - subtitle = "My subtitle", - timeZoneOffset = ZoneOffset.ofTotalSeconds(3600), - title = "My title", - track = "Security & Hacking", - type = "tutorial", - url = "https://talks.mrmcd.net/2018/talk/V3FUNG", + assertThat(networkModel.toSessionDatabaseModel().toSessionNetworkModel()).isEqualTo(networkModel) + } - changedDayIndex = true, - changedDuration = true, - changedIsCanceled = true, - changedIsNew = true, - changedLanguage = true, - changedRecordingOptOut = true, - changedRoomName = true, - changedSpeakers = true, - changedSubtitle = true, - changedStartTime = true, - changedTitle = true, - changedTrack = true, + @Test + fun `toRoom returns a Room instance`() { + val session = SessionAppModel( + sessionId = "", + roomIdentifier = "bccb8a5b-a268-4f17-90b9-b5966f5e34d8", + roomName = "Stage F", ) - assertThat(sessionNetworkModel.toSessionAppModel()).isEqualTo(sessionAppModel) + val expectedRoom = Room(identifier = "bccb8a5b-a268-4f17-90b9-b5966f5e34d8", name = "Stage F") + assertThat(session.toRoom()).isEqualTo(expectedRoom) } @Test fun `toDateInfo returns a DateInfo object derived from a session`() { - val session = Session( + val session = SessionDatabaseModel( sessionId = "", dateText = "2015-08-13", dayIndex = 3, @@ -202,17 +214,17 @@ class SessionExtensionsTest { @Test fun `toDayRanges returns a list of day ranges derived from a list of sessions`() { - val session0 = Session( + val session0 = SessionDatabaseModel( sessionId = "", dateText = "2019-08-02", dayIndex = 2, ) - val session1 = Session( + val session1 = SessionDatabaseModel( sessionId = "", dateText = "2019-08-01", dayIndex = 1, ) - val session1Copy = Session( + val session1Copy = SessionDatabaseModel( sessionId = "", dateText = "2019-08-01", dayIndex = 1, @@ -235,9 +247,9 @@ class SessionExtensionsTest { @Test fun `toHighlightDatabaseModel returns a Highlight object derived from a session`() { - val session = Session( + val session = SessionAppModel( sessionId = "4723", - highlight = true, + isHighlight = true, ) val highlight = Highlight(sessionId = 4723, isHighlight = true) assertThat(session.toHighlightDatabaseModel()).isEqualTo(highlight) @@ -245,12 +257,12 @@ class SessionExtensionsTest { @Test fun `sanitize moves the subtitle property value to the title property value if empty`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", subtitle = "Lorem ipsum", title = "", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", subtitle = "", title = "Lorem ipsum", @@ -260,12 +272,12 @@ class SessionExtensionsTest { @Test fun `sanitize clears the subtitle property value if the title property matches`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", subtitle = "Lorem ipsum", title = "Lorem ipsum", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", subtitle = "", title = "Lorem ipsum", @@ -275,12 +287,12 @@ class SessionExtensionsTest { @Test fun `sanitize keeps the subtitle property value if the title property value differs`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", subtitle = "Dolor sit amet", title = "Lorem ipsum", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", subtitle = "Dolor sit amet", title = "Lorem ipsum", @@ -290,66 +302,60 @@ class SessionExtensionsTest { @Test fun `sanitize clears the abstractt property value if the description property matches`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", abstractt = "Lorem ipsum", description = "Lorem ipsum", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", abstractt = "", description = "Lorem ipsum", ) - // The "abstractt" and "description" fields are not part of Session#equals for some reason. - assertThat(session.abstractt).isEqualTo(expected.abstractt) - assertThat(session.description).isEqualTo(expected.description) + assertThat(session).isEqualTo(expected) } @Test fun `sanitize keeps the abstractt property value if the description property value differs`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", abstractt = "Lorem ipsum", description = "Dolor sit amet", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", abstractt = "Lorem ipsum", description = "Dolor sit amet", ) - // The "abstractt" and "description" fields are not part of Session#equals for some reason. - assertThat(session.abstractt).isEqualTo(expected.abstractt) - assertThat(session.description).isEqualTo(expected.description) + assertThat(session).isEqualTo(expected) } @Test fun `sanitize moves the abstractt property value to the description property value if empty`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", abstractt = "Lorem ipsum", description = "", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", abstractt = "", description = "Lorem ipsum", ) - // The "abstractt" and "description" fields are not part of Session#equals for some reason. - assertThat(session.abstractt).isEqualTo(expected.abstractt) - assertThat(session.description).isEqualTo(expected.description) + assertThat(session).isEqualTo(expected) } @Test fun `sanitize clears the subtitle property value if the speakers property value matches`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", - speakers = listOf("Luke Skywalker"), + speakers = "Luke Skywalker", subtitle = "Luke Skywalker", title = "Some title", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", - speakers = listOf("Luke Skywalker"), + speakers = "Luke Skywalker", subtitle = "", title = "Some title", ) @@ -358,29 +364,117 @@ class SessionExtensionsTest { @Test fun `sanitize keeps the subtitle property value if the speakers property value differs`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", - speakers = listOf("Darth Vader"), + speakers = "Darth Vader", subtitle = "Lorem ipsum", title = "Some title", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", - speakers = listOf("Darth Vader"), + speakers = "Darth Vader", subtitle = "Lorem ipsum", title = "Some title", ) assertThat(session).isEqualTo(expected) } + @Test + fun `sanitize converts the language property value to lower case if it is not empty`() { + val session = SessionNetworkModel( + sessionId = "", + language = "EN", + ).sanitize() + val expected = SessionNetworkModel( + sessionId = "", + language = "en", + ) + assertThat(session).isEqualTo(expected) + } + + @Test + fun `sanitize keeps the language property value if it is empty`() { + val session = SessionNetworkModel( + sessionId = "", + language = "", + ).sanitize() + val expected = SessionNetworkModel( + sessionId = "", + language = "", + ) + assertThat(session).isEqualTo(expected) + } + + @Test + fun `sanitize replaces the track property value with the type property value for certain track property values`() { + val session = SessionNetworkModel( + sessionId = "", + track = "Sendezentrum-Bühne", + type = "Live", + ).sanitize() + val expected = SessionNetworkModel( + sessionId = "", + track = "Live", + type = "Live", + ) + assertThat(session).isEqualTo(expected) + } + + @Test + fun `sanitize keeps the track property value if the type property is empty`() { + val session = SessionNetworkModel( + sessionId = "", + track = "Art", + type = "", + ).sanitize() + val expected = SessionNetworkModel( + sessionId = "", + track = "Art", + type = "", + ) + assertThat(session).isEqualTo(expected) + } + + @Test + fun `sanitize replaces the track property value if roomName is classics and type is Other`() { + val session = SessionNetworkModel( + sessionId = "", + roomName = "classics", + track = "", + type = "Other", + ).sanitize() + val expected = SessionNetworkModel( + sessionId = "", + roomName = "classics", + track = "Classics", + type = "Other", + ) + assertThat(session).isEqualTo(expected) + } + + @Test + fun `sanitize replaces the track property value if roomName is rC3 Lounge`() { + val session = SessionNetworkModel( + sessionId = "", + roomName = "rC3 Lounge", + track = "", + ).sanitize() + val expected = SessionNetworkModel( + sessionId = "", + roomName = "rC3 Lounge", + track = "Music", + ) + assertThat(session).isEqualTo(expected) + } + @Test fun `sanitize copies the non-empty type property value to the track property if empty`() { - val session = Session( + val session = SessionNetworkModel( sessionId = "", track = "", type = "Workshop", ).sanitize() - val expected = Session( + val expected = SessionNetworkModel( sessionId = "", track = "Workshop", type = "Workshop", diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensionsTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensionsTest.kt index 0ff0cfd0a7..303d43214e 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensionsTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/dataconverters/ShiftExtensionsTest.kt @@ -76,7 +76,7 @@ class ShiftExtensionsTest { } @Test - fun `toSessionAppModel sessionizes a shift and handles time zone correctly`() { + fun `toSessionNetworkModel sessionizes a shift and handles time zone correctly`() { val day = Moment.parseDate("2019-01-02") val startsAt = day.toZonedDateTime(ZoneOffset.ofHours(4)) // 2019-01-02 04:00 with offset +4 => still 2019-01-02 00:00Z val shift = Shift( @@ -84,19 +84,19 @@ class ShiftExtensionsTest { timeZoneOffset = ZoneOffset.ofHours(2) // for whatever reason someone sets timeZoneOffset different than startsAtDate's offset ) val dayRange = DayRange(day) - val session = shift.toSessionAppModel(NoLogging, "", listOf(dayRange)) + val session = shift.toSessionNetworkModel(NoLogging, "", listOf(dayRange)) assertThat(session.startTime).isEqualTo(0) // nevertheless, we still expect sessions time data to be based on UTC - assertThat(session.relStartTime).isEqualTo(0) + assertThat(session.relativeStartTime).isEqualTo(0) } @Test - fun `toSessionAppModel sessionizes a shift and duration returns correct value in minutes`() { + fun `toSessionNetworkModel sessionizes a shift and duration returns correct value in minutes`() { val day = Moment.parseDate("2019-08-25") val startsAtDate = ZonedDateTime.of(2019, 8, 25, 12, 0, 0, 0, ZoneOffset.UTC) val endsAtDate = ZonedDateTime.of(2019, 8, 25, 12, 30, 13, 0, ZoneOffset.UTC) val dayRange = DayRange(day) val shift = Shift(startsAtDate = startsAtDate, endsAtDate = endsAtDate) - assertThat(shift.toSessionAppModel(NoLogging, "", listOf(dayRange)).duration).isEqualTo(30) + assertThat(shift.toSessionNetworkModel(NoLogging, "", listOf(dayRange)).duration).isEqualTo(30) } } diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModelTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModelTest.kt index 088c0794a7..6ffdbf0a24 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModelTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/details/SessionDetailsViewModelTest.kt @@ -93,7 +93,7 @@ class SessionDetailsViewModelTest { description = "Session description", track = "Session track", links = "[VOC projects](https://www.voc.com/projects/),[POC](https://poc.com/QXut1XBymAk)", - highlight = true, + isHighlight = true, ) val repository = createRepository(selectedSessionFlow = flowOf(session)) val fakeSessionPropertiesFormatter = mock { @@ -169,7 +169,7 @@ class SessionDetailsViewModelTest { description = "", track = "", links = "", - highlight = false, + isHighlight = false, ) val repository = createRepository(selectedSessionFlow = flowOf(session)) val fakeSessionPropertiesFormatter = mock { @@ -287,8 +287,8 @@ class SessionDetailsViewModelTest { @Test fun `favorSession() flags the session as a favorite and persists it`() { - val actualSession = Session(sessionId = "S3", highlight = false) - val expectedSession = Session(sessionId = "S3", highlight = true) + val actualSession = Session(sessionId = "S3", isHighlight = false) + val expectedSession = Session(sessionId = "S3", isHighlight = true) val repository = createRepository(selectedSession = actualSession) val viewModel = createViewModel(repository) viewModel.favorSession() @@ -298,8 +298,8 @@ class SessionDetailsViewModelTest { @Test fun `unfavorSession() unflags the session as a favorite and persists it`() { - val actualSession = Session(sessionId = "S4", highlight = true) - val expectedSession = Session(sessionId = "S4", highlight = false) + val actualSession = Session(sessionId = "S4", isHighlight = true) + val expectedSession = Session(sessionId = "S4", isHighlight = false) val repository = createRepository(selectedSession = actualSession) val viewModel = createViewModel(repository) viewModel.unfavorSession() diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/models/SessionIsChangedTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/models/SessionIsChangedTest.kt new file mode 100644 index 0000000000..017193c8a3 --- /dev/null +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/models/SessionIsChangedTest.kt @@ -0,0 +1,91 @@ +package nerd.tuxmobil.fahrplan.congress.models + +import com.google.common.truth.Truth.assertThat +import org.junit.jupiter.api.Test + +/** + * Covers [Session.isChanged]. + */ +class SessionIsChangedTest { + + @Test + fun `a default session is not marked as changed`() { + val session = createSession() + assertThat(session.isChanged).isFalse() + } + + @Test + fun `changedTitle = true marks a session as changed`() { + val session = createSession().copy(changedTitle = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedSubtitle = true marks a session as changed`() { + val session = createSession().copy(changedSubtitle = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedRoomName = true marks a session as changed`() { + val session = createSession().copy(changedRoomName = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedDayIndex = true marks a session as changed`() { + val session = createSession().copy(changedDayIndex = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedStartTime = true marks a session as changed`() { + val session = createSession().copy(changedStartTime = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedDuration = true marks a session as changed`() { + val session = createSession().copy(changedDuration = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedSpeakers = true marks a session as changed`() { + val session = createSession().copy(changedSpeakers = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedLanguage = true marks a session as changed`() { + val session = createSession().copy(changedLanguage = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedRecordingOptOut = true marks a session as changed`() { + val session = createSession().copy(changedRecordingOptOut = true) + assertThat(session.isChanged).isTrue() + } + + @Test + fun `changedTrack = true marks a session as changed`() { + val session = createSession().copy(changedTrack = true) + assertThat(session.isChanged).isTrue() + } + + private fun createSession() = Session( + sessionId = "", + changedTitle = false, + changedSubtitle = false, + changedRoomName = false, + changedDayIndex = false, + changedStartTime = false, + changedDuration = false, + changedSpeakers = false, + changedLanguage = false, + changedRecordingOptOut = false, + changedTrack = false, + ) + +} diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/models/SessionTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/models/SessionTest.kt index 811db5b507..41ef2e55d8 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/models/SessionTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/models/SessionTest.kt @@ -33,13 +33,13 @@ class SessionTest { // Not considered in equal nor hashCode. url = "https://example.com", - relStartTime = 500, + relativeStartTime = 500, roomIndex = 6, slug = "lorem-ipsum", abstractt = "Sodales ut etiam sit amet nisl purus", description = "Lorem ipsum dolor sit amet", links = "http://sample.com", - highlight = true, + isHighlight = true, hasAlarm = true, // Not considered in equal nor hashCode, too. @@ -59,13 +59,13 @@ class SessionTest { fun createSessionModifyingNonConsideredFields() = createSession().copy( url = "https://foobar-url.org", - relStartTime = 999, + relativeStartTime = 999, roomIndex = 13, slug = "foo-bar", abstractt = "Foo abstract", description = "Foo description", links = "https://foobar-links.org", - highlight = false, + isHighlight = false, hasAlarm = false, changedTitle = false, @@ -165,43 +165,6 @@ class SessionTest { assertThat(session1.hashCode()).isEqualTo(session2.hashCode()) } - @Test - fun `cancel marks a session as canceled and resets all change other flags`() { - val session = Session( - sessionId = "0", - changedTitle = true, - changedSubtitle = true, - changedRoomName = true, - changedDayIndex = true, - changedStartTime = true, - changedDuration = true, - changedSpeakers = true, - changedRecordingOptOut = true, - changedLanguage = true, - changedTrack = true, - changedIsNew = true, - changedIsCanceled = false, - ) - val comparableCanceledSession = Session( - sessionId = "0", - changedTitle = false, - changedSubtitle = false, - changedRoomName = false, - changedDayIndex = false, - changedStartTime = false, - changedDuration = false, - changedSpeakers = false, - changedRecordingOptOut = false, - changedLanguage = false, - changedTrack = false, - changedIsNew = false, - changedIsCanceled = true, - ) - val canceledSession = session.cancel() - assertThat(canceledSession).isEqualTo(comparableCanceledSession) - assertThat(canceledSession).isNotSameInstanceAs(session) - } - @Test fun `startsAt returns the start date converted to Moment`() { val session = Session(sessionId = "", dateUTC = 1582963200000L) diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryLoadAndParseScheduleTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryLoadAndParseScheduleTest.kt index b809639d9b..6f230317ac 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryLoadAndParseScheduleTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryLoadAndParseScheduleTest.kt @@ -236,7 +236,7 @@ class AppRepositoryLoadAndParseScheduleTest { private suspend fun assertStarredSessionsProperty() { testableAppRepository.starredSessions.test { - val session = AppSession(sessionId = "55", highlight = true) + val session = AppSession(sessionId = "55", isHighlight = true) assertThat(awaitItem()).isEqualTo(listOf(session)) } } @@ -245,7 +245,7 @@ class AppRepositoryLoadAndParseScheduleTest { testableAppRepository.changedSessions.test { val session = AppSession( sessionId = "55", - highlight = true, + isHighlight = true, changedLanguage = true, ) assertThat(awaitItem()).isEqualTo(listOf(session)) diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryMetaTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryMetaTest.kt index a7949c008a..a789545ecd 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryMetaTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositoryMetaTest.kt @@ -20,8 +20,6 @@ import org.mockito.kotlin.mock import org.threeten.bp.ZoneId import info.metadude.android.eventfahrplan.database.models.HttpHeader as HttpHeaderDatabaseModel import info.metadude.android.eventfahrplan.database.models.Meta as MetaDatabaseModel -import info.metadude.android.eventfahrplan.network.models.HttpHeader as HttpHeaderNetworkModel -import info.metadude.android.eventfahrplan.network.models.Meta as MetaNetworkModel import nerd.tuxmobil.fahrplan.congress.models.HttpHeader as HttpHeaderAppModel import nerd.tuxmobil.fahrplan.congress.models.Meta as MetaAppModel @@ -65,7 +63,7 @@ class AppRepositoryMetaTest { @Test fun `meta emits empty Meta model`() = runTest { - testableAppRepository.updateMeta(MetaNetworkModel()) + testableAppRepository.updateMeta(MetaDatabaseModel()) val expected = MetaAppModel() testableAppRepository.meta.test { val actual = awaitItem() @@ -75,13 +73,13 @@ class AppRepositoryMetaTest { @Test fun `meta emits custom Meta model`() = runTest { - testableAppRepository.updateMeta(MetaNetworkModel( + testableAppRepository.updateMeta(MetaDatabaseModel( numDays = 4, version = "1.2.3", timeZoneName = "Europe/Berlin", title = "37C3", subtitle = "Unlocked", - httpHeader = HttpHeaderNetworkModel(eTag = "abc", lastModified = "9000"), + httpHeader = HttpHeaderDatabaseModel(eTag = "abc", lastModified = "9000"), )) val expected = MetaAppModel( numDays = 4, diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositorySessionsTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositorySessionsTest.kt index a9c977e780..013daf6833 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositorySessionsTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/repositories/AppRepositorySessionsTest.kt @@ -7,14 +7,15 @@ import info.metadude.android.eventfahrplan.commons.testing.verifyInvokedOnce import info.metadude.android.eventfahrplan.database.repositories.SessionsDatabaseRepository import kotlinx.coroutines.test.runTest import nerd.tuxmobil.fahrplan.congress.TestExecutionContext -import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionsDatabaseModel -import nerd.tuxmobil.fahrplan.congress.models.Session +import nerd.tuxmobil.fahrplan.congress.dataconverters.toSessionAppModel import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever +import info.metadude.android.eventfahrplan.database.models.Session as SessionDatabaseModel +import nerd.tuxmobil.fahrplan.congress.models.Session as SessionAppModel /** * Test class to deal with sessions which interact with the [SessionsDatabaseRepository]. @@ -47,71 +48,71 @@ class AppRepositorySessionsTest { companion object { - private val SESSION_1001 = Session( + private val SESSION_1001 = SessionDatabaseModel( sessionId = "1001", changedIsCanceled = false, changedTitle = false, changedIsNew = false, ) - private val SESSION_1002 = Session( + private val SESSION_1002 = SessionDatabaseModel( sessionId = "1002", changedIsCanceled = true, changedTitle = false, changedIsNew = false, ) - private val SESSION_1003 = Session( + private val SESSION_1003 = SessionDatabaseModel( sessionId = "1003", changedIsCanceled = false, changedTitle = true, changedIsNew = false, ) - private val SESSION_1004 = Session( + private val SESSION_1004 = SessionDatabaseModel( sessionId = "1004", changedIsCanceled = false, changedTitle = false, changedIsNew = true, ) - private val SESSION_1005 = Session( + private val SESSION_1005 = SessionDatabaseModel( sessionId = "1005", changedIsCanceled = true, changedTitle = true, changedIsNew = true, ) - private val SESSION_2001 = Session( + private val SESSION_2001 = SessionDatabaseModel( sessionId = "2001", - highlight = false, + isHighlight = false, changedIsCanceled = false, ) - private val SESSION_2002 = Session( + private val SESSION_2002 = SessionDatabaseModel( sessionId = "2002", - highlight = true, + isHighlight = true, changedIsCanceled = false, ) - private val SESSION_2003 = Session( + private val SESSION_2003 = SessionDatabaseModel( sessionId = "2003", - highlight = true, + isHighlight = true, changedIsCanceled = true, ) - private val SESSION_2004 = Session( + private val SESSION_2004 = SessionDatabaseModel( sessionId = "2004", - highlight = false, + isHighlight = false, changedIsCanceled = true, ) - private val SESSION_3001 = Session( + private val SESSION_3001 = SessionDatabaseModel( sessionId = "3001", changedIsCanceled = false, ) - private val SESSION_3002 = Session( + private val SESSION_3002 = SessionDatabaseModel( sessionId = "3002", changedIsCanceled = true, ) @@ -128,7 +129,7 @@ class AppRepositorySessionsTest { @Test fun `loadChangedSessions filters out sessions which are not changed`() { val sessions = listOf(SESSION_1001, SESSION_1002, SESSION_1003, SESSION_1004, SESSION_1005) - whenever(sessionsDatabaseRepository.querySessionsOrderedByDateUtc()) doReturn sessions.toSessionsDatabaseModel() + whenever(sessionsDatabaseRepository.querySessionsOrderedByDateUtc()) doReturn sessions val changedSessions = testableAppRepository.loadChangedSessions() assertThat(changedSessions).containsExactly(SESSION_1002, SESSION_1003, SESSION_1004, SESSION_1005) verifyInvokedOnce(sessionsDatabaseRepository).querySessionsOrderedByDateUtc() @@ -138,7 +139,7 @@ class AppRepositorySessionsTest { fun `loadStarredSessions passes through an empty list`() = runTest { whenever(sessionsDatabaseRepository.querySessionsOrderedByDateUtc()) doReturn emptyList() testableAppRepository.starredSessions.test { - assertThat(awaitItem()).isEqualTo(emptyList()) + assertThat(awaitItem()).isEqualTo(emptyList()) } verifyInvokedOnce(sessionsDatabaseRepository).querySessionsOrderedByDateUtc() } @@ -146,9 +147,9 @@ class AppRepositorySessionsTest { @Test fun `loadStarredSessions filters out sessions which are not starred`() = runTest { val sessions = listOf(SESSION_2001, SESSION_2002, SESSION_2003, SESSION_2004) - whenever(sessionsDatabaseRepository.querySessionsOrderedByDateUtc()) doReturn sessions.toSessionsDatabaseModel() + whenever(sessionsDatabaseRepository.querySessionsOrderedByDateUtc()) doReturn sessions testableAppRepository.starredSessions.test { - assertThat(awaitItem()).containsExactly(SESSION_2002) + assertThat(awaitItem()).containsExactly(SESSION_2002.toSessionAppModel()) } verifyInvokedOnce(sessionsDatabaseRepository).querySessionsOrderedByDateUtc() } @@ -163,7 +164,7 @@ class AppRepositorySessionsTest { @Test fun `loadUncanceledSessionsForDayIndex filters out sessions which are canceled`() { val sessions = listOf(SESSION_3001, SESSION_3002) - whenever(sessionsDatabaseRepository.querySessionsForDayIndexOrderedByDateUtc(any())) doReturn sessions.toSessionsDatabaseModel() + whenever(sessionsDatabaseRepository.querySessionsForDayIndexOrderedByDateUtc(any())) doReturn sessions val uncanceledSessions = testableAppRepository.loadUncanceledSessionsForDayIndex(0) assertThat(uncanceledSessions).containsExactly(SESSION_3001) verifyInvokedOnce(sessionsDatabaseRepository).querySessionsForDayIndexOrderedByDateUtc(any()) diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanViewModelTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanViewModelTest.kt index 42bfb5c422..286e3c0167 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanViewModelTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanViewModelTest.kt @@ -33,7 +33,6 @@ import nerd.tuxmobil.fahrplan.congress.schedule.observables.ScrollToSessionParam import nerd.tuxmobil.fahrplan.congress.schedule.observables.TimeTextViewParameter import nerd.tuxmobil.fahrplan.congress.sharing.JsonSessionFormat import nerd.tuxmobil.fahrplan.congress.sharing.SimpleSessionFormat -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculatorTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculatorTest.kt index c406cd452c..521ba36a2c 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculatorTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/LayoutCalculatorTest.kt @@ -20,7 +20,7 @@ class LayoutCalculatorTest { val dateUTC = Moment.parseDate(date).plusMinutes(startTime.toLong()) session = session.copy(dateUTC = dateUTC.toMilliseconds()) } else { - session = session.copy(relStartTime = startTime) + session = session.copy(relativeStartTime = startTime) } return session diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModelTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModelTest.kt index b2d8fd56b1..0062a07ab0 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModelTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/MainViewModelTest.kt @@ -13,7 +13,6 @@ import nerd.tuxmobil.fahrplan.congress.TestExecutionContext import nerd.tuxmobil.fahrplan.congress.changes.ChangeStatistic import nerd.tuxmobil.fahrplan.congress.models.Alarm import nerd.tuxmobil.fahrplan.congress.models.Meta -import nerd.tuxmobil.fahrplan.congress.models.Session import nerd.tuxmobil.fahrplan.congress.net.HttpStatus import nerd.tuxmobil.fahrplan.congress.net.ParseResult import nerd.tuxmobil.fahrplan.congress.notifications.NotificationHelper @@ -34,6 +33,8 @@ import org.junit.jupiter.api.extension.ExtendWith import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock +import info.metadude.android.eventfahrplan.database.models.Session as SessionDatabaseModel +import nerd.tuxmobil.fahrplan.congress.models.Session as SessionAppModel @ExtendWith(MainDispatcherTestExtension::class) class MainViewModelTest { @@ -228,13 +229,13 @@ class MainViewModelTest { val repository = createRepository( loadScheduleStateFlow = flowOf(ParseSuccess), scheduleChangesSeen = false, - changedSessions = listOf(Session(sessionId = "changed-01", changedIsNew = true)) + changedSessions = listOf(SessionDatabaseModel(sessionId = "changed-01", changedIsNew = true)) ) val viewModel = createViewModel(repository) viewModel.loadScheduleUiState.test { assertThat(awaitItem()).isEqualTo(LoadScheduleUiState.Success.ParseSuccess) } - val expectedSessions = listOf(Session(sessionId = "changed-01", changedIsNew = true)) + val expectedSessions = listOf(SessionAppModel(sessionId = "changed-01", changedIsNew = true)) val expectedChangeStatistic = ChangeStatistic.of(expectedSessions, logging) val expectedScheduleChangesParameter = ScheduleChangesParameter(scheduleVersion = "", expectedChangeStatistic) viewModel.scheduleChangesParameter.test { @@ -369,7 +370,7 @@ class MainViewModelTest { private fun createRepository( loadScheduleStateFlow: Flow = emptyFlow(), scheduleChangesSeen: Boolean = true, - changedSessions: List = emptyList(), + changedSessions: List = emptyList(), updatedSelectedSessionId: Boolean = false, alarms: List = emptyList() ) = mock { diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/ScrollAmountCalculatorTimeZoneOffsetTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/ScrollAmountCalculatorTimeZoneOffsetTest.kt index a9624573f7..087c973788 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/ScrollAmountCalculatorTimeZoneOffsetTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/schedule/ScrollAmountCalculatorTimeZoneOffsetTest.kt @@ -78,7 +78,7 @@ class ScrollAmountCalculatorTimeZoneOffsetTest { dateText = moment.toZonedDateTime(ZoneOffset.UTC).toLocalDate().toString(), dateUTC = moment.toMilliseconds(), startTime = moment.minuteOfDay, - relStartTime = moment.minuteOfDay, // This might now always be the case, see ParserTask.parseFahrplan + relativeStartTime = moment.minuteOfDay, // This might now always be the case, see ParserTask.parseFahrplan duration = 60, roomName = "Main hall", ) diff --git a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChangesTest.kt b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChangesTest.kt index 609ca8f6c2..3b7a19e6ad 100644 --- a/app/src/test/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChangesTest.kt +++ b/app/src/test/java/nerd/tuxmobil/fahrplan/congress/serialization/ScheduleChangesTest.kt @@ -1,12 +1,11 @@ package nerd.tuxmobil.fahrplan.congress.serialization import com.google.common.truth.Truth.assertThat -import nerd.tuxmobil.fahrplan.congress.models.Session +import info.metadude.android.eventfahrplan.network.models.Session import nerd.tuxmobil.fahrplan.congress.serialization.ScheduleChanges.Companion.computeSessionsWithChangeFlags import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource -import org.threeten.bp.ZoneOffset class ScheduleChangesTest { @@ -80,7 +79,7 @@ class ScheduleChangesTest { sessionId = "", title = "title", subtitle = "subtitle", - speakers = listOf("speakers"), + speakers = "speakers", language = "language", roomName = "room", recordingOptOut = true, @@ -94,7 +93,7 @@ class ScheduleChangesTest { sessionId = "", title = "title", subtitle = "subtitle", - speakers = listOf("speakers"), + speakers = "speakers", language = "language", roomName = "room", recordingOptOut = true, @@ -108,7 +107,7 @@ class ScheduleChangesTest { sessionId = "", title = "title", subtitle = "subtitle", - speakers = listOf("speakers"), + speakers = "speakers", language = "language", roomName = "room", recordingOptOut = true, @@ -140,10 +139,10 @@ class ScheduleChangesTest { ), scenario1Of( scenarioDescription = "Speakers differ", - oldSessions = listOf(Session("1", speakers = listOf("Old speakers"))), - newSessions = listOf(Session("1", speakers = listOf("New speakers"))), + oldSessions = listOf(Session("1", speakers = "Old speakers")), + newSessions = listOf(Session("1", speakers = "New speakers")), expectedSessions = listOf( - Session("1", speakers = listOf("New speakers"), changedSpeakers = true) + Session("1", speakers = "New speakers", changedSpeakers = true) ), expectedOldCanceledSessions = emptyList(), expectedFoundNoteworthyChanges = true, @@ -151,15 +150,15 @@ class ScheduleChangesTest { scenario1Of( scenarioDescription = "Speakers differ in order", oldSessions = listOf( - Session(sessionId = "1", speakers = listOf("speaker1", "speaker2", "speaker3")) + Session(sessionId = "1", speakers = "speaker1, speaker2, speaker3") ), newSessions = listOf( - Session(sessionId = "1", speakers = listOf("speaker3", "speaker1", "speaker2")) + Session(sessionId = "1", speakers = "speaker3, speaker1, speaker2") ), expectedSessions = listOf( Session( sessionId = "1", - speakers = listOf("speaker3", "speaker1", "speaker2"), + speakers = "speaker3, speaker1, speaker2", changedSpeakers = true ) ), @@ -246,7 +245,7 @@ class ScheduleChangesTest { sessionId = "1", title = "Old title", subtitle = "Old subtitle", - speakers = listOf("Old speakers"), + speakers = "Old speakers", language = "Old language", roomName = "Old room", dayIndex = 2, @@ -271,7 +270,7 @@ class ScheduleChangesTest { sessionId = "1", title = "New title", subtitle = "New subtitle", - speakers = listOf("New speakers"), + speakers = "New speakers", language = "New language", roomName = "New room", dayIndex = 3, @@ -296,7 +295,7 @@ class ScheduleChangesTest { sessionId = "1", title = "New title", subtitle = "New subtitle", - speakers = listOf("New speakers"), + speakers = "New speakers", language = "New language", roomName = "New room", dayIndex = 3, @@ -353,18 +352,18 @@ class ScheduleChangesTest { ), scenario2Of( scenarioDescription = "Time zone offsets differ", - oldSessions = listOf(Session("1", timeZoneOffset = ZoneOffset.of("+02:00"))), - newSessions = listOf(Session("1", timeZoneOffset = ZoneOffset.of("+01:00"))), - expectedSessions = listOf(Session("1", timeZoneOffset = ZoneOffset.of("+01:00"))), + oldSessions = listOf(Session("1", timeZoneOffset = 2)), + newSessions = listOf(Session("1", timeZoneOffset = 1)), + expectedSessions = listOf(Session("1", timeZoneOffset = 1)), expectedOldCanceledSessions = emptyList(), expectedFoundNoteworthyChanges = false, expectedFoundChanges = true, ), scenario2Of( scenarioDescription = "Relative start times differ", - oldSessions = listOf(Session("1", relStartTime = 500)), - newSessions = listOf(Session("1", relStartTime = 600)), - expectedSessions = listOf(Session("1", relStartTime = 600)), + oldSessions = listOf(Session("1", relativeStartTime = 500)), + newSessions = listOf(Session("1", relativeStartTime = 600)), + expectedSessions = listOf(Session("1", relativeStartTime = 600)), expectedOldCanceledSessions = emptyList(), expectedFoundNoteworthyChanges = false, expectedFoundChanges = true, diff --git a/database/build.gradle b/database/build.gradle index a56d34064e..c3e86a5cc0 100644 --- a/database/build.gradle +++ b/database/build.gradle @@ -52,4 +52,9 @@ dependencies { androidTestRuntimeOnly Libs.androidTestRunner androidTestImplementation Libs.junitJupiterApi androidTestImplementation Libs.truth + + testImplementation Libs.junitJupiterApi + testRuntimeOnly Libs.junitJupiterEngine + testImplementation Libs.junitJupiterParams + testImplementation Libs.truth } diff --git a/database/src/androidTest/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensionsTest.kt b/database/src/androidTest/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensionsTest.kt index d83c3dc765..7d23b98531 100644 --- a/database/src/androidTest/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensionsTest.kt +++ b/database/src/androidTest/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensionsTest.kt @@ -2,7 +2,7 @@ package info.metadude.android.eventfahrplan.database.extensions import com.google.common.truth.Truth.assertThat import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.ABSTRACT -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY_INDEX import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DURATION import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_CANCELED import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_NEW @@ -11,10 +11,10 @@ import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.Se import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_ROOM_NAME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SPEAKERS import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SUBTITLE -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TIME +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_START_TIME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TITLE import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TRACK -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_TEXT import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_UTC import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DAY import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DESCR @@ -48,7 +48,7 @@ class SessionExtensionsTest { sessionId = "7331", abstractt = "Lorem ipsum", dayIndex = 3, - date = "2015-08-13", + dateText = "2015-08-13", dateUTC = 1439478900000L, description = "Lorem ipsum dolor sit amet", duration = 45, @@ -72,7 +72,7 @@ class SessionExtensionsTest { type = "tutorial", url = "https://talks.mrmcd.net/2018/talk/V3FUNG", - changedDay = true, + changedDayIndex = true, changedDuration = true, changedIsCanceled = true, changedIsNew = true, @@ -80,8 +80,8 @@ class SessionExtensionsTest { changedRecordingOptOut = true, changedRoomName = true, changedSpeakers = true, + changedStartTime = true, changedSubtitle = true, - changedTime = true, changedTitle = true, changedTrack = true ) @@ -89,7 +89,7 @@ class SessionExtensionsTest { assertThat(values.getAsInteger(SESSION_ID)).isEqualTo(7331) assertThat(values.getAsString(ABSTRACT)).isEqualTo("Lorem ipsum") assertThat(values.getAsInteger(DAY)).isEqualTo(3) - assertThat(values.getAsString(DATE)).isEqualTo("2015-08-13") + assertThat(values.getAsString(DATE_TEXT)).isEqualTo("2015-08-13") assertThat(values.getAsLong(DATE_UTC)).isEqualTo(1439478900000L) assertThat(values.getAsString(DESCR)).isEqualTo("Lorem ipsum dolor sit amet") assertThat(values.getAsInteger(DURATION)).isEqualTo(45) @@ -113,7 +113,7 @@ class SessionExtensionsTest { assertThat(values.getAsString(TYPE)).isEqualTo("tutorial") assertThat(values.getAsString(URL)).isEqualTo("https://talks.mrmcd.net/2018/talk/V3FUNG") - assertThat(values.getAsBoolean(CHANGED_DAY)).isEqualTo(true) + assertThat(values.getAsBoolean(CHANGED_DAY_INDEX)).isEqualTo(true) assertThat(values.getAsBoolean(CHANGED_DURATION)).isEqualTo(true) assertThat(values.getAsBoolean(CHANGED_IS_CANCELED)).isEqualTo(true) assertThat(values.getAsBoolean(CHANGED_IS_NEW)).isEqualTo(true) @@ -122,7 +122,7 @@ class SessionExtensionsTest { assertThat(values.getAsBoolean(CHANGED_ROOM_NAME)).isEqualTo(true) assertThat(values.getAsBoolean(CHANGED_SPEAKERS)).isEqualTo(true) assertThat(values.getAsBoolean(CHANGED_SUBTITLE)).isEqualTo(true) - assertThat(values.getAsBoolean(CHANGED_TIME)).isEqualTo(true) + assertThat(values.getAsBoolean(CHANGED_START_TIME)).isEqualTo(true) assertThat(values.getAsBoolean(CHANGED_TITLE)).isEqualTo(true) assertThat(values.getAsBoolean(CHANGED_TRACK)).isEqualTo(true) } diff --git a/database/src/main/java/info/metadude/android/eventfahrplan/database/contract/FahrplanContract.java b/database/src/main/java/info/metadude/android/eventfahrplan/database/contract/FahrplanContract.java index c0f2e9be81..a2c8037b75 100644 --- a/database/src/main/java/info/metadude/android/eventfahrplan/database/contract/FahrplanContract.java +++ b/database/src/main/java/info/metadude/android/eventfahrplan/database/contract/FahrplanContract.java @@ -104,7 +104,7 @@ interface Columns extends BaseColumns { /* 11 */ String ABSTRACT = "abstract"; /* 12 */ String DESCR = "descr"; /* 13 */ String REL_START = "relStart"; - /* 14 */ String DATE = "date"; + /* 14 */ String DATE_TEXT = "date"; /* 15 */ String LINKS = "links"; /* 16 */ String DATE_UTC = "dateUTC"; /* 17 */ String ROOM_INDEX = "room_idx"; @@ -113,13 +113,13 @@ interface Columns extends BaseColumns { /* 20 */ String CHANGED_TITLE = "changed_title"; /* 21 */ String CHANGED_SUBTITLE = "changed_subtitle"; /* 22 */ String CHANGED_ROOM_NAME = "changed_room"; - /* 23 */ String CHANGED_DAY = "changed_day"; + /* 23 */ String CHANGED_DAY_INDEX = "changed_day"; /* 24 */ String CHANGED_SPEAKERS = "changed_speakers"; /* 25 */ String CHANGED_RECORDING_OPTOUT = "changed_recording_optout"; /* 26 */ String CHANGED_LANGUAGE = "changed_language"; /* 27 */ String CHANGED_TRACK = "changed_track"; /* 28 */ String CHANGED_IS_NEW = "changed_is_new"; - /* 29 */ String CHANGED_TIME = "changed_time"; + /* 29 */ String CHANGED_START_TIME = "changed_time"; /* 30 */ String CHANGED_DURATION = "changed_duration"; /* 31 */ String CHANGED_IS_CANCELED = "changed_is_canceled"; /* 32 */ String SLUG = "slug"; diff --git a/database/src/main/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensions.kt b/database/src/main/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensions.kt index 07c4cac21b..d1a1d6e022 100644 --- a/database/src/main/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensions.kt +++ b/database/src/main/java/info/metadude/android/eventfahrplan/database/extensions/SessionExtensions.kt @@ -4,7 +4,7 @@ import android.content.ContentValues import androidx.core.content.contentValuesOf import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionByNotificationIdTable import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.ABSTRACT -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY_INDEX import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DURATION import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_CANCELED import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_NEW @@ -13,10 +13,10 @@ import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.Se import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_ROOM_NAME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SPEAKERS import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SUBTITLE -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TIME +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_START_TIME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TITLE import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TRACK -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_TEXT import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_UTC import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DAY import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DESCR @@ -48,7 +48,7 @@ fun Session.toContentValues() = contentValuesOf( SESSION_ID to sessionId, ABSTRACT to abstractt, DAY to dayIndex, - DATE to date, + DATE_TEXT to dateText, DATE_UTC to dateUTC, DESCR to description, DURATION to duration, @@ -71,7 +71,7 @@ fun Session.toContentValues() = contentValuesOf( TYPE to type, URL to url, - CHANGED_DAY to changedDay, + CHANGED_DAY_INDEX to changedDayIndex, CHANGED_DURATION to changedDuration, CHANGED_IS_CANCELED to changedIsCanceled, CHANGED_IS_NEW to changedIsNew, @@ -79,8 +79,8 @@ fun Session.toContentValues() = contentValuesOf( CHANGED_RECORDING_OPTOUT to changedRecordingOptOut, CHANGED_ROOM_NAME to changedRoomName, CHANGED_SPEAKERS to changedSpeakers, + CHANGED_START_TIME to changedStartTime, CHANGED_SUBTITLE to changedSubtitle, - CHANGED_TIME to changedTime, CHANGED_TITLE to changedTitle, CHANGED_TRACK to changedTrack ) diff --git a/database/src/main/java/info/metadude/android/eventfahrplan/database/models/Session.kt b/database/src/main/java/info/metadude/android/eventfahrplan/database/models/Session.kt index eb3598059f..bae21ffe21 100644 --- a/database/src/main/java/info/metadude/android/eventfahrplan/database/models/Session.kt +++ b/database/src/main/java/info/metadude/android/eventfahrplan/database/models/Session.kt @@ -8,7 +8,7 @@ data class Session( val sessionId: String, val abstractt: String = "", val dayIndex: Int = 0, // XML values start with 1 - val date: String = "", + val dateText: String = "", val dateUTC: Long = 0, val description: String = "", val duration: Int = 0, // minutes @@ -33,7 +33,7 @@ data class Session( val type: String = "", val url: String = "", - val changedDay: Boolean = false, + val changedDayIndex: Boolean = false, val changedDuration: Boolean = false, val changedIsCanceled: Boolean = false, val changedIsNew: Boolean = false, @@ -41,8 +41,8 @@ data class Session( val changedRecordingOptOut: Boolean = false, val changedRoomName: Boolean = false, val changedSpeakers: Boolean = false, + val changedStartTime: Boolean = false, val changedSubtitle: Boolean = false, - val changedTime: Boolean = false, val changedTitle: Boolean = false, val changedTrack: Boolean = false @@ -53,4 +53,19 @@ data class Session( const val RECORDING_OPT_OUT_OFF = false } + /** + * Keep in sync with [nerd.tuxmobil.fahrplan.congress.models.Session.isChanged]. + */ + val isChanged: Boolean + get() = changedTitle || + changedSubtitle || + changedRoomName || + changedDayIndex || + changedStartTime || + changedDuration || + changedSpeakers || + changedLanguage || + changedRecordingOptOut || + changedTrack + } diff --git a/database/src/main/java/info/metadude/android/eventfahrplan/database/repositories/RealSessionsDatabaseRepository.kt b/database/src/main/java/info/metadude/android/eventfahrplan/database/repositories/RealSessionsDatabaseRepository.kt index 08c1dc8702..166404b6f5 100644 --- a/database/src/main/java/info/metadude/android/eventfahrplan/database/repositories/RealSessionsDatabaseRepository.kt +++ b/database/src/main/java/info/metadude/android/eventfahrplan/database/repositories/RealSessionsDatabaseRepository.kt @@ -9,7 +9,7 @@ import info.metadude.android.eventfahrplan.commons.logging.Logging import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionByNotificationIdTable import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.ABSTRACT -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY_INDEX import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DURATION import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_CANCELED import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_NEW @@ -18,10 +18,10 @@ import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.Se import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_ROOM_NAME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SPEAKERS import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SUBTITLE -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TIME +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_START_TIME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TITLE import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TRACK -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_TEXT import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_UTC import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DAY import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DESCR @@ -201,7 +201,7 @@ internal class RealSessionsDatabaseRepository( Session( sessionId = cursor.getString(SESSION_ID), abstractt = cursor.getString(ABSTRACT), - date = cursor.getString(DATE), + dateText = cursor.getString(DATE_TEXT), dateUTC = cursor.getLong(DATE_UTC), dayIndex = cursor.getInt(DAY), description = cursor.getString(DESCR), @@ -224,7 +224,7 @@ internal class RealSessionsDatabaseRepository( type = cursor.getString(TYPE), url = cursor.getString(URL), recordingOptOut = recordingOptOut, - changedDay = cursor.getInt(CHANGED_DAY).isChanged, + changedDayIndex = cursor.getInt(CHANGED_DAY_INDEX).isChanged, changedDuration = cursor.getInt(CHANGED_DURATION).isChanged, changedIsCanceled = cursor.getInt(CHANGED_IS_CANCELED).isChanged, changedIsNew = cursor.getInt(CHANGED_IS_NEW).isChanged, @@ -232,8 +232,8 @@ internal class RealSessionsDatabaseRepository( changedRecordingOptOut = cursor.getInt(CHANGED_RECORDING_OPTOUT).isChanged, changedRoomName = cursor.getInt(CHANGED_ROOM_NAME).isChanged, changedSpeakers = cursor.getInt(CHANGED_SPEAKERS).isChanged, + changedStartTime = cursor.getInt(CHANGED_START_TIME).isChanged, changedSubtitle = cursor.getInt(CHANGED_SUBTITLE).isChanged, - changedTime = cursor.getInt(CHANGED_TIME).isChanged, changedTitle = cursor.getInt(CHANGED_TITLE).isChanged, changedTrack = cursor.getInt(CHANGED_TRACK).isChanged ) diff --git a/database/src/main/java/info/metadude/android/eventfahrplan/database/sqliteopenhelper/SessionsDBOpenHelper.kt b/database/src/main/java/info/metadude/android/eventfahrplan/database/sqliteopenhelper/SessionsDBOpenHelper.kt index 45e5dbd5d5..0891a02408 100644 --- a/database/src/main/java/info/metadude/android/eventfahrplan/database/sqliteopenhelper/SessionsDBOpenHelper.kt +++ b/database/src/main/java/info/metadude/android/eventfahrplan/database/sqliteopenhelper/SessionsDBOpenHelper.kt @@ -8,7 +8,7 @@ import androidx.core.database.sqlite.transaction import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionByNotificationIdTable import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.ABSTRACT -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DAY_INDEX import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_DURATION import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_CANCELED import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_IS_NEW @@ -16,11 +16,11 @@ import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.Se import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_RECORDING_OPTOUT import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_ROOM_NAME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SPEAKERS +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_START_TIME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_SUBTITLE -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TIME import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TITLE import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.CHANGED_TRACK -import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE +import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_TEXT import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DATE_UTC import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DAY import info.metadude.android.eventfahrplan.database.contract.FahrplanContract.SessionsTable.Columns.DESCR @@ -82,7 +82,7 @@ internal class SessionsDBOpenHelper(context: Context) : SQLiteOpenHelper( "$ABSTRACT TEXT, " + "$DESCR TEXT, " + "$REL_START INTEGER, " + - "$DATE TEXT, " + + "$DATE_TEXT TEXT, " + "$LINKS TEXT, " + "$DATE_UTC INTEGER, " + "$TIME_ZONE_OFFSET INTEGER DEFAULT NULL, " + @@ -93,13 +93,13 @@ internal class SessionsDBOpenHelper(context: Context) : SQLiteOpenHelper( "$CHANGED_TITLE INTEGER, " + "$CHANGED_SUBTITLE INTEGER, " + "$CHANGED_ROOM_NAME INTEGER, " + - "$CHANGED_DAY INTEGER, " + + "$CHANGED_DAY_INDEX INTEGER, " + "$CHANGED_SPEAKERS INTEGER, " + "$CHANGED_RECORDING_OPTOUT INTEGER, " + "$CHANGED_LANGUAGE INTEGER, " + "$CHANGED_TRACK INTEGER, " + "$CHANGED_IS_NEW INTEGER, " + - "$CHANGED_TIME INTEGER, " + + "$CHANGED_START_TIME INTEGER, " + "$CHANGED_DURATION INTEGER, " + "$CHANGED_IS_CANCELED INTEGER" + ");" @@ -136,13 +136,13 @@ internal class SessionsDBOpenHelper(context: Context) : SQLiteOpenHelper( addIntegerColumn(CHANGED_TITLE, default = 0) addIntegerColumn(CHANGED_SUBTITLE, default = 0) addIntegerColumn(CHANGED_ROOM_NAME, default = 0) - addIntegerColumn(CHANGED_DAY, default = 0) + addIntegerColumn(CHANGED_DAY_INDEX, default = 0) addIntegerColumn(CHANGED_SPEAKERS, default = 0) addIntegerColumn(CHANGED_RECORDING_OPTOUT, default = 0) addIntegerColumn(CHANGED_LANGUAGE, default = 0) addIntegerColumn(CHANGED_TRACK, default = 0) addIntegerColumn(CHANGED_IS_NEW, default = 0) - addIntegerColumn(CHANGED_TIME, default = 0) + addIntegerColumn(CHANGED_START_TIME, default = 0) addIntegerColumn(CHANGED_DURATION, default = 0) addIntegerColumn(CHANGED_IS_CANCELED, default = 0) } diff --git a/database/src/test/java/info/metadude/android/eventfahrplan/database/models/SessionTest.kt b/database/src/test/java/info/metadude/android/eventfahrplan/database/models/SessionTest.kt new file mode 100644 index 0000000000..35faf0b094 --- /dev/null +++ b/database/src/test/java/info/metadude/android/eventfahrplan/database/models/SessionTest.kt @@ -0,0 +1,56 @@ +package info.metadude.android.eventfahrplan.database.models + +import com.google.common.truth.Truth.assertThat +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments.of +import org.junit.jupiter.params.provider.MethodSource + +class SessionTest { + + companion object { + @JvmStatic + fun isChangedData() = listOf( + of(false, false, false, false, false, false, false, false, false, false, false), + of(true, false, false, false, false, false, false, false, false, false, true), + of(false, true, false, false, false, false, false, false, false, false, true), + of(false, false, true, false, false, false, false, false, false, false, true), + of(false, false, false, true, false, false, false, false, false, false, true), + of(false, false, false, false, true, false, false, false, false, false, true), + of(false, false, false, false, false, true, false, false, false, false, true), + of(false, false, false, false, false, false, true, false, false, false, true), + of(false, false, false, false, false, false, false, true, false, false, true), + of(false, false, false, false, false, false, false, false, true, false, true), + ) + } + + @ParameterizedTest(name = "{index}: changedTitle = {0}, changedSubtitle = {1}, changedRoomName = {2}, changedDayIndex = {3}, changedStartTime = {4}, changedDuration = {5}, changedSpeakers = {6}, changedLanguage = {7}, changedRecordingOptOut = {8}, changedTrack = {9} -> isChanged = {10}") + @MethodSource("isChangedData") + fun isChanged( + changedTitle: Boolean, + changedSubtitle: Boolean, + changedRoomName: Boolean, + changedDay: Boolean, + changedTime: Boolean, + changedDuration: Boolean, + changedSpeakers: Boolean, + changedLanguage: Boolean, + changedRecordingOptOut: Boolean, + changedTrack: Boolean, + isChanged: Boolean, + ) { + val session = Session("").copy( + changedTitle = changedTitle, + changedSubtitle = changedSubtitle, + changedRoomName = changedRoomName, + changedDayIndex = changedDay, + changedStartTime = changedTime, + changedDuration = changedDuration, + changedSpeakers = changedSpeakers, + changedLanguage = changedLanguage, + changedRecordingOptOut = changedRecordingOptOut, + changedTrack = changedTrack, + ) + assertThat(session.isChanged).isEqualTo(isChanged) + } + +} diff --git a/network/src/main/java/info/metadude/android/eventfahrplan/network/models/Session.kt b/network/src/main/java/info/metadude/android/eventfahrplan/network/models/Session.kt index a167bde475..eced4561cf 100644 --- a/network/src/main/java/info/metadude/android/eventfahrplan/network/models/Session.kt +++ b/network/src/main/java/info/metadude/android/eventfahrplan/network/models/Session.kt @@ -11,7 +11,7 @@ data class Session( var sessionId: String = "", var abstractt: String = "", var dayIndex: Int = 0, // XML values start with 1 - var date: String = "", + var dateText: String = "", var dateUTC: Long = 0, var description: String = "", var duration: Int = 0, // minutes @@ -56,4 +56,23 @@ data class Session( } + /** + * Returns a new session with [changedIsCanceled] set to `true` + * and all other change flags set to `false`. + */ + fun cancel() = copy( + changedIsCanceled = true, + changedIsNew = false, + changedTitle = false, + changedSubtitle = false, + changedRoomName = false, + changedDayIndex = false, + changedStartTime = false, + changedDuration = false, + changedSpeakers = false, + changedLanguage = false, + changedRecordingOptOut = false, + changedTrack = false, + ) + } diff --git a/network/src/main/java/info/metadude/android/eventfahrplan/network/serialization/FahrplanParser.java b/network/src/main/java/info/metadude/android/eventfahrplan/network/serialization/FahrplanParser.java index 49c89b3401..302e73e0df 100644 --- a/network/src/main/java/info/metadude/android/eventfahrplan/network/serialization/FahrplanParser.java +++ b/network/src/main/java/info/metadude/android/eventfahrplan/network/serialization/FahrplanParser.java @@ -140,7 +140,7 @@ private Boolean parseFahrplan(String fahrplan, String eTag, String lastModified) String roomGuid = ""; int day = 0; int dayChangeTime = 600; // Only provided by Pentabarf; corresponds to 10:00 am. - String date = ""; + String dateText = ""; int roomIndex = 0; int roomMapIndex = 0; boolean scheduleComplete = false; @@ -168,7 +168,7 @@ private Boolean parseFahrplan(String fahrplan, String eTag, String lastModified) if (name.equals("day")) { String index = parser.getAttributeValue(null, "index"); day = Integer.parseInt(index); - date = parser.getAttributeValue(null, "date"); + dateText = parser.getAttributeValue(null, "date"); String end = parser.getAttributeValue(null, "end"); if (end == null) { throw new MissingXmlAttributeException("day", "end"); @@ -196,7 +196,7 @@ private Boolean parseFahrplan(String fahrplan, String eTag, String lastModified) session.setDayIndex(day); session.setRoomName(Objects.requireNonNullElse(roomName, "")); session.setRoomGuid(Objects.requireNonNullElse(roomGuid, "")); - session.setDate(date); + session.setDateText(dateText); session.setRoomIndex(roomMapIndex); eventType = parser.next(); boolean isSessionDone = false; diff --git a/network/src/main/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidation.kt b/network/src/main/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidation.kt index 5efd32ade6..6220d9e134 100644 --- a/network/src/main/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidation.kt +++ b/network/src/main/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidation.kt @@ -25,8 +25,8 @@ internal class DateFieldValidation( } /** - * Returns true if the timestamps in the [Session.date] fields of each session are within a valid time range. - * The time range is defined by the [Session.date] fields of first and last session (which are sorted by [Session.dateUTC]). + * Returns true if the timestamps in the [Session.dateText] fields of each session are within a valid time range. + * The time range is defined by the [Session.dateText] fields of first and last session (which are sorted by [Session.dateUTC]). */ fun validate(sessions: List): Boolean { val sortedSessions = sessions.sortedBy { it.dateUTC } @@ -35,8 +35,8 @@ internal class DateFieldValidation( return true } - val firstDateString = sortedSessions[0].date - val lastDateString = sortedSessions.last().date + val firstDateString = sortedSessions[0].dateText + val lastDateString = sortedSessions.last().dateText val range = DayRange(Moment.parseDate(firstDateString), Moment.parseDate(lastDateString)) // Check if the time stamp in is within the time range (first : last day) diff --git a/network/src/test/java/info/metadude/android/eventfahrplan/network/models/SessionTest.kt b/network/src/test/java/info/metadude/android/eventfahrplan/network/models/SessionTest.kt new file mode 100644 index 0000000000..aa0467afbb --- /dev/null +++ b/network/src/test/java/info/metadude/android/eventfahrplan/network/models/SessionTest.kt @@ -0,0 +1,45 @@ +package info.metadude.android.eventfahrplan.network.models + +import com.google.common.truth.Truth.assertThat +import org.junit.jupiter.api.Test + +class SessionTest { + + @Test + fun `cancel marks a session as canceled and resets all change other flags`() { + val session = Session( + sessionId = "0", + changedTitle = true, + changedSubtitle = true, + changedRoomName = true, + changedDayIndex = true, + changedStartTime = true, + changedDuration = true, + changedSpeakers = true, + changedRecordingOptOut = true, + changedLanguage = true, + changedTrack = true, + changedIsNew = true, + changedIsCanceled = false, + ) + val comparableCanceledSession = Session( + sessionId = "0", + changedTitle = false, + changedSubtitle = false, + changedRoomName = false, + changedDayIndex = false, + changedStartTime = false, + changedDuration = false, + changedSpeakers = false, + changedRecordingOptOut = false, + changedLanguage = false, + changedTrack = false, + changedIsNew = false, + changedIsCanceled = true, + ) + val canceledSession = session.cancel() + assertThat(canceledSession).isEqualTo(comparableCanceledSession) + assertThat(canceledSession).isNotSameInstanceAs(session) + } + +} diff --git a/network/src/test/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidationTest.kt b/network/src/test/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidationTest.kt index f7d472c850..76507bce1e 100644 --- a/network/src/test/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidationTest.kt +++ b/network/src/test/java/info/metadude/android/eventfahrplan/network/validation/DateFieldValidationTest.kt @@ -17,8 +17,8 @@ class DateFieldValidationTest { val sessions = listOf( // date and dateUTC do not represent the same - Session(date = "2019-01-02", dateUTC = start.toMilliseconds(), sessionId = "1"), - Session(date = "2019-01-01", dateUTC = end.toMilliseconds(), sessionId = "2") + Session(dateText = "2019-01-02", dateUTC = start.toMilliseconds(), sessionId = "1"), + Session(dateText = "2019-01-01", dateUTC = end.toMilliseconds(), sessionId = "2") ) val isValid = validation.validate(sessions) @@ -38,10 +38,10 @@ class DateFieldValidationTest { val sessions = listOf( // date=jan 2 does not correspond to dateUTC field value // since session 1 defines range start, this leads to a problem, if another session has valid data, but is before session 1. - Session(date = "2019-01-02", dateUTC = start.toMilliseconds(), sessionId = "1"), + Session(dateText = "2019-01-02", dateUTC = start.toMilliseconds(), sessionId = "1"), // range starts with session 1 => session 2 is outside of the range - Session(date = "2019-01-01", dateUTC = Moment.parseDate("2019-01-01").toMilliseconds(), sessionId = "2"), - Session(date = "2019-01-03", dateUTC = end.toMilliseconds(), sessionId = "3") + Session(dateText = "2019-01-01", dateUTC = Moment.parseDate("2019-01-01").toMilliseconds(), sessionId = "2"), + Session(dateText = "2019-01-03", dateUTC = end.toMilliseconds(), sessionId = "3") ) val isValid = validation.validate(sessions) @@ -59,9 +59,9 @@ class DateFieldValidationTest { val end = Moment.parseDate("2019-01-03") val sessions = listOf( - Session(date = "2019-01-01", dateUTC = start.toMilliseconds(), sessionId = "1"), - Session(date = "2019-01-02", dateUTC = Moment.parseDate("2019-01-02").toMilliseconds(), sessionId = "2"), - Session(date = "2019-01-03", dateUTC = end.toMilliseconds(), sessionId = "3") + Session(dateText = "2019-01-01", dateUTC = start.toMilliseconds(), sessionId = "1"), + Session(dateText = "2019-01-02", dateUTC = Moment.parseDate("2019-01-02").toMilliseconds(), sessionId = "2"), + Session(dateText = "2019-01-03", dateUTC = end.toMilliseconds(), sessionId = "3") ) val isValid = validation.validate(sessions) @@ -92,8 +92,8 @@ class DateFieldValidationTest { val end = Moment.parseDate("2019-01-01") val sessions = listOf( - Session(date = "2019-01-01", dateUTC = start.toMilliseconds(), sessionId = "1"), - Session(date = "2019-01-01", dateUTC = end.toMilliseconds(), sessionId = "2") + Session(dateText = "2019-01-01", dateUTC = start.toMilliseconds(), sessionId = "1"), + Session(dateText = "2019-01-01", dateUTC = end.toMilliseconds(), sessionId = "2") ) val isValid = validation.validate(sessions) @@ -111,8 +111,8 @@ class DateFieldValidationTest { val end = Moment.parseDate("2019-01-02") val sessions = listOf( - Session(date = "2019-01-01", dateUTC = start.toMilliseconds(), sessionId = "1"), - Session(date = "2019-01-02", dateUTC = end.toMilliseconds(), sessionId = "2") + Session(dateText = "2019-01-01", dateUTC = start.toMilliseconds(), sessionId = "1"), + Session(dateText = "2019-01-02", dateUTC = end.toMilliseconds(), sessionId = "2") ) val isValid = validation.validate(sessions)