From 1f55a8bb9d9d2ec110615fc8f0868b752f9d268d Mon Sep 17 00:00:00 2001 From: zoff99 Date: Tue, 12 Mar 2024 16:54:59 +0100 Subject: [PATCH] show ip addresses for friends --- .../trifa/FriendInfoActivity.java | 15 +++++++ .../zoffcc/applications/trifa/FriendList.java | 5 +++ .../applications/trifa/FriendListHolder.java | 13 +++++++ .../applications/trifa/HelperFriend.java | 32 ++++++++++++--- .../applications/trifa/MainActivity.java | 23 +++++++++++ .../applications/trifa/TrifaToxService.java | 9 +++++ .../main/res/layout/activity_friendinfo.xml | 39 +++++++++++++++++++ .../src/main/res/layout/friend_list_entry.xml | 23 +++++++++-- .../res/layout/friend_list_entry_compact.xml | 23 +++++++++-- .../app/src/main/res/values/strings.xml | 1 + 10 files changed, 172 insertions(+), 11 deletions(-) diff --git a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendInfoActivity.java b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendInfoActivity.java index 727048393..ab2e0d759 100644 --- a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendInfoActivity.java +++ b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendInfoActivity.java @@ -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; @@ -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; @@ -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; @@ -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); @@ -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(). diff --git a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendList.java b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendList.java index 6c47a3db9..6f5c7280b 100644 --- a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendList.java +++ b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendList.java @@ -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; @@ -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; } diff --git a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendListHolder.java b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendListHolder.java index 1510988af..3f3c55937 100644 --- a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendListHolder.java +++ b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/FriendListHolder.java @@ -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; @@ -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; @@ -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); @@ -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) { diff --git a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/HelperFriend.java b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/HelperFriend.java index 852b2201c..95aab7241 100644 --- a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/HelperFriend.java +++ b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/HelperFriend.java @@ -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) diff --git a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/MainActivity.java b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/MainActivity.java index 9a0dec0e5..a767d25ca 100644 --- a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/MainActivity.java +++ b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/MainActivity.java @@ -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; @@ -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(); @@ -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) diff --git a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/TrifaToxService.java b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/TrifaToxService.java index 2b5deffb5..1bbde0c09 100644 --- a/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/TrifaToxService.java +++ b/android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/TrifaToxService.java @@ -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); @@ -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)) + " " + diff --git a/android-refimpl-app/app/src/main/res/layout/activity_friendinfo.xml b/android-refimpl-app/app/src/main/res/layout/activity_friendinfo.xml index d4133d66c..bbbbbf9f5 100644 --- a/android-refimpl-app/app/src/main/res/layout/activity_friendinfo.xml +++ b/android-refimpl-app/app/src/main/res/layout/activity_friendinfo.xml @@ -114,6 +114,45 @@ + + + + + + + + + + + + + Pubkey: Capabilities: Status: + IP: Alias remove Friends Relay Friends Relay Pubkey: