Skip to content

Commit

Permalink
visually show "old" filetransfers.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jul 10, 2022
1 parent 949e815 commit 880f12f
Show file tree
Hide file tree
Showing 19 changed files with 369 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import static com.zoffcc.applications.trifa.HelperMessage.set_message_queueing_from_id;
import static com.zoffcc.applications.trifa.HelperMessage.set_message_start_sending_from_id;
import static com.zoffcc.applications.trifa.HelperMessage.set_message_state_from_id;
import static com.zoffcc.applications.trifa.HelperMessage.update_message_in_db_filetransfer_kind;
import static com.zoffcc.applications.trifa.HelperMessage.update_single_message_from_messge_id;
import static com.zoffcc.applications.trifa.Identicon.bytesToHex;
import static com.zoffcc.applications.trifa.MainActivity.PREF__auto_accept_all_upto;
Expand Down Expand Up @@ -966,16 +967,20 @@ static void start_outgoing_ft(Message m)
ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_FTV2.value, ft.filesize, file_id_buffer,
ft.file_name, ft.file_name.length());
ft.kind = ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_FTV2.value;
m.filetransfer_kind = TOX_FILE_KIND_FTV2.value;
}
else
{
file_number = tox_file_send(tox_friend_by_public_key__wrapper(m.tox_friendpubkey),
ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_DATA.value, ft.filesize, file_id_buffer,
ft.file_name, ft.file_name.length());
ft.kind = ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_DATA.value;
m.filetransfer_kind = TOX_FILE_KIND_DATA.value;
}
// TODO: handle errors from tox_file_send() here -------

update_message_in_db_filetransfer_kind(m);

if (file_number < 0)
{
Log.i(TAG, "tox_file_send:EE:" + file_number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ static void update_message_in_db_messageid(final Message m)
}
}

static void update_message_in_db_filetransfer_kind(final Message m)
{
try
{
orma.updateMessage().
idEq(m.id).
filetransfer_kind(m.filetransfer_kind).
execute();
}
catch (Exception e)
{
e.printStackTrace();
}
}

static void update_message_in_db_resend_count(final Message m)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_CONTROL.TOX_FILE_CONTROL_RESUME;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_ID_LENGTH;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_AVATAR;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_DATA;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_FTV2;
import static com.zoffcc.applications.trifa.ToxVars.TOX_GROUP_CHAT_ID_SIZE;
import static com.zoffcc.applications.trifa.ToxVars.TOX_HASH_LENGTH;
Expand Down Expand Up @@ -5869,6 +5870,7 @@ else if (a_TOX_FILE_KIND == TOX_FILE_KIND_FTV2.value)
m.sent_timestamp = m.rcvd_timestamp;
m.text = filename_corrected + "\n" + file_size + " bytes";
m.sent_push = 0;
m.filetransfer_kind = TOX_FILE_KIND_FTV2.value;
long new_msg_id = -1;

if (message_list_activity != null)
Expand Down Expand Up @@ -6015,6 +6017,7 @@ public void run()
m.sent_timestamp = m.rcvd_timestamp;
m.text = filename_corrected + "\n" + file_size + " bytes";
m.sent_push = 0;
m.filetransfer_kind = TOX_FILE_KIND_DATA.value;
long new_msg_id = -1;

if (message_list_activity != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import static com.zoffcc.applications.trifa.TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_CONTROL.TOX_FILE_CONTROL_PAUSE;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_DATA;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_FTV2;

@Table
public class Message
Expand Down Expand Up @@ -128,6 +130,10 @@ public class Message
@Nullable
int sent_push = 0;

@Column(helpers = Column.Helpers.ALL, defaultExpr = "0")
@Nullable
int filetransfer_kind = TOX_FILE_KIND_DATA.value;

static Message deep_copy(Message in)
{
Message out = new Message();
Expand Down Expand Up @@ -160,6 +166,7 @@ static Message deep_copy(Message in)
out.msg_at_relay = in.msg_at_relay;
out.msg_idv3_hash = in.msg_idv3_hash;
out.sent_push = in.sent_push;
out.filetransfer_kind = in.filetransfer_kind;

return out;
}
Expand All @@ -175,6 +182,6 @@ public String toString()
", is_new=" + is_new + ", msg_id_hash=" + msg_id_hash + ", msg_version=" + msg_version +
", resend_count=" + resend_count + ", raw_msgv2_bytes=" + "xxxxxx" + ", storage_frame_work=" +
storage_frame_work + ", ft_outgoing_queued=" + ft_outgoing_queued + ", msg_at_relay=" + msg_at_relay +
", sent_push=" + sent_push;
", sent_push=" + sent_push + ", filetransfer_kind=" + filetransfer_kind;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@ static void add_outgoing_file(Context c, long friendnum, String filepath, String
m.storage_frame_work = false;
m.sent_push = 0;
m.is_new = false; // no notification for outgoing filetransfers
m.filetransfer_kind = TOX_FILE_KIND_DATA.value;

long new_msg_id = insert_into_message_db(m, update_message_view);
m.id = new_msg_id;
Expand Down Expand Up @@ -1509,6 +1510,7 @@ static void add_outgoing_file(Context c, long friendnum, String filepath, String
m.text = filename + "\n" + file_size + " bytes";
m.storage_frame_work = true;
m.is_new = false; // no notification for outgoing filetransfers
m.filetransfer_kind = TOX_FILE_KIND_DATA.value;

long new_msg_id = insert_into_message_db(m, update_message_view);
m.id = new_msg_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand All @@ -52,6 +51,7 @@

import java.net.URLConnection;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import info.guardianproject.iocipher.File;

Expand All @@ -69,6 +69,7 @@
import static com.zoffcc.applications.trifa.MessageListActivity.onLongClick_message_helper;
import static com.zoffcc.applications.trifa.TRIFAGlobals.MESSAGE_TEXT_SIZE;
import static com.zoffcc.applications.trifa.TRIFAGlobals.MESSAGE_TEXT_SIZE_FT_NORMAL;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_FTV2;
import static com.zoffcc.applications.trifa.TrifaToxService.orma;

public class MessageListHolder_file_incoming_state_cancel extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener
Expand All @@ -91,6 +92,7 @@ public class MessageListHolder_file_incoming_state_cancel extends RecyclerView.V
de.hdodenhof.circleimageview.CircleImageView img_avatar;
TextView date_time;
ViewGroup layout_message_container;
ViewGroup rounded_bg_container;
boolean is_selected = false;
TextView message_text_date_string;
ViewGroup message_text_date;
Expand All @@ -109,6 +111,7 @@ public MessageListHolder_file_incoming_state_cancel(View itemView, Context c)
ft_preview_container = (ViewGroup) itemView.findViewById(R.id.ft_preview_container);
ft_buttons_container = (ViewGroup) itemView.findViewById(R.id.ft_buttons_container);
ft_preview_image = (ImageButton) itemView.findViewById(R.id.ft_preview_image);
rounded_bg_container = (ViewGroup) itemView.findViewById(R.id.ft_incoming_rounded_bg);
textView = (EmojiTextViewLinks) itemView.findViewById(R.id.m_text);
imageView = (ImageView) itemView.findViewById(R.id.m_icon);
img_avatar = (de.hdodenhof.circleimageview.CircleImageView) itemView.findViewById(R.id.img_avatar);
Expand All @@ -134,6 +137,37 @@ public void bindMessageList(Message m)

message_ = m;

int drawable_id = R.drawable.rounded_orange_bg_with_border;
try
{
if (m.filetransfer_kind == TOX_FILE_KIND_FTV2.value)
{
drawable_id = R.drawable.rounded_orange_bg;
}

final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
rounded_bg_container.setBackgroundDrawable(ContextCompat.getDrawable(context, drawable_id));
}
else
{
rounded_bg_container.setBackground(ContextCompat.getDrawable(context, drawable_id));
}
}
catch (Exception e)
{
final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
rounded_bg_container.setBackgroundDrawable(ContextCompat.getDrawable(context, drawable_id));
}
else
{
rounded_bg_container.setBackground(ContextCompat.getDrawable(context, drawable_id));
}
}

is_selected = false;
if (selected_messages.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import static com.zoffcc.applications.trifa.HelperFiletransfer.get_filetransfer_filenum_from_id;
Expand All @@ -49,6 +50,7 @@
import static com.zoffcc.applications.trifa.MainActivity.VFS_ENCRYPT;
import static com.zoffcc.applications.trifa.MainActivity.tox_file_control;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_CONTROL.TOX_FILE_CONTROL_CANCEL;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_FTV2;
import static com.zoffcc.applications.trifa.TrifaToxService.orma;

public class MessageListHolder_file_incoming_state_pause_has_accepted extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener
Expand All @@ -67,6 +69,7 @@ public class MessageListHolder_file_incoming_state_pause_has_accepted extends Re
ImageView imageView;
de.hdodenhof.circleimageview.CircleImageView img_avatar;
TextView date_time;
ViewGroup rounded_bg_container;
TextView message_text_date_string;
ViewGroup message_text_date;

Expand All @@ -85,6 +88,7 @@ public MessageListHolder_file_incoming_state_pause_has_accepted(View itemView, C
ft_buttons_container = (ViewGroup) itemView.findViewById(R.id.ft_buttons_container);
ft_preview_image = (ImageButton) itemView.findViewById(R.id.ft_preview_image);
img_avatar = (de.hdodenhof.circleimageview.CircleImageView) itemView.findViewById(R.id.img_avatar);
rounded_bg_container = (ViewGroup) itemView.findViewById(R.id.ft_incoming_rounded_bg);
textView = (EmojiTextViewLinks) itemView.findViewById(R.id.m_text);
imageView = (ImageView) itemView.findViewById(R.id.m_icon);
img_avatar = (de.hdodenhof.circleimageview.CircleImageView) itemView.findViewById(R.id.img_avatar);
Expand All @@ -104,6 +108,37 @@ public void bindMessageList(Message m)
m = new Message();
}

int drawable_id = R.drawable.rounded_orange_bg_with_border;
try
{
if (m.filetransfer_kind == TOX_FILE_KIND_FTV2.value)
{
drawable_id = R.drawable.rounded_orange_bg;
}

final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
rounded_bg_container.setBackgroundDrawable(ContextCompat.getDrawable(context, drawable_id));
}
else
{
rounded_bg_container.setBackground(ContextCompat.getDrawable(context, drawable_id));
}
}
catch (Exception e)
{
final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
rounded_bg_container.setBackgroundDrawable(ContextCompat.getDrawable(context, drawable_id));
}
else
{
rounded_bg_container.setBackground(ContextCompat.getDrawable(context, drawable_id));
}
}

