Skip to content

Commit

Permalink
show ip addresses for friends
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Mar 12, 2024
1 parent 28f6939 commit 1f55a8b
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static com.zoffcc.applications.trifa.HelperFriend.get_friend_capabilities_from_pubkey;
import static com.zoffcc.applications.trifa.HelperFriend.main_get_friend;
import static com.zoffcc.applications.trifa.HelperFriend.set_friend_avatar_update;
import static com.zoffcc.applications.trifa.HelperFriend.tox_friend_by_public_key__wrapper;
import static com.zoffcc.applications.trifa.HelperFriend.tox_friend_get_public_key__wrapper;
import static com.zoffcc.applications.trifa.HelperGeneric.darkenColor;
import static com.zoffcc.applications.trifa.HelperGeneric.get_vfs_image_filename_friend_avatar;
Expand All @@ -55,6 +56,7 @@
import static com.zoffcc.applications.trifa.Identicon.create_avatar_identicon_for_pubkey;
import static com.zoffcc.applications.trifa.MainActivity.friend_list_fragment;
import static com.zoffcc.applications.trifa.MainActivity.main_handler_s;
import static com.zoffcc.applications.trifa.MainActivity.tox_friend_get_connection_ip;
import static com.zoffcc.applications.trifa.TRIFAGlobals.TRIFA_SYSTEM_MESSAGE_PEER_PUBKEY;
import static com.zoffcc.applications.trifa.ToxVars.TOX_CAPABILITY_DECODE;
import static com.zoffcc.applications.trifa.ToxVars.TOX_CAPABILITY_DECODE_TO_STRING;
Expand All @@ -71,6 +73,7 @@ public class FriendInfoActivity extends AppCompatActivity
TextView fi_relay_pubkey_textview = null;
TextView fi_toxcapabilities_textview = null;
TextView fi_relay_text = null;
TextView fi_ipaddr_text = null;
TextView friend_num_msgs_text = null;
Button remove_friend_relay_button = null;
TextView fi_pushurl_textview = null;
Expand All @@ -97,6 +100,7 @@ protected void onCreate(Bundle savedInstanceState)
alias_text = (EditText) findViewById(R.id.fi_alias_text);
fi_relay_pubkey_textview = (TextView) findViewById(R.id.fi_relay_pubkey_textview);
fi_relay_text = (TextView) findViewById(R.id.fi_relay_text);
fi_ipaddr_text = (TextView) findViewById(R.id.fi_ipaddr_text);
remove_friend_relay_button = (Button) findViewById(R.id.remove_friend_relay_button);
fi_pushurl_textview = (TextView) findViewById(R.id.fi_pushurl_textview);
fi_pushurl_text = (TextView) findViewById(R.id.fi_pushurl_text);
Expand All @@ -113,6 +117,17 @@ protected void onCreate(Bundle savedInstanceState)

alias_text.setText("");

fi_ipaddr_text.setText("");
try
{
final String ip_str = tox_friend_get_connection_ip(tox_friend_by_public_key__wrapper(friend_pubkey));
final String f_ip_str = ip_str.replaceAll("\0", "");
fi_ipaddr_text.setText(f_ip_str);
}
catch(Exception ignored)
{
}

