Store files in private app folder, delete files when message is deleted
This commit is contained in:
parent
431881cf50
commit
c9390f87fe
6 changed files with 69 additions and 46 deletions
|
@ -35,6 +35,7 @@ import org.linphone.core.Address;
|
||||||
import org.linphone.core.ChatMessage;
|
import org.linphone.core.ChatMessage;
|
||||||
import org.linphone.core.ChatMessageListenerStub;
|
import org.linphone.core.ChatMessageListenerStub;
|
||||||
import org.linphone.core.EventLog;
|
import org.linphone.core.EventLog;
|
||||||
|
import org.linphone.core.tools.Log;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
import org.linphone.utils.LinphoneUtils;
|
||||||
import org.linphone.utils.SelectableAdapter;
|
import org.linphone.utils.SelectableAdapter;
|
||||||
import org.linphone.utils.SelectableHelper;
|
import org.linphone.utils.SelectableHelper;
|
||||||
|
@ -91,6 +92,9 @@ public class ChatMessagesAdapter extends SelectableAdapter<ChatMessageViewHolder
|
||||||
}
|
}
|
||||||
if (state == ChatMessage.State.Displayed) {
|
if (state == ChatMessage.State.Displayed) {
|
||||||
mTransientMessages.remove(message);
|
mTransientMessages.remove(message);
|
||||||
|
} else if (state == ChatMessage.State.FileTransferDone) {
|
||||||
|
Log.i("[Chat Message] File transfer done");
|
||||||
|
// TODO: make picture public
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -468,6 +468,7 @@ public class ChatMessagesFragment extends Fragment
|
||||||
public void onDeleteSelection(Object[] objectsToDelete) {
|
public void onDeleteSelection(Object[] objectsToDelete) {
|
||||||
for (Object obj : objectsToDelete) {
|
for (Object obj : objectsToDelete) {
|
||||||
EventLog eventLog = (EventLog) obj;
|
EventLog eventLog = (EventLog) obj;
|
||||||
|
LinphoneUtils.deleteFileContentIfExists(eventLog);
|
||||||
eventLog.deleteFromDatabase();
|
eventLog.deleteFromDatabase();
|
||||||
}
|
}
|
||||||
((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
|
((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
|
||||||
|
@ -559,6 +560,7 @@ public class ChatMessagesFragment extends Fragment
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (item.getItemId() == R.id.delete_message) {
|
if (item.getItemId() == R.id.delete_message) {
|
||||||
|
LinphoneUtils.deleteFileContentIfExists(event);
|
||||||
mChatRoom.deleteMessage(message);
|
mChatRoom.deleteMessage(message);
|
||||||
((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
|
((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
|
||||||
.removeItem(mContextMenuMessagePosition);
|
.removeItem(mContextMenuMessagePosition);
|
||||||
|
@ -1385,6 +1387,8 @@ public class ChatMessagesFragment extends Fragment
|
||||||
@Override
|
@Override
|
||||||
public void onEphemeralMessageDeleted(ChatRoom chatRoom, EventLog eventLog) {
|
public void onEphemeralMessageDeleted(ChatRoom chatRoom, EventLog eventLog) {
|
||||||
Log.i("[Chat Room] Ephemeral message expired");
|
Log.i("[Chat Room] Ephemeral message expired");
|
||||||
|
LinphoneUtils.deleteFileContentIfExists(eventLog);
|
||||||
|
|
||||||
if (!((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
|
if (!((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
|
||||||
.removeFromHistory(eventLog)) {
|
.removeFromHistory(eventLog)) {
|
||||||
Log.w("[Chat Room] Ephemeral message not found, refresh list");
|
Log.w("[Chat Room] Ephemeral message not found, refresh list");
|
||||||
|
|
|
@ -43,7 +43,9 @@ import org.linphone.core.ChatRoom;
|
||||||
import org.linphone.core.ChatRoomListenerStub;
|
import org.linphone.core.ChatRoomListenerStub;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
import org.linphone.core.CoreListenerStub;
|
import org.linphone.core.CoreListenerStub;
|
||||||
|
import org.linphone.core.EventLog;
|
||||||
import org.linphone.core.ProxyConfig;
|
import org.linphone.core.ProxyConfig;
|
||||||
|
import org.linphone.utils.LinphoneUtils;
|
||||||
import org.linphone.utils.SelectableHelper;
|
import org.linphone.utils.SelectableHelper;
|
||||||
|
|
||||||
public class ChatRoomsFragment extends Fragment
|
public class ChatRoomsFragment extends Fragment
|
||||||
|
@ -257,6 +259,11 @@ public class ChatRoomsFragment extends Fragment
|
||||||
for (Object obj : objectsToDelete) {
|
for (Object obj : objectsToDelete) {
|
||||||
ChatRoom room = (ChatRoom) obj;
|
ChatRoom room = (ChatRoom) obj;
|
||||||
room.addListener(mChatRoomListener);
|
room.addListener(mChatRoomListener);
|
||||||
|
|
||||||
|
for (EventLog eventLog : room.getHistoryMessageEvents(0)) {
|
||||||
|
LinphoneUtils.deleteFileContentIfExists(eventLog);
|
||||||
|
}
|
||||||
|
|
||||||
core.deleteChatRoom(room);
|
core.deleteChatRoom(room);
|
||||||
}
|
}
|
||||||
if (mChatRoomDeletionPendingCount > 0) {
|
if (mChatRoomDeletionPendingCount > 0) {
|
||||||
|
|
|
@ -38,7 +38,6 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.R;
|
|
||||||
import org.linphone.core.Address;
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.Friend;
|
import org.linphone.core.Friend;
|
||||||
import org.linphone.core.FriendList;
|
import org.linphone.core.FriendList;
|
||||||
|
@ -190,53 +189,42 @@ public class FileUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteFile(String filePath) {
|
||||||
|
if (filePath == null || filePath.isEmpty()) return;
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (file.exists()) {
|
||||||
|
try {
|
||||||
|
if (file.delete()) {
|
||||||
|
Log.i("[File Utils] File deleted: ", filePath);
|
||||||
|
} else {
|
||||||
|
Log.e("[File Utils] Can't delete ", filePath);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("[File Utils] Can't delete ", filePath, ", exception: ", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e("[File Utils] File ", filePath, " doesn't exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getStorageDirectory(Context mContext) {
|
public static String getStorageDirectory(Context mContext) {
|
||||||
String storageDir =
|
File path = null;
|
||||||
Environment.getExternalStorageDirectory().getAbsolutePath()
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
+ "/"
|
Log.w("[File Utils] External storage is mounted");
|
||||||
+ mContext.getString(R.string.app_name);
|
String directory = Environment.DIRECTORY_DOWNLOADS;
|
||||||
File file = new File(storageDir);
|
path = mContext.getExternalFilesDir(directory);
|
||||||
if (!file.isDirectory() || !file.exists()) {
|
|
||||||
Log.w(
|
|
||||||
"[File Utils] Directory "
|
|
||||||
+ file
|
|
||||||
+ " doesn't seem to exists yet, let's create it");
|
|
||||||
boolean result = file.mkdirs();
|
|
||||||
if (!result) {
|
|
||||||
Log.e(
|
|
||||||
"[File Utils] Couldn't create media directory "
|
|
||||||
+ file.getAbsolutePath()
|
|
||||||
+ ", using external storage dir instead");
|
|
||||||
return Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
||||||
}
|
}
|
||||||
LinphoneManager.getInstance().getMediaScanner().scanFile(file, null);
|
|
||||||
|
if (path == null) {
|
||||||
|
Log.w("[File Utils] Couldn't get external storage path, using internal");
|
||||||
|
path = mContext.getFilesDir();
|
||||||
}
|
}
|
||||||
return storageDir;
|
|
||||||
|
return path.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRecordingsDirectory(Context mContext) {
|
public static String getRecordingsDirectory(Context mContext) {
|
||||||
String recordingsDir =
|
return getStorageDirectory(mContext);
|
||||||
Environment.getExternalStorageDirectory()
|
|
||||||
+ "/"
|
|
||||||
+ mContext.getString(R.string.app_name)
|
|
||||||
+ "/recordings";
|
|
||||||
File file = new File(recordingsDir);
|
|
||||||
if (!file.isDirectory() || !file.exists()) {
|
|
||||||
Log.w(
|
|
||||||
"[File Utils] Directory "
|
|
||||||
+ file
|
|
||||||
+ " doesn't seem to exists yet, let's create it");
|
|
||||||
boolean result = file.mkdirs();
|
|
||||||
if (!result) {
|
|
||||||
Log.e(
|
|
||||||
"[File Utils] Couldn't create recordings directory "
|
|
||||||
+ file.getAbsolutePath()
|
|
||||||
+ ", using external storage dir instead");
|
|
||||||
return Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
||||||
}
|
|
||||||
LinphoneManager.getInstance().getMediaScanner().scanFile(file, null);
|
|
||||||
}
|
|
||||||
return recordingsDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
|
|
@ -48,7 +48,10 @@ import org.linphone.R;
|
||||||
import org.linphone.core.Address;
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.Call;
|
import org.linphone.core.Call;
|
||||||
import org.linphone.core.CallLog;
|
import org.linphone.core.CallLog;
|
||||||
|
import org.linphone.core.ChatMessage;
|
||||||
|
import org.linphone.core.Content;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
|
import org.linphone.core.EventLog;
|
||||||
import org.linphone.core.Factory;
|
import org.linphone.core.Factory;
|
||||||
import org.linphone.core.LogCollectionState;
|
import org.linphone.core.LogCollectionState;
|
||||||
import org.linphone.core.ProxyConfig;
|
import org.linphone.core.ProxyConfig;
|
||||||
|
@ -410,4 +413,21 @@ public final class LinphoneUtils {
|
||||||
customText.setText(text);
|
customText.setText(text);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteFileContentIfExists(EventLog eventLog) {
|
||||||
|
if (eventLog.getType() == EventLog.Type.ConferenceChatMessage) {
|
||||||
|
ChatMessage message = eventLog.getChatMessage();
|
||||||
|
if (message != null) {
|
||||||
|
for (Content content : message.getContents()) {
|
||||||
|
if (content.isFile() && content.getFilePath() != null) {
|
||||||
|
Log.w(
|
||||||
|
"[Linphone Utils] Chat message is being deleted, file ",
|
||||||
|
content.getFilePath(),
|
||||||
|
" will also be deleted");
|
||||||
|
FileUtils.deleteFile(content.getFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<paths>
|
<paths>
|
||||||
<external-path
|
<files-path name="internal_files" path="." />
|
||||||
name="external_files"
|
<external-files-path name="downloads" path="Download/" />
|
||||||
path="." />
|
<external-files-path name="files" path="." />
|
||||||
</paths>
|
</paths>
|
Loading…
Reference in a new issue