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

small refactoring and UI tweaks #171

Merged
merged 14 commits into from
Mar 3, 2024
4 changes: 4 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ val SAVEDATA_PATH_WIDTH = 200.dp
val SAVEDATA_PATH_HEIGHT = 50.dp
val MYTOXID_WIDTH = 200.dp
val MYTOXID_HEIGHT = 50.dp
val MESSAGE_BOX_BOTTOM_PADDING = 4.dp
const val MSG_TEXT_FONT_SIZE_MIXED = 14.0f
const val MSG_TEXT_FONT_SIZE_EMOJI_ONLY = 55.0f
const val MAX_EMOJI_POP_SEARCH_LEN = 20
Expand All @@ -245,6 +246,9 @@ const val BG_COLOR_RELAY_CONTACT_ITEM = 0x448ABEB9
const val BG_COLOR_OWN_RELAY_CONTACT_ITEM = 0x44FFFFB9
const val URL_TEXTVIEW_URL_COLOR = 0xFF223DDC
const val NGC_PRIVATE_MSG_INDICATOR_COLOR = 0xFFFFA255
val MESSAGE_PUSH_CHECKMARK_COLOR = Color(0xFF2684A7)
val DELIVERY_CHECKMARK_COLOR = Color(0xFF2684A7)
val DELIVERY_CONFIRM_CHECKMARK_COLOR = Color(0xFF2684A7)
val MESSAGE_CHECKMARKS_ICON_SIZE = 12.dp
val MESSAGE_CHECKMARKS_CONTAINER_SIZE = 12.dp
var emojis_cat_all_gropued: ArrayList<ArrayList<ArrayList<EmojiStrAndName>>> = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class MainActivity
println("java.vendor:" + System.getProperty("java.vendor"))
println("java.version:" + System.getProperty("java.version"))
println("java.specification.vendor:" + System.getProperty("java.specification.vendor"))
println("java.vendor.version:" + System.getProperty("java.vendor.version"))
} catch (e: Exception)
{
e.printStackTrace()
Expand Down
55 changes: 51 additions & 4 deletions src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -868,19 +868,19 @@ class TrifaToxService
}

