Skip to content

Commit

Permalink
make audio message recording UI a bit more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Sep 14, 2024
1 parent 5573baf commit e6e4dbb
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,19 @@ static String only_date_time_format(long timestamp_in_millis)
}
}

static String seconds_time_format_or_empty(long time_in_seconds)
{
try
{
return MainActivity.df_seconds_time.format(new Date(time_in_seconds * 1000));
}
catch (Exception e)
{
e.printStackTrace();
return "";
}
}

static void waiting_for_orbot_info(final boolean enable)
{
if (enable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ public class MainActivity extends AppCompatActivity
static TrifaToxService tox_service_fg = null;
static long update_all_messages_global_timestamp = -1;
final static SimpleDateFormat df_date_time_long = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final static SimpleDateFormat df_seconds_time = new SimpleDateFormat("mm:ss");
final static SimpleDateFormat df_date_time_long_for_filename = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
final static SimpleDateFormat df_date_only = new SimpleDateFormat("yyyy-MM-dd");
static long last_updated_fps = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.content.ContextCompat;
import androidx.documentfile.provider.DocumentFile;

Expand All @@ -96,6 +97,7 @@
import static com.zoffcc.applications.trifa.HelperGeneric.do_fade_anim_on_fab;
import static com.zoffcc.applications.trifa.HelperGeneric.get_g_opts;
import static com.zoffcc.applications.trifa.HelperGeneric.get_uniq_tmp_filename;
import static com.zoffcc.applications.trifa.HelperGeneric.seconds_time_format_or_empty;
import static com.zoffcc.applications.trifa.HelperGeneric.set_g_opts;
import static com.zoffcc.applications.trifa.HelperGeneric.tox_friend_send_message_wrapper;
import static com.zoffcc.applications.trifa.HelperGeneric.trim_to_utf8_length_bytes;
Expand Down Expand Up @@ -127,6 +129,7 @@
import static com.zoffcc.applications.trifa.TRIFAGlobals.FT_OUTGOING_FILESIZE_NGC_MAX_TOTAL;
import static com.zoffcc.applications.trifa.TRIFAGlobals.GLOBAL_AUDIO_BITRATE;
import static com.zoffcc.applications.trifa.TRIFAGlobals.GLOBAL_VIDEO_BITRATE;
import static com.zoffcc.applications.trifa.TRIFAGlobals.MAX_FRIEND_AUDIO_RECORDING_MSG_SECONDS;
import static com.zoffcc.applications.trifa.TRIFAGlobals.NOTIFICATION_EDIT_ACTION.NOTIFICATION_EDIT_ACTION_REMOVE;
import static com.zoffcc.applications.trifa.TRIFAGlobals.TEXT_QUOTE_STRING_1;
import static com.zoffcc.applications.trifa.TRIFAGlobals.TEXT_QUOTE_STRING_2;
Expand Down Expand Up @@ -168,6 +171,9 @@ public class MessageListActivity extends AppCompatActivity
ImageButton ml_video_icon = null;
ImageButton ml_attach_button_01 = null;
ImageButton ml_button_recaudio = null;
ImageButton audio_rec_popup_button = null;
static TextView audio_rec_popup_time = null;
static ViewGroup audio_rec_popup_container = null;
static boolean ml_is_recording = false;
static boolean ml_is_rec_ok = false;
static int global_typing = 0;
Expand Down Expand Up @@ -338,6 +344,11 @@ public void onNothingSelected(AdapterView<?> parent)
ml_attach_button_01 = (ImageButton) findViewById(R.id.ml_button_01);
ml_button_recaudio = (ImageButton) findViewById(R.id.ml_button_recaudio);
ml_button_recaudio.setBackgroundColor(Color.TRANSPARENT);
audio_rec_popup_button = findViewById(R.id.audio_rec_popup_button);
audio_rec_popup_time = findViewById(R.id.audio_rec_popup_time);
audio_rec_popup_container = findViewById(R.id.audio_rec_popup_container);

audio_rec_popup_container.setVisibility(View.GONE);

ml_is_recording = false;
ml_is_rec_ok = false;
Expand Down Expand Up @@ -635,23 +646,21 @@ public void run()
};
t.start();

ml_button_recaudio.setOnClickListener(new View.OnClickListener()
{
ml_button_recaudio.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public void onClick(final View v)
{
public boolean onLongClick(View v) {

if (ml_is_rec_ok)
{
return;
return false;
}

if (ml_is_recording)
{
ml_is_rec_ok = true;
ml_is_recording = false;
return;
return false;
}

// display_toast("LONG", false, 0);
final Thread ml_rec_audio_thread = new Thread()
{
@Override
Expand All @@ -663,6 +672,9 @@ public void run()
((ImageButton) v).setImageResource(R.drawable.baseline_stop_circle_24);
v.setBackgroundColor(Color.parseColor("#FF0000"));

set_recording_pop_text_s("0:00");
set_recording_pop_visibilty_s(true);

try
{
Log.i(TAG, "onCreate:record_audio:start");
Expand All @@ -681,6 +693,7 @@ public void run()
{
((ImageButton) v).setImageResource(R.drawable.baseline_keyboard_voice_24);
v.setBackgroundColor(Color.TRANSPARENT);
set_recording_pop_visibilty_s(false);
ml_is_recording = false;
ml_is_rec_ok = false;
return;
Expand All @@ -701,6 +714,7 @@ public void run()
{
((ImageButton) v).setImageResource(R.drawable.baseline_keyboard_voice_24);
v.setBackgroundColor(Color.TRANSPARENT);
set_recording_pop_visibilty_s(false);
ml_is_recording = false;
ml_is_rec_ok = false;
return;
Expand All @@ -720,6 +734,7 @@ public void run()
// HINT: just in case of an endless loop, we return here
((ImageButton) v).setImageResource(R.drawable.baseline_keyboard_voice_24);
v.setBackgroundColor(Color.TRANSPARENT);
set_recording_pop_visibilty_s(false);
ml_is_recording = false;
ml_is_rec_ok = false;
return;
Expand All @@ -736,6 +751,7 @@ public void run()
// HINT: some problem on starting the recording
((ImageButton) v).setImageResource(R.drawable.baseline_keyboard_voice_24);
v.setBackgroundColor(Color.TRANSPARENT);
set_recording_pop_visibilty_s(false);
ml_is_recording = false;
ml_is_rec_ok = false;
return;
Expand All @@ -745,13 +761,15 @@ public void run()
{
try
{
Thread.sleep(100);
Thread.sleep(200);
}
catch (Exception ignored)
{
}

if (mAudioRecorder.progress() > 50)
set_recording_pop_text_s(seconds_time_format_or_empty(mAudioRecorder.progress()));

if (mAudioRecorder.progress() > MAX_FRIEND_AUDIO_RECORDING_MSG_SECONDS)
{
// HINT: stop after x seconds of recording so it does not record endless
Log.i(TAG, "onCreate:record_audio:auto_stop");
Expand All @@ -761,6 +779,7 @@ public void run()
}
((ImageButton) v).setImageResource(R.drawable.baseline_pending_24);
v.setBackgroundColor(Color.TRANSPARENT);
set_recording_pop_visibilty_s(false);
int rec_result = mAudioRecorder.stopRecord();
Log.i(TAG, "onCreate:record_audio:finished:res=" + rec_result);
if (rec_result == -1)
Expand All @@ -775,6 +794,7 @@ public void run()
}
((ImageButton) v).setImageResource(R.drawable.baseline_keyboard_voice_24);
v.setBackgroundColor(Color.TRANSPARENT);
set_recording_pop_visibilty_s(false);

if (ml_is_rec_ok)
{
Expand Down Expand Up @@ -807,6 +827,86 @@ public void run()
}
};
ml_rec_audio_thread.start();

return true;
}
});

audio_rec_popup_button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
if (ml_is_rec_ok)
{
return;
}

if (ml_is_recording)
{
ml_is_rec_ok = true;
ml_is_recording = false;
return;
}
}
});

audio_rec_popup_time.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
if (ml_is_rec_ok)
{
return;
}

if (ml_is_recording)
{
ml_is_rec_ok = true;
ml_is_recording = false;
return;
}
}
});

