Skip to content

Commit

Permalink
Using muted federated names. (#1368)
Browse files Browse the repository at this point in the history
* Using muted federated names.

- Also replaces overflowing text with simple marquees.
- Fixes #1364

* A few simplifications.

* A few updates.

* Remove material1 LocalContentColor. (#1366)

* Fixing comment bottom margin. Fixes #1365 (#1367)

* Switch blurNSFW and postActionBarMode to use enums. (#1369)

- Fixed some naming.
- Also cleaned up imports.
- Fixes #1352

* Dont show comment content when its deleted or removed. (#1371)

- Fixes #1335

* Use medium padding.

* A few more fixes.

* A few more fixes.

* Addressing comments
  • Loading branch information
dessalines authored Feb 12, 2024
1 parent 818f008 commit 8c9c615
Show file tree
Hide file tree
Showing 21 changed files with 231 additions and 116 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/jerboa/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package com.jerboa
const val DEBOUNCE_DELAY = 1000L
const val MAX_POST_TITLE_LENGTH = 200
const val DEFAULT_FONT_SIZE = 16
const val INSTANCE_FONT_SIZE = 9
1 change: 1 addition & 0 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ class MainActivity : AppCompatActivity() {
blurNSFW = appSettings.blurNSFW.toEnum(),
drawerState = drawerState,
followList = siteViewModel.getFollowList(),
showAvatar = siteViewModel.showAvatar(),
)
}

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import coil.imageLoader
import com.jerboa.api.API
import com.jerboa.api.ApiState
import com.jerboa.datatypes.BanFromCommunityData
import com.jerboa.datatypes.getDisplayName
import com.jerboa.db.APP_SETTINGS_DEFAULT
import com.jerboa.db.entity.AppSettings
import com.jerboa.ui.components.common.Route
Expand Down Expand Up @@ -457,10 +458,10 @@ fun personNameShown(
person: Person,
federatedName: Boolean = false,
): String {
val name = person.getDisplayName()
return if (!federatedName) {
person.display_name ?: person.name
name
} else {
val name = person.display_name ?: person.name
if (person.local) {
name
} else {
Expand All @@ -469,6 +470,9 @@ fun personNameShown(
}
}

/**
* Warning, do not use this for links and such, only for messages
*/
fun communityNameShown(community: Community): String {
return if (community.local) {
community.title
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/jerboa/datatypes/SampleData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ val samplePerson2 =
updated = "2021-10-11T07:14:53.548707",
actor_id = "https://lemmy.ml/u/homeless",
bio = null,
local = true,
local = false,
banner = null,
deleted = false,
matrix_user_id = null,
Expand Down Expand Up @@ -242,6 +242,8 @@ val sampleCommunity =
posting_restricted_to_mods = false,
)

val sampleCommunityFederated = sampleCommunity.copy(local = false)

val samplePostAggregates =
PostAggregates(
post_id = 135129,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ fun LazyListScope.commentNodeItem(
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
blurNSFW = blurNSFW,
showAvatar = showAvatar,
)
}
CommentNodeHeader(
Expand Down Expand Up @@ -695,6 +696,7 @@ fun PostAndCommunityContextHeader(
onCommunityClick: (community: Community) -> Unit,
onPostClick: (postId: PostId) -> Unit,
blurNSFW: BlurNSFW,
showAvatar: Boolean,
) {
Column(
modifier = Modifier.padding(top = LARGE_PADDING),
Expand All @@ -713,6 +715,7 @@ fun PostAndCommunityContextHeader(
onClick = onCommunityClick,
showDefaultIcon = false,
blurNSFW = blurNSFW,
showAvatar = showAvatar,
)
}
}
Expand All @@ -727,6 +730,7 @@ fun PostAndCommunityContextHeaderPreview() {
onCommunityClick = {},
onPostClick = {},
blurNSFW = BlurNSFW.NSFW,
showAvatar = true,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ fun CommentMentionNode(
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
blurNSFW = blurNSFW,
showAvatar = showAvatar,
)
CommentMentionNodeHeader(
personMentionView = personMentionView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ fun CommentReplyNodeInbox(
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
blurNSFW = blurNSFW,
showAvatar = showAvatar,
)
CommentReplyNodeHeader(
commentReplyView = commentReplyView,
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/jerboa/ui/components/common/AppBars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,15 @@ fun ActionBarButtonAndBadge(

@Composable
fun DotSpacer(
padding: Dp = SMALL_PADDING,
modifier: Modifier = Modifier,
padding: Dp = 0.dp,
style: TextStyle = MaterialTheme.typography.bodyMedium,
) {
Text(
text = stringResource(R.string.app_bars_dot_spacer),
style = style,
color = MaterialTheme.colorScheme.onBackground.muted,
modifier = Modifier.padding(horizontal = padding),
modifier = modifier.padding(horizontal = padding),
)
}

Expand Down
64 changes: 61 additions & 3 deletions app/src/main/java/com/jerboa/ui/components/common/TextBadge.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package com.jerboa.ui.components.common

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.jerboa.INSTANCE_FONT_SIZE
import com.jerboa.hostName
import com.jerboa.ui.theme.muted

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun TextBadge(
text: String,
Expand All @@ -33,12 +42,61 @@ fun TextBadge(
Text(
text = text,
style = textStyle,
overflow = TextOverflow.Clip,
maxLines = 1,
color = textColor,
modifier =
Modifier
.padding(horizontalTextPadding.dp, verticalTextPadding.dp),
.padding(horizontalTextPadding.dp, verticalTextPadding.dp)
.basicMarquee(),
)
}
}

/**
* Displays activitypub items (communities, users), with a smaller @instance shown
*/
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ItemAndInstanceTitle(
modifier: Modifier = Modifier,
title: String,
actorId: String?,
local: Boolean,
itemColor: Color = MaterialTheme.colorScheme.primary,
itemStyle: TextStyle = MaterialTheme.typography.bodyMedium,
instanceColor: Color = MaterialTheme.colorScheme.onSurface.muted,
instanceStyle: TextStyle = MaterialTheme.typography.bodySmall.copy(
fontSize = INSTANCE_FONT_SIZE.sp,
),
) {
val text = remember(title, local, itemColor) {
val serverStr = if (!local && actorId != null) {
"@${hostName(actorId)}"
} else {
null
}

buildAnnotatedString {
withStyle(
style = itemStyle.toSpanStyle().copy(color = itemColor),
) {
append(title)
}
serverStr?.let { server ->
withStyle(
style = instanceStyle.toSpanStyle().copy(
color = instanceColor,
),
) {
append(server)
}
}
}
}

Text(
text = text,
maxLines = 1,
modifier = modifier.basicMarquee(),
)
}
10 changes: 7 additions & 3 deletions app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import java.util.Date
@Composable
fun TimeAgo(
published: String,
modifier: Modifier = Modifier,
updated: String? = null,
precedingString: String? = null,
longTimeFormat: Boolean = false,
Expand All @@ -52,7 +53,7 @@ fun TimeAgo(
stringResource(R.string.time_ago_ago, it, publishedPretty)
} ?: run { publishedPretty }

Row {
Row(modifier = modifier) {
Text(
text = afterPreceding,
color = MaterialTheme.colorScheme.onBackground.muted,
Expand Down Expand Up @@ -106,7 +107,10 @@ fun dateStringToPretty(
@Preview
@Composable
fun TimeAgoPreview() {
TimeAgo(samplePerson.published, samplePerson.updated)
TimeAgo(
published = samplePerson.published,
updated = samplePerson.updated,
)
}

@Composable
Expand Down Expand Up @@ -134,7 +138,7 @@ fun ScoreAndTime(
fontSize = MaterialTheme.typography.bodyMedium.fontSize.times(1.3),
)
}
DotSpacer(0.dp, MaterialTheme.typography.bodyMedium)
DotSpacer(style = MaterialTheme.typography.bodyMedium)
TimeAgo(published = published, updated = updated)
}
}
Expand Down
Loading

0 comments on commit 8c9c615

Please sign in to comment.