@JvmStatic
fun safe_string(`in`: ByteArray?): String
fun safe_string(input: ByteArray?): String
{ // Log.i(TAG, "safe_string:in=" + in);
var out = ""
try
{
out = String(`in`!!, charset("UTF-8")) // Best way to decode using "UTF-8"
out = String(input!!, charset("UTF-8")) // Best way to decode using "UTF-8"
} catch (e: Exception)
{
e.printStackTrace()
Log.i(TAG, "safe_string:EE:" + e.message)
try
{
out = String(`in`!!)
out = String(input!!)
} catch (e2: Exception)
{
e2.printStackTrace()
Expand Down Expand Up @@ -944,7 +944,7 @@ class TrifaToxService
sent_timestampLt(cutoff_sent_time).
count()

Log.i(TAG, "resend_push_for_v3_messages:m_push_count=" + m_push_count)
// Log.i(TAG, "resend_push_for_v3_messages:m_push_count=" + m_push_count)
if (m_push_count < 1)
{
return
Expand Down Expand Up @@ -989,6 +989,21 @@ class TrifaToxService
max_resend_count_per_iteration = 20
}
var cur_resend_count_per_iteration = 0

// HINT: check if there is anything to resend first --------
var check_count = 0
try {
check_count = orma!!.selectFromMessage().directionEq(1)
.msg_versionEq(0)
.TRIFA_MESSAGE_TYPEEq(TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value)
.resend_countLt(MAX_TEXTMSG_RESEND_COUNT_OLDMSG_VERSION).readEq(false)
.count()
}
catch (_: Exception) {}
if (check_count == 0) { return }
// HINT: check if there is anything to resend first --------

Log.i(TAG, "resend_v3_messages: -- SQL --")
var m_v1: List<Message>? = null
m_v1 = if (friend_pubkey != null)
{
Expand All @@ -997,6 +1012,7 @@ class TrifaToxService
{
orma!!.selectFromMessage().directionEq(1).msg_versionEq(0).TRIFA_MESSAGE_TYPEEq(TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value).resend_countLt(MAX_TEXTMSG_RESEND_COUNT_OLDMSG_VERSION).readEq(false).orderBySent_timestampAsc().toList()
}
Log.i(TAG, "resend_v3_messages: -- SQL --")
if (m_v1 != null && m_v1.size > 0)
{
Log.i(TAG, "resend_v3_messages: we have " + m_v1.size + " messages to resend")
Expand Down Expand Up @@ -1058,6 +1074,21 @@ class TrifaToxService
var cur_resend_count_per_iteration = 0
// HINT: cutoff time "now" minus 25 seconds
val cutoff_sent_time = System.currentTimeMillis() - 25 * 1000

// HINT: check if there is anything to resend first --------
var check_count = 0
try {
check_count = orma!!.selectFromMessage().directionEq(1)
.TRIFA_MESSAGE_TYPEEq(TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value)
.msg_versionEq(0).readEq(false)
.resend_countLt(MAX_TEXTMSG_RESEND_COUNT_OLDMSG_VERSION)
.count()
}
catch (_: Exception) {}
if (check_count == 0) { return }
// HINT: check if there is anything to resend first --------

Log.i(TAG, "resend_old_messages: -- SQL --")
var m_v0: List<Message>? = null
m_v0 = if (friend_pubkey != null)
{
Expand All @@ -1070,6 +1101,7 @@ class TrifaToxService
// HINT: this is the specific resend for 1 friend only, when that friend comes online
orma!!.selectFromMessage().directionEq(1).TRIFA_MESSAGE_TYPEEq(TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value).msg_versionEq(0).readEq(false).resend_countLt(MAX_TEXTMSG_RESEND_COUNT_OLDMSG_VERSION).orderBySent_timestampAsc().toList()
}
Log.i(TAG, "resend_old_messages: -- SQL --")
if (m_v0 != null && m_v0.size > 0)
{
Log.i(TAG, "resend_old_messages: we have " + m_v0.size + " messages to resend")
Expand Down Expand Up @@ -1125,10 +1157,25 @@ class TrifaToxService
{
val max_resend_count_per_iteration = 10
var cur_resend_count_per_iteration = 0

// HINT: check if there is anything to resend first --------
var check_count = 0
try {
check_count = orma!!.selectFromMessage().
directionEq(1).TRIFA_MESSAGE_TYPEEq(TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value)
.msg_versionEq(1).readEq(false).
msg_at_relayEq(at_relay).count()
}
catch (_: Exception) {}
if (check_count == 0) { return }
// HINT: check if there is anything to resend first --------

Log.i(TAG, "resend_v2_messages: -- SQL --")
val m_v1 = orma!!.selectFromMessage().
directionEq(1).TRIFA_MESSAGE_TYPEEq(TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value)
.msg_versionEq(1).readEq(false).
msg_at_relayEq(at_relay).orderBySent_timestampAsc().toList()
Log.i(TAG, "resend_v2_messages: -- SQL --")
if (m_v1 != null && m_v1.size > 0)
{
Log.i(TAG, "resend_v2_messages: we have " + m_v1.size + " messages to resend")
Expand Down
65 changes: 63 additions & 2 deletions src/main/kotlin/com/zoffcc/applications/trifa2/ChatApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
Expand All @@ -33,23 +34,28 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.DragData
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.ExternalDragValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.onExternalDrag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.zoffcc.applications.trifa.AVState
import com.zoffcc.applications.trifa.HelperGeneric
import com.zoffcc.applications.trifa.HelperGeneric.send_message_onclick
import com.zoffcc.applications.trifa.HelperGroup
import com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper
import com.zoffcc.applications.trifa.HelperMessage.take_screen_shot_with_selection
import com.zoffcc.applications.trifa.HelperOSFile
import com.zoffcc.applications.trifa.Log
import com.zoffcc.applications.trifa.MainActivity
import com.zoffcc.applications.trifa.MainActivity.Companion.add_ngc_outgoing_file
Expand Down Expand Up @@ -91,7 +97,9 @@ import org.jetbrains.compose.resources.ExperimentalResourceApi
import java.io.File
import java.net.URI
import java.nio.file.LinkOption
import java.nio.file.Path
import kotlin.io.path.exists
import kotlin.io.path.name
import kotlin.io.path.toPath

private const val TAG = "trifa.Chatapp"
Expand Down Expand Up @@ -227,12 +235,18 @@ fun ChatApp(focusRequester: FocusRequester, displayTextField: Boolean = true, se
Image(painterResource("background.jpg"), modifier = Modifier.fillMaxSize(), contentDescription = null, contentScale = ContentScale.Crop)
Column(modifier = Modifier.fillMaxSize()) {
var isDragging by remember { mutableStateOf(false) }
var drag_value: ExternalDragValue? by remember { mutableStateOf(null) }
Box(Modifier.weight(1f)
.background(color = if (isDragging) Color.LightGray else Color.Transparent)
.onExternalDrag(
onDragStart = { isDragging = true },
onDragExit = { isDragging = false },
onDragStart = { value ->
drag_value = value
isDragging = true },
onDragExit = {
drag_value = null
isDragging = false },
onDrop = { value ->
drag_value = null
isDragging = false
// Log.i(TAG, "dropping file here")
if (value.dragData is DragData.FilesList) {
Expand All @@ -255,6 +269,7 @@ fun ChatApp(focusRequester: FocusRequester, displayTextField: Boolean = true, se
})) {
if (isDragging)
{
val scope = rememberCoroutineScope()
Column(modifier = Modifier.fillMaxSize()
.padding(all = 10.dp)
.dashedBorder(color = if (isDragging) DragAndDropColors.active else Color.Transparent,
Expand All @@ -265,8 +280,54 @@ fun ChatApp(focusRequester: FocusRequester, displayTextField: Boolean = true, se
modifier = Modifier.align(Alignment.CenterHorizontally),
color = DragAndDropColors.active
)
if (false)
{
Spacer(modifier = Modifier.weight(0.1f))
if (drag_value != null)
{
if (drag_value!!.dragData is DragData.FilesList)
{
var newFiles: List<Path>? = null
try
{
println("YYYYYYYYYYYYYYY11:drag_value=" + drag_value)
println("YYYYYYYYYYYYYYY22:drag_value=" + drag_value!!.dragData)
println("YYYYYYYYYYYYYYY33:drag_value=" + drag_value!!.dragData as DragData.FilesList)
println("YYYYYYYYYYYYYYY44:drag_value=" + (drag_value!!.dragData as DragData.FilesList).readFiles())
newFiles = (drag_value!!.dragData as DragData.FilesList).readFiles().mapNotNull { it1: String ->
URI(it1).toPath().takeIf { it.exists(LinkOption.NOFOLLOW_LINKS) }
}
} catch (e: Exception)
{
// e.printStackTrace()
}
if (newFiles != null)
{
newFiles!!.forEach {
if (it.toAbsolutePath().toString().isNotEmpty())
{
Log.i(TAG, "dropped file: " + it.toAbsolutePath() + " "
+ it.parent.normalize().name + " " + it.fileName.name)

HelperGeneric.AsyncImage(load = {
HelperGeneric.loadImageBitmap(File(it.toAbsolutePath().toString()))
}, painterFor = { remember { BitmapPainter(it) } },
contentDescription = "Image",
modifier = Modifier.size(150.dp)
)
}
}
}
}
}
}
Spacer(modifier = Modifier.weight(0.6f))
}
scope.launch {
if (drag_value != null) {
println("XXXXXXXXXXXXXXXdrag_value=" + drag_value)
}
}
}
else
{
Expand Down
Loading
Loading