audio_rec_popup_container.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
if (ml_is_rec_ok)
{
return;
}

if (ml_is_recording)
{
ml_is_rec_ok = true;
ml_is_recording = false;
return;
}
}
});

ml_button_recaudio.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
if (ml_is_rec_ok)
{
return;
}

if (ml_is_recording)
{
ml_is_rec_ok = true;
ml_is_recording = false;
return;
}

display_toast(v.getContext().getString(R.string.MessageListActivity_longpress_to_record_audiomsg), false, 0);
}
});

Expand All @@ -830,6 +930,7 @@ protected void onPause()

ml_button_recaudio.setImageResource(R.drawable.baseline_keyboard_voice_24);
ml_button_recaudio.setBackgroundColor(Color.TRANSPARENT);
set_recording_pop_visibilty_s(false);
ml_is_recording = false;
ml_is_rec_ok = false;

Expand Down Expand Up @@ -950,6 +1051,65 @@ protected void onResume()
wakeup_tox_thread();
}

static void set_recording_pop_text_s(final String t)
{
Runnable myRunnable = new Runnable()
{
@Override
public void run()
{
try
{
if (audio_rec_popup_time != null)
{
audio_rec_popup_time.setText(t);
}
}
catch (Exception e)
{
}
}
};

if (mla_handler_s != null)
{
mla_handler_s.post(myRunnable);
}
}

static void set_recording_pop_visibilty_s(final boolean visible)
{
Runnable myRunnable = new Runnable()
{
@Override
public void run()
{
try
{
if (audio_rec_popup_container != null)
{
if (visible)
{
audio_rec_popup_container.setVisibility(View.VISIBLE);
}
else
{
audio_rec_popup_container.setVisibility(View.GONE);
}
}
}
catch (Exception e)
{
}
}
};

if (mla_handler_s != null)
{
mla_handler_s.post(myRunnable);
}
}

static void stop_friend_typing_indicator_s()
{
Runnable myRunnable = new Runnable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public class TRIFAGlobals

static final int CONNECTION_STATUS_MANUAL_LOGOUT = 99;

static final int MAX_FRIEND_AUDIO_RECORDING_MSG_SECONDS = 10 * 60; // 10 minutes

static int VIDEO_FRAME_RATE_OUTGOING = 0;
static long last_video_frame_sent = -1;
static int count_video_frame_sent = 0;
Expand Down
Loading

0 comments on commit e6e4dbb

Please sign in to comment.