diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt index d12a4c411..f3ac34115 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt @@ -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) + } + } + } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt index c828decec..d905bb82b 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HashtagScreen.kt @@ -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) + } + } + } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt index c7497acf6..283344f62 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt @@ -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, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8d1857e1c..49fb0670c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,6 +34,8 @@ Login with a Private key to like Posts No Zap Amount Setup. Long Press to change Login with a Private key to be able to send Zaps + Login with a Private key to be able to Follow + Login with a Private key to be able to Unfollow Zaps View count Boost