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 more tooltips and infos #157

Merged
merged 4 commits into from
Feb 18, 2024
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
69 changes: 52 additions & 17 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ import com.vanniktech.emoji.ios.IosEmojiProvider
import com.vanniktech.emoji.search.SearchEmojiManager
import com.zoffcc.applications.ffmpegav.AVActivity.JAVA_AUDIO_IN_DEVICE_NAME
import com.zoffcc.applications.trifa.EmojiStrAndName
import com.zoffcc.applications.trifa.FriendSettingDetails
import com.zoffcc.applications.trifa.MainActivity.Companion.DEBUG_COMPOSE_UI_UPDATES
import com.zoffcc.applications.trifa.MainActivity.Companion.PREF__do_not_sync_av
import org.briarproject.briar.desktop.ui.Tooltip
Expand All @@ -202,7 +203,7 @@ val GROUPITEM_HEIGHT = 50.dp
val GROUP_PEER_HEIGHT = 33.dp
val SETTINGS_HEADER_SIZE = 56.dp
val CONTACT_COLUMN_WIDTH = 230.dp
val GROUPS_COLUMN_WIDTH = 200.dp
val GROUPS_COLUMN_WIDTH = 210.dp
val GROUP_PEER_COLUMN_WIDTH = 180.dp
val MESAGE_INPUT_LINE_HEIGHT = 58.dp
val MAIN_TOP_TAB_HEIGHT = 160.dp
Expand Down Expand Up @@ -1071,26 +1072,35 @@ fun App()
val ContactListScope = rememberCoroutineScope()
ContactList(contactList = contacts)
VerticalDivider()
if (contacts.selectedContactPubkey == null)
val friendsettings by friendsettingsstore.stateFlow.collectAsState()
if ((friendsettings.visible) && (contacts.selectedContactPubkey != null)) // show friend settings
{
ExplainerChat()
} else
FriendSettingDetails(contacts.selectedContactPubkey)
}
else // -- show friend messages
{
Log.i(TAG, "CONTACTS -> draw")
load_messages_for_friend(contacts.selectedContactPubkey)
ContactListScope.launch {
globalstore.try_clear_unread_message_count()
globalfrndstoreunreadmsgs.try_clear_unread_per_friend_message_count(contacts.selectedContactPubkey)
if (contacts.selectedContactPubkey == null)
{
ExplainerChat()
} else
{
Log.i(TAG, "CONTACTS -> draw")
load_messages_for_friend(contacts.selectedContactPubkey)
ContactListScope.launch {
globalstore.try_clear_unread_message_count()
globalfrndstoreunreadmsgs.try_clear_unread_per_friend_message_count(contacts.selectedContactPubkey)
}
ChatAppWithScaffold(focusRequester = focusRequester, contactList = contacts, ui_scale = ui_scale)
//LaunchedEffect(contacts.selectedContactPubkey) {
// focusRequester.requestFocus()
//}
}
ChatAppWithScaffold(focusRequester = focusRequester, contactList = contacts, ui_scale = ui_scale)
//LaunchedEffect(contacts.selectedContactPubkey) {
// focusRequester.requestFocus()
//}
}
}
}
UiMode.GROUPS ->
{
friendsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(true)
val groupfocusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -1135,32 +1145,37 @@ fun App()
}
UiMode.ADDFRIEND -> {
groupsettingsstore.visible(false)
friendsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
if (tox_running_state == "running") AddFriend()
else ExplainerToxNotRunning()
}
UiMode.ADDGROUP -> {
groupsettingsstore.visible(false)
friendsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
if (tox_running_state == "running") AddGroup()
else ExplainerToxNotRunning()
}
UiMode.SETTINGS -> {
groupsettingsstore.visible(false)
friendsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
SettingDetails()
}
UiMode.ABOUT -> {
groupsettingsstore.visible(false)
friendsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
AboutScreen()
}
else -> {
groupsettingsstore.visible(false)
friendsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
UiPlaceholder()
Expand Down Expand Up @@ -1213,6 +1228,8 @@ fun load_messages_for_friend(selectedContactPubkey: String?)
val friend_user = User(fname!!, picture = "friend_avatar.png", toxpk = selectedContactPubkey, color = ColorProvider.getColor(false))
uimessages.add(UIMessage(direction = TRIFAGlobals.TRIFA_MSG_DIRECTION.TRIFA_MSG_DIRECTION_RECVD.value,
user = friend_user, timeMs = it.rcvd_timestamp,
recvTimeMs = it.rcvd_timestamp,
sentTimeMs = it.sent_timestamp,
text = it.text, toxpk = it.tox_friendpubkey.uppercase(),
trifaMsgType = it.TRIFA_MESSAGE_TYPE, msgDatabaseId = it.id,
filename_fullpath = it.filename_fullpath, file_state = it.state))
Expand All @@ -1221,6 +1238,8 @@ fun load_messages_for_friend(selectedContactPubkey: String?)
{
uimessages.add(UIMessage(direction = TRIFAGlobals.TRIFA_MSG_DIRECTION.TRIFA_MSG_DIRECTION_SENT.value,
user = myUser, timeMs = it.sent_timestamp,
recvTimeMs = it.rcvd_timestamp,
sentTimeMs = it.sent_timestamp,
text = it.text, toxpk = it.tox_friendpubkey.uppercase(),
trifaMsgType = it.TRIFA_MESSAGE_TYPE, msgDatabaseId = it.id,
filename_fullpath = it.filename_fullpath, file_state = it.state))
Expand Down Expand Up @@ -1263,9 +1282,17 @@ fun load_groupmessages_for_friend(selectedGroupId: String?)
when (it.TRIFA_MESSAGE_TYPE)
{
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value ->
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced, msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = friend_user, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced,
sentTimeMs = it.sent_timestamp,
rcvdTimeMs = it.rcvd_timestamp,
syncdTimeMs = it.rcvd_timestamp,
msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = friend_user, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_FILE.value ->
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced, msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = friend_user, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced,
sentTimeMs = it.sent_timestamp,
rcvdTimeMs = it.rcvd_timestamp,
syncdTimeMs = it.rcvd_timestamp,
msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = friend_user, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))

}
}
Expand All @@ -1274,9 +1301,17 @@ fun load_groupmessages_for_friend(selectedGroupId: String?)
when (it.TRIFA_MESSAGE_TYPE)
{
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value ->
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced, msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = myUser, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced,
sentTimeMs = it.sent_timestamp,
rcvdTimeMs = it.rcvd_timestamp,
syncdTimeMs = it.rcvd_timestamp,
msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = myUser, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_FILE.value ->
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced, msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = myUser, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
uigroupmessages.add(UIGroupMessage(was_synced = it.was_synced,
sentTimeMs = it.sent_timestamp,
rcvdTimeMs = it.rcvd_timestamp,
syncdTimeMs = it.rcvd_timestamp,
msg_id_hash = it.msg_id_hash, message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = myUser, timeMs = it.sent_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
}
}
else ->
Expand Down
114 changes: 114 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/FriendSettingDetails.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.zoffcc.applications.trifa

import SETTINGS_HEADER_SIZE
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.zoffcc.applications.sorm.FriendList
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_friend_by_public_key
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_friend_get_name
import com.zoffcc.applications.trifa.ToxVars.TOX_CAPABILITY_DECODE
import com.zoffcc.applications.trifa.ToxVars.TOX_CAPABILITY_DECODE_TO_STRING
import org.briarproject.briar.desktop.ui.VerticallyScrollableArea
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n

@Composable
fun FriendSettingDetails(selectedContactPubkey: String?)
{
FriendSettingDetailV(i18n("ui.friend_settings_headline")) {
Spacer(modifier = Modifier.height(20.dp))
Row(Modifier.wrapContentHeight().fillMaxWidth().padding(start = 15.dp)) {
val f_num = tox_friend_by_public_key(selectedContactPubkey)
var f_name: String? = ""
try
{
f_name = tox_friend_get_name(f_num)
}
catch (_: Exception)
{
}
if ((f_name == null) || (f_name.isEmpty()))
{
f_name = ""
}

var f: FriendList? = null
try
{
f = HelperFriend.main_get_friend(selectedContactPubkey)
}
catch (_: Exception)
{
}

var caps: String = "BASIC"
if (f != null)
{
caps = TOX_CAPABILITY_DECODE_TO_STRING(TOX_CAPABILITY_DECODE(f.capabilities))
}

val t = "Name: " + f_name + "\n" +
"Public Key: " + selectedContactPubkey + "\n" +
"Capabilities: " + caps + "\n"
SelectionContainer(modifier = Modifier.padding(all = 0.dp)) {
Text(
text = t,
style = MaterialTheme.typography.subtitle1.copy(fontSize = 16.sp, lineHeight = TextUnit.Unspecified),
modifier = Modifier.padding(0.dp).weight(1.0f)
)
}
}
}
}

@Composable
fun FriendSettingDetailV(header: String, content: @Composable (ColumnScope.() -> Unit)) =
Column(Modifier.fillMaxSize()) {
Row(Modifier.fillMaxWidth().height(SETTINGS_HEADER_SIZE).padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween)
{
Text(header, style = MaterialTheme.typography.h4, color = MaterialTheme.colors.onSurface)
}
VerticallyScrollableArea { scrollState ->
LazyColumn(state = scrollState) {
item {
content()
}
}
}

}

@Composable
fun FriendDetailItem(
label: String,
description: String,
setting: @Composable (RowScope.() -> Unit),
) = Row(Modifier.fillMaxWidth().height(SETTINGS_HEADER_SIZE).padding(horizontal = 16.dp).semantics(mergeDescendants = true) { // it would be nicer to derive the contentDescriptions from the descendants automatically
// which is currently not supported in Compose for Desktop
// see https://github.com/JetBrains/compose-jb/issues/2111
contentDescription = description
}, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween) {
Text(label)
setting()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.zoffcc.applications.trifa

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

data class StateFriendSettings(val visible: Boolean = false,
val selectedContactPubkey: String? = null
)

const val StateFriendSettingsTAG = "trifa.FriendSettingsStore"

interface FriendSettingsStore
{
val stateFlow: StateFlow<StateFriendSettings>
val state get() = stateFlow.value
fun visible(value: Boolean)
}

fun CoroutineScope.createFriendSettingsStore(): FriendSettingsStore
{
val mutableStateFlow = MutableStateFlow(StateFriendSettings())

return object : FriendSettingsStore
{
override val stateFlow: StateFlow<StateFriendSettings> = mutableStateFlow
override fun visible(value: Boolean)
{
mutableStateFlow.value = state.copy(visible = value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ object HelperGeneric {
direction = TRIFAGlobals.TRIFA_MSG_DIRECTION.TRIFA_MSG_DIRECTION_SENT.value,
user = myUser,
timeMs = timestamp,
recvTimeMs = 0L,
sentTimeMs = timestamp,
text = msg!!, toxpk = friendPubkey.toUpperCase(),
trifaMsgType = TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value,
msgDatabaseId = row_id,
Expand Down
Loading
Loading