Adds a Toast for not having a private key when following/unfollowing people

pull/484/head
Vitor Pamplona 2023-07-01 17:16:56 -04:00
rodzic ed9c27341f
commit e402081777
4 zmienionych plików z 132 dodań i 15 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.ui.note
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@ -19,10 +20,12 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
@ -194,6 +197,7 @@ fun ShowFollowingOrUnfollowingButton(
accountViewModel: AccountViewModel
) {
val scope = rememberCoroutineScope()
val context = LocalContext.current
var isFollowing by remember { mutableStateOf(false) }
val accountFollowsState by accountViewModel.account.userProfile().live().follows.observeAsState()
@ -210,9 +214,41 @@ fun ShowFollowingOrUnfollowingButton(
}
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 {
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)
}
}
}
}
}

Wyświetl plik

@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.ui.screen.loggedIn
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@ -19,12 +20,14 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.NostrHashtagDataSource
import com.vitorpamplona.amethyst.ui.dal.HashtagFeedFilter
import com.vitorpamplona.amethyst.ui.screen.NostrHashtagFeedViewModel
@ -126,7 +129,8 @@ private fun HashtagActionOptions(
tag: String,
accountViewModel: AccountViewModel
) {
val coroutineScope = rememberCoroutineScope()
val scope = rememberCoroutineScope()
val context = LocalContext.current
val userState by accountViewModel.userProfile().live().follows.observeAsState()
val isFollowingTag by remember(userState) {
@ -136,8 +140,40 @@ private fun HashtagActionOptions(
}
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 {
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)
}
}
}
}
}

Wyświetl plik

@ -698,6 +698,7 @@ private fun ProfileActions(
accountViewModel: AccountViewModel
) {
val scope = rememberCoroutineScope()
val context = LocalContext.current
val accountLocalUserState by accountViewModel.accountLiveData.observeAsState()
val account = remember(accountLocalUserState) { accountLocalUserState?.account } ?: return
@ -734,18 +735,60 @@ private fun ProfileActions(
account.showUser(baseUser.pubkeyHex)
}
} 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 {
if (isUserFollowingLoggedIn) {
FollowButton(
{ scope.launch(Dispatchers.IO) { account.follow(baseUser) } },
R.string.follow_back
)
FollowButton(R.string.follow_back) {
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) {
account.follow(baseUser)
}
}
}
} else {
FollowButton(
{ scope.launch(Dispatchers.IO) { account.follow(baseUser) } },
R.string.follow
)
FollowButton(R.string.follow) {
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) {
account.follow(baseUser)
}
}
}
}
}
}
@ -1539,7 +1582,7 @@ fun UnfollowButton(onClick: () -> Unit) {
}
@Composable
fun FollowButton(onClick: () -> Unit, text: Int = R.string.follow) {
fun FollowButton(text: Int = R.string.follow, onClick: () -> Unit) {
Button(
modifier = Modifier.padding(start = 3.dp),
onClick = onClick,

Wyświetl plik

@ -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="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_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="view_count">View count</string>
<string name="boost">Boost</string>