more storage fixes [Christian Schneppe]

This commit is contained in:
12aw 2022-03-19 17:17:12 +01:00
parent ff0e3ca111
commit b69c397e4d
5 changed files with 31 additions and 21 deletions

View file

@ -16,7 +16,7 @@ public class StorageHelper {
if (type.equalsIgnoreCase("null")) {
return new File(getStorage(context, STORAGE_INDEX.get(), APP_DIRECTORY, type));
} else {
return new File(getAppMediaDirectory(context, type) + APP_DIRECTORY + " " + type + File.separator);
return new File(getAppMediaDirectory(context, type) + APP_DIRECTORY + " " + type);
}
}

View file

@ -15,6 +15,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.net.ssl.SSLHandshakeException;
@ -100,9 +101,17 @@ public class HttpDownloadConnection implements Transferable {
}
final String ext = extension.getExtension();
if (ext != null) {
message.setRelativeFilePath(String.format("%s.%s", message.getUuid(), ext));
if (message.getStatus() == Message.STATUS_RECEIVED) {
message.setRelativeFilePath(String.format("%s.%s", fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4), ext));
} else {
message.setRelativeFilePath("Sent/" + String.format("%s.%s", fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4), ext));
}
} else if (Strings.isNullOrEmpty(message.getRelativeFilePath())) {
message.setRelativeFilePath(message.getUuid());
if (message.getStatus() == Message.STATUS_RECEIVED) {
message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4));
} else {
message.setRelativeFilePath("Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4));
}
}
setupFile();
if (this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL && this.file.getKey() == null) {
@ -333,7 +342,7 @@ public class HttpDownloadConnection implements Transferable {
if (Strings.isNullOrEmpty(extension.getExtension()) && contentType != null) {
final String fileExtension = MimeUtils.guessExtensionFromMimeType(contentType);
if (fileExtension != null) {
mXmppConnectionService.getFileBackend().setupRelativeFilePath(message, String.format("%s.%s", message.getUuid(), fileExtension), contentType);
mXmppConnectionService.getFileBackend().setupRelativeFilePath(message, String.format("%s.%s", fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4), fileExtension), contentType);
Log.d(Config.LOGTAG, "rewriting name after not finding extension in url but in content type");
setupFile();
}

View file

@ -105,7 +105,7 @@ public class FileBackend {
private static final SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
private static final String FILE_PROVIDER = ".files";
public static final String APP_DIRECTORY = "blabber.im";
public static final String APP_DIRECTORY = "monocles chat";
public static final String FILES = "Files";
public static final String SENT_FILES = "Files" + File.separator + "Sent";
public static final String AUDIOS = "Audios";
@ -128,12 +128,12 @@ public class FileBackend {
}
private static void createNoMedia(Context context) {
final File nomedia_files = new File(getConversationsDirectory(context, FILES) + ".nomedia");
final File nomedia_audios = new File(getConversationsDirectory(context, AUDIOS) + ".nomedia");
final File nomedia_videos_sent = new File(getConversationsDirectory(context, SENT_VIDEOS) + ".nomedia");
final File nomedia_files_sent = new File(getConversationsDirectory(context, SENT_FILES) + ".nomedia");
final File nomedia_audios_sent = new File(getConversationsDirectory(context, SENT_AUDIOS) + ".nomedia");
final File nomedia_images_sent = new File(getConversationsDirectory(context, SENT_IMAGES) + ".nomedia");
final File nomedia_files = new File(getConversationsDirectory(context, FILES) + File.separator + ".nomedia");
final File nomedia_audios = new File(getConversationsDirectory(context, AUDIOS) + File.separator + ".nomedia");
final File nomedia_videos_sent = new File(getConversationsDirectory(context, SENT_VIDEOS) + File.separator + ".nomedia");
final File nomedia_files_sent = new File(getConversationsDirectory(context, SENT_FILES) + File.separator + ".nomedia");
final File nomedia_audios_sent = new File(getConversationsDirectory(context, SENT_AUDIOS) + File.separator + ".nomedia");
final File nomedia_images_sent = new File(getConversationsDirectory(context, SENT_IMAGES) + File.separator + ".nomedia");
if (!nomedia_files.exists()) {
try {
nomedia_files.createNewFile();
@ -244,7 +244,7 @@ public class FileBackend {
}
}
});
Log.d(Config.LOGTAG, "media scanner broadcasts file scan");
Log.d(Config.LOGTAG, "media scanner broadcasts file scan: " + file.getAbsolutePath());
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(file.getAbsolutePath())));
mXmppConnectionService.sendBroadcast(intent);
@ -412,13 +412,13 @@ public class FileBackend {
file = new DownloadableFile(path);
} else {
if (mime != null && mime.startsWith("image")) {
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, IMAGES) + path);
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, IMAGES) + File.separator + path);
} else if (mime != null && mime.startsWith("video")) {
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, VIDEOS) + path);
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, VIDEOS) + File.separator + path);
} else if (mime != null && mime.startsWith("audio")) {
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, AUDIOS) + path);
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, AUDIOS) + File.separator + path);
} else {
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, FILES) + path);
file = new DownloadableFile(getConversationsDirectory(mXmppConnectionService, FILES) + File.separator + path);
}
}
return file;

View file

@ -139,7 +139,8 @@ public class NotificationService {
@RequiresApi(api = Build.VERSION_CODES.O)
void updateChannels() {
mXmppConnectionService.mNotificationChannelExecutor.execute(this::initializeChannels);
//mXmppConnectionService.mNotificationChannelExecutor.execute(this::initializeChannels);
initializeChannels();
}
@RequiresApi(api = Build.VERSION_CODES.O)

View file

@ -496,7 +496,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
if (message.getStatus() == Message.STATUS_RECEIVED) {
filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "." + extension.main;
} else {
filename = "Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "." + extension.main;
filename = "Sent" + File.separator + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "." + extension.main;
}
xmppConnectionService.getFileBackend().setupRelativeFilePath(message, filename);
} else if (VALID_CRYPTO_EXTENSIONS.contains(extension.main)) {
@ -506,7 +506,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
if (message.getStatus() == Message.STATUS_RECEIVED) {
filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "." + extension.secondary;
} else {
filename = "Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "." + extension.secondary;
filename = "Sent" + File.separator + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "." + extension.secondary;
}
xmppConnectionService.getFileBackend().setupRelativeFilePath(message, filename);
} else {
@ -515,7 +515,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
if (message.getStatus() == Message.STATUS_RECEIVED) {
filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension.secondary != null ? ("." + extension.secondary) : "");
} else {
filename = "Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension.secondary != null ? ("." + extension.secondary) : "");
filename = "Sent" + File.separator + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension.secondary != null ? ("." + extension.secondary) : "");
}
xmppConnectionService.getFileBackend().setupRelativeFilePath(message, filename);
}
@ -531,7 +531,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
if (message.getStatus() == Message.STATUS_RECEIVED) {
filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension.main != null ? ("." + extension.main) : "");
} else {
filename = "Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension.main != null ? ("." + extension.main) : "");
filename = "Sent" + File.separator + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension.main != null ? ("." + extension.main) : "");
}
xmppConnectionService.getFileBackend().setupRelativeFilePath(message, filename);
}