Improve chat view and download images
This commit is contained in:
parent
b5d499799a
commit
6f005e7e0d
3 changed files with 60 additions and 49 deletions
|
@ -32,10 +32,11 @@
|
|||
|
||||
<ProgressBar
|
||||
android:id="@+id/spinner"
|
||||
android:visibility="gone"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
android:layout_marginTop="20dp"
|
||||
style="@android:style/Widget.ProgressBar.Horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="5dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
|
|
|
@ -66,6 +66,7 @@ import android.text.Editable;
|
|||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -210,6 +211,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
LinphoneAddress from = cr.getPeerAddress();
|
||||
if (from.asStringUriOnly().equals(sipUri)) {
|
||||
invalidate();
|
||||
messagesList.setSelection(adapter.getCount()-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,7 +241,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
|
||||
// Force hide keyboard
|
||||
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -329,6 +330,18 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
|
||||
registerForContextMenu(v);
|
||||
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);
|
||||
|
||||
return rlayout;
|
||||
|
@ -481,7 +494,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
LinphoneManager.addListener(this);
|
||||
|
||||
final LinphoneChatMessage msg = LinphoneManager.getInstance().getMessageUploadPending();
|
||||
if(msg != null){
|
||||
if(msg != null && msg.getTo().asString().equals(sipUri)){
|
||||
uploadLayout.setVisibility(View.VISIBLE);
|
||||
textLayout.setVisibility(View.GONE);
|
||||
if(msg.getFileTransferInformation() != null){
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Map.Entry;
|
|||
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.LinphoneBuffer;
|
||||
import org.linphone.core.LinphoneChatMessage;
|
||||
import org.linphone.core.LinphoneChatMessage.State;
|
||||
import org.linphone.core.LinphoneContent;
|
||||
|
@ -59,15 +60,13 @@ import android.widget.Button;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.RelativeLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public class BubbleChat {
|
||||
public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListener {
|
||||
private static final HashMap<String, Integer> emoticons = new HashMap<String, Integer>();
|
||||
static {
|
||||
emoticons.put(":)", R.drawable.emo_im_happy);
|
||||
|
@ -99,12 +98,13 @@ public class BubbleChat {
|
|||
emoticons.put(":'(", R.drawable.emo_im_crying);
|
||||
emoticons.put("$.$", R.drawable.emo_im_money_mouth);
|
||||
}
|
||||
|
||||
private RelativeLayout view;
|
||||
|
||||
private LinearLayout view;
|
||||
private ImageView statusView;
|
||||
private LinphoneChatMessage nativeMessage;
|
||||
private Context mContext;
|
||||
private static final int SIZE_MAX = 512;
|
||||
private ProgressBar spinner;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public BubbleChat(final Context context, LinphoneChatMessage message) {
|
||||
|
@ -113,50 +113,29 @@ public class BubbleChat {
|
|||
}
|
||||
nativeMessage = message;
|
||||
mContext = context;
|
||||
|
||||
view = new RelativeLayout(context);
|
||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
if (message.isOutgoing()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (message.isOutgoing()) {
|
||||
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);
|
||||
}
|
||||
|
||||
spinner = (ProgressBar) view.findViewById(R.id.spinner);
|
||||
|
||||
String externalBodyUrl = message.getExternalBodyUrl();
|
||||
LinphoneContent fileTransferContent = message.getFileTransferInformation();
|
||||
if (externalBodyUrl != null || fileTransferContent != null) {
|
||||
Button download = (Button) layout.findViewById(R.id.download);
|
||||
ImageView imageView = (ImageView) layout.findViewById(R.id.image);
|
||||
Button download = (Button) view.findViewById(R.id.download);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.image);
|
||||
|
||||
String appData = message.getAppData();
|
||||
if (appData == null) {
|
||||
LinphoneManager.addListener(this);
|
||||
if(LinphoneManager.getInstance().isMessagePending(nativeMessage)){
|
||||
download.setEnabled(false);
|
||||
ProgressBar spinner = (ProgressBar) layout.findViewById(R.id.spinner);
|
||||
ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
|
||||
spinner.setVisibility(View.VISIBLE);
|
||||
download.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
@ -165,7 +144,6 @@ public class BubbleChat {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
v.setEnabled(false);
|
||||
ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
|
||||
spinner.setVisibility(View.VISIBLE);
|
||||
v.setVisibility(View.GONE);
|
||||
|
||||
|
@ -178,11 +156,12 @@ public class BubbleChat {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
LinphoneManager.removeListener(this);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
loadBitmap(appData, imageView);
|
||||
}
|
||||
} else {
|
||||
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
||||
TextView msgView = (TextView) view.findViewById(R.id.message);
|
||||
if (msgView != null) {
|
||||
Spanned text = null;
|
||||
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()));
|
||||
|
||||
LinphoneChatMessage.State status = message.getStatus();
|
||||
statusView = (ImageView) layout.findViewById(R.id.status);
|
||||
statusView = (ImageView) view.findViewById(R.id.status);
|
||||
if (statusView != null) {
|
||||
if (status == LinphoneChatMessage.State.Delivered) {
|
||||
statusView.setImageResource(R.drawable.chat_message_delivered);
|
||||
|
@ -214,7 +193,7 @@ public class BubbleChat {
|
|||
}
|
||||
}
|
||||
|
||||
view.addView(layout);
|
||||
//view.addView(layout);
|
||||
}
|
||||
|
||||
public void updateStatusView() {
|
||||
|
@ -443,4 +422,22 @@ public class BubbleChat {
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue