Skip to content

Commit

Permalink
✨ Add link to Mastodon profile if connected
Browse files Browse the repository at this point in the history
closes #311
  • Loading branch information
jheubuch committed Jan 7, 2024
1 parent 25b78d2 commit 8dd877d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ data class User(
@SerializedName("trainDistance") val distance: Int,
@SerializedName("trainDuration") val duration: Int,
@SerializedName("points") val points: Int,
@SerializedName("twitterUrl") val twitterUrl: String?,
@SerializedName("mastodonUrl") val mastodonUrl: String?,
@SerializedName("privateProfile") val privateProfile: Boolean,
@SerializedName("home") var home: Station?,
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/kotlin/de/hbch/traewelling/ui/user/User.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hbch.traewelling.ui.user

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -15,6 +16,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -26,6 +28,7 @@ import de.hbch.traewelling.theme.AppTypography
import de.hbch.traewelling.theme.MainTheme
import de.hbch.traewelling.ui.composables.ButtonWithIconAndText
import de.hbch.traewelling.ui.composables.ProfilePicture
import de.hbch.traewelling.util.openLink

@Composable
fun UserCard(
Expand Down Expand Up @@ -57,6 +60,7 @@ private fun UserCardContent(
followAction: () -> Unit = { },
muteAction: () -> Unit = { }
) {
val context = LocalContext.current
ElevatedCard(
modifier = modifier.fillMaxWidth()
) {
Expand Down Expand Up @@ -90,10 +94,19 @@ private fun UserCardContent(
modifier = Modifier.padding(start = 8.dp)
)
}
if (user.mastodonUrl != null) {
Icon(
painter = painterResource(id = R.drawable.ic_mastodon),
contentDescription = null,
modifier = Modifier.padding(start = 8.dp).clickable {
context.openLink(user.mastodonUrl)
}
)
}
}
Text(
style = AppTypography.titleMedium,
text = user.username
text = "@${user.username}"
)
}
Row(
Expand Down Expand Up @@ -268,7 +281,6 @@ private fun UserCardPreview() {
10241024,
4711,
null,
null,
false,
null,
null,
Expand All @@ -286,7 +298,6 @@ private fun UserCardPreview() {
4568,
42,
null,
null,
true,
null,
null,
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/de/hbch/traewelling/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ fun Context.refreshJwt(onTokenReceived: (String) -> Unit = { }) {
}
}

fun Context.openLink(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
try {
startActivity(intent)
} catch (_: Exception) { }
}

@Composable
fun <T> T.useDebounce(
delayMillis: Long = 300L,
Expand Down

0 comments on commit 8dd877d

Please sign in to comment.