Skip to content

Commit 362b5cd

Browse files
Merge pull request #1385 from session-foundation/feature/avatar-picker-updates
New avatar editing rules
2 parents 744eb52 + aa77c24 commit 362b5cd

File tree

7 files changed

+79
-51
lines changed

7 files changed

+79
-51
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ dependencies {
442442
implementation(libs.androidx.navigation.compose)
443443

444444
implementation(libs.accompanist.permissions)
445-
implementation(libs.accompanist.drawablepainter)
446445

447446
implementation(libs.androidx.camera.camera2)
448447
implementation(libs.androidx.camera.lifecycle)

app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import androidx.compose.ui.layout.ContentScale
5454
import androidx.compose.ui.platform.LocalContext
5555
import androidx.compose.ui.res.painterResource
5656
import androidx.compose.ui.res.stringResource
57+
import androidx.compose.ui.text.AnnotatedString
5758
import androidx.compose.ui.tooling.preview.Preview
5859
import androidx.compose.ui.tooling.preview.PreviewParameter
5960
import androidx.compose.ui.unit.dp
@@ -85,8 +86,7 @@ import org.thoughtcrime.securesms.debugmenu.DebugActivity
8586
import org.thoughtcrime.securesms.home.PathActivity
8687
import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity
8788
import org.thoughtcrime.securesms.permissions.Permissions
88-
import org.thoughtcrime.securesms.preferences.SettingsViewModel.AvatarDialogState.TempAvatar
89-
import org.thoughtcrime.securesms.preferences.SettingsViewModel.AvatarDialogState.UserAvatar
89+
import org.thoughtcrime.securesms.preferences.SettingsViewModel.AvatarDialogState.*
9090
import org.thoughtcrime.securesms.preferences.appearance.AppearanceSettingsActivity
9191
import org.thoughtcrime.securesms.recoverypassword.RecoveryPasswordActivity
9292
import org.thoughtcrime.securesms.reviews.InAppReviewManager
@@ -100,9 +100,9 @@ import org.thoughtcrime.securesms.ui.DialogButtonData
100100
import org.thoughtcrime.securesms.ui.Divider
101101
import org.thoughtcrime.securesms.ui.GetString
102102
import org.thoughtcrime.securesms.ui.LargeItemButton
103-
import org.thoughtcrime.securesms.ui.LargeItemButtonWithDrawable
104103
import org.thoughtcrime.securesms.ui.LoadingDialog
105104
import org.thoughtcrime.securesms.ui.OpenURLAlertDialog
105+
import org.thoughtcrime.securesms.ui.PathDot
106106
import org.thoughtcrime.securesms.ui.components.AcccentOutlineCopyButton
107107
import org.thoughtcrime.securesms.ui.components.AccentOutlineButton
108108
import org.thoughtcrime.securesms.ui.components.Avatar
@@ -119,6 +119,8 @@ import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
119119
import org.thoughtcrime.securesms.ui.theme.ThemeColors
120120
import org.thoughtcrime.securesms.ui.theme.accentTextButtonColors
121121
import org.thoughtcrime.securesms.ui.theme.dangerButtonColors
122+
import org.thoughtcrime.securesms.ui.theme.primaryGreen
123+
import org.thoughtcrime.securesms.ui.theme.primaryYellow
122124
import org.thoughtcrime.securesms.util.FileProviderUtil
123125
import org.thoughtcrime.securesms.util.applyCommonWindowInsetsOnViews
124126
import org.thoughtcrime.securesms.util.push
@@ -533,10 +535,16 @@ class SettingsActivity : ScreenLockActionBarActivity() {
533535

534536
Cell {
535537
Column {
536-
Crossfade(if (hasPaths) R.drawable.ic_status else R.drawable.ic_path_yellow, label = "path") {
537-
LargeItemButtonWithDrawable(
538-
R.string.onionRoutingPath,
539-
it,
538+
Crossfade(if (hasPaths) primaryGreen else primaryYellow, label = "path") {
539+
LargeItemButton(
540+
AnnotatedString(stringResource(R.string.onionRoutingPath)),
541+
icon = {
542+
PathDot(
543+
modifier = Modifier.align(Alignment.Center),
544+
dotSize = LocalDimensions.current.iconSmall,
545+
color = it
546+
)
547+
},
540548
shape = if (BuildConfig.BUILD_TYPE != "release") RectangleShape
541549
else getCellTopShape()
542550
) { push<PathActivity>() }
@@ -843,7 +851,9 @@ class SettingsActivity : ScreenLockActionBarActivity() {
843851
.padding(LocalDimensions.current.xxxsSpacing)
844852
.align(Alignment.BottomEnd)
845853
,
846-
painter = painterResource(id = R.drawable.ic_plus),
854+
painter = painterResource(id =
855+
if(state.avatarDialogState is NoAvatar) R.drawable.ic_plus
856+
else R.drawable.ic_pencil),
847857
contentDescription = null,
848858
colorFilter = ColorFilter.tint(Color.Black)
849859
)

app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.IntrinsicSize
2323
import androidx.compose.foundation.layout.PaddingValues
2424
import androidx.compose.foundation.layout.Row
2525
import androidx.compose.foundation.layout.Spacer
26+
import androidx.compose.foundation.layout.fillMaxSize
2627
import androidx.compose.foundation.layout.fillMaxWidth
2728
import androidx.compose.foundation.layout.height
2829
import androidx.compose.foundation.layout.heightIn
@@ -33,6 +34,7 @@ import androidx.compose.foundation.layout.wrapContentSize
3334
import androidx.compose.foundation.lazy.LazyColumn
3435
import androidx.compose.foundation.lazy.itemsIndexed
3536
import androidx.compose.foundation.rememberScrollState
37+
import androidx.compose.foundation.shape.CircleShape
3638
import androidx.compose.foundation.shape.RoundedCornerShape
3739
import androidx.compose.foundation.text.BasicTextField
3840
import androidx.compose.foundation.verticalScroll
@@ -90,10 +92,10 @@ import androidx.compose.ui.tooling.preview.Preview
9092
import androidx.compose.ui.tooling.preview.PreviewParameter
9193
import androidx.compose.ui.unit.Dp
9294
import androidx.compose.ui.unit.dp
95+
import androidx.compose.ui.unit.times
9396
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
9497
import com.bumptech.glide.integration.compose.GlideSubcomposition
9598
import com.bumptech.glide.integration.compose.RequestState
96-
import com.google.accompanist.drawablepainter.rememberDrawablePainter
9799
import com.squareup.phrase.Phrase
98100
import kotlinx.coroutines.CoroutineScope
99101
import kotlinx.coroutines.Dispatchers
@@ -123,6 +125,61 @@ import org.thoughtcrime.securesms.ui.theme.primaryYellow
123125
import org.thoughtcrime.securesms.ui.theme.transparentButtonColors
124126
import kotlin.math.roundToInt
125127

128+
@Composable
129+
fun PathDot(
130+
modifier: Modifier = Modifier,
131+
dotSize: Dp = LocalDimensions.current.iconMedium,
132+
glowSize: Dp = LocalDimensions.current.xxsSpacing,
133+
color: Color = primaryGreen
134+
) {
135+
val fullSize = dotSize + 2*glowSize
136+
Box(
137+
modifier = modifier.size(fullSize),
138+
contentAlignment = Alignment.Center
139+
) {
140+
// Glow effect (outer circle with radial gradient)
141+
Canvas(modifier = Modifier.fillMaxSize()) {
142+
val center = Offset(this.size.width / 2, this.size.height / 2)
143+
val radius = (fullSize * 0.5f).toPx()
144+
145+
drawCircle(
146+
brush = Brush.radialGradient(
147+
colors = listOf(
148+
color, // Start color (opaque)
149+
color.copy(alpha = 0f) // End color (transparent)
150+
),
151+
center = center,
152+
radius = radius
153+
),
154+
center = center,
155+
radius = radius
156+
)
157+
}
158+
159+
// Inner solid dot
160+
Box(
161+
modifier = Modifier
162+
.size(dotSize)
163+
.background(
164+
color = color,
165+
shape = CircleShape
166+
)
167+
)
168+
}
169+
}
170+
171+
@Preview
172+
@Composable
173+
fun PreviewPathDot(){
174+
PreviewTheme {
175+
Box(
176+
modifier = Modifier.padding(20.dp)
177+
) {
178+
PathDot()
179+
}
180+
}
181+
}
182+
126183
data class RadioOption<T>(
127184
val value: T,
128185
val title: GetString,
@@ -202,14 +259,12 @@ fun ItemButtonWithDrawable(
202259
shape: Shape = RectangleShape,
203260
onClick: () -> Unit
204261
) {
205-
val context = LocalContext.current
206-
207262
ItemButton(
208263
annotatedStringText = AnnotatedString(stringResource(textId)),
209264
modifier = modifier,
210265
icon = {
211266
Image(
212-
painter = rememberDrawablePainter(drawable = AppCompatResources.getDrawable(context, icon)),
267+
painter = painterResource(id = icon),
213268
contentDescription = null,
214269
modifier = Modifier.align(Alignment.Center)
215270
)
@@ -280,7 +335,7 @@ fun LargeItemButton(
280335
@Composable
281336
fun LargeItemButton(
282337
annotatedStringText: AnnotatedString,
283-
@DrawableRes icon: Int,
338+
icon: @Composable BoxScope.() -> Unit,
284339
modifier: Modifier = Modifier,
285340
enabled: Boolean = true,
286341
colors: ButtonColors = transparentButtonColors(),

app/src/main/java/org/thoughtcrime/securesms/ui/theme/Dimensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ data class Dimensions(
3434
val iconLargeAvatar: Dp = 36.dp,
3535
val iconLarge: Dp = 46.dp,
3636
val iconXLarge: Dp = 60.dp,
37-
val iconXXLarge: Dp = 80.dp,
37+
val iconXXLarge: Dp = 90.dp,
3838
val iconXXLargeAvatar: Dp = 190.dp,
3939

4040
val shapeExtraSmall: Dp = 8.dp,

app/src/main/res/drawable/ic_path_yellow.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/src/main/res/drawable/ic_status.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ androidMinSdkVersion = "26"
33
androidTargetSdkVersion = "35"
44
androidCompileSdkVersion = "35"
55
accompanistPermissionsVersion = "0.37.3"
6-
accompanistThemeadapterAppcompatVersion = "0.33.1-alpha"
76
activityKtxVersion = "1.10.1"
87
androidImageCropperVersion = "4.5.0"
98
androidVersion = "125.6422.07"
@@ -79,7 +78,6 @@ huaweiPushVersion = "6.7.0.300"
7978
googlePlayReviewVersion = "2.0.2"
8079

8180
[libraries]
82-
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanistThemeadapterAppcompatVersion" }
8381
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanistPermissionsVersion" }
8482
android = { module = "io.github.webrtc-sdk:android", version.ref = "androidVersion" }
8583
android-image-cropper = { module = "com.vanniktech:android-image-cropper", version.ref = "androidImageCropperVersion" }

0 commit comments

Comments
 (0)