Skip to content

Commit

Permalink
more Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Dec 11, 2023
1 parent 162c35b commit 13598fd
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 26 deletions.
66 changes: 42 additions & 24 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
Expand All @@ -76,6 +77,8 @@ import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.draw.scale
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.FocusState
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
Expand All @@ -93,6 +96,7 @@ import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.key
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
Expand Down Expand Up @@ -966,6 +970,7 @@ fun App()
{
UiMode.CONTACTS ->
{
contactstore.visible(true)
val focusRequester = remember { FocusRequester() }
Row(modifier = Modifier.fillMaxWidth()) {
val contacts by contactstore.stateFlow.collectAsState()
Expand All @@ -987,6 +992,7 @@ fun App()
}
UiMode.GROUPS ->
{
contactstore.visible(false)
val groupfocusRequester = remember { FocusRequester() }
val groups by groupstore.stateFlow.collectAsState()
val grouppeers by grouppeerstore.stateFlow.collectAsState()
Expand Down Expand Up @@ -1014,16 +1020,27 @@ fun App()
}
}
UiMode.ADDFRIEND -> {
contactstore.visible(false)
if (tox_running_state == "running") AddFriend()
else ExplainerToxNotRunning()
}
UiMode.ADDGROUP -> {
contactstore.visible(false)
if (tox_running_state == "running") AddGroup()
else ExplainerToxNotRunning()
}
UiMode.SETTINGS -> SettingDetails()
UiMode.ABOUT -> AboutScreen()
else -> UiPlaceholder()
UiMode.SETTINGS -> {
contactstore.visible(false)
SettingDetails()
}
UiMode.ABOUT -> {
contactstore.visible(false)
AboutScreen()
}
else -> {
contactstore.visible(false)
UiPlaceholder()
}
}
}
}
Expand Down Expand Up @@ -1558,6 +1575,7 @@ private fun MainAppStart()
{
Window(onCloseRequest = { isAskingToClose = true }, title = "TRIfA",
icon = appIcon, state = state,
focusable = true,
onKeyEvent = {
when (it.key) {
Key.F11 -> {
Expand All @@ -1572,7 +1590,6 @@ private fun MainAppStart()
}
}
) {

if (isAskingToClose)
{
Dialog(
Expand Down Expand Up @@ -1606,38 +1623,39 @@ private fun MainAppStart()
}
}
}

val windowInfo = LocalWindowInfo.current
LaunchedEffect(windowInfo) {
snapshotFlow { windowInfo.isWindowFocused }.collect { onWindowFocused ->
onWindowFocused(onWindowFocused)
}
}
LaunchedEffect(state) {
snapshotFlow { state.isMinimized }.onEach(::onWindowMinimised).launchIn(this)
snapshotFlow { state.size }.onEach(::onWindowResize).launchIn(this)

snapshotFlow { state.position }.filter { it.isSpecified }.onEach(::onWindowRelocate).launchIn(this)
}
App()
/*
Box(modifier = Modifier.fillMaxSize().background(Color.White)) {
Column {
val dragAndDropModifier = Modifier.padding(horizontal = 4.dp, vertical = 4.dp)
var droppedFiles by remember { mutableStateOf<List<Path>>(emptyList()) }
DragAndDropFileBox(dragAndDropModifier.size(height = 200.dp, width = 400.dp)) { dragData ->
if (dragData is DragData.FilesList) {
val newFiles = dragData.readFiles().mapNotNull {
URI(it).toPath().takeIf { it.exists(LinkOption.NOFOLLOW_LINKS) }
}
droppedFiles = (droppedFiles + newFiles).distinct()
}
}
// FileListView(modifier = dragAndDropModifier, files = droppedFiles)
}
}
*/
}
} // ----------- main app screen -----------
// ----------- main app screen -----------
// ----------- main app screen -----------
}
}

@Suppress("UNUSED_PARAMETER")
private fun onWindowFocused(focused: Boolean)
{
println("onWindowFocused $focused")
globalstore.updateFocused(focused)
}

@Suppress("UNUSED_PARAMETER")
private fun onWindowMinimised(minimised: Boolean)
{
println("onWindowMinimised $minimised")
globalstore.updateMinimized(minimised)
}

@Suppress("UNUSED_PARAMETER")
private fun onWindowResize(size: DpSize)
{ // println("onWindowResize $size")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import org.briarproject.briar.desktop.contact.ContactItem

data class StateContacts(val contacts: List<ContactItem> = emptyList(), val selectedContactPubkey: String? = null, val selectedContact: ContactItem? = null)
data class StateContacts(val contacts: List<ContactItem> = emptyList(), val visible: Boolean = false, val selectedContactPubkey: String? = null, val selectedContact: ContactItem? = null)

const val TAG = "trifa.ContactsStore"

Expand All @@ -16,6 +16,7 @@ interface ContactStore
fun add(item: ContactItem)
fun remove(item: ContactItem)
fun select(pubkey: String?)
fun visible(value: Boolean)
fun clear()
fun update(item: ContactItem)
val stateFlow: StateFlow<StateContacts>
Expand Down Expand Up @@ -125,6 +126,12 @@ fun CoroutineScope.createContactStore(): ContactStore
global_semaphore_contactlist_ui.release()
}
}
override fun visible(value: Boolean)
{
global_semaphore_contactlist_ui.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
mutableStateFlow.value = state.copy(visible = value)
global_semaphore_contactlist_ui.release()
}

