diff --git a/touch/build.gradle b/touch/build.gradle index da4a87f3..9ca0353e 100644 --- a/touch/build.gradle +++ b/touch/build.gradle @@ -54,7 +54,7 @@ android { dependencies { // implementation 'com.github.NiciDieNase:chaosflix-common:1.3.2' - implementation 'de.nicidienase.chaosflix:common:2.0.1-SNAPSHOT' + implementation 'de.nicidienase.chaosflix:common:2.0.0-SNAPSHOT' implementation('com.mikepenz:aboutlibraries:6.1.1@aar') { transitive = true diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/DetailsViewModel.kt b/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/DetailsViewModel.kt index 7d133369..20a9a5bd 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/DetailsViewModel.kt +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/DetailsViewModel.kt @@ -6,6 +6,7 @@ import android.arch.lifecycle.ViewModel import de.nicidienase.chaosflix.common.ChaosflixDatabase import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentEvent 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.network.RecordingService import de.nicidienase.chaosflix.common.mediadata.sync.Downloader import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEvent @@ -13,7 +14,6 @@ import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItem import de.nicidienase.chaosflix.common.util.ThreadHandler import de.nicidienase.chaosflix.touch.OfflineItemManager import java.io.File - class DetailsViewModel( val database: ChaosflixDatabase, recordingApi: RecordingService @@ -88,7 +88,17 @@ class DetailsViewModel( return result } + fun getRelatedEvents(event: PersistentEvent): LiveData>{ + val data = MutableLiveData>() + handler.runOnBackgroundThread { + val guids = database.relatedEventDao().getRelatedEventsForEventSync(event.id).map { it.relatedEventGuid } + data.postValue(database.eventDao().findEventsByGUIDsSync(guids)) + } + return data + } + companion object { val TAG = DetailsViewModel::class.simpleName } -} \ No newline at end of file +} + diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/EventDetailsFragment.kt b/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/EventDetailsFragment.kt index 8db61ea0..57908f8e 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/EventDetailsFragment.kt +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/eventdetails/EventDetailsFragment.kt @@ -37,7 +37,6 @@ class EventDetailsFragment : Fragment() { private var listener: OnEventDetailsFragmentInteractionListener? = null - private var eventId: Long = 0 private var appBarExpanded: Boolean = false private lateinit var event: PersistentEvent private var watchlistItem: WatchlistItem? = null @@ -102,26 +101,32 @@ class EventDetailsFragment : Fragment() { ViewModelFactory(requireContext())) .get(DetailsViewModel::class.java) - viewModel.setEvent(eventId) + viewModel.setEvent(event) + .observe(this, Observer { + Log.d(TAG,"Loading Event ${event.title}, ${event.guid}") + updateBookmark(event.guid) + binding.thumbImage.transitionName = getString(R.string.thumbnail) + event.guid + Picasso.with(context) + .load(event.thumbUrl) + .noFade() + .into(binding.thumbImage, object : Callback { + override fun onSuccess() { +// startPostponedEnterTransition() + } + + override fun onError() { +// startPostponedEnterTransition() + } + }) + + }) + viewModel.getRelatedEvents(event).observe(this, Observer { + + }) + .observe(this, Observer { event: PersistentEvent? -> if (event != null) { - Log.d(TAG,"Loading Event ${event.title}, ${event.guid}") - this.event = event - updateBookmark() - binding.event = event - binding.thumbImage.transitionName = getString(R.string.thumbnail) + event.guid - Picasso.with(context) - .load(event.thumbUrl) - .noFade() - .into(binding.thumbImage, object : Callback { - override fun onSuccess() { -// startPostponedEnterTransition() - } - override fun onError() { -// startPostponedEnterTransition() - } - }) val relatedGuids = event.related?.map { it.relatedEventGuid } // val relatedIds: LongArray = event.metadata?.related?.keys?.toLongArray() ?: longArrayOf() @@ -134,8 +139,8 @@ class EventDetailsFragment : Fragment() { }) } - private fun updateBookmark() { - viewModel.getBookmarkForEvent(event.guid) + private fun updateBookmark(guid: String) { + viewModel.getBookmarkForEvent(guid) .observe(this, Observer { watchlistItem: WatchlistItem? -> this.watchlistItem = watchlistItem listener?.invalidateOptionsMenu()