Skip to content

Commit

Permalink
Chore: Set tum artemis server as default (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelberMartin authored Jan 3, 2025
1 parent 3047462 commit a22457d
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ internal fun Project.configureReleaseTypeFlavors(
}
}

private const val TUM_ARTEMIS_SERVER_URL = "https://artemis.cit.tum.de"

internal fun Project.configureInstanceSelectionFlavors(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
Expand All @@ -153,7 +155,7 @@ internal fun Project.configureInstanceSelectionFlavors(
buildConfigField(
"String",
ProductFlavors.BuildConfigFields.DefaultServerUrl,
"\"\""
"\"$TUM_ARTEMIS_SERVER_URL\""
)
}

Expand All @@ -169,7 +171,7 @@ internal fun Project.configureInstanceSelectionFlavors(
buildConfigField(
"String",
ProductFlavors.BuildConfigFields.DefaultServerUrl,
"\"https://artemis.cit.tum.de\""
"\"$TUM_ARTEMIS_SERVER_URL\""
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ import kotlinx.coroutines.flow.flowOf
class TestServerConfigurationProvider : ServerConfigurationService {
override val serverUrl: Flow<String> = flowOf(testServerUrl)

override val hasUserSelectedInstance: Flow<Boolean> = flowOf(true)

override suspend fun updateServerUrl(serverUrl: String) = Unit
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package de.tum.informatics.www1.artemis.native_app.core.datastore

import de.tum.informatics.www1.artemis.native_app.core.datastore.ServerConfigurationService
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf

class ServerConfigurationServiceStub(
override val serverUrl: Flow<String> = flowOf("https://example.com"),
override val hasUserSelectedInstance: Flow<Boolean> = flowOf(true)
override val serverUrl: Flow<String> = flowOf("https://example.com")
) : ServerConfigurationService {
override suspend fun updateServerUrl(serverUrl: String) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,5 @@ interface ServerConfigurationService {
val host: Flow<String>
get() = serverUrl.map { Url(it).host }

/**
* If [updateServerUrl] has ever been called.
*/
val hasUserSelectedInstance: Flow<Boolean>

suspend fun updateServerUrl(serverUrl: String)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package de.tum.informatics.www1.artemis.native_app.core.datastore.impl

import android.content.Context
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import de.tum.informatics.www1.artemis.native_app.core.datastore.BuildConfig
import de.tum.informatics.www1.artemis.native_app.core.datastore.ServerConfigurationService
import io.ktor.http.Url
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.Flow
Expand All @@ -28,7 +26,6 @@ internal class ServerConfigurationServiceImpl(
private val Context.serverCommunicationPreferences by preferencesDataStore("server_communication")

private val SERVER_URL_KEY = stringPreferencesKey("server_url")
private val HAS_SELECTED_INSTANCE_KEY = booleanPreferencesKey("has_selected_instance")
}

/**
Expand All @@ -47,28 +44,9 @@ internal class ServerConfigurationServiceImpl(
.shareIn(GlobalScope, SharingStarted.Eagerly, replay = 1)
}

override val host: Flow<String> =
serverUrl
.map { Url(it).host }

/**
* Use to decide if we want to show an instance selection UI to the user.
* If [BuildConfig.hasInstanceRestriction] is set to true, we never want to show such a UI.
*/
override val hasUserSelectedInstance: Flow<Boolean> =
if (BuildConfig.hasInstanceRestriction) flowOf(true)
else {
context
.serverCommunicationPreferences
.data
.map { it[HAS_SELECTED_INSTANCE_KEY] ?: false }
}


override suspend fun updateServerUrl(serverUrl: String) {
context.serverCommunicationPreferences.edit { data ->
data[SERVER_URL_KEY] = serverUrl
data[HAS_SELECTED_INSTANCE_KEY] = true
}
}
}
Loading

0 comments on commit a22457d

Please sign in to comment.