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 3 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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ private const val ARG_REMEMBER_ME = "rememberMe"

@Serializable
private sealed interface NestedDestination {
@Serializable
data object InstanceSelection : NestedDestination
@Serializable
data object CustomInstanceSelection : NestedDestination
@Serializable
Expand Down Expand Up @@ -212,12 +210,6 @@ private fun LoginUiScreen(
val nestedNavController = rememberNavController()
val serverConfigurationService: ServerConfigurationService = koinInject()

val hasSelectedInstance = serverConfigurationService
.hasUserSelectedInstance
.collectAsState(initial = null)
.value
?: return // Display nothing to avoid switching between destinations

// Force recomposition
val currentBackStack by nestedNavController.currentBackStackEntryAsState()
nestedNavController.currentBackStackEntryAsState().value
Expand Down Expand Up @@ -271,7 +263,7 @@ private fun LoginUiScreen(
.consumeWindowInsets(WindowInsets.systemBars)
.padding(top = paddingValues.calculateTopPadding()),
navController = nestedNavController,
startDestination = if (hasSelectedInstance) NestedDestination.Home else NestedDestination.InstanceSelection
startDestination = NestedDestination.Home
) {
animatedComposable<NestedDestination.Home> {
AccountScreen(
Expand All @@ -298,11 +290,7 @@ private fun LoginUiScreen(
.fillMaxSize()
.padding(horizontal = 16.dp)
) {
nestedNavController.navigate(NestedDestination.Home) {
popUpTo<NestedDestination.InstanceSelection> {
inclusive = true
}
}
nestedNavController.navigate(NestedDestination.Home)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.AlternateEmail
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.filled.Mail
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand Down Expand Up @@ -147,10 +146,6 @@ private fun SettingsScreen(

val scope = rememberCoroutineScope()

val hasUserSelectedInstance by serverConfigurationService.hasUserSelectedInstance.collectAsState(
initial = false
)

val accountDataService: AccountDataService = koinInject()
val networkStatusProvider: NetworkStatusProvider = koinInject()

Expand Down Expand Up @@ -230,7 +225,6 @@ private fun SettingsScreen(

AboutSection(
modifier = Modifier.fillMaxWidth(),
hasUserSelectedInstance = hasUserSelectedInstance,
serverUrl = serverUrl,
onOpenPrivacyPolicy = {
val link = URLBuilder(serverUrl).appendPathSegments("privacy").buildString()
Expand All @@ -242,9 +236,6 @@ private fun SettingsScreen(
linkOpener.openLink(link)
},
onOpenThirdPartyLicenses = onDisplayThirdPartyLicenses,
// it can only be unselected, if the user has navigated to the settings from the instance selection screen.
// Therefore, a simple navigate up will let the user select the server instance.
onRequestSelectServerInstance = onNavigateUp
)

BuildInformationSection(
Expand Down Expand Up @@ -341,9 +332,7 @@ private fun NotificationSection(modifier: Modifier, onOpenNotificationSettings:
@Composable
private fun AboutSection(
modifier: Modifier,
hasUserSelectedInstance: Boolean,
serverUrl: String,
onRequestSelectServerInstance: () -> Unit,
onOpenPrivacyPolicy: () -> Unit,
onOpenImprint: () -> Unit,
onOpenThirdPartyLicenses: () -> Unit
Expand All @@ -362,7 +351,7 @@ private fun AboutSection(
)
}

if (hasUserSelectedInstance) {
if (serverUrl.isNotEmpty()) {
ServerURLEntry(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.settings_server_url),
Expand All @@ -385,19 +374,12 @@ private fun AboutSection(
onClick = onOpenImprint
)
} else {
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
Text(
text = stringResource(id = R.string.settings_server_specifics_unavailable),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.error
)

Button(
onClick = onRequestSelectServerInstance
) {
Text(text = stringResource(id = R.string.settings_server_specifics_unavailable_select_instance_button))
}
}
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = stringResource(id = R.string.settings_server_specifics_unavailable),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.error
)
}

ButtonEntry(
Expand Down
Loading