File tree Expand file tree Collapse file tree
android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4242import java .nio .ByteBuffer ;
4343import java .util .List ;
4444import java .util .Random ;
45+ import java .util .concurrent .ExecutionException ;
4546
4647import androidx .core .content .FileProvider ;
4748
@@ -341,14 +342,32 @@ public static void set_filetransfer_accepted_from_id(long filetransfer_id)
341342 {
342343 try
343344 {
344- orma .updateFiletransfer ().idEq (filetransfer_id ).ft_accepted (true ).execute ();
345+ orma .updateFiletransfer ().idEq (filetransfer_id ).ft_accepted (true ).
346+ transfer_start_ts (System .currentTimeMillis ()).
347+ execute ();
345348 }
346349 catch (Exception e )
347350 {
348351 e .printStackTrace ();
349352 }
350353 }
351354
355+ public static String format_speed (float bytes_per_second ) {
356+ try {
357+ if (bytes_per_second > 1024 ) {
358+ if (bytes_per_second > (1024 * 1024 )) {
359+ return String .format ("%.2f MiB/s" , bytes_per_second / (1024 * 1024 ));
360+ } else {
361+ return String .format ("%.2f kiB/s" , bytes_per_second / 1024 );
362+ }
363+ } else {
364+ return String .format ("%.2f Bytes/s" , bytes_per_second );
365+ }
366+ } catch (Exception e ) {
367+ }
368+ return "? Bytes/s" ;
369+ }
370+
352371 public static long get_filetransfer_filenum_from_id (long filetransfer_id )
353372 {
354373 try
Original file line number Diff line number Diff line change 4949import static com .zoffcc .applications .trifa .MainActivity .main_handler_s ;
5050import static com .zoffcc .applications .trifa .TRIFAGlobals .PUSH_URL_TRIGGER_GET_MESSAGE_FOR_delta_ms_after ;
5151import static com .zoffcc .applications .trifa .TRIFAGlobals .PUSH_URL_TRIGGER_GET_MESSAGE_FOR_delta_ms_prev ;
52+ import static com .zoffcc .applications .trifa .ToxVars .TOX_FILE_CONTROL .TOX_FILE_CONTROL_RESUME ;
5253import static com .zoffcc .applications .trifa .ToxVars .TOX_HASH_LENGTH ;
5354import static com .zoffcc .applications .trifa .ToxVars .TOX_MESSAGE_TYPE .TOX_MESSAGE_TYPE_HIGH_LEVEL_ACK ;
5455import static com .zoffcc .applications .trifa .TrifaToxService .orma ;
Original file line number Diff line number Diff line change @@ -6924,6 +6924,20 @@ else if (ft.kind == TOX_FILE_KIND_FTV2.value)
69246924 }
69256925 else
69266926 {
6927+ if (position == 0)
6928+ {
6929+ // this is the first chunk of an outgoing FT
6930+ // remember this timestamp as FT start time
6931+ try
6932+ {
6933+ orma.updateFiletransfer().idEq(ft.id).transfer_start_ts(
6934+ System.currentTimeMillis()).execute();
6935+ }
6936+ catch(Exception e)
6937+ {
6938+ }
6939+ }
6940+
69276941 if (ft.storage_frame_work)
69286942 {
69296943 long file_chunk_length = length;
@@ -7073,6 +7087,20 @@ else if (ft.kind == TOX_FILE_KIND_FTV2.value)
70737087 }
70747088 else
70757089 {
7090+ if (position == 0)
7091+ {
7092+ // this is the first chunk of an outgoing FT
7093+ // remember this timestamp as FT start time
7094+ try
7095+ {
7096+ orma.updateFiletransfer().idEq(ft.id).transfer_start_ts(
7097+ System.currentTimeMillis()).execute();
7098+ }
7099+ catch(Exception e)
7100+ {
7101+ }
7102+ }
7103+
70767104 if (ft.storage_frame_work)
70777105 {
70787106 long file_chunk_length = length;
Original file line number Diff line number Diff line change 4040import androidx .core .content .ContextCompat ;
4141import androidx .recyclerview .widget .RecyclerView ;
4242
43+ import static com .zoffcc .applications .trifa .HelperFiletransfer .format_speed ;
4344import static com .zoffcc .applications .trifa .HelperFiletransfer .get_filetransfer_filenum_from_id ;
4445import static com .zoffcc .applications .trifa .HelperFiletransfer .remove_vfs_ft_from_cache ;
4546import static com .zoffcc .applications .trifa .HelperFiletransfer .set_filetransfer_state_from_id ;
@@ -209,8 +210,17 @@ public void bindMessageList(Message m)
209210 final int percent = (int ) (100f * (float ) ft_ .current_position / (float ) ft_ .filesize );
210211 // Log.i(TAG, "getView:033:STATE:RESUME:percent=" + percent + " cur=" + ft_.current_position + " size=" + ft_.filesize);
211212 ft_progressbar .setProgress (percent );
213+ long start_ts = ft_ .transfer_start_ts ;
214+ long now = System .currentTimeMillis ();
215+ long delta_ts_ms = now - start_ts ;
216+ if (delta_ts_ms < 1 )
217+ {
218+ delta_ts_ms = 1 ;
219+ }
220+ float speed_bytes_per_second = (((float )ft_ .current_position ) / (float )delta_ts_ms ) * 1000.0f ;
212221 // TODO: make text better
213- textView .setText ("" + message .text + "\n " + ft_ .current_position + "/" + ft_ .filesize + "\n receiving ..." );
222+ textView .setText ("" + message .text + "\n " + ft_ .current_position + "/" + ft_ .filesize + "\n receiving ..." +
223+ "\n " + format_speed (speed_bytes_per_second ));
214224 if (MESSAGE_TEXT_SIZE [PREF__global_font_size ] > MESSAGE_TEXT_SIZE_FT_SMALL )
215225 {
216226 textView .setTextSize (TypedValue .COMPLEX_UNIT_SP , MESSAGE_TEXT_SIZE_FT_SMALL );
Original file line number Diff line number Diff line change 5252import androidx .documentfile .provider .DocumentFile ;
5353import androidx .recyclerview .widget .RecyclerView ;
5454
55+ import static com .zoffcc .applications .trifa .HelperFiletransfer .format_speed ;
5556import static com .zoffcc .applications .trifa .HelperFiletransfer .get_filetransfer_filenum_from_id ;
5657import static com .zoffcc .applications .trifa .HelperFiletransfer .remove_ft_from_cache ;
5758import static com .zoffcc .applications .trifa .HelperFiletransfer .set_filetransfer_state_from_id ;
@@ -204,9 +205,18 @@ public void bindMessageList(Message m)
204205 final int percent = (int ) (100f * (float ) ft_ .current_position / (float ) ft_ .filesize );
205206 // Log.i(TAG, "getView:033:STATE:RESUME:percent=" + percent + " cur=" + ft_.current_position + " size=" + ft_.filesize);
206207 ft_progressbar .setProgress (percent );
208+ long start_ts = ft_ .transfer_start_ts ;
209+ long now = System .currentTimeMillis ();
210+ long delta_ts_ms = now - start_ts ;
211+ if (delta_ts_ms < 1 )
212+ {
213+ delta_ts_ms = 1 ;
214+ }
215+ float speed_bytes_per_second = (((float )ft_ .current_position ) / (float )delta_ts_ms ) * 1000.0f ;
207216 // TODO: make text better
208217 textView .setAutoLinkText (
209- "" + message .text + "\n " + ft_ .current_position + "/" + ft_ .filesize + "\n sending ..." );
218+ "" + message .text + "\n " + ft_ .current_position + "/" + ft_ .filesize + "\n sending ..." +
219+ "\n " + format_speed (speed_bytes_per_second ));
210220 }
211221 else
212222 {
You can’t perform that action at this time.
0 commit comments