diff --git a/src/android/org/linphone/chat/ChatEventsAdapter.java b/src/android/org/linphone/chat/ChatEventsAdapter.java index 019418f13..98e30ecf5 100644 --- a/src/android/org/linphone/chat/ChatEventsAdapter.java +++ b/src/android/org/linphone/chat/ChatEventsAdapter.java @@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. package org.linphone.chat; import android.Manifest; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -44,6 +46,7 @@ import android.view.ViewGroup; import android.webkit.MimeTypeMap; import android.widget.ImageView; import android.widget.RelativeLayout; +import android.widget.Toast; import org.linphone.LinphoneManager; import org.linphone.LinphoneUtils; @@ -72,6 +75,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static android.content.Context.CLIPBOARD_SERVICE; import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; public class ChatEventsAdapter extends ListSelectionAdapter implements ChatMessageListener { @@ -302,6 +306,12 @@ public class ChatEventsAdapter extends ListSelectionAdapter implements ChatMessa v.setEnabled(false); String filename = message.getFileTransferInformation().getName(); File file = new File(Environment.getExternalStorageDirectory(), filename); + int prefix = 1; + while (file.exists()) { + file = new File(Environment.getExternalStorageDirectory(), prefix + "_" + filename); + Log.w("File with that name already exists, renamed to " + prefix + "_" + filename); + prefix += 1; + } message.setListener(ChatEventsAdapter.this); message.setFileTransferFilepath(file.getPath()); message.downloadFile(); @@ -374,7 +384,6 @@ public class ChatEventsAdapter extends ListSelectionAdapter implements ChatMessa //TODO break; } - //holder.eventTime.setText(LinphoneUtils.timestampToHumanDate(mContext, event.getTime(), R.string.messages_date_format)); } return view; diff --git a/src/android/org/linphone/chat/ChatListFragment.java b/src/android/org/linphone/chat/ChatListFragment.java index 4c3b07035..7ee49db81 100644 --- a/src/android/org/linphone/chat/ChatListFragment.java +++ b/src/android/org/linphone/chat/ChatListFragment.java @@ -33,6 +33,7 @@ import android.widget.TextView; import org.linphone.contacts.ContactsManager; import org.linphone.core.ChatRoomListenerStub; +import org.linphone.core.EventLog; import org.linphone.ui.ListSelectionHelper; import org.linphone.contacts.ContactsUpdatedListener; import org.linphone.fragments.FragmentsAvailable; @@ -44,6 +45,8 @@ import org.linphone.core.ChatRoom; import org.linphone.core.Core; import org.linphone.core.CoreListenerStub; +import java.io.File; + import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST; public class ChatListFragment extends Fragment implements OnItemClickListener, ContactsUpdatedListener, ListSelectionHelper.DeleteListener { @@ -153,6 +156,19 @@ public class ChatListFragment extends Fragment implements OnItemClickListener, C mChatRoomDeletionPendingCount = objectsToDelete.length; for (Object obj : objectsToDelete) { ChatRoom room = (ChatRoom)obj; + + for (EventLog eventLog : room.getHistoryEvents(0)) { + if (eventLog.getType() == EventLog.Type.ConferenceChatMessage) { + ChatMessage message = eventLog.getChatMessage(); + if (message.getAppdata() != null) { + File file = new File(message.getAppdata()); + if (file.exists()) { + file.delete(); + } + } + } + } + room.setListener(new ChatRoomListenerStub() { @Override public void onStateChanged(ChatRoom room, ChatRoom.State state) { diff --git a/src/android/org/linphone/chat/GroupChatFragment.java b/src/android/org/linphone/chat/GroupChatFragment.java index 1e77cf96c..8d1134c9e 100644 --- a/src/android/org/linphone/chat/GroupChatFragment.java +++ b/src/android/org/linphone/chat/GroupChatFragment.java @@ -284,6 +284,15 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con public void onDeleteSelection(Object[] objectsToDelete) { for (Object obj : objectsToDelete) { EventLog eventLog = (EventLog)obj; + if (eventLog.getType() == EventLog.Type.ConferenceChatMessage) { + ChatMessage message = eventLog.getChatMessage(); + if (message.getAppdata() != null) { + File file = new File(message.getAppdata()); + if (file.exists()) { + file.delete(); + } + } + } eventLog.deleteFromDatabase(); } if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {