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

unread messages badges, add button to turn off AV sync and add some tooltips #153

Merged
merged 6 commits into from
Feb 14, 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
195 changes: 116 additions & 79 deletions src/main/kotlin/Main.kt

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.zoffcc.applications.ffmpegav.AVActivity.ffmpegav_init
import com.zoffcc.applications.trifa.MainActivity.Companion.AUDIO_PCM_DEBUG_FILES
import com.zoffcc.applications.trifa.MainActivity.Companion.PREF__audio_input_filter
import com.zoffcc.applications.trifa.MainActivity.Companion.PREF__audio_play_volume_percent
import com.zoffcc.applications.trifa.MainActivity.Companion.PREF__do_not_sync_av
import com.zoffcc.applications.trifa.MainActivity.Companion.PREF__v4l2_capture_force_mjpeg
import com.zoffcc.applications.trifa.MainActivity.Companion.set_audio_play_volume_percent
import global_prefs
Expand Down Expand Up @@ -430,11 +431,13 @@ data class AVState(val a: Int)

if (friendpubkey == null)
{
println("start_outgoing_video: friend pubkey is null!! ERROR !!");
println("start_outgoing_video: friend pubkey is null!! ERROR !!")
return
}

MainActivity.set_av_call_status(1)
MainActivity.tox_set_do_not_sync_av(PREF__do_not_sync_av)
println("tox_set_do_not_sync_av:1: " + PREF__do_not_sync_av)
ffmpegav_apply_audio_filter(PREF__audio_input_filter)
set_audio_play_volume_percent(PREF__audio_play_volume_percent)

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ import com.zoffcc.applications.trifa.VideoInFrame.setup_video_in_resolution
import com.zoffcc.applications.trifa_material.trifa_material.BuildConfig
import contactstore
import global_prefs
import globalfrndstoreunreadmsgs
import globalstore
import groupmessagestore
import grouppeerstore
import groupstore
import globalgrpstoreunreadmsgs
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -151,6 +153,7 @@ class MainActivity
var PREF__udp_enabled = 1
var PREF__audio_play_volume_percent = 100
var PREF__audio_input_filter = 0
var PREF__do_not_sync_av = 0
var PREF__v4l2_capture_force_mjpeg: Int = 0 // 0 -> auto, 1 -> force MJPEG video capture with v4l2 devices
var PREF__video_bitrate_mode: Int = 0 // 0 -> low, 1 -> normal, 2 -> high quality video capture and sending
var PREF__orbot_enabled_to_int = 0
Expand Down Expand Up @@ -3110,6 +3113,7 @@ class MainActivity
}
HelperNotification.displayNotification("new Message" + fname)
globalstore.increase_unread_message_count()
globalfrndstoreunreadmsgs.increase_unread_per_friend_message_count(toxpk!!)
}
} catch (_: Exception)
{
Expand Down Expand Up @@ -3169,6 +3173,7 @@ class MainActivity
}
HelperNotification.displayNotification("new Group Message" + grptitle)
globalstore.increase_unread_group_message_count()
globalgrpstoreunreadmsgs.increase_unread_per_group_message_count(groupid.lowercase())
}
} catch (_: Exception)
{
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import com.zoffcc.applications.trifa.TRIFAGlobals.global_last_activity_outgoung_
import com.zoffcc.applications.trifa.TRIFAGlobals.global_self_connection_status
import com.zoffcc.applications.trifa.TRIFAGlobals.global_self_last_went_offline_timestamp
import contactstore
import globalfrndstoreunreadmsgs
import globalgrpstoreunreadmsgs
import globalstore
import grouppeerstore
import groupstore
Expand Down Expand Up @@ -108,6 +110,7 @@ class TrifaToxService
globalstore.try_clear_unread_group_message_count()
} catch(_: Exception) {
}

val old_is_tox_started = is_tox_started
Log.i(TAG, "is_tox_started:==============================")
Log.i(TAG, "is_tox_started=" + is_tox_started)
Expand Down Expand Up @@ -1233,6 +1236,11 @@ class TrifaToxService
} catch (_: Exception)
{
}

try {
globalfrndstoreunreadmsgs.try_clear_unread_per_friend_message_count(tox_friend_get_public_key(it)!!)
} catch(_: Exception) {
}
}
}

Expand Down Expand Up @@ -1264,6 +1272,11 @@ class TrifaToxService
} catch (_: Exception)
{
}

try {
globalgrpstoreunreadmsgs.try_clear_unread_per_group_message_count(group_identifier)
} catch(_: Exception) {
}
}
conf_++
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.zoffcc.applications.trifa

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import java.util.*
import kotlin.collections.HashMap

data class groupstore_unread_messages_state(
val unread_per_group_message_count: HashMap<String, Int> = HashMap(),
)

