From e2043c21321eff5fbdd65653bc843869e10276fe Mon Sep 17 00:00:00 2001 From: Chiara Pellegrini Date: Mon, 9 Dec 2024 10:53:09 +0100 Subject: [PATCH 1/2] Changed argument of destination EventDetailsFragment --- .../java/it/bz/noi/community/MainActivity.kt | 10 +- .../data/api/OpendatahubApiService.kt | 2 +- .../it/bz/noi/community/data/models/Event.kt | 95 +++++++------ .../it/bz/noi/community/ui/MainViewModel.kt | 2 +- .../ui/eventDetails/EventDetailsFragment.kt | 133 +++++++++++++++--- .../ui/eventDetails/EventDetailsViewModel.kt | 6 +- .../noi/community/ui/today/TodayViewModel.kt | 4 +- .../ui/today/events/EventsAdapter.kt | 10 +- .../ui/today/events/EventsFragment.kt | 8 +- .../java/it/bz/noi/community/utils/Utils.kt | 11 +- .../main/res/navigation/mobile_navigation.xml | 6 +- 11 files changed, 194 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/it/bz/noi/community/MainActivity.kt b/app/src/main/java/it/bz/noi/community/MainActivity.kt index b64fe09..da1ca59 100644 --- a/app/src/main/java/it/bz/noi/community/MainActivity.kt +++ b/app/src/main/java/it/bz/noi/community/MainActivity.kt @@ -20,19 +20,17 @@ import androidx.navigation.findNavController import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupWithNavController -import it.bz.noi.community.ui.onboarding.OnboardingActivity.Companion.LOGOUT_REQUEST -import it.bz.noi.community.databinding.ActivityMainBinding import it.bz.noi.community.data.repository.AccountsManager +import it.bz.noi.community.databinding.ActivityMainBinding +import it.bz.noi.community.notifications.MessagingService import it.bz.noi.community.oauth.AuthManager import it.bz.noi.community.oauth.AuthStateStatus -import it.bz.noi.community.notifications.MessagingService -import it.bz.noi.community.storage.getWelcomeUnderstood import it.bz.noi.community.ui.WebViewFragment import it.bz.noi.community.ui.onboarding.OnboardingActivity +import it.bz.noi.community.ui.onboarding.OnboardingActivity.Companion.LOGOUT_REQUEST import it.bz.noi.community.utils.Utils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import net.openid.appauth.AuthorizationException class MainActivity : AppCompatActivity() { @@ -78,7 +76,7 @@ class MainActivity : AppCompatActivity() { setupActionBarWithNavController(navController, appBarConfiguration) binding.navView.setupWithNavController(navController) - navController.addOnDestinationChangedListener { controller, destination, arguments -> + navController.addOnDestinationChangedListener { _, destination, arguments -> when (destination.id) { R.id.navigation_more -> { supportActionBar?.hide() diff --git a/app/src/main/java/it/bz/noi/community/data/api/OpendatahubApiService.kt b/app/src/main/java/it/bz/noi/community/data/api/OpendatahubApiService.kt index 52b37c3..224adb7 100644 --- a/app/src/main/java/it/bz/noi/community/data/api/OpendatahubApiService.kt +++ b/app/src/main/java/it/bz/noi/community/data/api/OpendatahubApiService.kt @@ -27,7 +27,7 @@ interface OpendatahubApiService { @GET("v1/EventShort/{id}") suspend fun getEventDetails( @Path("id") eventID: String, - ): EventsResponse.Event + ): Event /*@GET("v1/EventShort/Detail/{id}") suspend fun getEventDetails( diff --git a/app/src/main/java/it/bz/noi/community/data/models/Event.kt b/app/src/main/java/it/bz/noi/community/data/models/Event.kt index a65765e..52b101e 100644 --- a/app/src/main/java/it/bz/noi/community/data/models/Event.kt +++ b/app/src/main/java/it/bz/noi/community/data/models/Event.kt @@ -4,53 +4,60 @@ package it.bz.noi.community.data.models +import android.os.Parcelable +import androidx.annotation.Keep import com.google.gson.annotations.SerializedName -import java.util.* +import kotlinx.parcelize.Parcelize +import java.util.Date + data class EventsResponse( @SerializedName("Items") val events: List -) { - data class Event( - @SerializedName("Id") - val eventId: String? = null, - @SerializedName("EventDescription") - val name: String? = null, - @SerializedName("EventDescriptionEN") - val nameEN: String? = null, - @SerializedName("EventDescriptionIT") - val nameIT: String? = null, - @SerializedName("EventDescriptionDE") - val nameDE: String? = null, - @SerializedName("EventTextEN") - val descriptionEN: String? = null, - @SerializedName("EventTextIT") - val descriptionIT: String? = null, - @SerializedName("EventTextDE") - val descriptionDE: String? = null, - @SerializedName("AnchorVenue") - val location: String? = null, - @SerializedName("Display5") - val eventOrganizer: String? = null, - @SerializedName("CompanyName") - val eventOrganizerFallback: String? = null, - @SerializedName("StartDate") - val startDate: Date, - @SerializedName("EndDate") - val endDate: Date, - @SerializedName("TechnologyFields") - val technologyFields: List? = null, - @SerializedName("ImageGallery") - val imageGallery: List? = null, - @SerializedName("AnchorVenueRoomMapping") - val roomName: String? = null, - @SerializedName("WebAddress") - val webAddress: String? = null - ) { - data class ImageGallery( - @SerializedName("ImageUrl") - val imageUrl: String? = null - ) - } -} +) +@Keep +@Parcelize +data class Event( + @SerializedName("Id") + val eventId: String? = null, + @SerializedName("EventDescription") + val name: String? = null, + @SerializedName("EventDescriptionEN") + val nameEN: String? = null, + @SerializedName("EventDescriptionIT") + val nameIT: String? = null, + @SerializedName("EventDescriptionDE") + val nameDE: String? = null, + @SerializedName("EventTextEN") + val descriptionEN: String? = null, + @SerializedName("EventTextIT") + val descriptionIT: String? = null, + @SerializedName("EventTextDE") + val descriptionDE: String? = null, + @SerializedName("AnchorVenue") + val location: String? = null, + @SerializedName("Display5") + val eventOrganizer: String? = null, + @SerializedName("CompanyName") + val eventOrganizerFallback: String? = null, + @SerializedName("StartDate") + val startDate: Date, + @SerializedName("EndDate") + val endDate: Date, + @SerializedName("TechnologyFields") + val technologyFields: List? = null, + @SerializedName("ImageGallery") + val imageGallery: List? = null, + @SerializedName("AnchorVenueRoomMapping") + val roomName: String? = null, + @SerializedName("WebAddress") + val webAddress: String? = null +) : Parcelable { + @Keep + @Parcelize + data class ImageGallery( + @SerializedName("ImageUrl") + val imageUrl: String? = null + ) : Parcelable +} diff --git a/app/src/main/java/it/bz/noi/community/ui/MainViewModel.kt b/app/src/main/java/it/bz/noi/community/ui/MainViewModel.kt index 308ea2c..bed3fb9 100644 --- a/app/src/main/java/it/bz/noi/community/ui/MainViewModel.kt +++ b/app/src/main/java/it/bz/noi/community/ui/MainViewModel.kt @@ -137,7 +137,7 @@ class MainViewModel( /** * mediator live data that emits the events to the observers */ - val mediatorEvents = MediatorLiveData>>() + val mediatorEvents = MediatorLiveData>>() init { mediatorEvents.addSource(events) { diff --git a/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt b/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt index 32eac81..83bbcb4 100644 --- a/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt +++ b/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt @@ -6,7 +6,6 @@ package it.bz.noi.community.ui.eventDetails import android.content.Intent import android.graphics.drawable.Drawable -import android.net.Uri import android.os.Bundle import android.provider.CalendarContract import android.provider.CalendarContract.Events @@ -25,11 +24,9 @@ import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels -import androidx.lifecycle.Observer import androidx.lifecycle.asLiveData import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager.HORIZONTAL import androidx.transition.TransitionInflater @@ -42,7 +39,7 @@ import com.google.android.material.card.MaterialCardView import it.bz.noi.community.R import it.bz.noi.community.data.api.ApiHelper import it.bz.noi.community.data.api.RetrofitBuilder -import it.bz.noi.community.data.models.EventsResponse +import it.bz.noi.community.data.models.Event import it.bz.noi.community.data.repository.JsonFilterRepository import it.bz.noi.community.databinding.FragmentEventDetailsBinding import it.bz.noi.community.ui.MainViewModel @@ -59,13 +56,13 @@ import it.bz.noi.community.utils.Utils.getEventOrganizer import it.bz.noi.community.utils.Utils.getImageUrl import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi -import java.util.* +import java.util.Date @OptIn(ExperimentalCoroutinesApi::class) class EventDetailsFragment : Fragment(), EventClickListener { private lateinit var binding: FragmentEventDetailsBinding - private val args: EventDetailsFragmentArgs by navArgs() + //private val args: EventDetailsFragmentArgs by navArgs() private val mainViewModel: MainViewModel by activityViewModels(factoryProducer = { ViewModelFactory( @@ -79,11 +76,11 @@ class EventDetailsFragment : Fragment(), EventClickListener { this@EventDetailsFragment) }) - private lateinit var allEvents: ArrayList + private lateinit var allEvents: ArrayList - private lateinit var selectedEvent: EventsResponse.Event + //private lateinit var selectedEvent: EventsResponse.Event - private val suggestedEvents = arrayListOf() + private val suggestedEvents = arrayListOf() private val suggestedEventsAdapter by lazy { EventsAdapter( @@ -125,6 +122,7 @@ class EventDetailsFragment : Fragment(), EventClickListener { } +/* mainViewModel.mediatorEvents.observe(viewLifecycleOwner) { when (it.status) { Status.SUCCESS -> { @@ -145,9 +143,9 @@ class EventDetailsFragment : Fragment(), EventClickListener { binding.addToCalendarOrSignup.text = getString(R.string.btn_sign_up) binding.addToCalendarOrSignup.setIconResource(R.drawable.ic_sign_up) binding.addToCalendarOrSignup.setOnClickListener { - val browserIntent = - Intent(Intent.ACTION_VIEW, Uri.parse(selectedEvent.webAddress)) - startActivity(browserIntent) +// val browserIntent = +// Intent(Intent.ACTION_VIEW, Uri.parse(selectedEvent.webAddress)) +// startActivity(browserIntent) } } else { binding.addToCalendarOrSignup.text = @@ -239,14 +237,15 @@ class EventDetailsFragment : Fragment(), EventClickListener { } } } +*/ -/* eventViewModel.eventFlow.asLiveData(Dispatchers.Main).observe(viewLifecycleOwner) { + eventViewModel.eventFlow.asLiveData(Dispatchers.Main).observe(viewLifecycleOwner) { when(it.status) { Status.SUCCESS -> { binding.progressBarLoading.isVisible = false val event = it.data!! - //loadEventData(event) + loadEventData(event) } Status.ERROR -> { binding.progressBarLoading.isVisible = false @@ -256,13 +255,111 @@ class EventDetailsFragment : Fragment(), EventClickListener { binding.progressBarLoading.isVisible = true } } - }*/ + } + } + + private fun loadEventData(event: Event) { + (requireActivity() as AppCompatActivity).supportActionBar?.title = + getEventName(event) + + setTransitionNames(event.eventId!!) + loadEventImage(getImageUrl(event)) + + setDate(event.startDate, event.endDate) + + if (event.webAddress != null) { + binding.addToCalendarOrSignup.text = getString(R.string.btn_sign_up) + binding.addToCalendarOrSignup.setIconResource(R.drawable.ic_sign_up) + binding.addToCalendarOrSignup.setOnClickListener { +// val browserIntent = +// Intent(Intent.ACTION_VIEW, Uri.parse(selectedEvent.webAddress)) +// startActivity(browserIntent) + } + } else { + binding.addToCalendarOrSignup.text = + getString(R.string.btn_add_to_calendar) + binding.addToCalendarOrSignup.setIconResource(R.drawable.ic_add_to_calendar) + binding.addToCalendarOrSignup.setOnClickListener { + val beginTime = event.startDate.time + val endTime = event.endDate.time + + val intent: Intent = Intent(Intent.ACTION_INSERT) + .setData(Events.CONTENT_URI) + .putExtra( + CalendarContract.EXTRA_EVENT_BEGIN_TIME, + beginTime + ) + .putExtra( + CalendarContract.EXTRA_EVENT_END_TIME, + endTime + ) + .putExtra(Events.TITLE, getEventName(event)) + .putExtra( + Events.DESCRIPTION, + getEventDescription(event) + ) + .putExtra(Events.EVENT_LOCATION, event.location) + .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY) + + startActivity(intent) + } + } + + binding.findOnMaps.setOnClickListener { + mainViewModel.getRoomMapping().observe(viewLifecycleOwner) { + when (it.status) { + Status.SUCCESS -> { + binding.progressBarLoading.isVisible = false + + val mapTitle = event.location + val mapUrl = it.data?.get(event.roomName) + ?: resources.getString(R.string.url_map) + + findNavController().navigate( + R.id.action_global_webViewFragment, bundleOf( + WebViewFragment.TITLE_ARG to mapTitle, + WebViewFragment.URL_ARG to Utils.addParamsToUrl( + mapUrl, + fullview = true, + hidezoom = true + ) + ) + ) + } + + Status.LOADING -> { + binding.progressBarLoading.isVisible = true + } + + Status.ERROR -> { + binding.progressBarLoading.isVisible = false + Toast.makeText( + requireContext(), + it.message, + Toast.LENGTH_LONG + ).show() + } + } + } + } + + binding.tvEventName.text = getEventName(event) + binding.tvEventLocation.text = event.location + binding.tvEventOrganizer.text = getEventOrganizer(event) + if (getEventDescription(event).isNullOrEmpty()) { + binding.tvAboutLabel.isVisible = false + binding.tvEventDescription.isVisible = false + } else + binding.tvEventDescription.text = getEventDescription(event) + + // FIXME -> come viene popolata la lista degli eventi? + //populateSuggestedEvents(events, event) } /** * populate the UI of the suggested filters */ - private fun populateSuggestedEvents(events: List) { + private fun populateSuggestedEvents(events: List, selectedEvent: Event) { suggestedEvents.clear() for (event in events) { if (suggestedEvents.size == 3) @@ -338,7 +435,7 @@ class EventDetailsFragment : Fragment(), EventClickListener { * Clicking on suggested event will result in open another EventDetailsFragment instance */ override fun onEventClick( - event: EventsResponse.Event, + event: Event, cardEvent: MaterialCardView, cardDate: CardView, eventName: TextView, @@ -363,7 +460,7 @@ class EventDetailsFragment : Fragment(), EventClickListener { findNavController().navigate( EventDetailsFragmentDirections.actionEventDetailsFragmentSelf( null, - allEvents.indexOf(event) + event ), extras ) diff --git a/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsViewModel.kt b/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsViewModel.kt index a17b6b7..196095c 100644 --- a/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsViewModel.kt +++ b/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsViewModel.kt @@ -9,7 +9,7 @@ import androidx.lifecycle.AbstractSavedStateViewModelFactory import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import it.bz.noi.community.data.api.ApiHelper -import it.bz.noi.community.data.models.EventsResponse +import it.bz.noi.community.data.models.Event import it.bz.noi.community.data.repository.MainRepository import it.bz.noi.community.utils.Resource import kotlinx.coroutines.flow.Flow @@ -26,10 +26,10 @@ class EventDetailsViewModel( private const val EVENT_ARG = "event" } - private val event = MutableStateFlow(savedStateHandle[EVENT_ARG]) + private val event = MutableStateFlow(savedStateHandle[EVENT_ARG]) private val eventId = MutableStateFlow(savedStateHandle[EVENT_ID_ARG]) - val eventFlow: Flow> = event.combine(eventId) { _event, _eventId -> + val eventFlow: Flow> = event.combine(eventId) { _event, _eventId -> Resource.loading(null) when { _event != null -> { diff --git a/app/src/main/java/it/bz/noi/community/ui/today/TodayViewModel.kt b/app/src/main/java/it/bz/noi/community/ui/today/TodayViewModel.kt index eb6fed8..74d67ee 100644 --- a/app/src/main/java/it/bz/noi/community/ui/today/TodayViewModel.kt +++ b/app/src/main/java/it/bz/noi/community/ui/today/TodayViewModel.kt @@ -5,8 +5,8 @@ package it.bz.noi.community.ui.today import androidx.lifecycle.ViewModel -import it.bz.noi.community.data.models.EventsResponse +import it.bz.noi.community.data.models.Event class TodayViewModel : ViewModel() { - val events = arrayListOf() + val events = arrayListOf() } diff --git a/app/src/main/java/it/bz/noi/community/ui/today/events/EventsAdapter.kt b/app/src/main/java/it/bz/noi/community/ui/today/events/EventsAdapter.kt index a316094..709192c 100644 --- a/app/src/main/java/it/bz/noi/community/ui/today/events/EventsAdapter.kt +++ b/app/src/main/java/it/bz/noi/community/ui/today/events/EventsAdapter.kt @@ -16,7 +16,7 @@ import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.google.android.material.card.MaterialCardView import it.bz.noi.community.R -import it.bz.noi.community.data.models.EventsResponse +import it.bz.noi.community.data.models.Event import it.bz.noi.community.utils.DateUtils.getDateIntervalString import it.bz.noi.community.utils.DateUtils.getHoursIntervalString import it.bz.noi.community.utils.Utils @@ -28,7 +28,7 @@ import it.bz.noi.community.utils.Utils.getEventName */ interface EventClickListener { fun onEventClick( - event: EventsResponse.Event, + event: Event, cardEvent: MaterialCardView, cardDate: CardView, eventName: TextView, @@ -47,7 +47,7 @@ interface EventClickListener { * fragment parameter to avoid clicked view to have the fade out animation */ class EventsAdapter( - private val events: List, + private val events: List, private val listener: EventClickListener, private val isSuggestedEvents: Boolean = false ) : @@ -82,7 +82,7 @@ class EventsAdapter( private val locationIcon = view.findViewById(R.id.ivLocation) private val timeIcon = view.findViewById(R.id.ivTime) - private lateinit var event: EventsResponse.Event + private lateinit var event: Event init { view.rootView.setOnClickListener { @@ -101,7 +101,7 @@ class EventsAdapter( } } - fun bind(event: EventsResponse.Event) { + fun bind(event: Event) { this.event = event eventName.text = getEventName(event) diff --git a/app/src/main/java/it/bz/noi/community/ui/today/events/EventsFragment.kt b/app/src/main/java/it/bz/noi/community/ui/today/events/EventsFragment.kt index 38291af..48430a3 100644 --- a/app/src/main/java/it/bz/noi/community/ui/today/events/EventsFragment.kt +++ b/app/src/main/java/it/bz/noi/community/ui/today/events/EventsFragment.kt @@ -23,7 +23,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager.HORIZONTAL import com.google.android.material.card.MaterialCardView import it.bz.noi.community.R -import it.bz.noi.community.data.models.EventsResponse +import it.bz.noi.community.data.models.Event import it.bz.noi.community.data.models.TimeFilter import it.bz.noi.community.data.models.TimeRange import it.bz.noi.community.databinding.FragmentEventsBinding @@ -162,7 +162,7 @@ class EventsFragment : Fragment(), EventClickListener, TimeFilterClickListener { } } - private fun retrieveList(events: List) { + private fun retrieveList(events: List) { todayViewModel.events.apply { clear() addAll(events) @@ -171,7 +171,7 @@ class EventsFragment : Fragment(), EventClickListener, TimeFilterClickListener { } override fun onEventClick( - event: EventsResponse.Event, + event: Event, cardEvent: MaterialCardView, cardDate: CardView, eventName: TextView, @@ -195,7 +195,7 @@ class EventsFragment : Fragment(), EventClickListener, TimeFilterClickListener { findNavController().navigate( TodayFragmentDirections.actionNavigationTodayToEventDetailsFragment( null, - todayViewModel.events.indexOf(event) + event ), extras ) diff --git a/app/src/main/java/it/bz/noi/community/utils/Utils.kt b/app/src/main/java/it/bz/noi/community/utils/Utils.kt index 3c9a063..b70199a 100644 --- a/app/src/main/java/it/bz/noi/community/utils/Utils.kt +++ b/app/src/main/java/it/bz/noi/community/utils/Utils.kt @@ -4,7 +4,6 @@ package it.bz.noi.community.utils -import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.net.Uri @@ -12,7 +11,7 @@ import androidx.lifecycle.SavedStateHandle import com.google.android.material.dialog.MaterialAlertDialogBuilder import it.bz.noi.community.BuildConfig import it.bz.noi.community.R -import it.bz.noi.community.data.models.EventsResponse +import it.bz.noi.community.data.models.Event import java.net.URLEncoder import java.text.Normalizer import java.util.* @@ -43,7 +42,7 @@ object Utils { return null } - fun getEventDescription(event: EventsResponse.Event): String? { + fun getEventDescription(event: Event): String? { return when (Locale.getDefault().language) { ITALIAN -> { event.descriptionIT @@ -59,7 +58,7 @@ object Utils { } } - fun getEventName(event: EventsResponse.Event, fallback: String = "N/D"): String { + fun getEventName(event: Event, fallback: String = "N/D"): String { return when (Locale.getDefault().language) { ITALIAN -> { event.nameIT ?: event.name ?: fallback @@ -75,14 +74,14 @@ object Utils { } } - fun getEventOrganizer(event: EventsResponse.Event, fallback: String = "N/D"): String { + fun getEventOrganizer(event: Event, fallback: String = "N/D"): String { return if (event.eventOrganizer.isNullOrEmpty()) event.eventOrganizerFallback ?: fallback else event.eventOrganizer } - fun getImageUrl(event: EventsResponse.Event): String? { + fun getImageUrl(event: Event): String? { var eventImageUrl = event.imageGallery?.firstOrNull { it.imageUrl != null }?.imageUrl if (eventImageUrl?.startsWith(HTTP_PREFIX) == true) { diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index 405d0c9..8b1db55 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -73,9 +73,9 @@ SPDX-License-Identifier: CC0-1.0 app:argType="string" app:nullable="true" /> + android:name="event" + app:argType="it.bz.noi.community.data.models.Event" + app:nullable="true" /> From 0b6ad726cb1db0f80b7f0398a97bcde7ac752d81 Mon Sep 17 00:00:00 2001 From: Chiara Pellegrini Date: Mon, 9 Dec 2024 11:37:10 +0100 Subject: [PATCH 2/2] Restored suggested events on event details fragment --- .../ui/eventDetails/EventDetailsFragment.kt | 147 +++--------------- 1 file changed, 22 insertions(+), 125 deletions(-) diff --git a/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt b/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt index 83bbcb4..1ba6d07 100644 --- a/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt +++ b/app/src/main/java/it/bz/noi/community/ui/eventDetails/EventDetailsFragment.kt @@ -6,6 +6,7 @@ package it.bz.noi.community.ui.eventDetails import android.content.Intent import android.graphics.drawable.Drawable +import android.net.Uri import android.os.Bundle import android.provider.CalendarContract import android.provider.CalendarContract.Events @@ -62,8 +63,6 @@ import java.util.Date class EventDetailsFragment : Fragment(), EventClickListener { private lateinit var binding: FragmentEventDetailsBinding - //private val args: EventDetailsFragmentArgs by navArgs() - private val mainViewModel: MainViewModel by activityViewModels(factoryProducer = { ViewModelFactory( ApiHelper(RetrofitBuilder.opendatahubApiService, RetrofitBuilder.communityApiService), @@ -78,8 +77,6 @@ class EventDetailsFragment : Fragment(), EventClickListener { private lateinit var allEvents: ArrayList - //private lateinit var selectedEvent: EventsResponse.Event - private val suggestedEvents = arrayListOf() private val suggestedEventsAdapter by lazy { @@ -121,110 +118,29 @@ class EventDetailsFragment : Fragment(), EventClickListener { } } + eventViewModel.eventFlow.asLiveData(Dispatchers.Main).observe(viewLifecycleOwner) { + when(it.status) { + Status.SUCCESS -> { + binding.progressBarLoading.isVisible = false + val event = it.data!! + loadEventData(event) + } + Status.ERROR -> { + binding.progressBarLoading.isVisible = false + Toast.makeText(requireContext(), it.message, Toast.LENGTH_LONG).show() + } + Status.LOADING -> { + binding.progressBarLoading.isVisible = true + } + } + } -/* mainViewModel.mediatorEvents.observe(viewLifecycleOwner) { when (it.status) { Status.SUCCESS -> { val events = it.data if (!events.isNullOrEmpty()) { - allEvents = events as ArrayList - selectedEvent = events[args.eventIndex] - - (requireActivity() as AppCompatActivity).supportActionBar?.title = - getEventName(selectedEvent) - - setTransitionNames(selectedEvent.eventId!!) - loadEventImage(getImageUrl(selectedEvent)) - - setDate(selectedEvent.startDate, selectedEvent.endDate) - - if (selectedEvent.webAddress != null) { - binding.addToCalendarOrSignup.text = getString(R.string.btn_sign_up) - binding.addToCalendarOrSignup.setIconResource(R.drawable.ic_sign_up) - binding.addToCalendarOrSignup.setOnClickListener { -// val browserIntent = -// Intent(Intent.ACTION_VIEW, Uri.parse(selectedEvent.webAddress)) -// startActivity(browserIntent) - } - } else { - binding.addToCalendarOrSignup.text = - getString(R.string.btn_add_to_calendar) - binding.addToCalendarOrSignup.setIconResource(R.drawable.ic_add_to_calendar) - binding.addToCalendarOrSignup.setOnClickListener { - val beginTime = selectedEvent.startDate.time - val endTime = selectedEvent.endDate.time - - val intent: Intent = Intent(Intent.ACTION_INSERT) - .setData(Events.CONTENT_URI) - .putExtra( - CalendarContract.EXTRA_EVENT_BEGIN_TIME, - beginTime - ) - .putExtra( - CalendarContract.EXTRA_EVENT_END_TIME, - endTime - ) - .putExtra(Events.TITLE, getEventName(selectedEvent)) - .putExtra( - Events.DESCRIPTION, - getEventDescription(selectedEvent) - ) - .putExtra(Events.EVENT_LOCATION, selectedEvent.location) - .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY) - - startActivity(intent) - } - } - - binding.findOnMaps.setOnClickListener { - mainViewModel.getRoomMapping().observe(viewLifecycleOwner, Observer { - when (it.status) { - Status.SUCCESS -> { - binding.progressBarLoading.isVisible = false - - val mapTitle = selectedEvent.location - val mapUrl = it.data?.get(selectedEvent.roomName) - ?: resources.getString(R.string.url_map) - - findNavController().navigate( - R.id.action_global_webViewFragment, bundleOf( - WebViewFragment.TITLE_ARG to mapTitle, - WebViewFragment.URL_ARG to Utils.addParamsToUrl( - mapUrl, - fullview = true, - hidezoom = true - ) - ) - ) - } - - Status.LOADING -> { - binding.progressBarLoading.isVisible = true - } - - Status.ERROR -> { - binding.progressBarLoading.isVisible = false - Toast.makeText( - requireContext(), - it.message, - Toast.LENGTH_LONG - ).show() - } - } - }) - } - - binding.tvEventName.text = getEventName(selectedEvent) - binding.tvEventLocation.text = selectedEvent.location - binding.tvEventOrganizer.text = getEventOrganizer(selectedEvent) - if (getEventDescription(selectedEvent).isNullOrEmpty()) { - binding.tvAboutLabel.isVisible = false - binding.tvEventDescription.isVisible = false - } else - binding.tvEventDescription.text = getEventDescription(selectedEvent) - - populateSuggestedEvents(events) + allEvents = events as ArrayList } else { binding.tvInterestingForYou.isVisible = false } @@ -237,25 +153,7 @@ class EventDetailsFragment : Fragment(), EventClickListener { } } } -*/ - - eventViewModel.eventFlow.asLiveData(Dispatchers.Main).observe(viewLifecycleOwner) { - when(it.status) { - Status.SUCCESS -> { - binding.progressBarLoading.isVisible = false - val event = it.data!! - loadEventData(event) - } - Status.ERROR -> { - binding.progressBarLoading.isVisible = false - Toast.makeText(requireContext(), it.message, Toast.LENGTH_LONG).show() - } - Status.LOADING -> { - binding.progressBarLoading.isVisible = true - } - } - } } private fun loadEventData(event: Event) { @@ -271,9 +169,9 @@ class EventDetailsFragment : Fragment(), EventClickListener { binding.addToCalendarOrSignup.text = getString(R.string.btn_sign_up) binding.addToCalendarOrSignup.setIconResource(R.drawable.ic_sign_up) binding.addToCalendarOrSignup.setOnClickListener { -// val browserIntent = -// Intent(Intent.ACTION_VIEW, Uri.parse(selectedEvent.webAddress)) -// startActivity(browserIntent) + val browserIntent = + Intent(Intent.ACTION_VIEW, Uri.parse(event.webAddress)) + startActivity(browserIntent) } } else { binding.addToCalendarOrSignup.text = @@ -352,8 +250,7 @@ class EventDetailsFragment : Fragment(), EventClickListener { } else binding.tvEventDescription.text = getEventDescription(event) - // FIXME -> come viene popolata la lista degli eventi? - //populateSuggestedEvents(events, event) + populateSuggestedEvents(allEvents, event) } /**