Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Feature/navigatum localization #1529

Merged
merged 4 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -32,8 +32,8 @@ class NavigaTumAPIClient(private val apiService: NavigaTumAPIService) {
return apiService.searchSingle(query)
}

fun getNavigationDetailsSingle(id: String): Single<NavigationDetailsDto> {
return apiService.getNavigationDetailsSingle(id)
fun getNavigationDetailsSingle(id: String, lang: String): Single<NavigationDetailsDto> {
return apiService.getNavigationDetailsSingle(id, lang)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationDetailsDto>

@GET(API_SEARCH)
Expand All @@ -27,13 +28,15 @@ interface NavigaTumAPIService {

@GET(API_GET)
fun getNavigationDetailsSingle(
@Path(ID_PARAM) id: String
@Path(ID_PARAM) id: String,
@Query(LANG_PARAM) lang: String
): Single<NavigationDetailsDto>

companion object {
private const val API_SEARCH = "api/search"
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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,8 +60,11 @@ class NavigationDetailsFragment : BaseFragment<Unit>(
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()
}
Expand Down Expand Up @@ -106,7 +110,7 @@ class NavigationDetailsFragment : BaseFragment<Unit>(
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
}
}
Comment on lines 110 to 116
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps someone with more android-fu can help me here. Is it possible to do this more elegantly with bindings, now that we don't do the translation anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know of a better way

Expand Down Expand Up @@ -158,17 +162,6 @@ class NavigationDetailsFragment : BaseFragment<Unit>(
.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() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down