try
{
alias_text.setText(orma.selectFromFriendList().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public class FriendList
@Nullable
String push_url;

@Column(indexed = true, defaultExpr = "", helpers = Column.Helpers.ALL)
@Nullable
String ip_addr_str;

@Column(indexed = true, defaultExpr = "0", helpers = Column.Helpers.ALL)
long capabilities = 0;

Expand Down Expand Up @@ -135,6 +139,7 @@ static FriendList deep_copy(FriendList in)
out.capabilities = in.capabilities;
out.msgv3_capability = in.msgv3_capability;
out.avatar_ftid_hex = in.avatar_ftid_hex;
out.ip_addr_str = in.ip_addr_str;

return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@
import static com.zoffcc.applications.trifa.MainActivity.cache_fnum_pubkey;
import static com.zoffcc.applications.trifa.MainActivity.cache_pubkey_fnum;
import static com.zoffcc.applications.trifa.MainActivity.friend_list_fragment;
import static com.zoffcc.applications.trifa.MainActivity.main_handler_s;
import static com.zoffcc.applications.trifa.MainActivity.tox_conference_invite;
import static com.zoffcc.applications.trifa.MainActivity.tox_conference_new;
import static com.zoffcc.applications.trifa.MainActivity.tox_friend_delete;
import static com.zoffcc.applications.trifa.MainActivity.tox_friend_get_connection_ip;
import static com.zoffcc.applications.trifa.MainActivity.toxav_add_av_groupchat;
import static com.zoffcc.applications.trifa.TRIFAGlobals.FL_NOTIFICATION_ICON_ALPHA_NOT_SELECTED;
import static com.zoffcc.applications.trifa.TRIFAGlobals.FL_NOTIFICATION_ICON_ALPHA_SELECTED;
Expand All @@ -101,6 +103,7 @@ public class FriendListHolder extends RecyclerView.ViewHolder implements View.On

private TextView textView;
private TextView statusText;
private TextView ip_addr_text;
private TextView unread_count;
private de.hdodenhof.circleimageview.CircleImageView avatar;
private ImageView f_status_icon;
Expand Down Expand Up @@ -132,6 +135,8 @@ public FriendListHolder(View itemView, Context c)

textView = (TextView) itemView.findViewById(R.id.f_name);
statusText = (TextView) itemView.findViewById(R.id.f_status_message);
ip_addr_text = (TextView) itemView.findViewById(R.id.f_ip_addr_text);

unread_count = (TextView) itemView.findViewById(R.id.f_unread_count);
avatar = (de.hdodenhof.circleimageview.CircleImageView) itemView.findViewById(R.id.f_avatar_icon);
f_status_icon = (ImageView) itemView.findViewById(R.id.f_status_icon);
Expand Down Expand Up @@ -159,6 +164,14 @@ public void bindFriendList(FriendList fl)
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);

try
{
ip_addr_text.setText(fl.ip_addr_str);
}
catch(Exception ignored)
{
}

friend_line_container.setBackground(null);
if (fl.last_online_timestamp == LAST_ONLINE_TIMSTAMP_ONLINE_OFFLINE)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,33 @@ synchronized static void update_friend_in_db_capabilities(FriendList f)

synchronized static void update_friend_in_db_connection_status(FriendList f)
{
orma.updateFriendList().
tox_public_key_stringEq(f.tox_public_key_string).
TOX_CONNECTION(f.TOX_CONNECTION).
TOX_CONNECTION_on_off(f.TOX_CONNECTION_on_off).
execute();
try
{
orma.updateFriendList().
tox_public_key_stringEq(f.tox_public_key_string).
TOX_CONNECTION(f.TOX_CONNECTION).
TOX_CONNECTION_on_off(f.TOX_CONNECTION_on_off).
execute();
}
catch (Exception e)
{
e.printStackTrace();
}
}

static void update_friend_in_db_ip_addr_str(FriendList f)
{
try
{
orma.updateFriendList().
tox_public_key_stringEq(f.tox_public_key_string).
ip_addr_str(f.ip_addr_str).
execute();
}
catch (Exception e)
{
e.printStackTrace();
}
}

synchronized static void update_friend_in_db_connection_status_real(FriendList f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
import static com.zoffcc.applications.trifa.HelperFriend.tox_friend_by_public_key__wrapper;
import static com.zoffcc.applications.trifa.HelperFriend.tox_friend_get_public_key__wrapper;
import static com.zoffcc.applications.trifa.HelperFriend.update_friend_in_db_capabilities;
import static com.zoffcc.applications.trifa.HelperFriend.update_friend_in_db_ip_addr_str;
import static com.zoffcc.applications.trifa.HelperGeneric.bytes_to_hex;
import static com.zoffcc.applications.trifa.HelperGeneric.del_g_opts;
import static com.zoffcc.applications.trifa.HelperGeneric.display_toast;
Expand Down Expand Up @@ -3112,6 +3113,8 @@ static void allocate_video_buffer_1(int frame_width_px1, int frame_height_px1, l

public static native int tox_friend_get_connection_status(long friend_number);

public static native String tox_friend_get_connection_ip(long friend_number);

public static native int tox_friend_delete(long friend_number);

public static native String tox_self_get_name();
Expand Down Expand Up @@ -4690,6 +4693,26 @@ static void android_tox_callback_friend_connection_status_cb_method(long friend_
}
}

if (a_TOX_CONNECTION != TOX_CONNECTION_NONE.value)
{
try
{
final String ip_str = tox_friend_get_connection_ip(tox_friend_by_public_key__wrapper(f.tox_public_key_string));
f.ip_addr_str = ip_str.replaceAll("\0", "");
update_friend_in_db_ip_addr_str(f);
}
catch(Exception e)
{
f.ip_addr_str = "";
update_friend_in_db_ip_addr_str(f);
}
}
else
{
f.ip_addr_str = "";
update_friend_in_db_ip_addr_str(f);
}

if (f.TOX_CONNECTION_real != a_TOX_CONNECTION)
{
if (f.TOX_CONNECTION_real == TOX_CONNECTION_NONE.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ public void run()

void load_and_add_all_friends()
{

// --- load and update all friends ---
long[] friends = MainActivity.tox_self_get_friend_list();
Log.i(TAG, "loading_friend:number_of_friends=" + friends.length);
Expand Down Expand Up @@ -873,6 +874,14 @@ public void run()
cache_fnum_pubkey.clear();
cache_confid_confnum.clear();

try
{
orma.updateFriendList().ip_addr_str("").execute();
}
catch(Exception e)
{
}

tox_self_capabilites = tox_self_get_capabilities();
//Log.i(TAG, "tox_self_capabilites:" + tox_self_capabilites + " decoded:" +
// TOX_CAPABILITY_DECODE_TO_STRING(TOX_CAPABILITY_DECODE(tox_self_capabilites)) + " " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,45 @@

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/fi_ipaddr_text_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginLeft="20dp"
android:layout_weight="0"
android:paddingLeft="4dp"
android:paddingRight="2dp"
android:paddingBottom="15dp"
android:text="@string/layout___ipaddress"
android:textAlignment="textStart"
android:textSize="16sp"
android:textStyle="bold" />

<TextView
android:id="@+id/fi_ipaddr_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="800"
android:fontFamily="monospace"
android:paddingLeft="4dp"
android:paddingBottom="15dp"
android:text="0.0.0.0 00000"
android:textIsSelectable="true"
android:textSize="16sp"
android:typeface="monospace" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
23 changes: 20 additions & 3 deletions android-refimpl-app/app/src/main/res/layout/friend_list_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/outside_friend_info_container"
android:layout_width="fill_parent"
android:layout_height="87dp"
android:layout_height="90dp"
android:layout_margin="0dp"
android:background="@null"
android:elevation="0dp"
Expand All @@ -12,7 +12,7 @@
<RelativeLayout
android:id="@+id/friend_line_container"
android:layout_width="fill_parent"
android:layout_height="85dp"
android:layout_height="88dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
Expand Down Expand Up @@ -110,12 +110,29 @@
android:typeface="monospace" />

<TextView
android:id="@+id/f_last_online_timestamp"
android:id="@+id/f_ip_addr_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/f_status_message"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:ellipsize="marquee"
android:fontFamily="monospace"
android:gravity="left"
android:maxLines="1"
android:paddingRight="6dp"
android:text="0.0.0.0"
android:textColor="@color/friend_list_text_color"
android:textSize="11sp"
android:typeface="monospace" />

<TextView
android:id="@+id/f_last_online_timestamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/f_ip_addr_text"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:ellipsize="marquee"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/outside_friend_info_container"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_height="53dp"
android:layout_margin="0dp"
android:background="@null"
android:elevation="0dp"
Expand All @@ -12,7 +12,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/friend_line_container"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_marginRight="5dp"
Expand Down Expand Up @@ -111,12 +111,29 @@
android:visibility="gone" />

<TextView
android:id="@+id/f_last_online_timestamp"
android:id="@+id/f_ip_addr_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/f_status_message"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:ellipsize="marquee"
android:fontFamily="monospace"
android:gravity="left"
android:maxLines="1"
android:paddingRight="6dp"
android:text="0.0.0.0"
android:textColor="@color/friend_list_text_color"
android:textSize="11sp"
android:typeface="monospace" />

<TextView
android:id="@+id/f_last_online_timestamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/f_ip_addr_text"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:ellipsize="marquee"
Expand Down
1 change: 1 addition & 0 deletions android-refimpl-app/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@
<string name="layout___pubkey">Pubkey:</string>
<string name="layout___capabilities">Capabilities:</string>
<string name="layout___status">Status:</string>
<string name="layout___ipaddress">IP:</string>
<string name="layout___alias">Alias</string>
<string name="layout___remove_friends_relay">remove Friends Relay</string>
<string name="layout___friends_relay_pubkey">Friends Relay Pubkey:</string>
Expand Down

0 comments on commit 1f55a8b

Please sign in to comment.