add handling for media.ccc.de/c/ links (to conferences)

This commit is contained in:
Felix 2020-02-08 18:47:14 +01:00
parent e1362ff23c
commit 6790640a4e
5 changed files with 40 additions and 7 deletions

View file

@ -214,6 +214,12 @@ class MediaRepository(
return event
}
suspend fun findConferenceForUri(data: Uri): Conference? {
val conference =
conferenceDao.findConferenceByAcronymSuspend(data.lastPathSegment)
return conference
}
private suspend fun searchEvent(queryString: String): Event? {
val searchEvents = recordingApi.searchEvents(queryString)
if (searchEvents.events.isNotEmpty()) {

View file

@ -19,6 +19,7 @@ import de.nicidienase.chaosflix.common.util.LiveDataMerger
import de.nicidienase.chaosflix.common.util.LiveEvent
import de.nicidienase.chaosflix.common.util.SingleLiveEvent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class BrowseViewModel(
val offlineItemManager: OfflineItemManager,

View file

@ -15,7 +15,7 @@ class SplashViewModel(
private val mediaRepository: MediaRepository
) : ViewModel() {
val state: SingleLiveEvent<LiveEvent<State, Event, Exception>> = SingleLiveEvent()
val state: SingleLiveEvent<LiveEvent<State, Any, Exception>> = SingleLiveEvent()
fun findEventForUri(data: Uri) = viewModelScope.launch(Dispatchers.IO) {
try {
@ -30,6 +30,19 @@ class SplashViewModel(
}
}
fun findConferenceForUri(data: Uri) = viewModelScope.launch(Dispatchers.IO) {
try {
val conference = mediaRepository.findConferenceForUri(data)
if (conference != null) {
state.postValue(LiveEvent(State.FOUND, conference))
} else {
state.postValue(LiveEvent(State.NOT_FOUND))
}
} catch (ex: Exception) {
state.postValue(LiveEvent(State.NOT_FOUND, error = ex))
}
}
enum class State {
FOUND,
NOT_FOUND

View file

@ -37,6 +37,10 @@
android:scheme="https"
android:host="media.ccc.de"
android:pathPrefix="/v/"/>
<data
android:scheme="https"
android:host="media.ccc.de"
android:pathPrefix="/c/"/>
</intent-filter>
</activity>
<activity android:name=".browse.BrowseActivity">

View file

@ -6,10 +6,12 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Conference
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
import de.nicidienase.chaosflix.common.viewmodel.SplashViewModel
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
import de.nicidienase.chaosflix.touch.browse.BrowseActivity
import de.nicidienase.chaosflix.touch.browse.eventslist.EventsListActivity
import de.nicidienase.chaosflix.touch.eventdetails.EventDetailsActivity
class SplashActivity : AppCompatActivity() {
@ -37,11 +39,10 @@ class SplashActivity : AppCompatActivity() {
viewModel.state.observe(this, Observer {
when (it.state) {
SplashViewModel.State.FOUND -> {
val event = it.data
if (event != null) {
goToEvent(event)
} else {
goToOverview()
when (val item = it.data) {
is Event -> goToEvent(item)
is Conference -> goToConference(item)
else -> goToOverview()
}
}
SplashViewModel.State.NOT_FOUND -> {
@ -51,7 +52,10 @@ class SplashActivity : AppCompatActivity() {
})
if (data != null) {
viewModel.findEventForUri(data)
when (data.pathSegments[0]) {
"v" -> viewModel.findEventForUri(data)
"c" -> viewModel.findConferenceForUri(data)
}
} else {
goToOverview()
}
@ -66,4 +70,9 @@ class SplashActivity : AppCompatActivity() {
EventDetailsActivity.launch(this, event)
finish()
}
private fun goToConference(conference: Conference) {
EventsListActivity.start(this, conference)
finish()
}
}