override fun update(item: ContactItem)
{
Expand Down
21 changes: 20 additions & 1 deletion src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import SnackBarToast
import UIGroupMessage
import UIMessage
import User
import androidx.compose.ui.platform.LocalWindowInfo
import avstatestore
import avstatestorecallstate
import avstatestorevcapfpsstate
import avstatestorevplayfpsstate
import com.notification.Notification
import com.zoffcc.applications.ffmpegav.AVActivity.ffmpegav_loadjni
import com.zoffcc.applications.jninotifications.NTFYActivity
import com.zoffcc.applications.jninotifications.NTFYActivity.jninotifications_loadjni
Expand Down Expand Up @@ -75,6 +77,7 @@ import com.zoffcc.applications.trifa.VideoInFrame.new_video_in_frame
import com.zoffcc.applications.trifa.VideoInFrame.setup_video_in_resolution
import contactstore
import global_prefs
import globalstore
import groupmessagestore
import grouppeerstore
import groupstore
Expand Down Expand Up @@ -1510,7 +1513,7 @@ class MainActivity
val msg_id_as_hex_string: String? = msg_id_buffer_compat.array()?.let {
bytesToHex(it, msg_id_buffer_compat.arrayOffset(), msg_id_buffer_compat.limit())
}
Log.i(TAG, "TOX_FILE_KIND_MESSAGEV2_SEND:MSGv2HASH:2=" + msg_id_as_hex_string);
// Log.i(TAG, "TOX_FILE_KIND_MESSAGEV2_SEND:MSGv2HASH:2=" + msg_id_as_hex_string);

try
{
Expand Down Expand Up @@ -2617,6 +2620,9 @@ class MainActivity
return add_tcp_relay_single(ip, key_hex, port.toLong())
}

/*
* put an incoming 1-on-1 text message into the database
*/
fun received_message_to_db(toxpk: String?, message_timestamp: Long, friend_message: String?): Long
{
val m = com.zoffcc.applications.sorm.Message()
Expand Down Expand Up @@ -2644,6 +2650,19 @@ class MainActivity
try
{
row_id = orma!!.insertIntoMessage(m)
if ((!globalstore.isFocused()) || (globalstore.isMinimized()) || (!contactstore.state.visible) || (contactstore.state.selectedContactPubkey != toxpk))
{
var fname: String? = ""
try
{
fname = " from " + tox_friend_get_name(tox_friend_by_public_key(toxpk))
}
catch (e2: Exception)
{
e2.printStackTrace()
}
HelperNotification.displayNotification("new Message" + fname)
}
} catch (e: Exception)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,48 @@ import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.launch
import java.io.File

data class globalstore_state(
val mainwindow_minimized: Boolean = false,
val mainwindow_focused: Boolean = true
)

interface GlobalStore {
fun updateMinimized(value: Boolean)
fun updateFocused(value: Boolean)
fun isMinimized(): Boolean
fun isFocused(): Boolean
val stateFlow: StateFlow<globalstore_state>
val state get() = stateFlow.value
}

fun CoroutineScope.createGlobalStore(): GlobalStore {
val mutableStateFlow = MutableStateFlow(globalstore_state())
return object : GlobalStore
{
override val stateFlow: StateFlow<globalstore_state> = mutableStateFlow

override fun updateMinimized(value: Boolean)
{
mutableStateFlow.value = state.copy(mainwindow_minimized = value)
}

override fun updateFocused(value: Boolean)
{
mutableStateFlow.value = state.copy(mainwindow_focused = value)
}

override fun isMinimized(): Boolean
{
return state.mainwindow_minimized
}

override fun isFocused(): Boolean
{
return state.mainwindow_focused
}
}
}

data class savepathenabled_state(
val savePathEnabled: Boolean = true,
val savePath: String = File(MainActivity.PREF__tox_savefile_dir).canonicalPath + File.separator
Expand Down
2 changes: 2 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,6 +73,7 @@ import com.zoffcc.applications.trifa.createAVStateStoreCallState
import com.zoffcc.applications.trifa.createAVStateStoreVideoCaptureFpsState
import com.zoffcc.applications.trifa.createAVStateStoreVideoPlayFpsState
import com.zoffcc.applications.trifa.createContactStore
import com.zoffcc.applications.trifa.createGlobalStore
import com.zoffcc.applications.trifa.createGroupPeerStore
import com.zoffcc.applications.trifa.createGroupStore
import com.zoffcc.applications.trifa.createSavepathStore
Expand All @@ -96,6 +97,7 @@ import kotlin.io.path.toPath
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 groupmessagestore = CoroutineScope(SupervisorJob()).createGroupMessageStore()
val contactstore = CoroutineScope(SupervisorJob()).createContactStore()
val grouppeerstore = CoroutineScope(SupervisorJob()).createGroupPeerStore()
Expand Down

0 comments on commit 13598fd

Please sign in to comment.