Tablet: Fix new chat conversation and display first listview element
This commit is contained in:
parent
3866fde790
commit
f68df2c584
7 changed files with 112 additions and 106 deletions
|
@ -449,23 +449,26 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
|
|
||||||
LinphoneAddress lAddress = null;
|
LinphoneAddress lAddress = null;
|
||||||
try {
|
if(sipUri == null){
|
||||||
lAddress = lc.interpretUrl(sipUri);
|
initNewChatConversation();
|
||||||
} catch (Exception e){
|
} else {
|
||||||
//TODO Error popup and quit chat
|
try {
|
||||||
}
|
lAddress = lc.interpretUrl(sipUri);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//TODO Error popup and quit chat
|
||||||
|
}
|
||||||
|
|
||||||
if (lAddress != null) {
|
if (lAddress != null) {
|
||||||
chatRoom = lc.getChatRoom(lAddress);
|
chatRoom = lc.getChatRoom(lAddress);
|
||||||
chatRoom.markAsRead();
|
chatRoom.markAsRead();
|
||||||
LinphoneActivity.instance().updateMissedChatCount();
|
LinphoneActivity.instance().updateMissedChatCount();
|
||||||
contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), lAddress);
|
contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), lAddress);
|
||||||
if(chatRoom != null) {
|
if (chatRoom != null) {
|
||||||
displayChatHeader(lAddress);
|
displayChatHeader(lAddress);
|
||||||
dispayMessageList();
|
dispayMessageList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispayMessageList() {
|
public void dispayMessageList() {
|
||||||
|
|
|
@ -185,14 +185,10 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
hideAndDisplayMessageIfNoChat();
|
hideAndDisplayMessageIfNoChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isVersionUsingNewChatStorage() {
|
public void displayFirstChat(){
|
||||||
try {
|
if(mConversations.size() > 0) {
|
||||||
Context context = LinphoneActivity.instance();
|
LinphoneActivity.instance().displayChat(mConversations.get(0));
|
||||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode >= 2200;
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -324,33 +320,6 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
LinphoneActivity.instance().displayChat(sipUri);
|
LinphoneActivity.instance().displayChat(sipUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean importAndroidStoredMessagedIntoLibLinphoneStorage() {
|
|
||||||
Log.w("Importing previous messages into new database...");
|
|
||||||
try {
|
|
||||||
ChatStorage db = LinphoneActivity.instance().getChatStorage();
|
|
||||||
List<String> conversations = db.getChatList();
|
|
||||||
for (int j = conversations.size() - 1; j >= 0; j--) {
|
|
||||||
String correspondent = conversations.get(j);
|
|
||||||
LinphoneChatRoom room = LinphoneManager.getLc().getOrCreateChatRoom(correspondent);
|
|
||||||
for (ChatMessage message : db.getMessages(correspondent)) {
|
|
||||||
LinphoneChatMessage msg = room.createLinphoneChatMessage(message.getMessage(), message.getUrl(), message.getStatus(), Long.parseLong(message.getTimestamp()), true, message.isIncoming());
|
|
||||||
if (message.getImage() != null) {
|
|
||||||
String path = saveImageAsFile(message.getId(), message.getImage());
|
|
||||||
if (path != null)
|
|
||||||
msg.setExternalBodyUrl(path);
|
|
||||||
}
|
|
||||||
msg.store();
|
|
||||||
}
|
|
||||||
db.removeDiscussion(correspondent);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String saveImageAsFile(int id, Bitmap bm) {
|
private String saveImageAsFile(int id, Bitmap bm) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -322,6 +322,12 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayFirstContact(){
|
||||||
|
if(contactsList.getAdapter().getCount() > 0){
|
||||||
|
LinphoneActivity.instance().displayContact((Contact) contactsList.getAdapter().getItem(0),false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void searchContacts() {
|
private void searchContacts() {
|
||||||
searchContacts(searchField.getText().toString());
|
searchContacts(searchField.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,17 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayFirstLog(){
|
||||||
|
if(mLogs.size() > 0){
|
||||||
|
LinphoneCallLog log = mLogs.get(0);
|
||||||
|
if (log.getDirection() == CallDirection.Incoming) {
|
||||||
|
LinphoneActivity.instance().displayHistoryDetail(mLogs.get(0).getFrom().toString(), mLogs.get(0));
|
||||||
|
} else {
|
||||||
|
LinphoneActivity.instance().displayHistoryDetail(mLogs.get(0).getTo().toString(), mLogs.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void removeCallLogs(){
|
private void removeCallLogs(){
|
||||||
int size = historyList.getAdapter().getCount();
|
int size = historyList.getAdapter().getCount();
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
private ImageView cancel;
|
private ImageView cancel;
|
||||||
private FragmentsAvailable currentFragment, nextFragment;
|
private FragmentsAvailable currentFragment, nextFragment;
|
||||||
private List<FragmentsAvailable> fragmentsHistory;
|
private List<FragmentsAvailable> fragmentsHistory;
|
||||||
private Fragment dialerFragment, messageListFragment;
|
private Fragment dialerFragment, chatListFragment, historyListFragment, contactListFragment;
|
||||||
private ChatFragment chatFragment;
|
private ChatFragment chatFragment;
|
||||||
private Fragment.SavedState dialerSavedState;
|
private Fragment.SavedState dialerSavedState;
|
||||||
private boolean newProxyConfig;
|
private boolean newProxyConfig;
|
||||||
|
@ -191,8 +191,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
cr.markAsRead();
|
cr.markAsRead();
|
||||||
}
|
}
|
||||||
displayMissedChats(getUnreadMessageCount());
|
displayMissedChats(getUnreadMessageCount());
|
||||||
if (messageListFragment != null && messageListFragment.isVisible()) {
|
if (chatListFragment != null && chatListFragment.isVisible()) {
|
||||||
((ChatListFragment) messageListFragment).refresh();
|
((ChatListFragment) chatListFragment).refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,12 +351,14 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
switch (newFragmentType) {
|
switch (newFragmentType) {
|
||||||
case HISTORY_LIST:
|
case HISTORY_LIST:
|
||||||
newFragment = new HistoryListFragment();
|
newFragment = new HistoryListFragment();
|
||||||
|
historyListFragment = newFragment;
|
||||||
break;
|
break;
|
||||||
case HISTORY_DETAIL:
|
case HISTORY_DETAIL:
|
||||||
newFragment = new HistoryDetailFragment();
|
newFragment = new HistoryDetailFragment();
|
||||||
break;
|
break;
|
||||||
case CONTACTS_LIST:
|
case CONTACTS_LIST:
|
||||||
newFragment = new ContactsListFragment();
|
newFragment = new ContactsListFragment();
|
||||||
|
contactListFragment = newFragment;
|
||||||
break;
|
break;
|
||||||
case CONTACT_DETAIL:
|
case CONTACT_DETAIL:
|
||||||
newFragment = new ContactDetailsFragment();
|
newFragment = new ContactDetailsFragment();
|
||||||
|
@ -382,7 +384,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
break;
|
break;
|
||||||
case CHAT_LIST:
|
case CHAT_LIST:
|
||||||
newFragment = new ChatListFragment();
|
newFragment = new ChatListFragment();
|
||||||
messageListFragment = newFragment;
|
chatListFragment = newFragment;
|
||||||
break;
|
break;
|
||||||
case CHAT:
|
case CHAT:
|
||||||
newFragment = new ChatFragment();
|
newFragment = new ChatFragment();
|
||||||
|
@ -617,67 +619,66 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sipUri == null) {
|
String pictureUri = null;
|
||||||
Bundle extras = new Bundle();
|
String thumbnailUri = null;
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
String displayName = null;
|
||||||
} else {
|
|
||||||
LinphoneAddress lAddress;
|
LinphoneAddress lAddress = null;
|
||||||
|
if(sipUri != null) {
|
||||||
try {
|
try {
|
||||||
lAddress = LinphoneManager.getLc().interpretUrl(sipUri);
|
lAddress = LinphoneManager.getLc().interpretUrl(sipUri);
|
||||||
} catch (LinphoneCoreException e) {
|
} catch (LinphoneCoreException e) {
|
||||||
//TODO display error message
|
//TODO display error message
|
||||||
Log.e("Cannot display chat",e);
|
Log.e("Cannot display chat", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
|
||||||
String displayName = contact != null ? contact.getName() : null;
|
displayName = contact != null ? contact.getName() : null;
|
||||||
|
|
||||||
String pictureUri = null;
|
if (contact != null && contact.getPhotoUri() != null) {
|
||||||
String thumbnailUri = null;
|
|
||||||
if(contact != null && contact.getPhotoUri() != null){
|
|
||||||
pictureUri = contact.getPhotoUri().toString();
|
pictureUri = contact.getPhotoUri().toString();
|
||||||
thumbnailUri = contact.getThumbnailUri().toString();
|
thumbnailUri = contact.getThumbnailUri().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentFragment == FragmentsAvailable.CHAT_LIST || currentFragment == FragmentsAvailable.CHAT) {
|
|
||||||
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
|
|
||||||
if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CHAT) {
|
|
||||||
ChatFragment chatFragment = (ChatFragment) fragment2;
|
|
||||||
chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri);
|
|
||||||
} else {
|
|
||||||
Bundle extras = new Bundle();
|
|
||||||
extras.putString("SipUri", sipUri);
|
|
||||||
if (lAddress.getDisplayName() != null) {
|
|
||||||
extras.putString("DisplayName", displayName);
|
|
||||||
extras.putString("PictureUri", pictureUri);
|
|
||||||
extras.putString("ThumbnailUri", thumbnailUri);
|
|
||||||
}
|
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(isTablet()){
|
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
|
|
||||||
displayChat(sipUri);
|
|
||||||
} else {
|
|
||||||
Bundle extras = new Bundle();
|
|
||||||
extras.putString("SipUri", sipUri);
|
|
||||||
if (lAddress.getDisplayName() != null) {
|
|
||||||
extras.putString("DisplayName", displayName);
|
|
||||||
extras.putString("PictureUri", pictureUri);
|
|
||||||
extras.putString("ThumbnailUri", thumbnailUri);
|
|
||||||
}
|
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (messageListFragment != null && messageListFragment.isVisible()) {
|
|
||||||
((ChatListFragment) messageListFragment).refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
LinphoneService.instance().resetMessageNotifCount();
|
|
||||||
LinphoneService.instance().removeMessageNotification();
|
|
||||||
displayMissedChats(getUnreadMessageCount());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentFragment == FragmentsAvailable.CHAT_LIST || currentFragment == FragmentsAvailable.CHAT) {
|
||||||
|
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
|
||||||
|
if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CHAT) {
|
||||||
|
ChatFragment chatFragment = (ChatFragment) fragment2;
|
||||||
|
chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri);
|
||||||
|
} else {
|
||||||
|
Bundle extras = new Bundle();
|
||||||
|
extras.putString("SipUri", sipUri);
|
||||||
|
if (sipUri != null && lAddress.getDisplayName() != null) {
|
||||||
|
extras.putString("DisplayName", displayName);
|
||||||
|
extras.putString("PictureUri", pictureUri);
|
||||||
|
extras.putString("ThumbnailUri", thumbnailUri);
|
||||||
|
}
|
||||||
|
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(isTablet()){
|
||||||
|
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
|
||||||
|
displayChat(sipUri);
|
||||||
|
} else {
|
||||||
|
Bundle extras = new Bundle();
|
||||||
|
extras.putString("SipUri", sipUri);
|
||||||
|
if (sipUri != null && lAddress.getDisplayName() != null) {
|
||||||
|
extras.putString("DisplayName", displayName);
|
||||||
|
extras.putString("PictureUri", pictureUri);
|
||||||
|
extras.putString("ThumbnailUri", thumbnailUri);
|
||||||
|
}
|
||||||
|
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chatListFragment != null && chatListFragment.isVisible()) {
|
||||||
|
((ChatListFragment) chatListFragment).refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
LinphoneService.instance().resetMessageNotifCount();
|
||||||
|
LinphoneService.instance().removeMessageNotification();
|
||||||
|
displayMissedChats(getUnreadMessageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -690,15 +691,30 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
history_selected.setVisibility(View.VISIBLE);
|
history_selected.setVisibility(View.VISIBLE);
|
||||||
LinphoneManager.getLc().resetMissedCallsCount();
|
LinphoneManager.getLc().resetMissedCallsCount();
|
||||||
displayMissedCalls(0);
|
displayMissedCalls(0);
|
||||||
|
if(isTablet()) {
|
||||||
|
if (historyListFragment != null && historyListFragment.isVisible()) {
|
||||||
|
((HistoryListFragment) historyListFragment).displayFirstLog();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (id == R.id.contacts) {
|
} else if (id == R.id.contacts) {
|
||||||
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, null);
|
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, null);
|
||||||
contacts_selected.setVisibility(View.VISIBLE);
|
contacts_selected.setVisibility(View.VISIBLE);
|
||||||
|
if(isTablet()) {
|
||||||
|
if (contactListFragment != null && contactListFragment.isVisible()) {
|
||||||
|
((ContactsListFragment) contactListFragment).displayFirstContact();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (id == R.id.dialer) {
|
} else if (id == R.id.dialer) {
|
||||||
changeCurrentFragment(FragmentsAvailable.DIALER, null);
|
changeCurrentFragment(FragmentsAvailable.DIALER, null);
|
||||||
dialer_selected.setVisibility(View.VISIBLE);
|
dialer_selected.setVisibility(View.VISIBLE);
|
||||||
} else if (id == R.id.chat) {
|
} else if (id == R.id.chat) {
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
|
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
|
||||||
chat_selected.setVisibility(View.VISIBLE);
|
chat_selected.setVisibility(View.VISIBLE);
|
||||||
|
if(isTablet()) {
|
||||||
|
if (chatListFragment != null && chatListFragment.isVisible()) {
|
||||||
|
((ChatListFragment) chatListFragment).displayFirstChat();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (id == R.id.cancel){
|
} else if (id == R.id.cancel){
|
||||||
hideTopBar();
|
hideTopBar();
|
||||||
displayDialer();
|
displayDialer();
|
||||||
|
@ -765,7 +781,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateChatListFragment(ChatListFragment fragment) {
|
public void updateChatListFragment(ChatListFragment fragment) {
|
||||||
messageListFragment = fragment;
|
chatListFragment = fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStatusFragment(StatusFragment fragment) {
|
public void updateStatusFragment(StatusFragment fragment) {
|
||||||
|
@ -826,8 +842,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
|
|
||||||
public int onMessageSent(String to, String message) {
|
public int onMessageSent(String to, String message) {
|
||||||
getChatStorage().deleteDraft(to);
|
getChatStorage().deleteDraft(to);
|
||||||
if (messageListFragment != null && messageListFragment.isVisible()) {
|
if (chatListFragment != null && chatListFragment.isVisible()) {
|
||||||
((ChatListFragment) messageListFragment).refresh();
|
((ChatListFragment) chatListFragment).refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getChatStorage().saveTextMessage("", to, message, System.currentTimeMillis());
|
return getChatStorage().saveTextMessage("", to, message, System.currentTimeMillis());
|
||||||
|
|
|
@ -267,7 +267,8 @@ public class ConferenceAndMultiCall extends SampleTest {
|
||||||
|
|
||||||
private void startConference() {
|
private void startConference() {
|
||||||
startTwoCalls();
|
startTwoCalls();
|
||||||
|
|
||||||
|
solo.clickOnView(solo.getView(org.linphone.R.id.options));
|
||||||
solo.clickOnView(solo.getView(org.linphone.R.id.conference));
|
solo.clickOnView(solo.getView(org.linphone.R.id.conference));
|
||||||
solo.sleep(1000);
|
solo.sleep(1000);
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class Contacts extends SampleTest {
|
||||||
Assert.assertTrue(solo.searchText(iContext.getString(org.linphone.test.R.string.contact_name)));
|
Assert.assertTrue(solo.searchText(iContext.getString(org.linphone.test.R.string.contact_name)));
|
||||||
|
|
||||||
solo.clickOnText(iContext.getString(org.linphone.test.R.string.contact_name));
|
solo.clickOnText(iContext.getString(org.linphone.test.R.string.contact_name));
|
||||||
solo.clickOnView(solo.getView(org.linphone.R.id.delete_contact));
|
solo.clickOnView(solo.getView(org.linphone.R.id.deleteContact));
|
||||||
solo.sleep(1000);
|
solo.sleep(1000);
|
||||||
solo.clickOnView(solo.getView(org.linphone.R.id.delete_button));
|
solo.clickOnView(solo.getView(org.linphone.R.id.delete_button));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue