Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Set tum artemis server as default #257

Merged
merged 7 commits into from
Jan 3, 2025
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 @@ -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
Loading