date_time.setText(long_date_time_format(m.rcvd_timestamp));

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.MotionEvent;
Expand Down Expand Up @@ -49,6 +51,7 @@
import static com.zoffcc.applications.trifa.MainActivity.tox_file_control;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_CONTROL.TOX_FILE_CONTROL_CANCEL;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_CONTROL.TOX_FILE_CONTROL_RESUME;
import static com.zoffcc.applications.trifa.ToxVars.TOX_FILE_KIND.TOX_FILE_KIND_FTV2;
import static com.zoffcc.applications.trifa.TrifaToxService.orma;

public class MessageListHolder_file_incoming_state_pause_not_yet_accepted extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener
Expand All @@ -68,6 +71,7 @@ public class MessageListHolder_file_incoming_state_pause_not_yet_accepted extend
TextView date_time;
TextView message_text_date_string;
ViewGroup message_text_date;
ViewGroup rounded_bg_container;

public MessageListHolder_file_incoming_state_pause_not_yet_accepted(View itemView, Context c)
{
Expand All @@ -83,6 +87,7 @@ public MessageListHolder_file_incoming_state_pause_not_yet_accepted(View itemVie
ft_preview_container = (ViewGroup) itemView.findViewById(R.id.ft_preview_container);
ft_buttons_container = (ViewGroup) itemView.findViewById(R.id.ft_buttons_container);
ft_preview_image = (ImageButton) itemView.findViewById(R.id.ft_preview_image);
rounded_bg_container = (ViewGroup) itemView.findViewById(R.id.ft_incoming_rounded_bg);
textView = (TextView) itemView.findViewById(R.id.m_text);
img_avatar = (de.hdodenhof.circleimageview.CircleImageView) itemView.findViewById(R.id.img_avatar);
date_time = (TextView) itemView.findViewById(R.id.date_time);
Expand Down Expand Up @@ -113,6 +118,37 @@ public void bindMessageList(Message m)

final Message message = m;

int drawable_id = R.drawable.rounded_orange_bg_with_border;
try
{
if (m.filetransfer_kind == TOX_FILE_KIND_FTV2.value)
{
drawable_id = R.drawable.rounded_orange_bg;
}

final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
rounded_bg_container.setBackgroundDrawable(ContextCompat.getDrawable(context, drawable_id));
}
else
{
rounded_bg_container.setBackground(ContextCompat.getDrawable(context, drawable_id));
}
}
catch (Exception e)
{
final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
rounded_bg_container.setBackgroundDrawable(ContextCompat.getDrawable(context, drawable_id));
}
else
{
rounded_bg_container.setBackground(ContextCompat.getDrawable(context, drawable_id));
}
}

// --------- message date header (show only if different from previous message) ---------
// --------- message date header (show only if different from previous message) ---------
// --------- message date header (show only if different from previous message) ---------
Expand Down
Loading

0 comments on commit 880f12f

Please sign in to comment.