interface GroupstoreUnreadMessages {
fun increase_unread_per_group_message_count(groupid: String)
fun get_unread_per_group_message_count(groupid: String): Int
fun try_clear_unread_per_group_message_count(groupid: String?)
fun hard_clear_unread_per_group_message_count(groupid: String)
val stateFlow: StateFlow<groupstore_unread_messages_state>
val state get() = stateFlow.value
}

@OptIn(DelicateCoroutinesApi::class)
fun CoroutineScope.createGroupstoreUnreadMessages(): GroupstoreUnreadMessages {
val mutableStateFlow = MutableStateFlow(groupstore_unread_messages_state())
return object : GroupstoreUnreadMessages
{
override val stateFlow: StateFlow<groupstore_unread_messages_state> = mutableStateFlow

override fun increase_unread_per_group_message_count(groupid: String)
{
val tmp = HashMap(state.unread_per_group_message_count)
val old_value_ = tmp.get(groupid)
val old_value: Int = if (old_value_ == null) 0 else old_value_
tmp.put(groupid, old_value + 1)
mutableStateFlow.value = state.copy(unread_per_group_message_count = tmp)
}

override fun get_unread_per_group_message_count(groupid: String): Int
{
val tmp = state.unread_per_group_message_count.get(groupid)
if (tmp == null)
{
return 0
}
else
{
return tmp
}
}

override fun hard_clear_unread_per_group_message_count(groupid: String)
{
val tmp = HashMap(state.unread_per_group_message_count)
tmp.remove(groupid)
mutableStateFlow.value = state.copy(unread_per_group_message_count = tmp)
}

override fun try_clear_unread_per_group_message_count(groupid: String?)
{
var unread_count = 0
try
{
unread_count = TrifaToxService.orma!!.selectFromGroupMessage()
.group_identifierEq(groupid!!.lowercase())
.directionEq(TRIFAGlobals.TRIFA_MSG_DIRECTION.TRIFA_MSG_DIRECTION_RECVD.value)
.is_newEq(true).count()
if (unread_count != 0)
{
val tmp = HashMap(state.unread_per_group_message_count)
tmp.put(groupid, unread_count)
mutableStateFlow.value = state.copy(unread_per_group_message_count = tmp)
return
}
}
catch (e: Exception)
{
e.printStackTrace()
}
val tmp = HashMap(state.unread_per_group_message_count)
tmp.remove(groupid)
mutableStateFlow.value = state.copy(unread_per_group_message_count = tmp)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ fun CoroutineScope.createGlobalStore(): GlobalStore {
{
mutableStateFlow.value = state.copy(contacts_unread_group_message_count = (state.contacts_unread_group_message_count + 1))
}

override fun get_unread_group_message_count(): Int
{
return state.contacts_unread_group_message_count
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.zoffcc.applications.trifa

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import java.util.*
import kotlin.collections.HashMap

data class unread_messages_state(
val unread_per_friend_message_count: HashMap<String, Int> = HashMap(),
)

interface UnreadMessages {
fun increase_unread_per_friend_message_count(friend_pubkey: String)
fun get_unread_per_friend_message_count(friend_pubkey: String): Int
fun try_clear_unread_per_friend_message_count(friend_pubkey: String?)
fun hard_clear_unread_per_friend_message_count(friend_pubkey: String)
val stateFlow: StateFlow<unread_messages_state>
val state get() = stateFlow.value
}

@OptIn(DelicateCoroutinesApi::class)
fun CoroutineScope.createUnreadMessages(): UnreadMessages {
val mutableStateFlow = MutableStateFlow(unread_messages_state())
return object : UnreadMessages
{
override val stateFlow: StateFlow<unread_messages_state> = mutableStateFlow

override fun increase_unread_per_friend_message_count(friend_pubkey: String)
{
val tmp = HashMap(state.unread_per_friend_message_count)
val old_value_ = tmp.get(friend_pubkey)
val old_value: Int = if (old_value_ == null) 0 else old_value_
tmp.put(friend_pubkey, old_value + 1)
mutableStateFlow.value = state.copy(unread_per_friend_message_count = tmp)
}

override fun get_unread_per_friend_message_count(friend_pubkey: String): Int
{
val tmp = state.unread_per_friend_message_count.get(friend_pubkey)
if (tmp == null)
{
return 0
}
else
{
return tmp
}
}

override fun hard_clear_unread_per_friend_message_count(friend_pubkey: String)
{
val tmp = HashMap(state.unread_per_friend_message_count)
tmp.remove(friend_pubkey)
mutableStateFlow.value = state.copy(unread_per_friend_message_count = tmp)
}

override fun try_clear_unread_per_friend_message_count(friend_pubkey: String?)
{
var unread_count = 0
try
{
unread_count = TrifaToxService.orma!!.selectFromMessage()
.tox_friendpubkeyEq(friend_pubkey!!.uppercase())
.directionEq(TRIFAGlobals.TRIFA_MSG_DIRECTION.TRIFA_MSG_DIRECTION_RECVD.value)
.is_newEq(true).count()
if (unread_count != 0)
{
val tmp = HashMap(state.unread_per_friend_message_count)
tmp.put(friend_pubkey, unread_count)
mutableStateFlow.value = state.copy(unread_per_friend_message_count = tmp)
return
}
}
catch (e: Exception)
{
e.printStackTrace()
}
val tmp = HashMap(state.unread_per_friend_message_count)
tmp.remove(friend_pubkey)
mutableStateFlow.value = state.copy(unread_per_friend_message_count = tmp)
}
}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa2/ChatApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ import com.zoffcc.applications.trifa.createGlobalStore
import com.zoffcc.applications.trifa.createGroupPeerStore
import com.zoffcc.applications.trifa.createGroupSettingsStore
import com.zoffcc.applications.trifa.createGroupStore
import com.zoffcc.applications.trifa.createGroupstoreUnreadMessages
import com.zoffcc.applications.trifa.createSavepathStore
import com.zoffcc.applications.trifa.createToxDataStore
import com.zoffcc.applications.trifa.createUnreadMessages
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
Expand All @@ -93,6 +95,8 @@ private const val TAG = "trifa.Chatapp"
val myUser = User("Me", picture = null, toxpk = "AAA")
val messagestore = CoroutineScope(SupervisorJob()).createMessageStore()
val globalstore = CoroutineScope(SupervisorJob()).createGlobalStore()
val globalfrndstoreunreadmsgs = CoroutineScope(SupervisorJob()).createUnreadMessages()
val globalgrpstoreunreadmsgs = CoroutineScope(SupervisorJob()).createGroupstoreUnreadMessages()
val groupmessagestore = CoroutineScope(SupervisorJob()).createGroupMessageStore()
val contactstore = CoroutineScope(SupervisorJob()).createContactStore()
val grouppeerstore = CoroutineScope(SupervisorJob()).createGroupPeerStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Alignment.Companion.Start
import androidx.compose.ui.Alignment.Companion.Top
import androidx.compose.ui.Alignment.Companion.TopEnd
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow.Companion.Ellipsis
import androidx.compose.ui.text.toUpperCase
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import globalfrndstoreunreadmsgs
import globalstore
import org.briarproject.briar.desktop.ui.NumberBadge
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n

@Composable
Expand All @@ -52,12 +58,15 @@ fun ContactItemView(
horizontalArrangement = spacedBy(0.dp),
modifier = Modifier.weight(1f, fill = true),
) {

Box(Modifier.align(Top).padding(vertical = 0.dp)) {
ProfileCircle(45.dp, contactItem)
//NumberBadge(
// num = contactItem.unread,
// modifier = Modifier.align(TopEnd).offset(6.dp, (-6).dp)
//)
val current_friendtorerunreadmessagesstore by globalfrndstoreunreadmsgs.stateFlow.collectAsState()
val num_unread = current_friendtorerunreadmessagesstore.unread_per_friend_message_count.get(contactItem.pubkey)
NumberBadge(
num = if (num_unread == null) 0 else num_unread,
modifier = Modifier.align(TopEnd).offset(6.dp, (-6).dp)
)
}
ContactItemViewInfo(
contactItem = contactItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
Expand All @@ -18,7 +19,9 @@ import androidx.compose.ui.unit.dp
import com.zoffcc.applications.trifa.HelperGeneric.delete_friend_wrapper
import com.zoffcc.applications.trifa.StateContacts
import contactstore
import globalfrndstoreunreadmsgs
import globalstore
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand All @@ -27,6 +30,7 @@ import org.briarproject.briar.desktop.ui.VerticallyScrollableArea
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
import randomDebugBorder

@OptIn(DelicateCoroutinesApi::class)
@Composable
fun ContactList(
contactList: StateContacts,
Expand All @@ -47,9 +51,11 @@ fun ContactList(
key = { item -> item.pubkey },
contentType = { item -> item::class }
) { item ->
val ListItemViewScope = rememberCoroutineScope()
ListItemView(
onSelect = {
GlobalScope.launch { globalstore.try_clear_unread_message_count() }
ListItemViewScope.launch { globalstore.try_clear_unread_message_count() }
globalfrndstoreunreadmsgs.hard_clear_unread_per_friend_message_count(item.pubkey)
contactstore.select(item.pubkey)
},
selected = (contactList.selectedContactPubkey == item.pubkey)
Expand Down
Loading
Loading