Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connect on matrix #1206

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/main/java/com/jerboa/feat/UserActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,11 @@ fun shareLink(url: String, ctx: Context) {
val shareIntent = Intent.createChooser(intent, ctx.getString(R.string.share))
ctx.startActivitySafe(shareIntent)
}

/**
* Opens matrix for that user
*/
fun openMatrix(matrixId: String, ctx: Context) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://matrix.to/#/$matrixId"))
ctx.startActivitySafe(intent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ fun MenuItem(
)
}

@Composable
fun MenuItem(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
textModifier: Modifier = Modifier,
icon: @Composable (() -> Unit),
textStyle: TextStyle = MaterialTheme.typography.bodyMedium,
MV-GH marked this conversation as resolved.
Show resolved Hide resolved
) {
DropdownMenuItem(
text = {
Text(
text = text,
style = textStyle,
modifier = textModifier,
)
},
leadingIcon = icon,
onClick = onClick,
modifier = modifier,
)
}

@Composable
fun MenuItem(
text: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import androidx.compose.foundation.layout.Row
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.material.icons.Icons
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.Divider
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
Expand All @@ -27,12 +29,14 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.jerboa.R
import com.jerboa.datatypes.samplePersonView
import com.jerboa.datatypes.types.PersonView
import com.jerboa.datatypes.types.SortType
import com.jerboa.feat.openMatrix
import com.jerboa.personNameShown
import com.jerboa.ui.components.common.DotSpacer
import com.jerboa.ui.components.common.LargerCircularIcon
Expand All @@ -42,6 +46,7 @@ import com.jerboa.ui.components.common.PictrsBannerImage
import com.jerboa.ui.components.common.SortOptionsDialog
import com.jerboa.ui.components.common.SortTopOptionsDialog
import com.jerboa.ui.components.common.TimeAgo
import com.jerboa.ui.theme.MARKDOWN_BAR_ICON_SIZE
import com.jerboa.ui.theme.MEDIUM_PADDING
import com.jerboa.ui.theme.PROFILE_BANNER_SIZE
import com.jerboa.ui.theme.muted
Expand Down Expand Up @@ -155,7 +160,10 @@ fun PersonProfileHeader(
onBack: (() -> Unit)? = null,
isLoggedIn: () -> Boolean,
siteVersion: String,
matrixId: String?,
) {
val ctx = LocalContext.current

var showSortOptions by remember { mutableStateOf(false) }
var showTopOptions by remember { mutableStateOf(false) }
var showMoreOptions by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -247,6 +255,9 @@ fun PersonProfileHeader(
showMoreOptions = false
onMessagePersonClick()
},
openMatrix = matrixId?.let {
{ openMatrix(matrixId, ctx) }
},
)
}
}
Expand Down Expand Up @@ -278,6 +289,7 @@ fun PersonProfileMoreDropdown(
onBlockPersonClick: () -> Unit,
onReportPersonClick: () -> Unit,
onMessagePersonClick: () -> Unit,
openMatrix: (() -> Unit)?,
Copy link
Member

@dessalines dessalines Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm.... not a fan of optional params, as they often result in places you don't catch them. Probably best would be

hasMatrixId: Boolean,
onOpenMatrixClick: () -> Unit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional params have indeed been a footgun but this param is not optional. You are forced to pass null or a lambda. Not doing will result in a compile error. That would not be the case if I did openMatrix: (() -> Unit)? = null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmk cool.

) {
DropdownMenu(
expanded = expanded,
Expand All @@ -288,6 +300,22 @@ fun PersonProfileMoreDropdown(
onClick = onMessagePersonClick,
icon = Icons.Outlined.Message,
)

if (openMatrix != null) {
MenuItem(
text = stringResource(R.string.matrix_send_msg),
icon = {
Icon(
painter = painterResource(R.drawable.matrix_favicon),
contentDescription = null,
modifier = Modifier.size(MARKDOWN_BAR_ICON_SIZE),
)
},
onClick = openMatrix,
)
}

Divider()
MenuItem(
text = stringResource(R.string.person_profile_block_person),
onClick = onBlockPersonClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,19 @@ fun PersonProfileActivity(
ApiState.Loading, ApiState.Refreshing -> {
// Prevents tabs from jumping around during loading/refreshing
PersonProfileHeader(
scrollBehavior = scrollBehavior,
personName = ctx.getString(R.string.loading),
myProfile = false,
selectedSortType = personProfileViewModel.sortType,
onClickSortType = {},
onBlockPersonClick = {},
onReportPersonClick = {},
onMessagePersonClick = {},
selectedSortType = personProfileViewModel.sortType,
openDrawer = ::openDrawer,
scrollBehavior = scrollBehavior,
onBack = onBack,
isLoggedIn = { false },
siteVersion = siteViewModel.siteVersion(),
matrixId = null,
)
}
is ApiState.Holder -> {
Expand Down Expand Up @@ -267,6 +268,7 @@ fun PersonProfileActivity(
onBack = onBack,
isLoggedIn = { !account.isAnon() },
siteVersion = siteViewModel.siteVersion(),
matrixId = person.matrix_user_id,
)
}
else -> {}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/matrix_favicon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="32dp" android:viewportHeight="520"
android:viewportWidth="520" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M13.7,11.9v496.2h35.7V520H0V0h49.4v11.9H13.7z"/>
<path android:fillColor="#FF000000" android:pathData="M166.3,169.2v25.1h0.7c6.7,-9.6 14.8,-17 24.2,-22.2c9.4,-5.3 20.3,-7.9 32.5,-7.9c11.7,0 22.4,2.3 32.1,6.8c9.7,4.5 17,12.6 22.1,24c5.5,-8.1 13,-15.3 22.4,-21.5c9.4,-6.2 20.6,-9.3 33.5,-9.3c9.8,0 18.9,1.2 27.3,3.6c8.4,2.4 15.5,6.2 21.5,11.5c6,5.3 10.6,12.1 14,20.6c3.3,8.5 5,18.7 5,30.7v124.1h-50.9V249.6c0,-6.2 -0.2,-12.1 -0.7,-17.6c-0.5,-5.5 -1.8,-10.3 -3.9,-14.3c-2.2,-4.1 -5.3,-7.3 -9.5,-9.7c-4.2,-2.4 -9.9,-3.6 -17,-3.6c-7.2,0 -13,1.4 -17.4,4.1c-4.4,2.8 -7.9,6.3 -10.4,10.8c-2.5,4.4 -4.2,9.4 -5,15.1c-0.8,5.6 -1.3,11.3 -1.3,17v103.3h-50.9v-104c0,-5.5 -0.1,-10.9 -0.4,-16.3c-0.2,-5.4 -1.3,-10.3 -3.1,-14.9c-1.8,-4.5 -4.8,-8.2 -9,-10.9c-4.2,-2.7 -10.3,-4.1 -18.5,-4.1c-2.4,0 -5.6,0.5 -9.5,1.6c-3.9,1.1 -7.8,3.1 -11.5,6.1c-3.7,3 -6.9,7.3 -9.5,12.9c-2.6,5.6 -3.9,13 -3.9,22.1v107.6h-50.9V169.2H166.3z"/>
<path android:fillColor="#FF000000" android:pathData="M506.3,508.1V11.9h-35.7V0H520v520h-49.4v-11.9H506.3z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,5 @@
<string name="open_link_external">Open link in external</string>
<string name="no_activity_found">No activity (app) found that can open this link</string>
<string name="markdownHelper_insertSpoiler">Insert spoiler</string>
<string name="matrix_send_msg">Connect on Matrix</string>
MV-GH marked this conversation as resolved.
Show resolved Hide resolved
</resources>