Do not erase previously downloaded file if new one has the same name + delete file when deleting message
This commit is contained in:
parent
7c9e041e14
commit
5bedf459e3
3 changed files with 35 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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())) {
|
||||
|
|
Loading…
Reference in a new issue