Improve chat view and download images

This commit is contained in:
Margaux Clerc 2015-08-11 14:28:37 +02:00
parent b5d499799a
commit 6f005e7e0d
3 changed files with 60 additions and 49 deletions

View file

@ -32,10 +32,11 @@
<ProgressBar <ProgressBar
android:id="@+id/spinner" android:id="@+id/spinner"
android:visibility="gone" android:visibility="gone"
android:indeterminate="true" android:layout_marginTop="20dp"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="5dp" />
<TextView <TextView
android:id="@+id/time" android:id="@+id/time"

View file

@ -66,6 +66,7 @@ import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -210,6 +211,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
LinphoneAddress from = cr.getPeerAddress(); LinphoneAddress from = cr.getPeerAddress();
if (from.asStringUriOnly().equals(sipUri)) { if (from.asStringUriOnly().equals(sipUri)) {
invalidate(); invalidate();
messagesList.setSelection(adapter.getCount()-1);
} }
} }
@ -239,7 +241,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
// Force hide keyboard // Force hide keyboard
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
return view; return view;
} }
@ -329,6 +330,18 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
registerForContextMenu(v); registerForContextMenu(v);
RelativeLayout rlayout = new RelativeLayout(context); RelativeLayout rlayout = new RelativeLayout(context);
if(message.isOutgoing()){
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layoutParams.setMargins(100, 10, 10, 10);
v.setLayoutParams(layoutParams);
} else {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.setMargins(10, 10, 100, 10);
v.setLayoutParams(layoutParams);
}
rlayout.addView(v); rlayout.addView(v);
return rlayout; return rlayout;
@ -481,7 +494,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
LinphoneManager.addListener(this); LinphoneManager.addListener(this);
final LinphoneChatMessage msg = LinphoneManager.getInstance().getMessageUploadPending(); final LinphoneChatMessage msg = LinphoneManager.getInstance().getMessageUploadPending();
if(msg != null){ if(msg != null && msg.getTo().asString().equals(sipUri)){
uploadLayout.setVisibility(View.VISIBLE); uploadLayout.setVisibility(View.VISIBLE);
textLayout.setVisibility(View.GONE); textLayout.setVisibility(View.GONE);
if(msg.getFileTransferInformation() != null){ if(msg.getFileTransferInformation() != null){

View file

@ -28,6 +28,7 @@ import java.util.Map.Entry;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R; import org.linphone.R;
import org.linphone.core.LinphoneBuffer;
import org.linphone.core.LinphoneChatMessage; import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneChatMessage.State; import org.linphone.core.LinphoneChatMessage.State;
import org.linphone.core.LinphoneContent; import org.linphone.core.LinphoneContent;
@ -59,15 +60,13 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
/** /**
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
public class BubbleChat { public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListener {
private static final HashMap<String, Integer> emoticons = new HashMap<String, Integer>(); private static final HashMap<String, Integer> emoticons = new HashMap<String, Integer>();
static { static {
emoticons.put(":)", R.drawable.emo_im_happy); emoticons.put(":)", R.drawable.emo_im_happy);
@ -100,11 +99,12 @@ public class BubbleChat {
emoticons.put("$.$", R.drawable.emo_im_money_mouth); emoticons.put("$.$", R.drawable.emo_im_money_mouth);
} }
private RelativeLayout view; private LinearLayout view;
private ImageView statusView; private ImageView statusView;
private LinphoneChatMessage nativeMessage; private LinphoneChatMessage nativeMessage;
private Context mContext; private Context mContext;
private static final int SIZE_MAX = 512; private static final int SIZE_MAX = 512;
private ProgressBar spinner;
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
public BubbleChat(final Context context, LinphoneChatMessage message) { public BubbleChat(final Context context, LinphoneChatMessage message) {
@ -114,49 +114,28 @@ public class BubbleChat {
nativeMessage = message; nativeMessage = message;
mContext = context; mContext = context;
view = new RelativeLayout(context); if (message.isOutgoing()) {
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); view = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_outgoing, null);
view.setBackgroundResource(R.drawable.chat_bubble_outgoing);
} else {
view = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_incoming, null);
view.setBackgroundResource(R.drawable.chat_bubble_incoming);
}
if (message.isOutgoing()) { spinner = (ProgressBar) view.findViewById(R.id.spinner);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
view.setBackgroundResource(R.drawable.chat_bubble_outgoing);
}
else {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
view.setBackgroundResource(R.drawable.chat_bubble_incoming);
}
layoutParams.setMargins(10, 0, 10, 0);
view.setId(message.getStorageId());
view.setLayoutParams(layoutParams);
LinearLayout layout;
if (context.getResources().getBoolean(R.bool.display_time_aside)) {
if (message.isOutgoing()) {
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_alt_outgoing, null);
} else {
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_alt_incoming, null);
}
} else {
if (message.isOutgoing()) {
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_outgoing, null);
} else {
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_incoming, null);
}
}
String externalBodyUrl = message.getExternalBodyUrl(); String externalBodyUrl = message.getExternalBodyUrl();
LinphoneContent fileTransferContent = message.getFileTransferInformation(); LinphoneContent fileTransferContent = message.getFileTransferInformation();
if (externalBodyUrl != null || fileTransferContent != null) { if (externalBodyUrl != null || fileTransferContent != null) {
Button download = (Button) layout.findViewById(R.id.download); Button download = (Button) view.findViewById(R.id.download);
ImageView imageView = (ImageView) layout.findViewById(R.id.image); ImageView imageView = (ImageView) view.findViewById(R.id.image);
String appData = message.getAppData(); String appData = message.getAppData();
if (appData == null) { if (appData == null) {
LinphoneManager.addListener(this);
if(LinphoneManager.getInstance().isMessagePending(nativeMessage)){ if(LinphoneManager.getInstance().isMessagePending(nativeMessage)){
download.setEnabled(false); download.setEnabled(false);
ProgressBar spinner = (ProgressBar) layout.findViewById(R.id.spinner); ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
spinner.setVisibility(View.VISIBLE); spinner.setVisibility(View.VISIBLE);
download.setVisibility(View.GONE); download.setVisibility(View.GONE);
} else { } else {
@ -165,7 +144,6 @@ public class BubbleChat {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
v.setEnabled(false); v.setEnabled(false);
ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
spinner.setVisibility(View.VISIBLE); spinner.setVisibility(View.VISIBLE);
v.setVisibility(View.GONE); v.setVisibility(View.GONE);
@ -178,11 +156,12 @@ public class BubbleChat {
}); });
} }
} else { } else {
LinphoneManager.removeListener(this);
imageView.setVisibility(View.VISIBLE); imageView.setVisibility(View.VISIBLE);
loadBitmap(appData, imageView); loadBitmap(appData, imageView);
} }
} else { } else {
TextView msgView = (TextView) layout.findViewById(R.id.message); TextView msgView = (TextView) view.findViewById(R.id.message);
if (msgView != null) { if (msgView != null) {
Spanned text = null; Spanned text = null;
String msg = message.getText(); String msg = message.getText();
@ -199,11 +178,11 @@ public class BubbleChat {
} }
} }
TextView timeView = (TextView) layout.findViewById(R.id.time); TextView timeView = (TextView) view.findViewById(R.id.time);
timeView.setText(timestampToHumanDate(context, message.getTime())); timeView.setText(timestampToHumanDate(context, message.getTime()));
LinphoneChatMessage.State status = message.getStatus(); LinphoneChatMessage.State status = message.getStatus();
statusView = (ImageView) layout.findViewById(R.id.status); statusView = (ImageView) view.findViewById(R.id.status);
if (statusView != null) { if (statusView != null) {
if (status == LinphoneChatMessage.State.Delivered) { if (status == LinphoneChatMessage.State.Delivered) {
statusView.setImageResource(R.drawable.chat_message_delivered); statusView.setImageResource(R.drawable.chat_message_delivered);
@ -214,7 +193,7 @@ public class BubbleChat {
} }
} }
view.addView(layout); //view.addView(layout);
} }
public void updateStatusView() { public void updateStatusView() {
@ -443,4 +422,22 @@ public class BubbleChat {
} }
return null; return null;
} }
@Override
public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
}
@Override
public void onLinphoneChatMessageFileTransferReceived(LinphoneChatMessage msg, LinphoneContent content, LinphoneBuffer buffer) {
}
@Override
public void onLinphoneChatMessageFileTransferSent(LinphoneChatMessage msg, LinphoneContent content, int offset, int size, LinphoneBuffer bufferToFill) {
}
@Override
public void onLinphoneChatMessageFileTransferProgressChanged(LinphoneChatMessage msg, LinphoneContent content, int offset, int total) {
if(nativeMessage.getStorageId() == msg.getStorageId())
spinner.setProgress(offset * 100 / total);
}
} }