apply some refactoring recommendations

This commit is contained in:
Felix 2019-12-29 17:55:46 +01:00
parent 02f55a0cba
commit 91dfbccad4
4 changed files with 26 additions and 28 deletions

View file

@ -25,13 +25,13 @@ data class ConferenceDto(
val conferenceID: Long
get() = getIdFromUrl()
val eventsByTags: Map<String, List<EventDto>> by lazy { getEventsMap(events) }
val sensibleTags: Set<String>
private val eventsByTags: Map<String, List<EventDto>> by lazy { getEventsMap(events) }
private val sensibleTags: Set<String>
val tagsUsefull: Boolean
init {
sensibleTags = ConferenceUtil.getSensibleTags(eventsByTags.keys, acronym)
tagsUsefull = sensibleTags.size > 0
tagsUsefull = sensibleTags.isNotEmpty()
}
private fun getEventsMap(events: List<EventDto>?): Map<String, List<EventDto>> {
@ -39,15 +39,15 @@ data class ConferenceDto(
val untagged = ArrayList<EventDto>()
if (events != null) {
for (event in events) {
if (event.tags?.isNotEmpty() ?: false) {
if (event.tags?.isNotEmpty() == true) {
for (tag in event.tags!!) {
val list: MutableList<EventDto>
if (map.keys.contains(tag)) {
list = map[tag]!!
} else {
list = ArrayList<EventDto>()
map.put(tag, list)
list = ArrayList()
map[tag] = list
}
list.add(event)
}
@ -56,7 +56,7 @@ data class ConferenceDto(
}
}
if (untagged.size > 0) {
map.put("untagged", untagged)
map["untagged"] = untagged
}
}
return map

View file

@ -12,11 +12,11 @@ import android.text.Spanned
import de.nicidienase.chaosflix.common.mediadata.entities.recording.EventDto
@Entity(tableName = "event",
foreignKeys = arrayOf(ForeignKey(
entity = Conference::class,
onDelete = ForeignKey.CASCADE,
parentColumns = (arrayOf("id")),
childColumns = arrayOf("conferenceId"))),
foreignKeys = [ForeignKey(
entity = Conference::class,
onDelete = ForeignKey.CASCADE,
parentColumns = (arrayOf("id")),
childColumns = arrayOf("conferenceId"))],
indices = [
Index("guid", unique = true),
Index("frontendLink"),
@ -82,8 +82,7 @@ data class Event(
parcel.createStringArray(),
parcel.createStringArray(),
parcel.createTypedArrayList(RelatedEvent),
parcel.createTypedArrayList(Recording)) {
}
parcel.createTypedArrayList(Recording))
@Ignore
constructor(event: EventDto, conferenceId: Long = 0) : this(

View file

@ -10,15 +10,17 @@ import android.os.Parcelable
import de.nicidienase.chaosflix.common.mediadata.entities.recording.RecordingDto
@Entity(tableName = "recording",
foreignKeys = arrayOf(ForeignKey(
entity = Event::class,
onDelete = ForeignKey.CASCADE,
parentColumns = (arrayOf("id")),
childColumns = arrayOf("eventId"))),
indices = arrayOf(
Index("eventId"),
Index("url", unique = true),
Index("backendId", unique = true)))
foreignKeys = [ForeignKey(
entity = Event::class,
onDelete = ForeignKey.CASCADE,
parentColumns = ([("id")]),
childColumns = ["eventId"])],
indices = [
Index("eventId"),
Index("url", unique = true),
Index("backendId", unique = true)
]
)
data class Recording(
@PrimaryKey(autoGenerate = true)
var id: Long = 0,
@ -60,8 +62,7 @@ data class Recording(
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readLong()) {
}
parcel.readLong())
@Ignore
constructor(rec: RecordingDto, eventId: Long = 0) : this(

View file

@ -188,9 +188,7 @@ class Downloader(
val conferenceId = database.conferenceDao().findConferenceByAcronymSync(acronym)?.id
?: updateConferencesAndGet(acronym)
if (conferenceId == -1L) {
throw IllegalStateException("Could not find Conference for event")
}
check(conferenceId != -1L) { "Could not find Conference for event" }
val persistentEvent = Event(event, conferenceId)
val id = database.eventDao().insert(persistentEvent)