mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-07-13 20:04:30 +02:00
Adds a Toast for not having a private key when following/unfollowing people
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -19,10 +20,12 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
@ -194,6 +197,7 @@ fun ShowFollowingOrUnfollowingButton(
|
|||||||
accountViewModel: AccountViewModel
|
accountViewModel: AccountViewModel
|
||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
var isFollowing by remember { mutableStateOf(false) }
|
var isFollowing by remember { mutableStateOf(false) }
|
||||||
val accountFollowsState by accountViewModel.account.userProfile().live().follows.observeAsState()
|
val accountFollowsState by accountViewModel.account.userProfile().live().follows.observeAsState()
|
||||||
@ -210,9 +214,41 @@ fun ShowFollowingOrUnfollowingButton(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isFollowing) {
|
if (isFollowing) {
|
||||||
UnfollowButton { scope.launch(Dispatchers.IO) { accountViewModel.unfollow(baseAuthor) } }
|
UnfollowButton {
|
||||||
|
if (!accountViewModel.isWriteable()) {
|
||||||
|
scope.launch {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_unfollow),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
accountViewModel.unfollow(baseAuthor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
FollowButton({ scope.launch(Dispatchers.IO) { accountViewModel.follow(baseAuthor) } })
|
FollowButton {
|
||||||
|
if (!accountViewModel.isWriteable()) {
|
||||||
|
scope.launch {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_follow),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
accountViewModel.follow(baseAuthor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn
|
package com.vitorpamplona.amethyst.ui.screen.loggedIn
|
||||||
|
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -19,12 +20,14 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.service.NostrHashtagDataSource
|
import com.vitorpamplona.amethyst.service.NostrHashtagDataSource
|
||||||
import com.vitorpamplona.amethyst.ui.dal.HashtagFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.HashtagFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.screen.NostrHashtagFeedViewModel
|
import com.vitorpamplona.amethyst.ui.screen.NostrHashtagFeedViewModel
|
||||||
@ -126,7 +129,8 @@ private fun HashtagActionOptions(
|
|||||||
tag: String,
|
tag: String,
|
||||||
accountViewModel: AccountViewModel
|
accountViewModel: AccountViewModel
|
||||||
) {
|
) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
val userState by accountViewModel.userProfile().live().follows.observeAsState()
|
val userState by accountViewModel.userProfile().live().follows.observeAsState()
|
||||||
val isFollowingTag by remember(userState) {
|
val isFollowingTag by remember(userState) {
|
||||||
@ -136,8 +140,40 @@ private fun HashtagActionOptions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isFollowingTag) {
|
if (isFollowingTag) {
|
||||||
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { accountViewModel.account.unfollow(tag) } }
|
UnfollowButton {
|
||||||
|
if (!accountViewModel.isWriteable()) {
|
||||||
|
scope.launch {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_unfollow),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
accountViewModel.account.unfollow(tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
FollowButton({ coroutineScope.launch(Dispatchers.IO) { accountViewModel.account.follow(tag) } })
|
FollowButton {
|
||||||
|
if (!accountViewModel.isWriteable()) {
|
||||||
|
scope.launch {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_follow),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
accountViewModel.account.follow(tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -698,6 +698,7 @@ private fun ProfileActions(
|
|||||||
accountViewModel: AccountViewModel
|
accountViewModel: AccountViewModel
|
||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
val accountLocalUserState by accountViewModel.accountLiveData.observeAsState()
|
val accountLocalUserState by accountViewModel.accountLiveData.observeAsState()
|
||||||
val account = remember(accountLocalUserState) { accountLocalUserState?.account } ?: return
|
val account = remember(accountLocalUserState) { accountLocalUserState?.account } ?: return
|
||||||
@ -734,18 +735,60 @@ private fun ProfileActions(
|
|||||||
account.showUser(baseUser.pubkeyHex)
|
account.showUser(baseUser.pubkeyHex)
|
||||||
}
|
}
|
||||||
} else if (isLoggedInFollowingUser) {
|
} else if (isLoggedInFollowingUser) {
|
||||||
UnfollowButton { scope.launch(Dispatchers.IO) { account.unfollow(baseUser) } }
|
UnfollowButton {
|
||||||
|
if (!accountViewModel.isWriteable()) {
|
||||||
|
scope.launch {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_unfollow),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
account.unfollow(baseUser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isUserFollowingLoggedIn) {
|
if (isUserFollowingLoggedIn) {
|
||||||
FollowButton(
|
FollowButton(R.string.follow_back) {
|
||||||
{ scope.launch(Dispatchers.IO) { account.follow(baseUser) } },
|
if (!accountViewModel.isWriteable()) {
|
||||||
R.string.follow_back
|
scope.launch {
|
||||||
)
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_follow),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
account.follow(baseUser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
FollowButton(
|
FollowButton(R.string.follow) {
|
||||||
{ scope.launch(Dispatchers.IO) { account.follow(baseUser) } },
|
if (!accountViewModel.isWriteable()) {
|
||||||
R.string.follow
|
scope.launch {
|
||||||
)
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_follow),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
account.follow(baseUser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1539,7 +1582,7 @@ fun UnfollowButton(onClick: () -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FollowButton(onClick: () -> Unit, text: Int = R.string.follow) {
|
fun FollowButton(text: Int = R.string.follow, onClick: () -> Unit) {
|
||||||
Button(
|
Button(
|
||||||
modifier = Modifier.padding(start = 3.dp),
|
modifier = Modifier.padding(start = 3.dp),
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
<string name="login_with_a_private_key_to_like_posts">Login with a Private key to like Posts</string>
|
<string name="login_with_a_private_key_to_like_posts">Login with a Private key to like Posts</string>
|
||||||
<string name="no_zap_amount_setup_long_press_to_change">No Zap Amount Setup. Long Press to change</string>
|
<string name="no_zap_amount_setup_long_press_to_change">No Zap Amount Setup. Long Press to change</string>
|
||||||
<string name="login_with_a_private_key_to_be_able_to_send_zaps">Login with a Private key to be able to send Zaps</string>
|
<string name="login_with_a_private_key_to_be_able_to_send_zaps">Login with a Private key to be able to send Zaps</string>
|
||||||
|
<string name="login_with_a_private_key_to_be_able_to_follow">Login with a Private key to be able to Follow</string>
|
||||||
|
<string name="login_with_a_private_key_to_be_able_to_unfollow">Login with a Private key to be able to Unfollow</string>
|
||||||
<string name="zaps">Zaps</string>
|
<string name="zaps">Zaps</string>
|
||||||
<string name="view_count">View count</string>
|
<string name="view_count">View count</string>
|
||||||
<string name="boost">Boost</string>
|
<string name="boost">Boost</string>
|
||||||
|
Reference in New Issue
Block a user