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

implement share #609

Merged
merged 1 commit into from
Dec 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fun PollComposable(
rejectionText: String,
commentCount: Int,
onProfileCardClicked: () -> Unit,
onShareClicked: () -> Unit,
modifier: Modifier = Modifier
) {
Box(
Expand Down Expand Up @@ -120,7 +121,7 @@ fun PollComposable(
}
PollIcon(
id = R.drawable.ic_share,
modifier = Modifier.background(MaterialTheme.colorScheme.primary, PollIconShape)
modifier = Modifier.background(MaterialTheme.colorScheme.primary, PollIconShape).clickable(onClick = onShareClicked)
)
PollIcon(
id = R.drawable.ic_warning,
Expand Down Expand Up @@ -257,6 +258,7 @@ private fun PollComposablePreview() {
rejectionText = "Last 5 Days",
commentCount = 265,
onProfileCardClicked = {},
onShareClicked = {},
modifier = Modifier.padding(16.dp)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.bounswe.predictionpolls.R
import com.bounswe.predictionpolls.domain.poll.Poll
import com.bounswe.predictionpolls.domain.poll.PollOption
import com.bounswe.predictionpolls.extensions.fromISO8601
import com.bounswe.predictionpolls.utils.shareLink
import kotlinx.collections.immutable.ImmutableList


Expand All @@ -25,11 +29,13 @@ fun Polls(
modifier: Modifier = Modifier,
onPollClicked: (id: String) -> Unit = {},
) {
val context = LocalContext.current
LazyColumn(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(polls) {
val frontEndUrl = stringResource(id = R.string.front_end_url)
PollComposable(
modifier = Modifier.clickable {
onPollClicked(it.polId)
Expand All @@ -52,7 +58,10 @@ fun Polls(
commentCount = it.commentCount,
onProfileCardClicked = {
onProfileClicked(it.pollCreatorUsername)
}
},
onShareClicked = {
context.shareLink(frontEndUrl+ "/vote/" + it.polId)
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.bounswe.predictionpolls.R
import com.bounswe.predictionpolls.domain.poll.Poll
import com.bounswe.predictionpolls.extensions.fromISO8601
import com.bounswe.predictionpolls.ui.common.poll.DiscreteVoteOption
import com.bounswe.predictionpolls.ui.common.poll.PollComposable
import com.bounswe.predictionpolls.ui.common.poll.ReadOnlyDiscretePollOptions
import com.bounswe.predictionpolls.ui.theme.PredictionPollsTheme
import com.bounswe.predictionpolls.utils.shareLink


@Composable
Expand Down Expand Up @@ -72,6 +76,8 @@ fun ProfileScreen(
when (profileScreenUiState) {
is ProfileScreenUiState.ProfileAndFeedFetched -> {
items(profileScreenUiState.feed) {
val context = LocalContext.current
val frontEndUrl = stringResource(id = R.string.front_end_url)
PollComposable(
pollCreatorProfilePictureUri = it.creatorProfilePictureUri,
pollCreatorName = it.pollCreatorName,
Expand All @@ -91,6 +97,9 @@ fun ProfileScreen(
commentCount = it.commentCount,
onProfileCardClicked = {
onProfileClicked(it.pollCreatorUsername)
},
onShareClicked = {
context.shareLink(frontEndUrl+ "/vote/" + it.polId)
}
)
}
Expand Down Expand Up @@ -183,7 +192,8 @@ private fun ProfileScreenPreview() {
dueDate = "",
rejectionText = "Last 5 days",
commentCount = 530,
onProfileCardClicked = {}
onProfileCardClicked = {},
onShareClicked = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ private fun PollVotePreview() {
dueDate = "",
rejectionText = "Last 5 days",
commentCount = 145,
onProfileCardClicked = {}
onProfileCardClicked = {},
onShareClicked = {}
)
}, currentPointsReserved = 125, onPointsReservedChanged = {}, onVotePressed = {})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bounswe.predictionpolls.ui.vote

import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand All @@ -12,9 +11,11 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.bounswe.predictionpolls.R
import com.bounswe.predictionpolls.ui.common.poll.ContinuousVoteOption
import com.bounswe.predictionpolls.ui.common.poll.DiscreteVoteOption
import com.bounswe.predictionpolls.ui.common.poll.PollComposable
import com.bounswe.predictionpolls.utils.shareLink

@Composable
fun PollVoteScreen(
Expand Down Expand Up @@ -46,6 +47,7 @@ fun PollVoteScreen(
PollVote(
pollContent = {
val poll = state.poll
val frontEndUrl = remember { context.getString(R.string.front_end_url) }
PollComposable(
pollCreatorProfilePictureUri = poll.creatorProfilePictureUri,
pollCreatorName = poll.pollCreatorName,
Expand All @@ -72,7 +74,10 @@ fun PollVoteScreen(
rejectionText = poll.rejectionText ?: "",
commentCount = 0,
onProfileCardClicked = {
Log.d("TAG", "Polls: ${poll.pollCreatorUsername}")
onProfileCardClicked(poll.pollCreatorUsername)
},
onShareClicked = {
context.shareLink(frontEndUrl + "/vote/" + poll.polId)
}
)
},
Expand Down Expand Up @@ -113,7 +118,10 @@ fun PollVoteScreen(
rejectionText = poll.rejectionText ?: "",
commentCount = 0,
onProfileCardClicked = {
Log.d("TAG", "Polls: ${poll.pollCreatorUsername}")
onProfileCardClicked(poll.pollCreatorUsername)
},
onShareClicked = {
context.shareLink(context.getString(R.string.front_end_url) + "/vote/" + poll.polId)
}
)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.bounswe.predictionpolls.utils

import android.content.Context
import android.content.Intent

fun Context.shareLink(url: String) {
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url)
type = "text/plain"
}
startActivity(Intent.createChooser(sendIntent, "Share link using"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@

<string name="logged_out_notification">You have signed out successfully</string>
<string name="login_required_notification">Please sign in to access this page.</string>
<string name="front_end_url">http://ec2-3-78-169-139.eu-central-1.compute.amazonaws.com:3000</string>
</resources>