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"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/colorH"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical" >
<LinearLayout <LinearLayout
android:id="@+id/top_bar" android:background="@color/colorH"
android:orientation="horizontal" android:layout_width="match_parent"
android:background="@color/colorF" android:layout_height="match_parent"
android:layout_width="match_parent" android:orientation="vertical" >
android:layout_height="60dp">
<ImageView <LinearLayout
android:id="@+id/back" android:id="@+id/top_bar"
android:src="@drawable/back" android:orientation="horizontal"
android:background="@drawable/toolbar_button" android:background="@color/colorF"
android:contentDescription="@string/content_description_back" android:layout_width="match_parent"
android:layout_width="0dp" android:layout_height="60dp">
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="18dp"/>
<View <ImageView
android:layout_width="0dp" android:id="@+id/back"
android:layout_height="match_parent" android:src="@drawable/back"
android:layout_weight="0.6"/> 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 <View
android:id="@+id/add_contact" android:layout_width="0dp"
android:src="@drawable/contact_add" android:layout_height="match_parent"
android:background="@drawable/toolbar_button" android:layout_weight="0.6"/>
android:contentDescription="@string/content_description_add_contact"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="15dp"/>
<ImageView <ImageView
android:id="@+id/goto_contact" android:id="@+id/add_contact"
android:visibility="gone" android:src="@drawable/contact_add"
android:src="@drawable/contact" android:background="@drawable/toolbar_button"
android:background="@drawable/toolbar_button" android:contentDescription="@string/content_description_add_contact"
android:contentDescription="@string/content_description_contacts" android:layout_width="0dp"
android:layout_width="0dp" android:layout_height="match_parent"
android:layout_height="match_parent" android:layout_weight="0.2"
android:layout_weight="0.2" android:padding="15dp"/>
android:padding="15dp"/>
</LinearLayout>
<ScrollView <ImageView
android:layout_width="match_parent" android:id="@+id/goto_contact"
android:layout_height="match_parent"> 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 <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:gravity="center"
android:padding="20dp"
android:orientation="vertical">
<RelativeLayout <LinearLayout
android:id="@+id/avatar_layout" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:gravity="center"> android:padding="20dp"
android:orientation="vertical">
<ImageView <RelativeLayout
android:id="@+id/contact_picture" android:id="@+id/avatar_layout"
android:src="@drawable/avatar" android:layout_width="match_parent"
android:contentDescription="@string/content_description_contact_picture" android:layout_height="wrap_content"
android:layout_width="100dp" android:gravity="center">
android:layout_height="100dp"/>
<ImageView <ImageView
android:id="@+id/mask" android:id="@+id/contact_picture"
android:src="@drawable/avatar_mask" android:src="@drawable/avatar"
android:layout_width="100dp" android:contentDescription="@string/content_description_contact_picture"
android:layout_height="100dp"/> 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 </RelativeLayout>
android:id="@+id/contact_name"
style="@style/font5"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/contact_address" android:id="@+id/contact_name"
style="@style/font2" style="@style/font5"
android:layout_width="wrap_content" android:gravity="center_horizontal"
android:layout_height="wrap_content"/> android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout <TextView
android:layout_width="match_parent" android:id="@+id/contact_address"
android:layout_height="wrap_content" style="@style/font2"
android:gravity="center" android:layout_width="wrap_content"
android:orientation="horizontal"> android:layout_height="wrap_content"/>
<ImageView <LinearLayout
android:id="@+id/call" android:layout_width="match_parent"
android:src="@drawable/call_start_body_default" android:layout_height="wrap_content"
android:contentDescription="@string/content_description_call" android:gravity="center"
android:layout_width="60dp" android:orientation="horizontal">
android:layout_height="60dp"
android:layout_margin="10dp"/>
<ImageView <ImageView
android:id="@+id/chat" android:id="@+id/call"
android:src="@drawable/chat_start_body_default" android:src="@drawable/call_start_body_default"
android:contentDescription="@string/content_description_chat" android:contentDescription="@string/content_description_call"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:layout_margin="10dp"/> 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 </LinearLayout>
android:id="@+id/log_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View <LinearLayout
android:background="@color/colorE" android:id="@+id/log_row"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="1dp"/> android:layout_height="wrap_content"
android:orientation="vertical">
<TextView <View
android:text="@string/call" android:background="@color/colorE"
style="@style/font13" android:layout_width="wrap_content"
android:textAllCaps="true" android:layout_height="1dp"/>
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout <TextView
android:layout_width="match_parent" android:text="@string/call"
android:layout_height="wrap_content" style="@style/font13"
android:orientation="horizontal" android:textAllCaps="true"
android:gravity="center" android:layout_marginTop="2dp"
android:padding="10dp"> android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView <LinearLayout
android:id="@+id/direction" android:layout_width="match_parent"
android:paddingLeft="10dp" android:layout_height="wrap_content"
android:paddingRight="10dp" android:orientation="horizontal"
android:layout_width="wrap_content" android:gravity="center"
android:layout_height="wrap_content"/> android:padding="10dp">
<TextView <ImageView
android:id="@+id/date" android:id="@+id/direction"
style="@style/font10" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/time" android:id="@+id/date"
style="@style/font10" style="@style/font10"
android:layout_width="wrap_content" android:paddingRight="10dp"
android:layout_height="wrap_content"/> android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout> <TextView
</LinearLayout> android:id="@+id/time"
</LinearLayout> 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.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import org.linphone.LinphoneManager;
import org.linphone.contacts.ContactsManager; import org.linphone.contacts.ContactsManager;
import org.linphone.contacts.LinphoneContact; import org.linphone.contacts.LinphoneContact;
import org.linphone.LinphoneUtils; import org.linphone.LinphoneUtils;
import org.linphone.R; import org.linphone.R;
import org.linphone.activities.LinphoneActivity; import org.linphone.activities.LinphoneActivity;
import org.linphone.core.Address; 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.core.Factory;
import org.linphone.mediastream.Log;
public class HistoryDetailFragment extends Fragment implements OnClickListener { public class HistoryDetailFragment extends Fragment implements OnClickListener {
private ImageView dialBack, chat, addToContacts, goToContact, back; private ImageView dialBack, chat, addToContacts, goToContact, back;
@ -43,6 +49,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
private ImageView contactPicture, callDirection; private ImageView contactPicture, callDirection;
private TextView contactName, contactAddress, time, date; private TextView contactName, contactAddress, time, date;
private String sipUri, displayName, pictureUri; private String sipUri, displayName, pictureUri;
private RelativeLayout mWaitLayout;
private LinphoneContact contact; private LinphoneContact contact;
@Override @Override
@ -57,6 +64,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
view = inflater.inflate(R.layout.history_detail, container, false); 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 = (ImageView) view.findViewById(R.id.call);
dialBack.setOnClickListener(this); dialBack.setOnClickListener(this);
@ -159,12 +169,32 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} if (id == R.id.call) { } if (id == R.id.call) {
LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri)); LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri));
} else if (id == R.id.chat) { } 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) { } else if (id == R.id.add_contact) {
String uri = sipUri; Address addr = Factory.instance().createAddress(sipUri);
Address addr = null; String uri = addr.asStringUriOnly();
addr = Factory.instance().createAddress(sipUri);
uri = addr.asStringUriOnly();
if (addr != null && addr.getDisplayName() != null) if (addr != null && addr.getDisplayName() != null)
LinphoneActivity.instance().displayContactsForEdition(addr.asStringUriOnly(), addr.getDisplayName()); LinphoneActivity.instance().displayContactsForEdition(addr.asStringUriOnly(), addr.getDisplayName());
else else