Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following software is expected to be available:

# How it works

The app will download a discovery list from `https://discovery.eduroam.app/v2/discovery.json`, and
The app will download a discovery list from `https://discovery.eduroam.app/v3/discovery.json`, and
present a searchable list of all institutions to the user. We filter on name and keywords (no
abbreviations available for now).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import retrofit2.http.Headers
import retrofit2.http.Url

interface GetEduroamApi {
@GET("v2/discovery.json")
@GET("v3/discovery.json")
suspend fun discover(): Response<DiscoveryResult>

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import kotlinx.serialization.Serializable
@Parcelize
@Serializable
data class DiscoveryContent(
val institutions: List<Organization>,
val providers: List<Organization>,
val seq: Long
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import kotlinx.serialization.Serializable
@Parcelize
@Serializable
data class DiscoveryResult(
@SerialName("http://letswifi.app/discovery#v2")
@SerialName("http://letswifi.app/discovery#v3")
val content: DiscoveryContent
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.eduroam.geteduroam.models

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class LocalizedName(
val display: String,
val lang: String? = null
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.util.Locale
data class Organization(
val country: String,
val id: String,
val name: Map<String, String>,
val name: List<LocalizedName>,
val profiles: List<Profile>,
) : Parcelable {

Expand All @@ -24,9 +24,9 @@ data class Organization(

fun getLocalizedName(): String {
val userLanguage = Locale.getDefault().language.lowercase()
return name[userLanguage] ?: // 1st option: the name in the user's language
name[LANGUAGE_KEY_FALLBACK] ?: // 2nd option: the name in the fallback language (english)
name.values.firstOrNull() ?: // 3rd option: any name we can find
return name.find { it.lang == userLanguage }?.display ?: // 1st option: the name in the user's language
name.find { it.lang == null }?.display ?: // 2nd option: the name in the fallback language
name.firstOrNull()?.display ?: // 3rd option: any name we can find
id // 4th option: the ID, which is always set
Comment on lines 26 to 30

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in commit 4c78c5f.

}

Expand All @@ -37,15 +37,15 @@ data class Organization(
*/
fun improveMatchWords() : Boolean {
if (matchWordsLevel == 0) {
matchWords = name.values.toList()
matchWords = name.map { it.display }
matchWordsLevel = 1
return true
} else if (matchWordsLevel == 1) {
// Split on anything which is non-alphanumeric
val namesWords = name.values.map { it.split(DELIMITER).filter { it.isNotEmpty() }}.toMutableList()
val namesWords = name.map { it.display.split(DELIMITER).filter { it.isNotEmpty() }}.toMutableList()
val namesAbbreviations = namesWords.map { nameWords -> nameWords.map { word -> word.first() }.joinToString("") }
val words = mutableListOf<String>()
words += name.values.toList()
words += name.map { it.display }
words += namesWords.flatten()
words += namesAbbreviations
matchWords = words
Expand All @@ -60,7 +60,5 @@ data class Organization(

companion object {
private val DELIMITER = "\\W+".toRegex()

const val LANGUAGE_KEY_FALLBACK = "any"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class Profile(
@SerialName("eapconfig_endpoint")
val eapconfigEndpoint: String? = null,
val id: String,
val name: Map<String, String>,
val name: List<LocalizedName> = emptyList(),
val oauth: Boolean = false,
@SerialName("authorization_endpoint")
val authorizationEndpoint: String? = null,
Expand All @@ -40,9 +40,9 @@ data class Profile(

fun getLocalizedName(): String {
val userLanguage = Locale.getDefault().language.lowercase()
return name[userLanguage] ?: // 1st option: the name in the user's language
name[LANGUAGE_KEY_FALLBACK] ?: // 2nd option: the name in the fallback language (english)
name.values.firstOrNull() ?: // 3rd option: any name we can find
return name.find { it.lang == userLanguage }?.display ?: // 1st option: the name in the user's language
name.find { it.lang == null }?.display ?: // 2nd option: the name in the fallback language
name.firstOrNull()?.display ?: // 3rd option: any name we can find
id // 4th option: the ID, which is always set
}
fun createConfiguration() : Configuration {
Expand All @@ -57,8 +57,5 @@ data class Profile(
)
}

companion object {
private const val LANGUAGE_KEY_FALLBACK = "any"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ import androidx.lifecycle.flowWithLifecycle
import app.eduroam.geteduroam.R
import app.eduroam.geteduroam.config.model.EAPIdentityProviderList
import app.eduroam.geteduroam.models.Configuration
import app.eduroam.geteduroam.models.LocalizedName
import app.eduroam.geteduroam.models.Organization
import app.eduroam.geteduroam.models.ConfigSource
import app.eduroam.geteduroam.models.Organization.Companion.LANGUAGE_KEY_FALLBACK
import app.eduroam.geteduroam.ui.ErrorData
import app.eduroam.geteduroam.ui.theme.AppTheme
import kotlinx.coroutines.flow.distinctUntilChanged
Expand Down Expand Up @@ -331,7 +331,7 @@ fun SelectOrganizationContent(
organization = Organization(
country = if (configuredOrganization.source == ConfigSource.Url) stringResource(R.string.configuration_source_custom_host) else configuredOrganization.country ?: "",
id = configuredOrganization.id,
name = mapOf(LANGUAGE_KEY_FALLBACK to (configuredOrganization.name ?: configuredOrganization.id)),
name = listOf(LocalizedName(display = configuredOrganization.name ?: configuredOrganization.id)),
profiles = emptyList()
),
configuredOrganization = configuredOrganization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SelectOrganizationViewModel @Inject constructor(
val discoveryResult = response.body()
if (response.isSuccessful && discoveryResult != null) {
withContext(Dispatchers.Main) {
allOrganizations = discoveryResult.content.institutions
allOrganizations = discoveryResult.content.providers
uiState = uiState.copy(isLoading = false)
if (uiState.filter.isNotEmpty()) {
onSearchTextChange(uiState.filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import app.eduroam.geteduroam.config.model.ProviderInfo
import app.eduroam.geteduroam.config.model.localizedMatch
import app.eduroam.geteduroam.models.Configuration
import app.eduroam.geteduroam.organizations.TermsOfUseDialog
import app.eduroam.geteduroam.models.LocalizedName
import app.eduroam.geteduroam.models.Profile
import app.eduroam.geteduroam.models.ConfigSource
import app.eduroam.geteduroam.organizations.ConfiguredOrganization
Expand Down Expand Up @@ -531,6 +532,6 @@ private fun Preview_SelectProfileModal() {
}

private val profileList = listOf(
PresentProfile(Profile(id = "id", name = mapOf("any" to "First profile"), type = Profile.Type.eapConfig), true),
PresentProfile(Profile(id = "id", name = mapOf("any" to "Second profile"), type = Profile.Type.eapConfig), false),
PresentProfile(Profile(id = "id", name = listOf(LocalizedName(display = "First profile")), type = Profile.Type.eapConfig), true),
PresentProfile(Profile(id = "id", name = listOf(LocalizedName(display = "Second profile")), type = Profile.Type.eapConfig), false),
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import app.eduroam.geteduroam.di.repository.DiscoveryRepository
import app.eduroam.geteduroam.di.repository.NotificationRepository
import app.eduroam.geteduroam.di.repository.StorageRepository
import app.eduroam.geteduroam.models.DiscoveryResult
import app.eduroam.geteduroam.models.LocalizedName
import app.eduroam.geteduroam.models.Organization
import app.eduroam.geteduroam.models.Profile
import app.eduroam.geteduroam.ui.ErrorData
Expand Down Expand Up @@ -129,7 +130,7 @@ class SelectProfileViewModel @Inject constructor(
null
}
if (institutionResult != null) {
val selectedInstitution = institutionResult.content.institutions.find { it.id == institutionId }
val selectedInstitution = institutionResult.content.providers.find { it.id == institutionId }
if (selectedInstitution != null) {
applySelectedInstitution(selectedInstitution)
} else {
Expand Down Expand Up @@ -212,7 +213,7 @@ class SelectProfileViewModel @Inject constructor(
try {
val profile = resolveLetswifiProfile(Profile(
id = customHost.toString(),
name = mapOf("any" to context.getString(R.string.name)),
name = listOf(LocalizedName(display = context.getString(R.string.name))),
type = Profile.Type.letswifi,
letswifiEndpoint = customHost.toString()
))
Expand Down
Loading