From 845acd4a06508424285626c74c4c590fd54fb0ac Mon Sep 17 00:00:00 2001 From: ctsk <9384305+ctsk@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:48:52 +0100 Subject: [PATCH 1/4] Add language parameter to navigatum queries --- .../in/tumcampusapp/api/navigatum/NavigaTumAPIClient.kt | 8 ++++---- .../in/tumcampusapp/api/navigatum/NavigaTumAPIService.kt | 7 +++++-- .../component/other/locations/LocationManager.kt | 3 ++- .../tumui/roomfinder/NavigationDetailsFragment.kt | 6 +++++- .../tumui/roomfinder/NavigationDetailsViewModel.kt | 4 ++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIClient.kt b/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIClient.kt index 3a920871f8..4fda31130a 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIClient.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIClient.kt @@ -21,8 +21,8 @@ class NavigaTumAPIClient(private val apiService: NavigaTumAPIService) { .body() } - fun getNavigationDetails(id: String): NavigationDetails? { - return apiService.getNavigationDetails(id) + fun getNavigationDetails(id: String, lang: String): NavigationDetails? { + return apiService.getNavigationDetails(id, lang) .execute() .body() ?.toNavigationDetails() @@ -32,8 +32,8 @@ class NavigaTumAPIClient(private val apiService: NavigaTumAPIService) { return apiService.searchSingle(query) } - fun getNavigationDetailsSingle(id: String): Single { - return apiService.getNavigationDetailsSingle(id) + fun getNavigationDetailsSingle(id: String, lang: String): Single { + return apiService.getNavigationDetailsSingle(id, lang) } companion object { diff --git a/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIService.kt b/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIService.kt index 8649a55c76..59ecc07c47 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIService.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/NavigaTumAPIService.kt @@ -17,7 +17,8 @@ interface NavigaTumAPIService { @GET(API_GET) fun getNavigationDetails( - @Path(ID_PARAM) id: String + @Path(ID_PARAM) id: String, + @Query(LANG_PARAM) lang: String ): Call @GET(API_SEARCH) @@ -27,7 +28,8 @@ interface NavigaTumAPIService { @GET(API_GET) fun getNavigationDetailsSingle( - @Path(ID_PARAM) id: String + @Path(ID_PARAM) id: String, + @Query(LANG_PARAM) lang: String ): Single companion object { @@ -35,5 +37,6 @@ interface NavigaTumAPIService { private const val QUERY_PARAM = "q" private const val ID_PARAM = "id" private const val API_GET = "api/get/{$ID_PARAM}" + private const val LANG_PARAM = "lang" } } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt index 5ccfeb170d..a7d9c7696c 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt @@ -274,7 +274,8 @@ class LocationManager @Inject constructor(c: Context) { var geo: Geo? = null if (searchResult != null && searchResult.sections.isNotEmpty() && searchResult.sections[0].entries.isNotEmpty()) { val location = searchResult.sections[0].entries[0].id - val locationDetails = NavigaTumAPIClient.getInstance(mContext).getNavigationDetails(location) + // The language does not matter + val locationDetails = NavigaTumAPIClient.getInstance(mContext).getNavigationDetails(location, "de"); locationDetails?.let { geo = locationDetails.geo } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt index c4fbd239c6..ed57be70ca 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt @@ -12,6 +12,7 @@ import androidx.core.content.res.ResourcesCompat import androidx.core.os.bundleOf import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope +import androidx.preference.PreferenceManager import com.squareup.picasso.Picasso import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding import de.tum.`in`.tumcampusapp.R @@ -59,8 +60,11 @@ class NavigationDetailsFragment : BaseFragment( handleDetailsLoading() } + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + val lang = sharedPreferences.getString("language_preference", null) ?: "de" + navigationEntityId?.let { - viewModel.loadNavigationDetails(navigationEntityId!!) + viewModel.loadNavigationDetails(navigationEntityId!!, lang) } ?: run { showLoadingError() } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsViewModel.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsViewModel.kt index 37f52f43f0..0853f745cf 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsViewModel.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsViewModel.kt @@ -17,10 +17,10 @@ class NavigationDetailsViewModel @Inject constructor( private var disposable: Disposable? = null - fun loadNavigationDetails(navigationEntityId: String) { + fun loadNavigationDetails(navigationEntityId: String, language: String) { state.value = state.value.copy(isLoading = true) disposable = navigaTumAPIClient - .getNavigationDetailsSingle(navigationEntityId) + .getNavigationDetailsSingle(navigationEntityId, language) .subscribeOn(Schedulers.io()) .map { it.toNavigationDetails() } .doOnError(Utils::log) From 463fc724d3beb399c075ee82aa59730a60c9b4cd Mon Sep 17 00:00:00 2001 From: ctsk <9384305+ctsk@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:57:41 +0100 Subject: [PATCH 2/4] Remove 'getTranslationForPropertyTitle' --- .../tumui/roomfinder/NavigationDetailsFragment.kt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt index ed57be70ca..e8dbff3288 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt @@ -110,7 +110,7 @@ class NavigationDetailsFragment : BaseFragment( private fun showNavigationDetailsProperties(navigationDetails: NavigationDetails) { navigationDetails.properties.forEach { property -> val propertyRow = NavigationPropertyRowBinding.inflate(layoutInflater, binding.propsList, true) - propertyRow.propertyName.text = getTranslationForPropertyTitle(property.title) + propertyRow.propertyName.text = property.title propertyRow.propertyValue.text = property.value } } @@ -162,17 +162,6 @@ class NavigationDetailsFragment : BaseFragment( .into(binding.photoView) } - private fun getTranslationForPropertyTitle(title: String): String { - return when (title) { - "Raumkennung" -> getString(R.string.room_id) - "Adresse" -> getString(R.string.address) - "Architekten-Name" -> getString(R.string.architect_name) - "Sitzplätze" -> getString(R.string.seats) - "Anzahl Räume" -> getString(R.string.number_of_rooms) - else -> title - } - } - private fun getCapitalizeType(type: String): String { return type.replaceFirstChar { it.titlecase() } } From 77567b5ee54c7a8ba0570b33f69dcff5e4c5280c Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 14 Nov 2022 19:02:48 +0100 Subject: [PATCH 3/4] Clarifed a comment --- .../tumcampusapp/component/other/locations/LocationManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt index a7d9c7696c..ea9fc4a0ce 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt @@ -274,7 +274,7 @@ class LocationManager @Inject constructor(c: Context) { var geo: Geo? = null if (searchResult != null && searchResult.sections.isNotEmpty() && searchResult.sections[0].entries.isNotEmpty()) { val location = searchResult.sections[0].entries[0].id - // The language does not matter + // The language does not matter, as we only use the geo information from this request val locationDetails = NavigaTumAPIClient.getInstance(mContext).getNavigationDetails(location, "de"); locationDetails?.let { geo = locationDetails.geo From afc2de8f5acc7f17972ef1dd85cab9dd61fec9e0 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 14 Nov 2022 19:18:01 +0100 Subject: [PATCH 4/4] Formatting fix --- .../tumcampusapp/component/other/locations/LocationManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt index ea9fc4a0ce..473dfb497e 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/other/locations/LocationManager.kt @@ -275,7 +275,7 @@ class LocationManager @Inject constructor(c: Context) { if (searchResult != null && searchResult.sections.isNotEmpty() && searchResult.sections[0].entries.isNotEmpty()) { val location = searchResult.sections[0].entries[0].id // The language does not matter, as we only use the geo information from this request - val locationDetails = NavigaTumAPIClient.getInstance(mContext).getNavigationDetails(location, "de"); + val locationDetails = NavigaTumAPIClient.getInstance(mContext).getNavigationDetails(location, "de") locationDetails?.let { geo = locationDetails.geo }