diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/adapter')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java | 13 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java | 77 |
2 files changed, 67 insertions, 23 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java index 98250af94..1a7795a77 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java @@ -43,7 +43,7 @@ public class AccountAdapter extends ArrayAdapter<Account> { } TextView statusView = (TextView) view.findViewById(R.id.account_status); ImageView imageView = (ImageView) view.findViewById(R.id.account_image); - imageView.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48))); + imageView.setImageBitmap(activity.avatarService().get(account, activity.getPixel(56))); statusView.setText(getContext().getString(account.getStatus().getReadableId())); switch (account.getStatus()) { case ONLINE: @@ -57,17 +57,6 @@ public class AccountAdapter extends ArrayAdapter<Account> { statusView.setTextColor(activity.getWarningTextColor()); break; } - final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status); - final boolean isDisabled = (account.getStatus() == Account.State.DISABLED); - tglAccountState.setChecked(!isDisabled,false); - tglAccountState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b == isDisabled && activity instanceof ManageAccountActivity) { - ((ManageAccountActivity) activity).onClickTglAccountState(account,b); - } - } - }); return view; } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 10179d7e9..d19a5cfec 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.ui.adapter; import android.content.ActivityNotFoundException; +import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; @@ -20,6 +21,7 @@ import android.text.style.StyleSpan; import android.text.util.Linkify; import android.util.DisplayMetrics; import android.util.Patterns; +import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; @@ -28,11 +30,13 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import java.lang.ref.WeakReference; import java.net.URL; +import java.util.HashMap; import java.util.List; import java.util.concurrent.RejectedExecutionException; import java.util.regex.Matcher; @@ -50,6 +54,7 @@ import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.UIHelper; +import nl.changer.audiowife.AudioWife; public class MessageAdapter extends ArrayAdapter<Message> { @@ -78,6 +83,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } }; private boolean mIndicateReceived = false; + private HashMap<Integer, AudioWife> audioPlayer; private boolean mUseWhiteBackground = false; public MessageAdapter(ConversationActivity activity, List<Message> messages) { @@ -118,9 +124,9 @@ public class MessageAdapter extends ArrayAdapter<Message> { private int getMessageTextColor(boolean onDark, boolean primary) { if (onDark) { - return activity.getResources().getColor(primary ? R.color.white : R.color.white70); + return activity.getResources().getColor(primary ? R.color.green900 : R.color.primary); } else { - return activity.getResources().getColor(primary ? R.color.black87 : R.color.black54); + return activity.getResources().getColor(primary ? R.color.green900 : R.color.primary); } } @@ -130,6 +136,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { boolean error = false; if (viewHolder.indicatorReceived != null) { viewHolder.indicatorReceived.setVisibility(View.GONE); + viewHolder.indicatorRead.setVisibility(View.GONE); } if (viewHolder.edit_indicator != null) { @@ -177,6 +184,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { case Message.STATUS_SEND_DISPLAYED: if (mIndicateReceived) { viewHolder.indicatorReceived.setVisibility(View.VISIBLE); + viewHolder.indicatorRead.setVisibility(View.VISIBLE); } break; case Message.STATUS_SEND_FAILED: @@ -255,6 +263,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } private void displayInfoMessage(ViewHolder viewHolder, String text, boolean darkBackground) { + viewHolder.aw_player.setVisibility(View.GONE); if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } @@ -267,6 +276,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } private void displayDecryptionFailed(ViewHolder viewHolder, boolean darkBackground) { + viewHolder.aw_player.setVisibility(View.GONE); if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } @@ -280,6 +290,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } private void displayHeartMessage(final ViewHolder viewHolder, final String body) { + viewHolder.aw_player.setVisibility(View.GONE); if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } @@ -373,6 +384,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text) { + viewHolder.aw_player.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.VISIBLE); @@ -388,6 +400,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } private void displayOpenableMessage(ViewHolder viewHolder,final Message message) { + viewHolder.aw_player.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.VISIBLE); @@ -403,6 +416,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } private void displayLocationMessage(ViewHolder viewHolder, final Message message) { + viewHolder.aw_player.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.VISIBLE); @@ -419,13 +433,14 @@ public class MessageAdapter extends ArrayAdapter<Message> { private void displayImageMessage(ViewHolder viewHolder, final Message message) { + viewHolder.aw_player.setVisibility(View.GONE); if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } viewHolder.messageBody.setVisibility(View.GONE); viewHolder.image.setVisibility(View.VISIBLE); FileParams params = message.getFileParams(); - double target = metrics.density * 288; + double target = metrics.density * 200; int scalledW; int scalledH; if (params.width <= params.height) { @@ -449,6 +464,30 @@ public class MessageAdapter extends ArrayAdapter<Message> { viewHolder.image.setOnLongClickListener(openContextMenu); } + private void displayAudioMessage(ViewHolder viewHolder, final Message message, int position) { + if (audioPlayer == null) audioPlayer = new HashMap<>(); + viewHolder.image.setVisibility(View.GONE); + viewHolder.messageBody.setVisibility(View.GONE); + if (viewHolder.download_button != null) viewHolder.download_button.setVisibility(View.GONE); + viewHolder.aw_player.setVisibility(View.VISIBLE); + Uri audioFile = Uri.fromFile(activity.xmppConnectionService.getFileBackend().getFile(message)); + + AudioWife audioWife = audioPlayer.get(position); + RelativeLayout vg = new RelativeLayout(activity); + if (audioWife == null) { + audioWife = new AudioWife(); + audioWife.init(getContext(), audioFile); + audioPlayer.put(position, audioWife); + + LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + audioWife.useDefaultUi(vg, layoutInflater); + viewHolder.aw_player.addView(audioWife.getPlayerUi()); + } else { + audioWife.cleanPlayerUi(); + viewHolder.aw_player.addView(audioWife.getPlayerUi()); + } + } + private void loadMoreMessages(Conversation conversation) { conversation.setLastClearHistory(0); conversation.setHasMessagesLeftOnServer(true); @@ -480,6 +519,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { .findViewById(R.id.message_box); viewHolder.contact_picture = (ImageView) view .findViewById(R.id.message_photo); + viewHolder.aw_player = (ViewGroup) view.findViewById(R.id.aw_player); viewHolder.download_button = (Button) view .findViewById(R.id.download_button); viewHolder.indicator = (ImageView) view @@ -493,6 +533,8 @@ public class MessageAdapter extends ArrayAdapter<Message> { .findViewById(R.id.message_time); viewHolder.indicatorReceived = (ImageView) view .findViewById(R.id.indicator_received); + viewHolder.indicatorRead = (ImageView) view + .findViewById(R.id.indicator_read); break; case RECEIVED: view = activity.getLayoutInflater().inflate( @@ -501,6 +543,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { .findViewById(R.id.message_box); viewHolder.contact_picture = (ImageView) view .findViewById(R.id.message_photo); + viewHolder.aw_player = (ViewGroup) view.findViewById(R.id.aw_player); viewHolder.download_button = (Button) view .findViewById(R.id.download_button); viewHolder.indicator = (ImageView) view @@ -534,7 +577,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } } - boolean darkBackground = (type == RECEIVED && (!isInValidSession || !mUseWhiteBackground)); + boolean darkBackground = (type == SENT && (!isInValidSession || !mUseWhiteBackground)); if (type == STATUS) { if ("LOAD_MORE".equals(message.getBody())) { @@ -606,7 +649,12 @@ public class MessageAdapter extends ArrayAdapter<Message> { if (message.getFileParams().width > 0) { displayImageMessage(viewHolder,message); } else { - displayOpenableMessage(viewHolder, message); + String mimeType = message.getMimeType(); + if (mimeType != null) { + if (message.getMimeType().startsWith("audio/")) + displayAudioMessage(viewHolder, message, position); + else displayOpenableMessage(viewHolder, message); + } else displayOpenableMessage(viewHolder, message); } } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (activity.hasPgp()) { @@ -635,7 +683,8 @@ public class MessageAdapter extends ArrayAdapter<Message> { displayLocationMessage(viewHolder,message); } else if (message.bodyIsHeart()) { displayHeartMessage(viewHolder, message.getBody().trim()); - } else if (message.treatAsDownloadable() == Message.Decision.MUST) { + } else if (message.treatAsDownloadable() == Message.Decision.MUST || + message.treatAsDownloadable() == Message.Decision.SHOULD) { try { URL url = new URL(message.getBody()); displayDownloadableMessage(viewHolder, @@ -656,11 +705,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { if (type == RECEIVED) { if(isInValidSession) { - if (mUseWhiteBackground) { - viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_white); - } else { - viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received); - } + viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received); viewHolder.encryption.setVisibility(View.GONE); } else { viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning); @@ -669,6 +714,14 @@ public class MessageAdapter extends ArrayAdapter<Message> { } } + if (type == SENT) { + if (mUseWhiteBackground) { + viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_sent_white); + } else { + viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_sent); + } + } + displayStatus(viewHolder, message, type, darkBackground); return view; @@ -727,9 +780,11 @@ public class MessageAdapter extends ArrayAdapter<Message> { protected LinearLayout message_box; protected Button download_button; + protected ViewGroup aw_player; protected ImageView image; protected ImageView indicator; protected ImageView indicatorReceived; + protected ImageView indicatorRead; protected TextView time; protected TextView messageBody; protected ImageView contact_picture; |