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

NGC groups added #14

Merged
merged 7 commits into from
Oct 15, 2023
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
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ org.jetbrains.compose.experimental.uikit.enabled=true
android.defaults.buildfeatures.buildconfig=true
# Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental
kotlin.version=1.9.10
compose.version=1.5.3
multiplatform.version=1.9.10
kotlin.version=1.9.20-RC
compose.version=1.5.10-rc01
multiplatform.version=1.9.20-RC
28 changes: 14 additions & 14 deletions src/main/java/com/zoffcc/applications/sorm/GroupMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,52 @@ public class GroupMessage

@Column(indexed = true, helpers = Column.Helpers.ALL, defaultExpr = "")
@Nullable
String message_id_tox = ""; // Tox Group Message_ID (4 bytes as hex string lowercase)
public String message_id_tox = ""; // Tox Group Message_ID (4 bytes as hex string lowercase)

@Column(indexed = true, defaultExpr = "-1", helpers = Column.Helpers.ALL)
String group_identifier = "-1"; // f_key -> GroupDB.group_identifier
public String group_identifier = "-1"; // f_key -> GroupDB.group_identifier

@Column(indexed = true, helpers = Column.Helpers.ALL)
String tox_group_peer_pubkey;
public String tox_group_peer_pubkey;

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
int private_message = 0; // 0 -> message to group, 1 -> msg privately to/from peer
public int private_message = 0; // 0 -> message to group, 1 -> msg privately to/from peer

@Column(indexed = true, defaultExpr = "", helpers = Column.Helpers.ALL)
@Nullable
String tox_group_peername = ""; // saved for backup, when conference is offline!
public String tox_group_peername = ""; // saved for backup, when conference is offline!

@Column(indexed = true, helpers = Column.Helpers.ALL)
int direction = 0; // 0 -> msg received, 1 -> msg sent
public int direction = 0; // 0 -> msg received, 1 -> msg sent

@Column(indexed = true)
int TOX_MESSAGE_TYPE = 0; // 0 -> normal, 1 -> action
public int TOX_MESSAGE_TYPE = 0; // 0 -> normal, 1 -> action

@Column(indexed = true, defaultExpr = "0")
int TRIFA_MESSAGE_TYPE = TRIFA_MSG_TYPE_TEXT.value;
public int TRIFA_MESSAGE_TYPE = TRIFA_MSG_TYPE_TEXT.value;

@Column(helpers = Column.Helpers.ALL)
@Nullable
long sent_timestamp = 0L;
public long sent_timestamp = 0L;

@Column(indexed = true)
@Nullable
long rcvd_timestamp = 0L;
public long rcvd_timestamp = 0L;

@Column(helpers = Column.Helpers.ALL)
boolean read = false;
public boolean read = false;

@Column(indexed = true, helpers = Column.Helpers.ALL)
boolean is_new = true;
public boolean is_new = true;

@Column(helpers = Column.Helpers.ALL)
@Nullable
String text = null;
public String text = null;

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
boolean was_synced = false;
public boolean was_synced = false;

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
Expand Down
129 changes: 129 additions & 0 deletions src/main/java/com/zoffcc/applications/trifa/ChatColors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* [TRIfA], Java part of Tox Reference Implementation for Android
* Copyright (C) 2017 Zoff <[email protected]>
* <p>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

package com.zoffcc.applications.trifa;

