Skip to content

Commit

Permalink
incoming audio messages nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Sep 21, 2024
1 parent 87288e7 commit 9202ee1
Show file tree
Hide file tree
Showing 13 changed files with 1,164 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ public void onPause()
try
{
View child;
Log.i(TAG, "onPause:getChildCount=" + listingsView.getChildCount());
for (int i = 0; i < listingsView.getChildCount(); i++)
{
child = listingsView.getChildAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ public void onClick(View v)
// Log.i(TAG, "onClick");
}

void DetachedFromWindow(boolean release)
{
/*
ft_audio_player.onPause();
if (release)
{
ft_audio_player.onStop();
}
*/
}

@Override
public boolean onLongClick(final View v)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public void onViewDetachedFromWindow(@NonNull RecyclerView.ViewHolder holder) {
}
catch(Exception e)
{
Log.i(TAG, "onViewDetachedFromWindow:G:activity_stop()");
}
try
{
((GroupMessageListHolder_file_incoming_state_cancel) holder).DetachedFromWindow(false);
}
catch(Exception e)
{
}
super.onViewDetachedFromWindow(holder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ public void onPause()
try
{
View child;
Log.i(TAG, "onPause:getChildCount=" + listingsView.getChildCount());
for (int i = 0; i < listingsView.getChildCount(); i++)
{
child = listingsView.getChildAt(i);
Expand All @@ -468,6 +467,14 @@ public void onPause()
catch(Exception e1)
{
}
try
{
RecyclerView.ViewHolder vh = listingsView.getChildViewHolder(child);
((MessageListHolder_file_incoming_state_cancel) vh).DetachedFromWindow(true);
}
catch(Exception e1)
{
}
}
}
catch(Exception e2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class MessageListHolder_file_incoming_state_cancel extends RecyclerView.V
boolean is_selected = false;
TextView message_text_date_string;
ViewGroup message_text_date;
me.jagar.chatvoiceplayerlibrary.vVoicePlayerView ft_audio_player;

public MessageListHolder_file_incoming_state_cancel(View itemView, Context c)
{
Expand All @@ -124,6 +125,7 @@ public MessageListHolder_file_incoming_state_cancel(View itemView, Context c)
ft_export_button_container = (ViewGroup) itemView.findViewById(R.id.ft_export_button_container);
ft_export_button = (ImageButton) itemView.findViewById(R.id.ft_export_button);
ft_share_button = (ImageButton) itemView.findViewById(R.id.ft_share_button);
ft_audio_player = itemView.findViewById(R.id.ft_audio_player);
}

@SuppressLint("ClickableViewAccessibility")
Expand All @@ -140,6 +142,9 @@ public void bindMessageList(Message m)

message_ = m;

ft_audio_player.setVisibility(View.GONE);
ft_preview_image.getLayoutParams().height = (int)dp2px(150);

int drawable_id = R.drawable.rounded_orange_bg_with_border;
try
{
Expand Down Expand Up @@ -282,6 +287,7 @@ public void bindMessageList(Message m)

boolean is_image = false;
boolean is_video = false;
boolean is_audio = false;
try
{
String mimeType = URLConnection.guessContentTypeFromName(message.filename_fullpath.toLowerCase());
Expand All @@ -304,6 +310,11 @@ public void bindMessageList(Message m)
{
is_video = true;
}

if (mimeType.startsWith("audio/"))
{
is_audio = true;
}
}
catch (Exception e)
{
Expand Down Expand Up @@ -439,6 +450,33 @@ else if (is_video) // ---- a video ----
e.printStackTrace();
}
}
else if (is_audio) // ---- an audio file ----
{
if (PREF__compact_chatlist)
{
textView.setVisibility(View.GONE);
imageView.setVisibility(View.GONE);
}

ft_progressbar.setVisibility(View.GONE);
ft_buttons_container.setVisibility(View.GONE);
button_ok.setVisibility(View.GONE);
button_cancel.setVisibility(View.GONE);

ft_preview_container.setVisibility(View.VISIBLE);
ft_preview_image.setVisibility(View.GONE);

ft_audio_player.setVisibility(View.VISIBLE);

resize_viewgroup(ft_preview_container, 55);
resize_view(ft_preview_image, 1);

if (VFS_ENCRYPT)
{
ft_audio_player.refreshPlayer(message2.filename_fullpath);
ft_audio_player.refreshVisualizer();
}
}
else // ---- not an image or a video ----
{
final Drawable d3 = new IconicsDrawable(this.context).
Expand Down Expand Up @@ -676,6 +714,15 @@ public void onClick(View v)
// Log.i(TAG, "onClick");
}

void DetachedFromWindow(boolean release)
{
ft_audio_player.onPause();
if (release)
{
ft_audio_player.onStop();
}
}

@Override
public boolean onLongClick(final View v)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,20 @@ else if (my_msg.direction == 0)
@Override
public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder)
{
Log.i(TAG, "onViewDetachedFromWindow:M");
try
{
((MessageListHolder_file_outgoing_state_cancel) holder).DetachedFromWindow(false);
}
catch(Exception e)
{
Log.i(TAG, "onViewDetachedFromWindow:M:activity_stop()");
}

try
{
((MessageListHolder_file_incoming_state_cancel) holder).DetachedFromWindow(false);
}
catch(Exception e1)
{
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.zoffcc.applications.trifa;

import android.media.MediaDataSource;
import android.os.Build;

import java.io.IOException;

import androidx.annotation.RequiresApi;

@RequiresApi(api = Build.VERSION_CODES.M)
public class VFileMediaDataSource extends MediaDataSource
{
private info.guardianproject.iocipher.RandomAccessFile f;
private long streamLength = -1, lastReadEndPosition;

public VFileMediaDataSource(info.guardianproject.iocipher.RandomAccessFile f)
{
this.f = f;
try
{
this.streamLength = f.length();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
if (streamLength <= 0)
{
throw new RuntimeException();
}
}

@Override
public synchronized void close()
{
}

@Override
public synchronized int readAt(long position, byte[] buffer, int offset, int size)
{
if (position >= streamLength)
{
return -1;
}

if (position + size > streamLength)
{
size -= (position + size) - streamLength;
}

if (position < 0)
{
position = 0;
}

try
{
this.f.seek(position);
return this.f.read(buffer, offset, size);
}
catch(Exception e)
{
return -1;
}
}

@Override
public synchronized long getSize()
{
return streamLength;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ public void run()
}.execute();
}

public static void vupdateVisualizer(final Context context, final info.guardianproject.iocipher.File vfile, final PlayerVisualizerSeekbar playerVisualizerSeekbar){
new AsyncTask<Void, Void, byte[]>()
{
@Override
protected byte[] doInBackground(Void... voids) {
return vfileToBytes(vfile);
}

@Override
protected void onPostExecute(final byte[] bytes) {
super.onPostExecute(bytes);
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run()
{
playerVisualizerSeekbar.setBytes(bytes);
playerVisualizerSeekbar.invalidate();
}
});
}
}.execute();
}

public static byte[] fileToBytes(File file)
{
if (file.length() > MAX_FILE_SIZE_BYTES)
Expand All @@ -60,4 +83,27 @@ public static byte[] fileToBytes(File file)
}
return bytes;
}

public static byte[] vfileToBytes(info.guardianproject.iocipher.File vfile)
{
if (vfile.length() > MAX_FILE_SIZE_BYTES)
{
return null;
}
byte[] bytes = null;
try
{
int size = (int) vfile.length();
bytes = new byte[size];
BufferedInputStream buf = new BufferedInputStream(new info.guardianproject.iocipher.FileInputStream(vfile));
buf.read(bytes, 0, bytes.length);
buf.close();
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return bytes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public void updateVisualizer(File file) {
FileUtils.updateVisualizer(getContext(), file, this);
}

public void vupdateVisualizer(info.guardianproject.iocipher.File vfile) {

FileUtils.vupdateVisualizer(getContext(), vfile, this);
}

public void setBytes(byte[] bytes){
this.bytes = bytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.net.URLConnection;


public class VoicePlayerView extends LinearLayout {
public class VoicePlayerView extends LinearLayout {

private int playPaueseBackgroundColor, shareBackgroundColor, viewBackgroundColor,
seekBarProgressColor, seekBarThumbColor, progressTimeColor, timingBackgroundColor,
Expand Down
Loading

0 comments on commit 9202ee1

Please sign in to comment.