From 025cf8acc91a1bd2726852b37c14700e4b02d055 Mon Sep 17 00:00:00 2001 From: Christian <9384305+ctsk@users.noreply.github.com> Date: Mon, 14 Nov 2022 19:27:47 +0100 Subject: [PATCH] Feature/navigatum localization (#1529) * Add language parameter to navigatum queries * Remove 'getTranslationForPropertyTitle' --- .../api/navigatum/NavigaTumAPIClient.kt | 8 ++++---- .../api/navigatum/NavigaTumAPIService.kt | 7 +++++-- .../other/locations/LocationManager.kt | 3 ++- .../roomfinder/NavigationDetailsFragment.kt | 19 ++++++------------- .../roomfinder/NavigationDetailsViewModel.kt | 4 ++-- 5 files changed, 19 insertions(+), 22 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..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 @@ -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, as we only use the geo information from this request + 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..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 @@ -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() } @@ -106,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 } } @@ -158,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() } } 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)