mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-26 22:20:24 +00:00
undo database-split and other fixes
This commit is contained in:
parent
c2a83fae2d
commit
76a2a204a8
16 changed files with 158 additions and 77 deletions
|
@ -1,14 +1,28 @@
|
|||
package de.nicidienase.chaosflix.common.mediadata.entities
|
||||
package de.nicidienase.chaosflix.common
|
||||
|
||||
import android.arch.persistence.db.SupportSQLiteDatabase
|
||||
import android.arch.persistence.room.Database
|
||||
import android.arch.persistence.room.RoomDatabase
|
||||
import android.arch.persistence.room.TypeConverters
|
||||
import android.arch.persistence.room.migration.Migration
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.Converters
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.ConferenceDao
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.ConferenceGroup
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.ConferenceGroupDao
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.EventDao
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentConference
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentItem
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentRecording
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentRelatedEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.RecordingDao
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.RelatedEventDao
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.*
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEventDao
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.progress.PlaybackProgress
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.progress.PlaybackProgressDao
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItem
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItemDao
|
||||
|
||||
@Database(entities = arrayOf(
|
||||
PersistentItem::class,
|
||||
|
@ -17,11 +31,13 @@ import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItem
|
|||
PersistentRecording::class,
|
||||
PersistentRelatedEvent::class,
|
||||
ConferenceGroup::class,
|
||||
|
||||
PlaybackProgress::class,
|
||||
WatchlistItem::class,
|
||||
OfflineEvent::class), version = 5, exportSchema = true)
|
||||
OfflineEvent::class
|
||||
), version = 5, exportSchema = true)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class MediaDatabase : RoomDatabase() {
|
||||
abstract class ChaosflixDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun conferenceGroupDao(): ConferenceGroupDao
|
||||
abstract fun conferenceDao(): ConferenceDao
|
||||
|
@ -29,6 +45,11 @@ abstract class MediaDatabase : RoomDatabase() {
|
|||
abstract fun relatedEventDao(): RelatedEventDao
|
||||
abstract fun recordingDao(): RecordingDao
|
||||
|
||||
abstract fun playbackProgressDao(): PlaybackProgressDao
|
||||
abstract fun watchlistItemDao(): WatchlistItemDao
|
||||
abstract fun offlineEventDao(): OfflineEventDao
|
||||
|
||||
|
||||
companion object {
|
||||
val migration_2_3 = object : Migration(2, 3) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
|
@ -59,5 +80,3 @@ abstract class MediaDatabase : RoomDatabase() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package de.nicidienase.chaosflix.common
|
||||
|
||||
import android.arch.persistence.room.Room
|
||||
import android.content.Context
|
||||
|
||||
class DatabaseFactory (context: Context) {
|
||||
val mediaDatabase by lazy {
|
||||
Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
ChaosflixDatabase::class.java, "mediaccc.de")
|
||||
.addMigrations(
|
||||
ChaosflixDatabase.migration_2_3,
|
||||
ChaosflixDatabase.migration_3_4)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
}
|
|
@ -34,36 +34,33 @@ data class Conference(
|
|||
}
|
||||
|
||||
private fun getEventsMap(events: List<Event>?): Map<String,List<Event>>{
|
||||
val map = HashMap<String, MutableList<Event>>()
|
||||
val untagged = ArrayList<Event>()
|
||||
if (events != null) {
|
||||
for (event in events) {
|
||||
if (event.tags?.isNotEmpty() ?: false) {
|
||||
for (tag in event.tags!!) {
|
||||
if (tag != null) {
|
||||
val map = HashMap<String, MutableList<Event>>()
|
||||
val untagged = ArrayList<Event>()
|
||||
if (events != null) {
|
||||
for (event in events) {
|
||||
if (event.tags?.isNotEmpty() ?: false) {
|
||||
for (tag in event.tags!!) {
|
||||
|
||||
val list: MutableList<Event>
|
||||
if (map.keys.contains(tag)) {
|
||||
list = map[tag]!!
|
||||
} else {
|
||||
list = ArrayList<Event>()
|
||||
map.put(tag, list)
|
||||
}
|
||||
list.add(event)
|
||||
} else {
|
||||
untagged.add(event)
|
||||
}
|
||||
}
|
||||
val list: MutableList<Event>
|
||||
if (map.keys.contains(tag)) {
|
||||
list = map[tag]!!
|
||||
} else {
|
||||
untagged.add(event)
|
||||
list = ArrayList<Event>()
|
||||
map.put(tag, list)
|
||||
}
|
||||
list.add(event)
|
||||
|
||||
}
|
||||
if (untagged.size > 0) {
|
||||
map.put("untagged", untagged)
|
||||
}
|
||||
} else {
|
||||
untagged.add(event)
|
||||
}
|
||||
return map
|
||||
}
|
||||
if (untagged.size > 0) {
|
||||
map.put("untagged", untagged)
|
||||
}
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
|
||||
private fun getIdFromUrl(url: String = this.url): Long {
|
||||
|
@ -85,7 +82,7 @@ data class Conference(
|
|||
return hashSet
|
||||
}
|
||||
|
||||
override fun compareTo(conference: Conference): Int {
|
||||
return slug.compareTo(conference.slug)
|
||||
override fun compareTo(other: Conference): Int {
|
||||
return slug.compareTo(other.slug)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,15 +57,15 @@ data class Event(@SerializedName("conference_id")
|
|||
fun getSpeakerString(): String?
|
||||
= persons?.joinToString(", ")
|
||||
|
||||
override fun compareTo(event: Event): Int {
|
||||
return slug.compareTo(event.slug)
|
||||
override fun compareTo(other: Event): Int {
|
||||
return slug.compareTo(other.slug)
|
||||
}
|
||||
|
||||
override fun equals(obj: Any?): Boolean {
|
||||
return if (obj is Event) {
|
||||
guid == obj.guid
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return if (other is Event) {
|
||||
guid == other.guid
|
||||
} else {
|
||||
super.equals(obj)
|
||||
super.equals(other)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,11 +23,10 @@ data class Recording(
|
|||
@SerializedName("event_url")
|
||||
var eventUrl: String = "",
|
||||
@SerializedName("conference_url")
|
||||
var conferenceUrl: String = ""
|
||||
var conferenceUrl: String = "",
|
||||
var recordingID: Long
|
||||
) {
|
||||
|
||||
var recordingID: Long
|
||||
|
||||
init {
|
||||
val strings = url.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
recordingID = (strings[strings.size - 1]).toLong()
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.os.Parcelable
|
|||
|
||||
@Entity(
|
||||
tableName = "conference_group",
|
||||
indices = [Index(value = "name", unique = true)])
|
||||
indices = [Index(value = ["name"], unique = true)])
|
||||
data class ConferenceGroup(
|
||||
var name: String = ""
|
||||
): PersistentItem(), Parcelable {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence
|
||||
|
||||
import android.arch.persistence.room.*
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.Ignore
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Conference
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.Conference
|
||||
|
||||
@Entity(tableName = "conference")
|
||||
data class PersistentConference(
|
||||
|
|
|
@ -103,6 +103,7 @@ data class PersistentEvent(
|
|||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
||||
return Html.fromHtml(description, Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
return Html.fromHtml(description)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence
|
|||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
import android.os.Parcelable
|
||||
|
||||
@Entity
|
||||
abstract class PersistentItem(@PrimaryKey(autoGenerate = true)
|
||||
|
|
|
@ -28,9 +28,11 @@ data class PersistentRecording(
|
|||
var recordingUrl: String = "",
|
||||
var url: String = "",
|
||||
var eventUrl: String = "",
|
||||
var conferenceUrl: String = ""
|
||||
var conferenceUrl: String = "",
|
||||
var backendId: Long = 0
|
||||
) : PersistentItem(), Parcelable {
|
||||
|
||||
@Ignore
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readLong(),
|
||||
parcel.readInt(),
|
||||
|
@ -67,7 +69,8 @@ data class PersistentRecording(
|
|||
recordingUrl = rec.recordingUrl,
|
||||
url = rec.url,
|
||||
eventUrl = rec.eventUrl,
|
||||
conferenceUrl = rec.conferenceUrl)
|
||||
conferenceUrl = rec.conferenceUrl,
|
||||
backendId = rec.recordingID )
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeLong(eventId)
|
||||
|
@ -101,4 +104,5 @@ data class PersistentRecording(
|
|||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +1,41 @@
|
|||
package de.nicidienase.chaosflix.touch.sync
|
||||
package de.nicidienase.chaosflix.common.mediadata.sync
|
||||
|
||||
import android.content.Intent
|
||||
import android.support.v4.app.JobIntentService
|
||||
import de.nicidienase.chaosflix.common.mediadata.sync.Downloader
|
||||
import de.nicidienase.chaosflix.touch.ViewModelFactory
|
||||
import de.nicidienase.chaosflix.common.DatabaseFactory
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentConference
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentItem
|
||||
import de.nicidienase.chaosflix.common.mediadata.network.ApiFactory
|
||||
|
||||
class DownloadJobService : JobIntentService() {
|
||||
|
||||
override fun onHandleWork(intent: Intent) {
|
||||
val downloader = Downloader(ViewModelFactory.recordingApi, ViewModelFactory.database)
|
||||
val entity: String? = intent.getStringExtra(ENTITY_KEY)
|
||||
val id: Long = intent.getLongExtra(ID_KEY, -1)
|
||||
if (entity != null) {
|
||||
when (entity) {
|
||||
// ENTITY_KEY_EVERYTHING -> downloader.updateEverything()
|
||||
val downloader = Downloader(
|
||||
ApiFactory(resources).recordingApi,
|
||||
DatabaseFactory(applicationContext).mediaDatabase)
|
||||
val entityType: String? = intent.getStringExtra(ENTITY_KEY)
|
||||
|
||||
if (entityType != null) {
|
||||
when (entityType) {
|
||||
ENTITY_KEY_CONFERENCES -> downloader.updateConferencesAndGroups()
|
||||
ENTITY_KEY_EVENTS -> downloader.updateEventsForConference(id)
|
||||
ENTITY_KEY_RECORDINGS -> downloader.updateRecordingsForEvent(id)
|
||||
ENTITY_KEY_EVENTS -> {
|
||||
val item = intent.getParcelableExtra<PersistentConference>(ITEM_KEY)
|
||||
downloader.updateEventsForConference(item as PersistentConference)
|
||||
}
|
||||
ENTITY_KEY_RECORDINGS -> {
|
||||
val item = intent.getParcelableExtra<PersistentEvent>(ITEM_KEY)
|
||||
downloader.updateRecordingsForEvent(item as PersistentEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ENTITY_KEY: String = "entity_key"
|
||||
// val ENTITY_KEY_EVERYTHING = "everything"
|
||||
val ITEM_KEY: String = "item_key"
|
||||
val ENTITY_KEY_CONFERENCES: String = "conferences"
|
||||
val ENTITY_KEY_EVENTS: String = "events"
|
||||
val ENTITY_KEY_RECORDINGS: String = "recodings"
|
||||
val ID_KEY: String = "id_key"
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import android.arch.lifecycle.LiveData
|
|||
import android.database.sqlite.SQLiteConstraintException
|
||||
import android.util.Log
|
||||
import de.nicidienase.chaosflix.common.Util
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.MediaDatabase
|
||||
import de.nicidienase.chaosflix.common.ChaosflixDatabase
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.ConferencesWrapper
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.Event
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.Recording
|
||||
|
@ -16,10 +16,9 @@ import de.nicidienase.chaosflix.common.mediadata.network.RecordingService
|
|||
import de.nicidienase.chaosflix.common.util.LiveEvent
|
||||
import de.nicidienase.chaosflix.common.util.SingleLiveEvent
|
||||
import de.nicidienase.chaosflix.common.util.ThreadHandler
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class Downloader(val recordingApi: RecordingService,
|
||||
val database: MediaDatabase) {
|
||||
val database: ChaosflixDatabase) {
|
||||
|
||||
private val threadHandler = ThreadHandler()
|
||||
|
||||
|
|
|
@ -1,19 +1,54 @@
|
|||
package de.nicidienase.chaosflix.common.userdata.entities.download
|
||||
|
||||
import android.arch.persistence.room.*
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.PersistentEvent
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.PersistentRecording
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentItem
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentRecording
|
||||
|
||||
@Entity(tableName = "offline_event",
|
||||
indices = arrayOf(Index(value = "event_id", unique = true)))
|
||||
indices = arrayOf(Index(value = ["event_guid"], unique = true)))
|
||||
data class OfflineEvent(
|
||||
@ColumnInfo(name = "event_id") var eventId: Long,
|
||||
@ColumnInfo(name = "event_guid") var eventGuid: String,
|
||||
@ColumnInfo(name = "recording_id") var recordingId: Long,
|
||||
@ColumnInfo(name = "download_reference") var downloadReference: Long,
|
||||
@ColumnInfo(name = "local_path") var localPath: String){
|
||||
|
||||
@PrimaryKey(autoGenerate = true) var id: Long = 0
|
||||
@ColumnInfo(name = "local_path") var localPath: String): PersistentItem(), Parcelable {
|
||||
|
||||
@Ignore var event: PersistentEvent? = null
|
||||
@Ignore var recording: PersistentRecording? = null
|
||||
|
||||
@Ignore
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readString(),
|
||||
parcel.readLong(),
|
||||
parcel.readLong(),
|
||||
parcel.readString()) {
|
||||
event = parcel.readParcelable(PersistentEvent::class.java.classLoader)
|
||||
recording = parcel.readParcelable(PersistentRecording::class.java.classLoader)
|
||||
}
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(eventGuid)
|
||||
parcel.writeLong(recordingId)
|
||||
parcel.writeLong(downloadReference)
|
||||
parcel.writeString(localPath)
|
||||
parcel.writeParcelable(event, flags)
|
||||
parcel.writeParcelable(recording, flags)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<OfflineEvent> {
|
||||
override fun createFromParcel(parcel: Parcel): OfflineEvent {
|
||||
return OfflineEvent(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<OfflineEvent?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -11,11 +11,11 @@ interface OfflineEventDao{
|
|||
@Insert
|
||||
fun insert(vararg items: OfflineEvent)
|
||||
|
||||
@Query("SELECT * FROM offline_event WHERE event_id = :id LIMIT 1")
|
||||
fun getByEventId(id: Long): LiveData<OfflineEvent>
|
||||
@Query("SELECT * FROM offline_event WHERE event_guid = :guid LIMIT 1")
|
||||
fun getByEventId(guid: String): LiveData<OfflineEvent>
|
||||
|
||||
@Query("SELECT * FROM offline_event WHERE event_id = :id LIMIT 1")
|
||||
fun getByEventIdSynchronous(id: Long): OfflineEvent
|
||||
@Query("SELECT * FROM offline_event WHERE event_guid = :guid LIMIT 1")
|
||||
fun getByEventIdSynchronous(guid: String): OfflineEvent
|
||||
|
||||
@Query("SELECT * FROM offline_event WHERE download_reference = :ref LIMIT 1")
|
||||
fun getByDownloadReference(ref: Long): LiveData<OfflineEvent>
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.arch.persistence.room.Index
|
|||
import android.arch.persistence.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "playback_progress",
|
||||
indices = arrayOf(Index(value = "event_id",unique = true)))
|
||||
indices = arrayOf(Index(value = ["event_id"],unique = true)))
|
||||
data class PlaybackProgress (@PrimaryKey
|
||||
@ColumnInfo(name = "event_id")
|
||||
var eventId: Long,
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.arch.persistence.room.Index
|
|||
import android.arch.persistence.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "watchlist_item",
|
||||
indices = arrayOf(Index(value = "event_id",unique = true)))
|
||||
indices = arrayOf(Index(value = ["event_id"],unique = true)))
|
||||
data class WatchlistItem(@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0,
|
||||
@ColumnInfo(name = "event_id")
|
||||
|
|
Loading…
Reference in a new issue