setup search for events

This commit is contained in:
Felix 2020-03-29 14:42:29 +02:00
parent 9137d5c38a
commit 4859b7ed44
6 changed files with 58 additions and 61 deletions

View file

@ -26,6 +26,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import retrofit2.Response
class MediaRepository(
@ -170,17 +171,17 @@ class MediaRepository(
return persistantEvents
}
private suspend fun saveEvent(event: EventDto): Event {
private suspend fun saveEvent(event: EventDto): Event = withContext(Dispatchers.IO){
val acronym = event.conferenceUrl.split("/").last()
val conferenceId = conferenceDao.findConferenceByAcronym(acronym)?.id
?: updateConferencesAndGet(acronym)?.id
?: updateConferencesAndGet(acronym)?.id
checkNotNull(conferenceId) { "Could not find Conference for event" }
val persistentEvent = Event(event, conferenceId)
val id = eventDao.insert(persistentEvent)
persistentEvent.id = id
return persistentEvent
return@withContext persistentEvent
}
private suspend fun updateConferencesAndGet(acronym: String): Conference? {
@ -215,22 +216,14 @@ class MediaRepository(
}
suspend fun findEvents(queryString: String): List<Event> {
val events = recordingApi.searchEvents(queryString)
return events.events.mapNotNull {
val conference = findConferenceForUri(Uri.parse(it.conferenceUrl))
return@mapNotNull if(conference != null){
Event(it, conference.id)
} else {
Log.e("TAG", "Could not find conference for event")
null
}
val eventsResponse = recordingApi.searchEvents(queryString)
return eventsResponse.events.mapNotNull {
saveEvent(it)
}
}
suspend fun findConferenceForUri(data: Uri): Conference? {
val conference =
conferenceDao.findConferenceByAcronymSuspend(data.lastPathSegment)
return conference
return conferenceDao.findConferenceByAcronymSuspend(data.lastPathSegment)
}
private suspend fun searchEvent(queryString: String): Event? {

View file

@ -40,23 +40,6 @@
android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity android:name=".browse.BrowseActivity">
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity
android:name=".browse.eventslist.EventsListActivity"
android:parentActivityName=".browse.BrowseActivity"/>
<activity
android:name=".eventdetails.EventDetailsActivity"
android:parentActivityName=".browse.eventslist.EventsListActivity"/>
<activity
android:name=".about.AboutActivity"
android:parentActivityName=".browse.BrowseActivity"/>
<activity
android:name=".playback.PlayerActivity"

View file

@ -1,11 +1,13 @@
package de.nicidienase.chaosflix.touch
import android.app.SearchManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController
@ -55,6 +57,21 @@ class NavigationActivity : AppCompatActivity() {
binding.bottomNavigation.getOrCreateBadge(R.id.livestreamListFragment).number = roomCount
}
})
if(Intent.ACTION_SEARCH == intent?.action) {
intent.getStringExtra(SearchManager.QUERY)?.also { query ->
findNavController(R.id.nav_host).navigate(R.id.searchFragment, bundleOf("query" to query))
}
}
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
if(Intent.ACTION_SEARCH == intent?.action) {
intent.getStringExtra(SearchManager.QUERY)?.also { query ->
findNavController(R.id.nav_host).navigate(R.id.searchFragment, bundleOf("query" to query))
}
}
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {

View file

@ -33,21 +33,19 @@ class ConferenceGroupFragment : BrowseFragment() {
val view = inflater.inflate(R.layout.fragment_conferences_page, container, false)
if (view is RecyclerView) {
val context = view.getContext()
val recyclerView = view
layoutManager = if (columnCount <= 1) {
LinearLayoutManager(context)
} else {
GridLayoutManager(context, columnCount)
}
recyclerView.layoutManager = layoutManager
view.layoutManager = layoutManager
val conferencesAdapter = ConferenceRecyclerViewAdapter {
findNavController().navigate(
ConferencesTabBrowseFragmentDirections.actionConferencesTabBrowseFragmentToEventsListFragment(conference = it)
)
// TODO navigate to events-list for conference
}
conferencesAdapter?.setHasStableIds(true)
recyclerView.adapter = conferencesAdapter
conferencesAdapter.setHasStableIds(true)
view.adapter = conferencesAdapter
viewModel.getConferencesByGroup(conferenceGroup.id).observe(viewLifecycleOwner, Observer<List<Conference>> { conferenceList: List<Conference>? ->
if (conferenceList != null) {
if (conferenceList.isNotEmpty()) {
@ -78,6 +76,11 @@ class ConferenceGroupFragment : BrowseFragment() {
}
}
override fun onDestroyView() {
super.onDestroyView()
layoutManager = null
}
companion object {
private val TAG = ConferenceGroupFragment::class.java.simpleName
private const val ARG_COLUMN_COUNT = "column-count"

View file

@ -26,6 +26,7 @@ class ConferencesTabBrowseFragment : BrowseFragment(), SearchView.OnQueryTextLis
private var snackbar: Snackbar? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
Log.d(TAG, "onCreate")
if (arguments != null) {
mColumnCount = arguments!!.getInt(ARG_COLUMN_COUNT)
@ -46,6 +47,7 @@ class ConferencesTabBrowseFragment : BrowseFragment(), SearchView.OnQueryTextLis
setupToolbar(binding.incToolbar.toolbar, R.string.app_name)
overlay = binding.incOverlay.loadingOverlay
binding.search.setOnClickListener {
requireActivity().onSearchRequested()
}
viewModel.getConferenceGroups().observe(viewLifecycleOwner, Observer<List<ConferenceGroup?>> { conferenceGroups: List<ConferenceGroup?> ->
if (conferenceGroups.isNotEmpty()) {

View file

@ -100,30 +100,6 @@ class EventDetailsFragment : Fragment() {
(activity as AppCompatActivity).setSupportActionBar(binding.animToolbar)
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)
binding.relatedItemsList.apply {
relatedEventsAdapter = EventRecyclerViewAdapter {
viewModel.relatedEventSelected(it)
}
adapter = relatedEventsAdapter
val orientation = RecyclerView.VERTICAL
layoutManager =
LinearLayoutManager(context, orientation, false)
val itemDecoration = DividerItemDecoration(
binding.relatedItemsList.context,
orientation
)
addItemDecoration(itemDecoration)
}
binding.appbar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
val v = Math.abs(verticalOffset).toDouble() / appBarLayout.totalScrollRange
if (appBarExpanded xor (v > 0.8)) {
requireActivity().invalidateOptionsMenu()
appBarExpanded = v > 0.8
// binding.collapsingToolbar.isTitleEnabled = appBarExpanded
}
})
viewModel = ViewModelProvider(this, ViewModelFactory.getInstance(requireContext()))
.get(DetailsViewModel::class.java)
@ -162,6 +138,29 @@ class EventDetailsFragment : Fragment() {
})
}
binding.relatedItemsList.apply {
relatedEventsAdapter = EventRecyclerViewAdapter {
viewModel.relatedEventSelected(it)
}
adapter = relatedEventsAdapter
val orientation = RecyclerView.VERTICAL
layoutManager =
LinearLayoutManager(context, orientation, false)
val itemDecoration = DividerItemDecoration(
binding.relatedItemsList.context,
orientation
)
addItemDecoration(itemDecoration)
}
binding.appbar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
val v = Math.abs(verticalOffset).toDouble() / appBarLayout.totalScrollRange
if (appBarExpanded xor (v > 0.8)) {
requireActivity().invalidateOptionsMenu()
appBarExpanded = v > 0.8
// binding.collapsingToolbar.isTitleEnabled = appBarExpanded
}
})
viewModel.state.observe(viewLifecycleOwner, Observer { liveEvent ->