Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 5a1d4f6

Browse files
authored
✨ Add link to Mastodon profile if connected (#316)
closes #311
1 parent 25b78d2 commit 5a1d4f6

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

app/src/main/kotlin/de/hbch/traewelling/api/models/user/User.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ data class User(
1212
@SerializedName("trainDistance") val distance: Int,
1313
@SerializedName("trainDuration") val duration: Int,
1414
@SerializedName("points") val points: Int,
15-
@SerializedName("twitterUrl") val twitterUrl: String?,
1615
@SerializedName("mastodonUrl") val mastodonUrl: String?,
1716
@SerializedName("privateProfile") val privateProfile: Boolean,
1817
@SerializedName("home") var home: Station?,

app/src/main/kotlin/de/hbch/traewelling/ui/user/User.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.hbch.traewelling.ui.user
22

3+
import androidx.compose.foundation.clickable
34
import androidx.compose.foundation.layout.Arrangement
45
import androidx.compose.foundation.layout.Column
56
import androidx.compose.foundation.layout.Row
@@ -15,6 +16,7 @@ import androidx.compose.runtime.getValue
1516
import androidx.compose.runtime.livedata.observeAsState
1617
import androidx.compose.ui.Alignment
1718
import androidx.compose.ui.Modifier
19+
import androidx.compose.ui.platform.LocalContext
1820
import androidx.compose.ui.res.painterResource
1921
import androidx.compose.ui.res.stringResource
2022
import androidx.compose.ui.tooling.preview.Preview
@@ -26,6 +28,7 @@ import de.hbch.traewelling.theme.AppTypography
2628
import de.hbch.traewelling.theme.MainTheme
2729
import de.hbch.traewelling.ui.composables.ButtonWithIconAndText
2830
import de.hbch.traewelling.ui.composables.ProfilePicture
31+
import de.hbch.traewelling.util.openLink
2932

3033
@Composable
3134
fun UserCard(
@@ -57,6 +60,7 @@ private fun UserCardContent(
5760
followAction: () -> Unit = { },
5861
muteAction: () -> Unit = { }
5962
) {
63+
val context = LocalContext.current
6064
ElevatedCard(
6165
modifier = modifier.fillMaxWidth()
6266
) {
@@ -90,10 +94,19 @@ private fun UserCardContent(
9094
modifier = Modifier.padding(start = 8.dp)
9195
)
9296
}
97+
if (user.mastodonUrl != null) {
98+
Icon(
99+
painter = painterResource(id = R.drawable.ic_mastodon),
100+
contentDescription = null,
101+
modifier = Modifier.padding(start = 8.dp).clickable {
102+
context.openLink(user.mastodonUrl)
103+
}
104+
)
105+
}
93106
}
94107
Text(
95108
style = AppTypography.titleMedium,
96-
text = user.username
109+
text = "@${user.username}"
97110
)
98111
}
99112
Row(
@@ -268,7 +281,6 @@ private fun UserCardPreview() {
268281
10241024,
269282
4711,
270283
null,
271-
null,
272284
false,
273285
null,
274286
null,
@@ -286,7 +298,6 @@ private fun UserCardPreview() {
286298
4568,
287299
42,
288300
null,
289-
null,
290301
true,
291302
null,
292303
null,

app/src/main/kotlin/de/hbch/traewelling/util/Extensions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ fun Context.refreshJwt(onTokenReceived: (String) -> Unit = { }) {
264264
}
265265
}
266266

267+
fun Context.openLink(url: String) {
268+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
269+
try {
270+
startActivity(intent)
271+
} catch (_: Exception) { }
272+
}
273+
267274
@Composable
268275
fun <T> T.useDebounce(
269276
delayMillis: Long = 300L,

0 commit comments

Comments
 (0)