public class ChatColors
{
private static final String TAG = "trifa.ChatCols";

static int[] PeerAvatarColors = {
//
// https://www.w3schools.com/colors/colors_picker.asp
//
// ** too dark ** // Color.parseColor("#0000FF"), // Blue
Color.parseColor("#6666ff"), // * lighter blue *
//
// ** // Color.parseColor("#FF00FF"), // Fuchsia
//
Color.parseColor("#00FFFF"), // Aqua
//
Color.parseColor("#008000"), // Green
//
Color.parseColor("#dce775"), // Lime
//
// ** too dark ** // Color.parseColor("#800000"), // Maroon
Color.parseColor("#f06292"), // * lighter red *
//
// ** too dark ** // Color.parseColor("#000080"), // Navy
Color.parseColor("#42a5f5"), // * lighter blue *
//
Color.parseColor("#808000"), // Olive
//
Color.parseColor("#800080"), // Purple
//
// ** too dark ** // Color.parseColor("#FF0000"), // Red
Color.parseColor("#ff4d4d"), // * lighter red *
//
Color.parseColor("#008080"), // Teal
//
// ** too bright ** // Color.parseColor("#FFFF00") // Yellow
Color.parseColor("#cccc00"), // * darker yellow *
//
};

static int get_size()
{
return PeerAvatarColors.length;
}

static int get_shade(int color, String pubkey)
{
// Log.i(TAG, "get_shade:pubkey=" + pubkey + " pubkey.substring(0, 1)=" + pubkey.substring(0, 1));
// Log.i(TAG, "get_shade:pubkey=" + pubkey + " pubkey.substring(1, 2)=" + pubkey.substring(1, 2));

float factor =
(Integer.parseInt(pubkey.substring(0, 1), 16) + (Integer.parseInt(pubkey.substring(1, 2), 16) * 16)) /
255.0f;

final float range = 0.5f;
final float min_value = 1.0f - (range * 0.6f);
factor = (factor * range) + min_value;

return manipulateColor(color, factor);
}

public static int manipulateColor(int color, float factor)
{
// Log.i(TAG, "manipulateColor:color=" + color + " factor=" + factor);

int a = Color.alpha(color);
int r = Math.round(Color.red(color) * factor);
int g = Math.round(Color.green(color) * factor);
int b = Math.round(Color.blue(color) * factor);
return Color.argb(a, Math.min(r, 255), Math.min(g, 255), Math.min(b, 255));
}

static int hash_to_bucket(String hash_value, int number_of_buckets)
{
try
{
int ret = 0;
int value = (Integer.parseInt(hash_value.substring(hash_value.length() - 1, hash_value.length() - 0), 16) +
(Integer.parseInt(hash_value.substring(hash_value.length() - 2, hash_value.length() - 1), 16) *
16) +
(Integer.parseInt(hash_value.substring(hash_value.length() - 3, hash_value.length() - 2), 16) *
(16 * 2)) +
(Integer.parseInt(hash_value.substring(hash_value.length() - 4, hash_value.length() - 3), 16) *
(16 * 3)));

// Log.i(TAG, "hash_to_bucket:value=" + value);

ret = (value % number_of_buckets);

// BigInteger bigInt = new BigInteger(1, hash_value.getBytes());
// int ret = (int) (bigInt.longValue() % (long) number_of_buckets);
// // Log.i(TAG, "hash_to_bucket:" + "ret=" + ret + " hash_as_int=" + bigInt + " hash=" + hash_value);
return ret;
}
catch (Exception e)
{
e.printStackTrace();
Log.i(TAG, "hash_to_bucket:EE:" + e.getMessage());
return 0;
}
}

public static int get_ngc_peer_color(String peer_pubkey)
{
return ChatColors.get_shade(
ChatColors.PeerAvatarColors[hash_to_bucket(peer_pubkey, ChatColors.get_size())],
peer_pubkey);
}
}
151 changes: 151 additions & 0 deletions src/main/java/com/zoffcc/applications/trifa/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package com.zoffcc.applications.trifa;

