Added chat room creation/go to from history

This commit is contained in:
Sylvain Berfini 2017-12-01 11:39:48 +01:00
parent f14e4e6f3f
commit f5aa91f44f
2 changed files with 191 additions and 150 deletions

View file

@ -1,173 +1,184 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/colorH"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/top_bar"
android:orientation="horizontal"
android:background="@color/colorF"
android:layout_width="match_parent"
android:layout_height="60dp">
<LinearLayout
android:background="@color/colorH"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/back"
android:src="@drawable/back"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="18dp"/>
<LinearLayout
android:id="@+id/top_bar"
android:orientation="horizontal"
android:background="@color/colorF"
android:layout_width="match_parent"
android:layout_height="60dp">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"/>
<ImageView
android:id="@+id/back"
android:src="@drawable/back"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="18dp"/>
<ImageView
android:id="@+id/add_contact"
android:src="@drawable/contact_add"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_add_contact"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="15dp"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"/>
<ImageView
android:id="@+id/goto_contact"
android:visibility="gone"
android:src="@drawable/contact"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_contacts"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="15dp"/>
</LinearLayout>
<ImageView
android:id="@+id/add_contact"
android:src="@drawable/contact_add"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_add_contact"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="15dp"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/goto_contact"
android:visibility="gone"
android:src="@drawable/contact"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_contacts"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/avatar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"
android:orientation="vertical">
<ImageView
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="100dp"
android:layout_height="100dp"/>
<RelativeLayout
android:id="@+id/avatar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="100dp"
android:layout_height="100dp"/>
<ImageView
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="100dp"
android:layout_height="100dp"/>
</RelativeLayout>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="100dp"
android:layout_height="100dp"/>
<TextView
android:id="@+id/contact_name"
style="@style/font5"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<TextView
android:id="@+id/contact_address"
style="@style/font2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/contact_name"
style="@style/font5"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/contact_address"
style="@style/font2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/call"
android:src="@drawable/call_start_body_default"
android:contentDescription="@string/content_description_call"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/chat"
android:src="@drawable/chat_start_body_default"
android:contentDescription="@string/content_description_chat"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"/>
<ImageView
android:id="@+id/call"
android:src="@drawable/call_start_body_default"
android:contentDescription="@string/content_description_call"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"/>
</LinearLayout>
<ImageView
android:id="@+id/chat"
android:src="@drawable/chat_start_body_default"
android:contentDescription="@string/content_description_chat"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"/>
<LinearLayout
android:id="@+id/log_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<View
android:background="@color/colorE"
android:layout_width="wrap_content"
android:layout_height="1dp"/>
<LinearLayout
android:id="@+id/log_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="@string/call"
style="@style/font13"
android:textAllCaps="true"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<View
android:background="@color/colorE"
android:layout_width="wrap_content"
android:layout_height="1dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="10dp">
<TextView
android:text="@string/call"
style="@style/font13"
android:textAllCaps="true"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/direction"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="10dp">
<TextView
android:id="@+id/date"
style="@style/font10"
android:paddingRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/direction"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/time"
style="@style/font10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/date"
style="@style/font10"
android:paddingRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/time"
style="@style/font10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<include layout="@layout/wait_layout" android:id="@+id/waitScreen"/>
</RelativeLayout>

View file

@ -27,15 +27,21 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.linphone.LinphoneManager;
import org.linphone.contacts.ContactsManager;
import org.linphone.contacts.LinphoneContact;
import org.linphone.LinphoneUtils;
import org.linphone.R;
import org.linphone.activities.LinphoneActivity;
import org.linphone.core.Address;
import org.linphone.core.ChatRoom;
import org.linphone.core.ChatRoomListenerStub;
import org.linphone.core.Core;
import org.linphone.core.Factory;
import org.linphone.mediastream.Log;
public class HistoryDetailFragment extends Fragment implements OnClickListener {
private ImageView dialBack, chat, addToContacts, goToContact, back;
@ -43,6 +49,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
private ImageView contactPicture, callDirection;
private TextView contactName, contactAddress, time, date;
private String sipUri, displayName, pictureUri;
private RelativeLayout mWaitLayout;
private LinphoneContact contact;
@Override
@ -57,6 +64,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
view = inflater.inflate(R.layout.history_detail, container, false);
mWaitLayout = view.findViewById(R.id.waitScreen);
mWaitLayout.setVisibility(View.GONE);
dialBack = (ImageView) view.findViewById(R.id.call);
dialBack.setOnClickListener(this);
@ -159,12 +169,32 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} if (id == R.id.call) {
LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri));
} else if (id == R.id.chat) {
LinphoneActivity.instance().displayChat(sipUri, null, null);
Core lc = LinphoneManager.getLc();
Address participant = Factory.instance().createAddress(sipUri);
ChatRoom room = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
if (room != null) {
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly());
} else {
mWaitLayout.setVisibility(View.VISIBLE);
ChatRoom chatRoom = LinphoneManager.getLc().createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
chatRoom.setListener(new ChatRoomListenerStub() {
@Override
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
if (newState == ChatRoom.State.Created) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly());
} else if (newState == ChatRoom.State.CreationFailed) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().displayChatRoomError();
Log.e("Group chat room for address " + cr.getPeerAddress() + " has failed !");
}
}
});
chatRoom.addParticipant(participant);
}
} else if (id == R.id.add_contact) {
String uri = sipUri;
Address addr = null;
addr = Factory.instance().createAddress(sipUri);
uri = addr.asStringUriOnly();
Address addr = Factory.instance().createAddress(sipUri);
String uri = addr.asStringUriOnly();
if (addr != null && addr.getDisplayName() != null)
LinphoneActivity.instance().displayContactsForEdition(addr.asStringUriOnly(), addr.getDisplayName());
else