Replaced previous group chat creation view by InfoGroupChatFragment

This commit is contained in:
Sylvain Berfini 2017-10-23 15:13:35 +02:00
parent f223246f9c
commit f1c17e1a93
7 changed files with 278 additions and 77 deletions

View file

@ -84,6 +84,7 @@
android:text="@string/chat_room_participants" /> android:text="@string/chat_room_participants" />
<ImageView <ImageView
android:id="@+id/addParticipants"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
@ -99,13 +100,12 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:divider="@color/colorE" android:divider="@color/colorE"
android:dividerHeight="1dp" android:dividerHeight="1dp">
android:fastScrollAlwaysVisible="true"
android:fastScrollEnabled="true">
</ListView> </ListView>
<LinearLayout <LinearLayout
android:id="@+id/leaveGroupLayout"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"

View file

@ -40,9 +40,9 @@
</RelativeLayout> </RelativeLayout>
<CheckBox <ImageView
android:id="@+id/delete" android:id="@+id/delete"
android:button="@drawable/chat_group_delete" android:src="@drawable/chat_group_delete"
android:contentDescription="@string/content_description_delete" android:contentDescription="@string/content_description_delete"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View file

@ -78,7 +78,7 @@ import org.linphone.fragments.EmptyFragment;
import org.linphone.fragments.FragmentsAvailable; import org.linphone.fragments.FragmentsAvailable;
import org.linphone.fragments.HistoryDetailFragment; import org.linphone.fragments.HistoryDetailFragment;
import org.linphone.fragments.HistoryListFragment; import org.linphone.fragments.HistoryListFragment;
import org.linphone.chat.InfoGroupChatFragment; import org.linphone.chat.GroupInfoFragment;
import org.linphone.contacts.LinphoneContact; import org.linphone.contacts.LinphoneContact;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.LinphoneManager.AddressType; import org.linphone.LinphoneManager.AddressType;
@ -434,7 +434,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
fragment = new ChatCreationFragment(); fragment = new ChatCreationFragment();
break; break;
case INFO_GROUP_CHAT: case INFO_GROUP_CHAT:
fragment = new InfoGroupChatFragment(); fragment = new GroupInfoFragment();
break; break;
case GROUP_CHAT: case GROUP_CHAT:
fragment = new GroupChatFragment(); fragment = new GroupChatFragment();
@ -709,13 +709,20 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
extras.putString("PictureUri", pictureUri); extras.putString("PictureUri", pictureUri);
extras.putString("ThumbnailUri", thumbnailUri); extras.putString("ThumbnailUri", thumbnailUri);
} }
if(sipUri == null && message == null && fileUri == null) { if (sipUri == null && message == null && fileUri == null) {
changeCurrentFragment(FragmentsAvailable.CREATE_CHAT, extras); changeCurrentFragment(FragmentsAvailable.CREATE_CHAT, extras);
} else { } else {
changeCurrentFragment(FragmentsAvailable.GROUP_CHAT, extras); changeCurrentFragment(FragmentsAvailable.GROUP_CHAT, extras);
} }
} }
public void displayChatGroupInfos(ArrayList<ContactAddress> contacts, boolean isAlreadyCreatedGroup) {
Bundle extras = new Bundle();
extras.putBoolean("isAlreadyCreatedGroup", isAlreadyCreatedGroup);
extras.putSerializable("ContactAddress", contacts);
changeCurrentFragment(FragmentsAvailable.INFO_GROUP_CHAT, extras);
}
public void displayChat(String sipUri, String message, String fileUri) { public void displayChat(String sipUri, String message, String fileUri) {
if (getResources().getBoolean(R.bool.disable_chat)) { if (getResources().getBoolean(R.bool.disable_chat)) {
return; return;

View file

@ -52,7 +52,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
private ListView contactsList; private ListView contactsList;
private LinearLayout contactsSelectedLayout; private LinearLayout contactsSelectedLayout;
private HorizontalScrollView contactsSelectLayout; private HorizontalScrollView contactsSelectLayout;
private List<ContactAddress> contactsSelected; private ArrayList<ContactAddress> contactsSelected;
private ImageView allContacts, linphoneContacts; private ImageView allContacts, linphoneContacts;
private boolean onlyDisplayLinphoneContacts; private boolean onlyDisplayLinphoneContacts;
private View allContactsSelected, linphoneContactsSelected; private View allContactsSelected, linphoneContactsSelected;
@ -62,12 +62,9 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
private ProgressBar contactsFetchInProgress; private ProgressBar contactsFetchInProgress;
private SearchContactsListAdapter searchAdapter; private SearchContactsListAdapter searchAdapter;
private ImageView back, next, confirm; private ImageView back, next, confirm;
private boolean displayChatGroupCreation;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
displayChatGroupCreation = false;
mInflater = inflater; mInflater = inflater;
View view = inflater.inflate(R.layout.chat_create, container, false); View view = inflater.inflate(R.layout.chat_create, container, false);
contactsSelected = new ArrayList<>(); contactsSelected = new ArrayList<>();
@ -170,23 +167,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
return view; return view;
} }
private void displayChatGroupCreation() {
displayChatGroupCreation = true;
confirm.setVisibility(View.VISIBLE);
confirm.setEnabled(subjectField.getText().length() > 0);
next.setVisibility(View.GONE);
subjectLayout.setVisibility(View.VISIBLE);
contactsList.setVisibility(View.GONE);
searchLayout.setVisibility(View.GONE);
allContacts.setVisibility(View.INVISIBLE);
linphoneContacts.setVisibility(View.INVISIBLE);
allContactsSelected.setVisibility(View.INVISIBLE);
linphoneContactsSelected.setVisibility(View.INVISIBLE);
}
private void displayChatCreation() { private void displayChatCreation() {
displayChatGroupCreation = false;
next.setVisibility(View.VISIBLE); next.setVisibility(View.VISIBLE);
next.setEnabled(contactsSelected.size() > 0); next.setEnabled(contactsSelected.size() > 0);
confirm.setVisibility(View.GONE); confirm.setVisibility(View.GONE);
@ -298,20 +279,13 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
allContactsSelected.setVisibility(View.INVISIBLE); allContactsSelected.setVisibility(View.INVISIBLE);
updateList(); updateList();
} else if (id == R.id.back) { } else if (id == R.id.back) {
if (displayChatGroupCreation) { getFragmentManager().popBackStackImmediate();
displayChatCreation();
} else {
getFragmentManager().popBackStackImmediate();
}
} else if (id == R.id.next) { } else if (id == R.id.next) {
if (contactsSelected.size() == 1) { if (contactsSelected.size() == 1) {
LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", ""); LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", "");
} else { } else {
displayChatGroupCreation(); LinphoneActivity.instance().displayChatGroupInfos(contactsSelected, false);
} }
} else if (id == R.id.confirm) {
//TODO get chatRoom URI
//LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", "");
} else if (id == R.id.clearSearchField) { } else if (id == R.id.clearSearchField) {
searchField.setText(""); searchField.setText("");
searchAdapter.searchContacts("", contactsList); searchAdapter.searchContacts("", contactsList);

View file

@ -0,0 +1,126 @@
/*
GroupChatFragment.java
Copyright (C) 2017 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.chat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.linphone.LinphoneUtils;
import org.linphone.R;
import org.linphone.activities.LinphoneActivity;
import org.linphone.contacts.ContactAddress;
import org.linphone.contacts.LinphoneContact;
import java.util.ArrayList;
import java.util.List;
public class GroupInfoAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<ContactAddress> mItems;
private View.OnClickListener mDeleteListener;
public GroupInfoAdapter(LayoutInflater inflater, List<ContactAddress> items) {
mInflater = inflater;
mItems = items;
}
@Override
public int getCount() {
return mItems.size();
}
@Override
public Object getItem(int i) {
return mItems.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = mInflater.inflate(R.layout.chat_infos_cell, null);
}
final ContactAddress ca = (ContactAddress)getItem(i);
LinphoneContact c = ca.getContact();
TextView name = view.findViewById(R.id.name);
ImageView avatar = view.findViewById(R.id.contact_picture);
ImageView delete = view.findViewById(R.id.delete);
final LinearLayout isAdmin = view.findViewById(R.id.isAdminLayout);
final LinearLayout isNotAdmin = view.findViewById(R.id.isNotAdminLayout);
name.setText(c.getFullName());
if (c.hasPhoto()) {
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), avatar, c.getThumbnailUri());
}
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mDeleteListener != null) {
mDeleteListener.onClick(view);
}
}
});
delete.setTag(ca);
isAdmin.setVisibility(ca.isAdmin() ? View.VISIBLE : View.GONE);
isNotAdmin.setVisibility(ca.isAdmin() ? View.GONE : View.VISIBLE);
isAdmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isNotAdmin.setVisibility(View.VISIBLE);
isAdmin.setVisibility(View.GONE);
ca.setAdmin(false);
}
});
isNotAdmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isNotAdmin.setVisibility(View.GONE);
isAdmin.setVisibility(View.VISIBLE);
ca.setAdmin(true);
}
});
return view;
}
public void setOnDeleteClickListener(View.OnClickListener onClickListener) {
mDeleteListener = onClickListener;
}
public void updateDataSet(ArrayList<ContactAddress> mParticipants) {
mItems = mParticipants;
notifyDataSetChanged();
}
}

View file

@ -0,0 +1,134 @@
/*
InfoGroupChatFragment.java
Copyright (C) 2017 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.chat;
import android.app.Fragment;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import org.linphone.R;
import org.linphone.contacts.ContactAddress;
import java.util.ArrayList;
public class GroupInfoFragment extends Fragment {
private ImageView mBackButton, mConfirmButton, mAddParticipantsButton;
private EditText mSubjectField;
private LayoutInflater mInflater;
private ListView mParticipantsList;
private LinearLayout mLeaveGroupButton;
private GroupInfoAdapter mAdapter;
private boolean mIsAlreadyCreatedGroup;
private ArrayList<ContactAddress> mParticipants;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mInflater = inflater;
View view = inflater.inflate(R.layout.chat_infos, container, false);
if (getArguments() == null || getArguments().isEmpty()) {
return null;
}
mParticipants = (ArrayList<ContactAddress>) getArguments().getSerializable("ContactAddress");
mIsAlreadyCreatedGroup = getArguments().getBoolean("isAlreadyCreatedGroup");
mParticipantsList = view.findViewById(R.id.chat_room_participants);
mAdapter = new GroupInfoAdapter(mInflater, mParticipants);
mAdapter.setOnDeleteClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ContactAddress ca = (ContactAddress) view.getTag();
mParticipants.remove(ca);
mAdapter.updateDataSet(mParticipants);
mParticipantsList.setAdapter(mAdapter);
mConfirmButton.setEnabled(mSubjectField.getText().length() > 0 && mParticipants.size() > 1);
}
});
mParticipantsList.setAdapter(mAdapter);
mSubjectField = view.findViewById(R.id.subjectField);
mSubjectField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
mConfirmButton.setEnabled(mSubjectField.getText().length() > 0 && mParticipants.size() > 1);
}
});
mBackButton = view.findViewById(R.id.back);
mBackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getFragmentManager().popBackStackImmediate();
}
});
mConfirmButton = view.findViewById(R.id.confirm);
mConfirmButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//TODO
}
});
mConfirmButton.setEnabled(mSubjectField.getText().length() > 0 && mParticipants.size() > 1);
mLeaveGroupButton = view.findViewById(R.id.leaveGroupLayout);
mLeaveGroupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//TODO
}
});
mLeaveGroupButton.setVisibility(mIsAlreadyCreatedGroup ? View.VISIBLE : View.GONE);
mAddParticipantsButton = view.findViewById(R.id.addParticipants);
mAddParticipantsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mIsAlreadyCreatedGroup) {
//TODO
} else {
getFragmentManager().popBackStackImmediate();
}
}
});
//TODO handle contacts removal
return view;
}
}

View file

@ -1,40 +0,0 @@
/*
InfoGroupChatFragment.java
Copyright (C) 2017 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.chat;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.linphone.R;
public class InfoGroupChatFragment extends Fragment {
private LayoutInflater mInflater;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mInflater = inflater;
View view = inflater.inflate(R.layout.chat_infos, container, false);
return view;
}
}