public class Color {

private final float[] mComponents;

public Color() {
// This constructor is required for compatibility with previous APIs
mComponents = new float[] { 0.0f, 0.0f, 0.0f, 1.0f };
}

/**
* </p>Parse the color string, and return the corresponding color-int.
* If the string cannot be parsed, throws an IllegalArgumentException
* exception. Supported formats are:</p>
*
* <ul>
* <li><code>#RRGGBB</code></li>
* <li><code>#AARRGGBB</code></li>
* </ul>
*
* <p>The following names are also accepted: <code>red</code>, <code>blue</code>,
* <code>green</code>, <code>black</code>, <code>white</code>, <code>gray</code>,
* <code>cyan</code>, <code>magenta</code>, <code>yellow</code>, <code>lightgray</code>,
* <code>darkgray</code>, <code>grey</code>, <code>lightgrey</code>, <code>darkgrey</code>,
* <code>aqua</code>, <code>fuchsia</code>, <code>lime</code>, <code>maroon</code>,
* <code>navy</code>, <code>olive</code>, <code>purple</code>, <code>silver</code>,
* and <code>teal</code>.</p>
*/
public static int parseColor(String colorString) {
if (colorString.charAt(0) == '#') {
// Use a long to avoid rollovers on #ffXXXXXX
long color = Long.parseLong(colorString.substring(1), 16);
if (colorString.length() == 7) {
// Set the alpha value
color |= 0x00000000ff000000;
} else if (colorString.length() != 9) {
throw new IllegalArgumentException("Unknown color");
}
return (int)color;
}
throw new IllegalArgumentException("Unknown color");
}

public static float alpha(long color) {
if ((color & 0x3fL) == 0L) return ((color >> 56) & 0xff) / 255.0f;
return ((color >> 6) & 0x3ff) / 1023.0f;
}

/**
* Return the alpha component of a color int. This is the same as saying
* color >>> 24
*/
public static int alpha(int color) {
return color >>> 24;
}

/**
* Return the red component of a color int. This is the same as saying
* (color >> 16) & 0xFF
*/
public static int red(int color) {
return (color >> 16) & 0xFF;
}

/**
* Return the green component of a color int. This is the same as saying
* (color >> 8) & 0xFF
*/
public static int green(int color) {
return (color >> 8) & 0xFF;
}

/**
* Return the blue component of a color int. This is the same as saying
* color & 0xFF
*/
public static int blue(int color) {
return color & 0xFF;
}

/**
* Return a color-int from red, green, blue components.
* The alpha component is implicitly 255 (fully opaque).
* These component values should be \([0..255]\), but there is no
* range check performed, so if they are out of range, the
* returned color is undefined.
*
* @param red Red component \([0..255]\) of the color
* @param green Green component \([0..255]\) of the color
* @param blue Blue component \([0..255]\) of the color
*/
public static int rgb(
int red,
int green,
int blue) {
return 0xff000000 | (red << 16) | (green << 8) | blue;
}

/**
* Return a color-int from red, green, blue float components
* in the range \([0..1]\). The alpha component is implicitly
* 1.0 (fully opaque). If the components are out of range, the
* returned color is undefined.
*
* @param red Red component \([0..1]\) of the color
* @param green Green component \([0..1]\) of the color
* @param blue Blue component \([0..1]\) of the color
*/
public static int rgb(float red, float green, float blue) {
return 0xff000000 |
((int) (red * 255.0f + 0.5f) << 16) |
((int) (green * 255.0f + 0.5f) << 8) |
(int) (blue * 255.0f + 0.5f);
}

/**
* Return a color-int from alpha, red, green, blue components.
* These component values should be \([0..255]\), but there is no
* range check performed, so if they are out of range, the
* returned color is undefined.
* @param alpha Alpha component \([0..255]\) of the color
* @param red Red component \([0..255]\) of the color
* @param green Green component \([0..255]\) of the color
* @param blue Blue component \([0..255]\) of the color
*/
public static int argb(
int alpha,
int red,
int green,
int blue) {
return (alpha << 24) | (red << 16) | (green << 8) | blue;
}

/**
* Return a color-int from alpha, red, green, blue float components
* in the range \([0..1]\). If the components are out of range, the
* returned color is undefined.
*
* @param alpha Alpha component \([0..1]\) of the color
* @param red Red component \([0..1]\) of the color
* @param green Green component \([0..1]\) of the color
* @param blue Blue component \([0..1]\) of the color
*/
public static int argb(float alpha, float red, float green, float blue) {
return ((int) (alpha * 255.0f + 0.5f) << 24) |
((int) (red * 255.0f + 0.5f) << 16) |
((int) (green * 255.0f + 0.5f) << 8) |
(int) (blue * 255.0f + 0.5f);
}
}
Loading
Loading