Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zed.rainxch.profile.presentation

import zed.rainxch.core.domain.model.AppTheme
import zed.rainxch.core.domain.model.FontTheme
import zed.rainxch.profile.presentation.model.ProxyType

sealed interface ProfileAction {
data object OnNavigateBackClick : ProfileAction
Expand All @@ -15,6 +16,7 @@ sealed interface ProfileAction {
data object OnLogoutDismiss : ProfileAction
data object OnHelpClick : ProfileAction
data object OnLoginClick : ProfileAction
data object OnClearCacheClick : ProfileAction
data class OnFontThemeSelected(val fontTheme: FontTheme) : ProfileAction
data class OnProxyTypeSelected(val type: ProxyType) : ProfileAction
data class OnProxyHostChanged(val host: String) : ProfileAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import zed.rainxch.profile.presentation.components.LogoutDialog
import zed.rainxch.profile.presentation.components.sections.about
import zed.rainxch.profile.presentation.components.sections.logout
import zed.rainxch.profile.presentation.components.sections.networkSection
import zed.rainxch.profile.presentation.components.sections.othersSection
import zed.rainxch.profile.presentation.components.sections.profile
import zed.rainxch.profile.presentation.components.sections.settings

Expand Down Expand Up @@ -160,7 +161,7 @@ fun ProfileScreen(
)

item {
Spacer(Modifier.height(16.dp))
Spacer(Modifier.height(32.dp))
}

settings(
Expand All @@ -169,7 +170,7 @@ fun ProfileScreen(
)

item {
Spacer(Modifier.height(16.dp))
Spacer(Modifier.height(32.dp))
}

networkSection(
Expand All @@ -178,7 +179,16 @@ fun ProfileScreen(
)

item {
Spacer(Modifier.height(16.dp))
Spacer(Modifier.height(32.dp))
}

othersSection(
state = state,
onAction = onAction
)

item {
Spacer(Modifier.height(32.dp))
}

about(
Expand All @@ -187,7 +197,7 @@ fun ProfileScreen(
)

item {
Spacer(Modifier.height(16.dp))
Spacer(Modifier.height(32.dp))
}

if (state.isUserLoggedIn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zed.rainxch.core.domain.model.AppTheme
import zed.rainxch.core.domain.model.FontTheme
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.profile.domain.model.UserProfile
import zed.rainxch.profile.presentation.model.ProxyType

data class ProfileState(
val userProfile: UserProfile? = null,
Expand All @@ -21,17 +22,5 @@ data class ProfileState(
val proxyPassword: String = "",
val isProxyPasswordVisible: Boolean = false,
val autoDetectClipboardLinks: Boolean = true,
)

enum class ProxyType {
NONE, SYSTEM, HTTP, SOCKS;

companion object {
fun fromConfig(config: ProxyConfig): ProxyType = when (config) {
is ProxyConfig.None -> NONE
is ProxyConfig.System -> SYSTEM
is ProxyConfig.Http -> HTTP
is ProxyConfig.Socks -> SOCKS
}
}
}
val cacheSize: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.getString
import org.jetbrains.compose.resources.stringResource
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.core.domain.repository.ProxyRepository
import zed.rainxch.core.domain.repository.ThemesRepository
Expand All @@ -22,6 +21,7 @@ import zed.rainxch.githubstore.core.presentation.res.failed_to_save_proxy_settin
import zed.rainxch.githubstore.core.presentation.res.invalid_proxy_port
import zed.rainxch.githubstore.core.presentation.res.proxy_host_required
import zed.rainxch.profile.domain.repository.ProfileRepository
import zed.rainxch.profile.presentation.model.ProxyType

class ProfileViewModel(
private val browserHelper: BrowserHelper,
Expand All @@ -43,6 +43,7 @@ class ProfileViewModel(
loadUserProfile()
loadVersionName()
loadProxyConfig()
observeCacheSize()

hasLoadedInitialData = true
}
Expand All @@ -56,6 +57,12 @@ class ProfileViewModel(
private val _events = Channel<ProfileEvent>()
val events = _events.receiveAsFlow()

private fun observeCacheSize() {
viewModelScope.launch {

}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

private fun loadVersionName() {
viewModelScope.launch {
_state.update {
Expand Down Expand Up @@ -172,6 +179,10 @@ class ProfileViewModel(
)
}

ProfileAction.OnClearCacheClick -> {

}

is ProfileAction.OnThemeColorSelected -> {
viewModelScope.launch {
themesRepository.setThemeColor(action.themeColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@ import androidx.compose.ui.unit.dp
import zed.rainxch.githubstore.core.presentation.res.*
import org.jetbrains.compose.resources.stringResource
import zed.rainxch.profile.presentation.ProfileAction
import zed.rainxch.profile.presentation.components.SectionHeader

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
fun LazyListScope.about(
versionName: String,
onAction: (ProfileAction) -> Unit,
) {
item {
Text(
text = stringResource(Res.string.section_about),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.outline,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(start = 8.dp)
SectionHeader(
text = stringResource(Res.string.section_about)
)

Spacer(Modifier.height(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fun LazyListScope.appearanceSection(
}
)

VerticalSpacer(16.dp)
VerticalSpacer(8.dp)
}

ToggleSettingCard(
Expand All @@ -124,7 +124,7 @@ fun LazyListScope.appearanceSection(
}
)

VerticalSpacer(16.dp)
VerticalSpacer(8.dp)

ToggleSettingCard(
title = stringResource(Res.string.auto_detect_clipboard_links),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import org.jetbrains.compose.resources.stringResource
import zed.rainxch.githubstore.core.presentation.res.*
import zed.rainxch.profile.presentation.ProfileAction
import zed.rainxch.profile.presentation.ProfileState
import zed.rainxch.profile.presentation.ProxyType
import zed.rainxch.profile.presentation.components.SectionHeader
import zed.rainxch.profile.presentation.model.ProxyType

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
fun LazyListScope.networkSection(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package zed.rainxch.profile.presentation.components.sections

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Storage
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.stringResource
import zed.rainxch.core.presentation.components.ExpressiveCard
import zed.rainxch.githubstore.core.presentation.res.Res
import zed.rainxch.githubstore.core.presentation.res.section_network
import zed.rainxch.profile.presentation.ProfileAction
import zed.rainxch.profile.presentation.ProfileState
import zed.rainxch.profile.presentation.components.SectionHeader

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
fun LazyListScope.othersSection(
state: ProfileState,
onAction: (ProfileAction) -> Unit
) {
item {
SectionHeader(
text = "Storage".uppercase()
)

Spacer(Modifier.height(8.dp))

ExpressiveCard {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
Icon(
imageVector = Icons.Outlined.Storage,
contentDescription = null,
modifier = Modifier
.size(44.dp)
.clip(RoundedCornerShape(36.dp))
.background(MaterialTheme.colorScheme.surfaceContainerLow)
.padding(8.dp)
)

Column (
modifier = Modifier.weight(1f),
verticalArrangement = Arrangement.spacedBy(2.dp),
horizontalAlignment = Alignment.Start
) {
Text(
text = "Clear Cache",
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onSurface
)

Text(
text = "Current size: ${state.cacheSize}",
style = MaterialTheme.typography.titleSmall,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}

Button(
onClick = {
onAction(ProfileAction.OnClearCacheClick)
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
shape = RoundedCornerShape(12.dp),
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
contentColor = MaterialTheme.colorScheme.onSurface
)
) {
Text(
text = "Clear",
style = MaterialTheme.typography.titleMediumEmphasized,
fontWeight = FontWeight.Bold
)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package zed.rainxch.profile.presentation.model;

import zed.rainxch.core.domain.model.ProxyConfig

enum class ProxyType {
NONE, SYSTEM, HTTP, SOCKS;

companion object {
fun fromConfig(config: ProxyConfig): ProxyType = when (config) {
is ProxyConfig.None -> NONE
is ProxyConfig.System -> SYSTEM
is ProxyConfig.Http -> HTTP
is ProxyConfig.Socks -> SOCKS
}
}
}