mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 12:53:08 +00:00
add separate classes for persistency
This commit is contained in:
parent
004eac4ffe
commit
0892291abe
22 changed files with 479 additions and 120 deletions
|
@ -2,9 +2,8 @@ package de.nicidienase.chaosflix.common.entities
|
|||
|
||||
import android.arch.persistence.room.Database
|
||||
import android.arch.persistence.room.RoomDatabase
|
||||
import de.nicidienase.chaosflix.common.entities.recording.ConferenceDao
|
||||
import de.nicidienase.chaosflix.common.entities.recording.EventDao
|
||||
import de.nicidienase.chaosflix.common.entities.recording.RecordingDao
|
||||
import android.arch.persistence.room.TypeConverters
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.*
|
||||
import de.nicidienase.chaosflix.common.entities.userdata.PlaybackProgress
|
||||
import de.nicidienase.chaosflix.common.entities.userdata.PlaybackProgressDao
|
||||
import de.nicidienase.chaosflix.common.entities.userdata.WatchlistItem
|
||||
|
@ -14,7 +13,17 @@ import de.nicidienase.chaosflix.common.entities.userdata.WatchlistItemDao
|
|||
* Created by felix on 04.10.17.
|
||||
*/
|
||||
|
||||
@Database(entities = arrayOf(PlaybackProgress::class, WatchlistItem::class), version = 1, exportSchema = false)
|
||||
@Database(entities = arrayOf(
|
||||
PersistentConference::class,
|
||||
PersistentEvent::class,
|
||||
PersistentRecording::class,
|
||||
ConferenceGroup::class,
|
||||
SpeakerRelation::class,
|
||||
Person::class,
|
||||
Tag::class,
|
||||
PlaybackProgress::class,
|
||||
WatchlistItem::class), version = 1, exportSchema = false)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class ChaosflixDatabase : RoomDatabase() {
|
||||
abstract fun playbackProgressDao(): PlaybackProgressDao
|
||||
abstract fun watchlistItemDao(): WatchlistItemDao
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package de.nicidienase.chaosflix.common.entities
|
||||
|
||||
import android.arch.persistence.room.TypeConverter
|
||||
|
||||
class Converters{
|
||||
@TypeConverter
|
||||
fun longArrayToString(longArray: LongArray): String
|
||||
= longArray.joinToString(separator = "|")
|
||||
|
||||
@TypeConverter
|
||||
fun stringToLongArray(string: String): LongArray
|
||||
= string.split("|").map { it.toLong() }.toLongArray()
|
||||
}
|
|
@ -1,34 +1,48 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording
|
||||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
import android.arch.persistence.room.Ignore
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
|
||||
@Entity(tableName = "conference")
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
open class Conference(
|
||||
val acronym: String,
|
||||
var acronym: String = "",
|
||||
|
||||
@JsonProperty("aspect_ratio")
|
||||
val aspectRatio: String,
|
||||
val title: String,
|
||||
val slug: String,
|
||||
@JsonProperty("webgen_location") val webgenLocation: String,
|
||||
@JsonProperty("schedule_url") val scheduleUrl: String?,
|
||||
@JsonProperty("logo_url") val logoUrl: String,
|
||||
@JsonProperty("images_url") val imagesUrl: String,
|
||||
var aspectRatio: String = "",
|
||||
|
||||
var title: String = "",
|
||||
|
||||
var slug: String = "",
|
||||
|
||||
@JsonProperty("webgen_location")
|
||||
var webgenLocation: String = "",
|
||||
|
||||
@JsonProperty("schedule_url")
|
||||
var scheduleUrl: String? = "",
|
||||
|
||||
@JsonProperty("logo_url")
|
||||
var logoUrl: String = "",
|
||||
|
||||
@JsonProperty("images_url")
|
||||
var imagesUrl: String = "",
|
||||
|
||||
@JsonProperty("recordings_url")
|
||||
val recordingsUrl: String,
|
||||
val url: String,
|
||||
var recordingsUrl: String = "",
|
||||
|
||||
var url: String = "",
|
||||
|
||||
@JsonProperty("updated_at")
|
||||
val updatedAt: String,
|
||||
val events: List<Event>?
|
||||
var updatedAt: String,
|
||||
|
||||
var events: List<Event>?
|
||||
|
||||
) : Parcelable, Comparable<Conference> {
|
||||
|
||||
@PrimaryKey
|
||||
val apiID: Long
|
||||
var conferenceID: Long
|
||||
|
||||
val eventsByTags: HashMap<String, MutableList<Event>>
|
||||
|
||||
val sensibleTags: MutableSet<String> = HashSet()
|
||||
|
@ -36,24 +50,23 @@ open class Conference(
|
|||
init {
|
||||
eventsByTags = HashMap<String, MutableList<Event>>()
|
||||
val untagged = ArrayList<Event>()
|
||||
if(this.events != null){
|
||||
for (event in this.events) {
|
||||
val events = this.events
|
||||
if (events != null) {
|
||||
for (event in events) {
|
||||
if (event.tags?.isNotEmpty() ?: false) {
|
||||
if(event.tags != null){
|
||||
for (tag in event.tags) {
|
||||
if (tag != null) {
|
||||
for (tag in event.tags!!) {
|
||||
if (tag != null) {
|
||||
|
||||
val list: MutableList<Event>
|
||||
if (eventsByTags.keys.contains(tag)) {
|
||||
list = eventsByTags[tag]!!
|
||||
} else {
|
||||
list = ArrayList<Event>()
|
||||
eventsByTags.put(tag, list)
|
||||
}
|
||||
list.add(event)
|
||||
val list: MutableList<Event>
|
||||
if (eventsByTags.keys.contains(tag)) {
|
||||
list = eventsByTags[tag]!!
|
||||
} else {
|
||||
untagged.add(event)
|
||||
list = ArrayList<Event>()
|
||||
eventsByTags.put(tag, list)
|
||||
}
|
||||
list.add(event)
|
||||
} else {
|
||||
untagged.add(event)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -65,17 +78,20 @@ open class Conference(
|
|||
}
|
||||
}
|
||||
val strings = url.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
apiID = (strings[strings.size - 1]).toLong()
|
||||
conferenceID = (strings[strings.size - 1]).toLong()
|
||||
|
||||
for (s in eventsByTags.keys) {
|
||||
if (!(acronym.equals(s) || s.matches(Regex.fromLiteral("\\d+")))) {
|
||||
sensibleTags.add(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun areTagsUsefull(): Boolean = sensibleTags.size > 0
|
||||
|
||||
@Ignore
|
||||
protected constructor(`in`: Parcel) : this(
|
||||
`in`.readString(),
|
||||
`in`.readString(),
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
|
||||
@Dao
|
||||
interface ConferenceDao{
|
||||
|
||||
}
|
|
@ -1,49 +1,75 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording
|
||||
|
||||
import android.arch.persistence.room.Embedded
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.Metadata
|
||||
|
||||
import java.util.*
|
||||
|
||||
@Entity(tableName = "event")
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
open class Event(@JsonProperty("conference_id") var conferenceId: Long,
|
||||
val guid: String,
|
||||
val title: String,
|
||||
val subtitle: String?,
|
||||
val slug: String,
|
||||
val link: String?,
|
||||
val description: String?,
|
||||
@JsonProperty("original_language") val originalLanguage: String,
|
||||
val persons: List<String>?,
|
||||
val tags: List<String>?,
|
||||
val date: String?,
|
||||
@JsonProperty("release_date") val releaseDate: String,
|
||||
@JsonProperty("updated_at") val updatedAt: String,
|
||||
val length: Long = 0,
|
||||
@JsonProperty("thumb_url") val thumbUrl: String,
|
||||
@JsonProperty("poster_url") val posterUrl: String,
|
||||
@JsonProperty("frontend_link") val frontendLink: String?,
|
||||
val url: String,
|
||||
@JsonProperty("conference_url") val conferenceUrl: String,
|
||||
val recordings: List<Recording>?,
|
||||
@Embedded val metadata: Metadata,
|
||||
@JsonProperty("promoted") val isPromoted: Boolean = false
|
||||
open class Event(@JsonProperty("conference_id")
|
||||
var conferenceId: Long = 0,
|
||||
|
||||
var guid: String = "",
|
||||
|
||||
var title: String = "",
|
||||
|
||||
var subtitle: String? = "",
|
||||
|
||||
var slug: String = "",
|
||||
|
||||
var link: String? = "",
|
||||
|
||||
var description: String? = "",
|
||||
|
||||
@JsonProperty("original_language")
|
||||
var originalLanguage: String = "",
|
||||
|
||||
var persons: Array<String>?,
|
||||
|
||||
var tags: Array<String>?,
|
||||
|
||||
var date: String? = "",
|
||||
|
||||
@JsonProperty("release_date")
|
||||
var releaseDate: String = "",
|
||||
|
||||
@JsonProperty("updated_at")
|
||||
var updatedAt: String = "",
|
||||
|
||||
var length: Long = 0,
|
||||
|
||||
@JsonProperty("thumb_url")
|
||||
var thumbUrl: String = "",
|
||||
|
||||
@JsonProperty("poster_url")
|
||||
var posterUrl: String = "",
|
||||
|
||||
@JsonProperty("frontend_link")
|
||||
var frontendLink: String? = "",
|
||||
|
||||
var url: String = "",
|
||||
|
||||
@JsonProperty("conference_url")
|
||||
var conferenceUrl: String = "",
|
||||
|
||||
var recordings: List<Recording>?,
|
||||
|
||||
var metadata: Metadata?,
|
||||
|
||||
@JsonProperty("promoted")
|
||||
var isPromoted: Boolean = false
|
||||
) : Parcelable, Comparable<Event> {
|
||||
|
||||
@PrimaryKey
|
||||
val apiID: Long
|
||||
var eventID: Long
|
||||
@JsonProperty("view_count")
|
||||
var viewCount: Int = 0
|
||||
|
||||
init {
|
||||
val strings = url.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
apiID = strings[strings.size - 1].toLong()
|
||||
eventID = strings[strings.size - 1].toLong()
|
||||
|
||||
val split = conferenceUrl.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
conferenceId = (split[split.size - 1]).toLong()
|
||||
|
@ -64,8 +90,8 @@ open class Event(@JsonProperty("conference_id") var conferenceId: Long,
|
|||
link = `in`.readString(),
|
||||
description = `in`.readString(),
|
||||
originalLanguage = `in`.readString(),
|
||||
persons = `in`.createStringArrayList(),
|
||||
tags = `in`.createStringArrayList(),
|
||||
persons = `in`.createStringArray(),
|
||||
tags = `in`.createStringArray(),
|
||||
date = `in`.readString(),
|
||||
releaseDate = `in`.readString(),
|
||||
updatedAt = `in`.readString(),
|
||||
|
@ -88,8 +114,8 @@ open class Event(@JsonProperty("conference_id") var conferenceId: Long,
|
|||
dest.writeString(link)
|
||||
dest.writeString(description)
|
||||
dest.writeString(originalLanguage)
|
||||
dest.writeStringList(persons)
|
||||
dest.writeStringList(tags)
|
||||
dest.writeStringArray(persons)
|
||||
dest.writeStringArray(tags)
|
||||
dest.writeString(date)
|
||||
dest.writeString(releaseDate)
|
||||
dest.writeString(updatedAt)
|
||||
|
@ -121,7 +147,8 @@ open class Event(@JsonProperty("conference_id") var conferenceId: Long,
|
|||
}
|
||||
|
||||
fun getOptimalStream(): Recording {
|
||||
recordings!!
|
||||
val recordings = recordings!!
|
||||
|
||||
val result = ArrayList<Recording>()
|
||||
for (r in recordings) {
|
||||
if (r.isHighQuality && r.mimeType == "video/mp4")
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
|
||||
@Dao
|
||||
interface EventDao{
|
||||
|
||||
}
|
|
@ -1,47 +1,44 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording
|
||||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
|
||||
|
||||
@Entity(tableName = "recording")
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
open class Recording(
|
||||
val size: Int = 0,
|
||||
val length: Int = 0,
|
||||
var size: Int = 0,
|
||||
var length: Int = 0,
|
||||
@JsonProperty("mime_type")
|
||||
val mimeType: String,
|
||||
val language: String,
|
||||
val filename: String,
|
||||
val state: String,
|
||||
val folder: String,
|
||||
var mimeType: String = "",
|
||||
var language: String = "",
|
||||
var filename: String = "",
|
||||
var state: String = "",
|
||||
var folder: String = "",
|
||||
@JsonProperty("high_quality")
|
||||
val isHighQuality: Boolean = false,
|
||||
val width: Int = 0,
|
||||
val height: Int = 0,
|
||||
var isHighQuality: Boolean = false,
|
||||
var width: Int = 0,
|
||||
var height: Int = 0,
|
||||
@JsonProperty("updated_at")
|
||||
val updatedAt: String,
|
||||
var updatedAt: String = "",
|
||||
@JsonProperty("recording_url")
|
||||
val recordingUrl: String,
|
||||
val url: String,
|
||||
var recordingUrl: String = "",
|
||||
var url: String = "",
|
||||
@JsonProperty("event_url")
|
||||
val eventUrl: String,
|
||||
var eventUrl: String = "",
|
||||
@JsonProperty("conference_url")
|
||||
val conferenceUrl: String
|
||||
var conferenceUrl: String = ""
|
||||
) : Parcelable {
|
||||
|
||||
val apiID: Long
|
||||
val parentEventID: Long
|
||||
var recordingID: Long
|
||||
var eventID: Long
|
||||
|
||||
init {
|
||||
val strings = url!!.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
apiID = (strings[strings.size - 1]).toLong()
|
||||
val split = eventUrl!!.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
parentEventID = (split[split.size - 1]).toLong()
|
||||
|
||||
val strings = url.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
recordingID = (strings[strings.size - 1]).toLong()
|
||||
val split = eventUrl.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
eventID = (split[split.size - 1]).toLong()
|
||||
}
|
||||
|
||||
protected constructor(`in`: Parcel) : this(
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
|
||||
@Dao
|
||||
interface RecordingDao{
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
import android.arch.persistence.room.Insert
|
||||
import android.arch.persistence.room.OnConflictStrategy
|
||||
import android.arch.persistence.room.Query
|
||||
import io.reactivex.Flowable
|
||||
|
||||
@Dao
|
||||
interface ConferenceDao{
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertConferences(vararg conferences: PersistentConference)
|
||||
|
||||
@Query("SELECT * FROM conference")
|
||||
fun getAllConferences(): Flowable<List<PersistentConference>>
|
||||
|
||||
@Query("SELECT * FROM conference WHERE title LIKE :search")
|
||||
fun findConferenceByTitle(search: String): Flowable<List<PersistentConference>>
|
||||
|
||||
@Query("SELECT * FROM conference WHERE conferenceId = :id")
|
||||
fun findConferenceById(id: Long): Flowable<List<PersistentConference>>
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.Index
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "conference_group", indices = arrayOf(Index(value = "name", unique = true)))
|
||||
class ConferenceGroup{
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var conferenceGroupId: Long = 0
|
||||
var name: String = ""
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
import android.arch.persistence.room.Insert
|
||||
import android.arch.persistence.room.Query
|
||||
import io.reactivex.Flowable
|
||||
|
||||
@Dao
|
||||
interface ConferenceGroupDao{
|
||||
@Query("SELECT * FROM conference_group")
|
||||
fun getAll(): Flowable<List<ConferenceGroup>>
|
||||
|
||||
@Insert
|
||||
fun addConferenceGroup(vararg conferenceGroup: ConferenceGroup)
|
||||
|
||||
@Query("SELECT * FROM conference_group WHERE name = :name LIMIT 1")
|
||||
fun getConferenceGroupByName(name: String)
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
import android.arch.persistence.room.Insert
|
||||
import android.arch.persistence.room.OnConflictStrategy
|
||||
import android.arch.persistence.room.Query
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Conference
|
||||
import io.reactivex.Flowable
|
||||
|
||||
@Dao
|
||||
interface EventDao{
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertEvent(vararg events: PersistentEvent)
|
||||
|
||||
@Query("SELECT * FROM event")
|
||||
fun getAllEvents(): Flowable<List<PersistentEvent>>
|
||||
|
||||
@Query("SELECT * FROM event WHERE title LIKE :search")
|
||||
fun findEventByTitle(search: String): Flowable<List<PersistentEvent>>
|
||||
|
||||
@Query("SELECT * FROM event WHERE eventId = :id")
|
||||
fun findEventById(id: Long): Flowable<List<PersistentEvent>>
|
||||
|
||||
@Query("SELECT * FROM event WHERE conferenceId = :id")
|
||||
fun getEventsForConference(id: Long):Flowable<List<PersistentEvent>>
|
||||
|
||||
@Query("SELECT * FROM speaker_relation INNER JOIN event on speaker_relation.eventId = event.eventId WHERE speaker_relation.personID = :id")
|
||||
fun getEventsBySpeakerId(id: Long): Flowable<List<PersistentEvent>>
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording
|
||||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
|
@ -0,0 +1,39 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.*
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Conference
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event
|
||||
|
||||
@Entity(tableName = "conference")
|
||||
open class PersistentConference(
|
||||
@PrimaryKey
|
||||
var conferenceId: Long = 0,
|
||||
var acronym: String = "",
|
||||
var aspectRatio: String = "",
|
||||
var title: String = "",
|
||||
var slug: String = "",
|
||||
var webgenLocation: String = "",
|
||||
var scheduleUrl: String? = "",
|
||||
var logoUrl: String = "",
|
||||
var imagesUrl: String = "",
|
||||
var recordingsUrl: String = "",
|
||||
var url: String = "",
|
||||
var updatedAt: String = ""
|
||||
// events: List<Event>? = null
|
||||
) {
|
||||
// @Relation(parentColumn = "conferenceId", entityColumn = "eventId")
|
||||
// var events: List<PersistentEvent>?
|
||||
|
||||
// init {
|
||||
// this.events = events?.map { PersistentEvent(it) }
|
||||
// }
|
||||
|
||||
@Ignore
|
||||
constructor(con: Conference) : this(con.conferenceID,
|
||||
con.acronym, con.aspectRatio, con.title, con.slug, con.webgenLocation,
|
||||
con.scheduleUrl, con.logoUrl, con.imagesUrl, con.recordingsUrl, con.url,
|
||||
con.updatedAt)
|
||||
|
||||
fun toConference() = Conference(acronym, aspectRatio, title, slug, webgenLocation,
|
||||
scheduleUrl, logoUrl, imagesUrl, recordingsUrl, url, updatedAt, null)
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.*
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Recording
|
||||
|
||||
@Entity(tableName = "event",
|
||||
foreignKeys = arrayOf(ForeignKey(
|
||||
entity = PersistentConference::class,
|
||||
parentColumns = (arrayOf("conferenceId")),
|
||||
childColumns = arrayOf("conferenceId"))))
|
||||
|
||||
open class PersistentEvent(@PrimaryKey(autoGenerate = false)
|
||||
var eventId: Long = 0,
|
||||
var conferenceId: Long = 0,
|
||||
var guid: String = "",
|
||||
var title: String = "",
|
||||
var subtitle: String? = "",
|
||||
var slug: String = "",
|
||||
var link: String? = "",
|
||||
var description: String? = "",
|
||||
var originalLanguage: String = "",
|
||||
var date: String? = "",
|
||||
var releaseDate: String = "",
|
||||
var updatedAt: String = "",
|
||||
var length: Long = 0,
|
||||
var thumbUrl: String = "",
|
||||
var posterUrl: String = "",
|
||||
var frontendLink: String? = "",
|
||||
var url: String = "",
|
||||
var conferenceUrl: String = "",
|
||||
@Embedded
|
||||
var metadata: Metadata? = null,
|
||||
|
||||
var isPromoted: Boolean = false,
|
||||
var viewCount: Int = 0,
|
||||
|
||||
persons: Array<String>? = null,
|
||||
tags: Array<String>? = null,
|
||||
recordings: List<Recording>? = null
|
||||
) {
|
||||
// @Relation(parentColumn = "eventId", entityColumn = "recordingId")
|
||||
@Ignore
|
||||
var recordings: List<PersistentRecording>? = recordings?.map { PersistentRecording(it) }
|
||||
|
||||
// @Relation(parentColumn = "eventId", entityColumn = "personID")
|
||||
@Ignore
|
||||
var persons: List<Person>? = persons?.map { Person(it) }
|
||||
|
||||
// @Relation(parentColumn = "eventId", entityColumn = "tagID")
|
||||
@Ignore
|
||||
var tags: List<Tag>? = tags?.map { Tag(it) }
|
||||
|
||||
@Ignore
|
||||
constructor(event: Event) : this(event.eventID,
|
||||
event.conferenceId, event.guid, event.title,
|
||||
event.subtitle, event.slug, event.link, event.description,
|
||||
event.originalLanguage, event.date, event.releaseDate,
|
||||
event.updatedAt, event.length, event.thumbUrl, event.posterUrl,
|
||||
event.frontendLink, event.url, event.conferenceUrl,
|
||||
event.metadata, event.isPromoted, event.viewCount,
|
||||
event.persons, event.tags, event.recordings)
|
||||
|
||||
fun toEvent(): Event = Event(conferenceId, guid, title, subtitle, slug, link, description,
|
||||
originalLanguage, persons?.map { it.person }?.toTypedArray(),
|
||||
tags?.map { it.tag }?.toTypedArray(), date, releaseDate, updatedAt, length,
|
||||
thumbUrl, posterUrl, frontendLink, url, conferenceUrl, recordings?.map { it.toRecording() }, metadata, isPromoted)
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.ForeignKey
|
||||
import android.arch.persistence.room.Ignore
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Recording
|
||||
|
||||
@Entity(tableName = "recording",
|
||||
foreignKeys = arrayOf(ForeignKey(
|
||||
entity = PersistentEvent::class,
|
||||
parentColumns = (arrayOf("eventId")),
|
||||
childColumns = arrayOf("eventId"))))
|
||||
open class PersistentRecording(
|
||||
@PrimaryKey
|
||||
var recordingId: Long,
|
||||
var eventId: Long,
|
||||
var size: Int = 0,
|
||||
var length: Int = 0,
|
||||
var mimeType: String = "",
|
||||
var language: String = "",
|
||||
var filename: String = "",
|
||||
var state: String = "",
|
||||
var folder: String = "",
|
||||
var isHighQuality: Boolean = false,
|
||||
var width: Int = 0,
|
||||
var height: Int = 0,
|
||||
var updatedAt: String = "",
|
||||
var recordingUrl: String = "",
|
||||
var url: String = "",
|
||||
var eventUrl: String = "",
|
||||
var conferenceUrl: String = ""
|
||||
) {
|
||||
@Ignore
|
||||
constructor(rec: Recording) : this(rec.recordingID, rec.eventID,
|
||||
rec.size, rec.length, rec.mimeType,
|
||||
rec.language, rec.filename, rec.state, rec.folder, rec.isHighQuality,
|
||||
rec.width, rec.height, rec.updatedAt, rec.recordingUrl, rec.url,
|
||||
rec.eventUrl, rec.conferenceUrl)
|
||||
|
||||
fun toRecording(): Recording = Recording(size, length, mimeType, language,
|
||||
filename, state, folder, isHighQuality, width, height, updatedAt,
|
||||
recordingUrl, url, eventUrl, conferenceUrl)
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.Index
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "person", indices = arrayOf(Index(value = "person", unique = true)))
|
||||
class Person (var person: String) {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var personId: Long = 0
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
import android.arch.persistence.room.Insert
|
||||
import android.arch.persistence.room.OnConflictStrategy
|
||||
import android.arch.persistence.room.Query
|
||||
import io.reactivex.Flowable
|
||||
|
||||
@Dao
|
||||
interface PersonDao{
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insertPersion(vararg person: Person)
|
||||
|
||||
@Query("SELECT * FROM person")
|
||||
fun getAll(): Flowable<List<Person>>
|
||||
|
||||
@Query("SELECT * FROM person WHERE personID = :id")
|
||||
fun getByID(id: Long): Flowable<List<Person>>
|
||||
|
||||
@Query("SELECT * FROM person WHERE name = :name")
|
||||
fun getByName(): Flowable<List<Person>>
|
||||
|
||||
@Query("SELECT * FROM speaker_relation INNER JOIN person on speaker_relation.personID = person.personID WHERE speaker_relation.eventId = :id")
|
||||
fun getSpeakerForEvent(id: Long): Flowable<List<Person>>
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Dao
|
||||
import android.arch.persistence.room.Insert
|
||||
import android.arch.persistence.room.OnConflictStrategy
|
||||
import android.arch.persistence.room.Query
|
||||
import io.reactivex.Flowable
|
||||
|
||||
@Dao
|
||||
interface RecordingDao{
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertRecording(vararg recordings: PersistentRecording)
|
||||
|
||||
@Query("SELECT * FROM recording")
|
||||
fun getAllRecordings(): Flowable<List<PersistentRecording>>
|
||||
|
||||
@Query("SELECT * FROM recording WHERE recordingId = :id")
|
||||
fun findRecordingById(id: Long): Flowable<List<PersistentRecording>>
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.ForeignKey
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "speaker_relation",
|
||||
foreignKeys = arrayOf(
|
||||
ForeignKey(
|
||||
entity = Person::class,
|
||||
parentColumns = arrayOf("personId"),
|
||||
childColumns = arrayOf("personId")),
|
||||
ForeignKey(
|
||||
entity = PersistentEvent::class,
|
||||
parentColumns = arrayOf("eventId"),
|
||||
childColumns = arrayOf("eventId")
|
||||
)))
|
||||
class SpeakerRelation(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var speakerRelationId: Long = 0,
|
||||
var personId: Long,
|
||||
var eventId: Long
|
||||
)
|
|
@ -0,0 +1,11 @@
|
|||
package de.nicidienase.chaosflix.common.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.Index
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "tag" ,indices = arrayOf(Index(value = "tag", unique = true)))
|
||||
class Tag (var tag: String){
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var tagID = 0
|
||||
}
|
|
@ -3,7 +3,7 @@ package de.nicidienase.chaosflix.common
|
|||
import de.nicidienase.chaosflix.common.entities.recording.Conference
|
||||
import de.nicidienase.chaosflix.common.entities.recording.ConferencesWrapper
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Metadata
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.Metadata
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Recording
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito.*
|
||||
|
|
Loading…
Reference in a new issue