Skip to content

Commit

Permalink
sync: smoother cloudcommunity mapping (fixes #5009) (#5010)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Jan 13, 2025
1 parent b4f99ee commit d0be8f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2192
versionName "0.21.92"
versionCode 2193
versionName "0.21.93"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,18 @@ class ServerUrlMapper(private val context: Context, private val settings: Shared
)

private fun extractBaseUrl(url: String): String? {
val regex = Regex("^(https?://).*?@(.*?):")
return regex.find(url)?.let {
val protocol = it.groupValues[1]
val address = it.groupValues[2]
"$protocol$address"
return try {
val uri = Uri.parse(url)
"${uri.scheme}://${uri.host}${if (uri.port != -1) ":${uri.port}" else ""}"
} catch (e: Exception) {
null
}
}

fun processUrl(url: String): UrlMapping {
val extractedUrl = extractBaseUrl(url)

val primaryUrlMapping = serverMappings.entries.find { it.key.contains(extractedUrl ?: "") }

return if (primaryUrlMapping != null) {
val alternativeUrl = primaryUrlMapping.value
UrlMapping(url, alternativeUrl, extractedUrl)
} else {
UrlMapping(url, null, extractedUrl)
}
val alternativeUrl = extractedUrl?.let { serverMappings[it] }
return UrlMapping(url, alternativeUrl, extractedUrl)
}

fun updateUrlPreferences(editor: SharedPreferences.Editor, uri: Uri, alternativeUrl: String, url: String, settings: SharedPreferences) {
Expand Down

0 comments on commit d0be8f8

Please sign in to comment.