diff options
6 files changed, 26 insertions, 34 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 5436cd0ce..add0736d5 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -71,8 +71,8 @@ public class FileBackend { } private void createNoMedia() { - final File nomedia_files = new File(getConversationsFileDirectory() + ".nomedia"); - final File nomedia_audios = new File(getConversationsAudioDirectory() + ".nomedia"); + final File nomedia_files = new File(getConversationsDirectory("Files") + ".nomedia"); + final File nomedia_audios = new File(getConversationsDirectory("Audios") + ".nomedia"); if (!nomedia_files.exists()) { try { nomedia_files.createNewFile(); @@ -90,8 +90,8 @@ public class FileBackend { } public void updateMediaScanner(File file) { - if (file.getAbsolutePath().startsWith(getConversationsImageDirectory()) - || file.getAbsolutePath().startsWith(getConversationsVideoDirectory())) { + if (file.getAbsolutePath().startsWith(getConversationsDirectory("Images")) + || file.getAbsolutePath().startsWith(getConversationsDirectory("Videos"))) { Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(file)); mXmppConnectionService.sendBroadcast(intent); @@ -129,17 +129,17 @@ public class FileBackend { } else { String mime = message.getMimeType(); if (mime != null && mime.startsWith("image")) { - file = new DownloadableFile(getConversationsImageDirectory() + path); + file = new DownloadableFile(getConversationsDirectory("Images") + path); } else if (mime != null && mime.startsWith("video")) { - file = new DownloadableFile(getConversationsVideoDirectory() + path); + file = new DownloadableFile(getConversationsDirectory("Videos") + path); } else if (mime != null && mime.startsWith("audio")) { - file = new DownloadableFile(getConversationsAudioDirectory() + path); + file = new DownloadableFile(getConversationsDirectory("Audios") + path); } else { - file = new DownloadableFile(getConversationsFileDirectory() + path); + file = new DownloadableFile(getConversationsDirectory("Files") + path); } } if (encrypted) { - return new DownloadableFile(getConversationsFileDirectory() + file.getName() + ".pgp"); + return new DownloadableFile(getConversationsDirectory("Files") + file.getName() + ".pgp"); } else { return file; } @@ -168,24 +168,12 @@ public class FileBackend { return true; } - public static String getConversationsFileDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/files/"; - } - - public static String getConversationsImageDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/images/"; - } - - public static String getConversationsVideoDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/videos/"; - } - - public static String getConversationsAudioDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/audios/"; - } - - public static String getConversationsDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/"; + public static String getConversationsDirectory(final String type) { + if (type == "null") { + return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/"; + } else { + return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger" + "/" + type + "/"; + } } public Bitmap resize(Bitmap originalBitmap, int size) { diff --git a/src/main/java/de/pixart/messenger/services/ExportLogsService.java b/src/main/java/de/pixart/messenger/services/ExportLogsService.java index 67e6ccaa7..d7948d651 100644 --- a/src/main/java/de/pixart/messenger/services/ExportLogsService.java +++ b/src/main/java/de/pixart/messenger/services/ExportLogsService.java @@ -40,7 +40,7 @@ import de.pixart.messenger.xmpp.jid.Jid; public class ExportLogsService extends Service { private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - private static final String DIRECTORY_STRING_FORMAT = FileBackend.getConversationsDirectory() + "/chats/%s"; + private static final String DIRECTORY_STRING_FORMAT = FileBackend.getConversationsDirectory("Chats") + "%s"; private static final String MESSAGE_STRING_FORMAT = "(%s) %s: %s\n"; private static final int NOTIFICATION_ID = 1; private static AtomicBoolean running = new AtomicBoolean(false); @@ -179,7 +179,7 @@ public class ExportLogsService extends Service { // Get hold of the db: FileInputStream InputFile = new FileInputStream(this.getDatabasePath(DatabaseBackend.DATABASE_NAME)); // Set the output folder on the SDcard - File directory = new File(FileBackend.getConversationsDirectory() + "/database/"); + File directory = new File(FileBackend.getConversationsDirectory("Database")); // Create the folder if it doesn't exist: if (!directory.exists()) { directory.mkdirs(); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index da1d7e77d..c515aeb29 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -676,7 +676,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (treatAsFile) { String path = m.getRelativeFilePath(); Log.d(Config.LOGTAG, "Path = " + path); - if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory())) { + if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory("null"))) { deleteFile.setVisible(true); deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m))); } diff --git a/src/main/java/de/pixart/messenger/ui/RecordingActivity.java b/src/main/java/de/pixart/messenger/ui/RecordingActivity.java index e5e43f290..dab401309 100644 --- a/src/main/java/de/pixart/messenger/ui/RecordingActivity.java +++ b/src/main/java/de/pixart/messenger/ui/RecordingActivity.java @@ -120,7 +120,7 @@ public class RecordingActivity extends Activity implements View.OnClickListener private File getOutputFile() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US); - return new File(FileBackend.getConversationsAudioDirectory() + "/" + return new File(FileBackend.getConversationsDirectory("Audios") + "/" + dateFormat.format(new Date()) + ".m4a"); } diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java index 7573e40c7..0c37515cd 100644 --- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java +++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java @@ -175,7 +175,7 @@ public class WelcomeActivity extends XmppActivity { private boolean BackupAvailable() { // Set the folder on the SDcard - File filePath = new File(FileBackend.getConversationsDirectory() + "/database/database.db.crypt"); + File filePath = new File(FileBackend.getConversationsDirectory("Database") + "database.db.crypt"); Log.d(Config.LOGTAG, "DB Path: " + filePath.toString()); if (filePath.exists()) { Log.d(Config.LOGTAG, "DB Path existing"); @@ -188,7 +188,7 @@ public class WelcomeActivity extends XmppActivity { private void checkDatabase(String DecryptionKey) throws IOException { // Set the folder on the SDcard - File directory = new File(FileBackend.getConversationsDirectory() + "/database/"); + File directory = new File(FileBackend.getConversationsDirectory("Database")); // Set the input file stream up: FileInputStream InputFile = new FileInputStream(directory.getPath() + "/database.db.crypt"); // Temp output for DB checks @@ -252,7 +252,7 @@ public class WelcomeActivity extends XmppActivity { // Set location for the db: final OutputStream OutputFile = new FileOutputStream(this.getDatabasePath(DatabaseBackend.DATABASE_NAME)); // Set the folder on the SDcard - File directory = new File(FileBackend.getConversationsDirectory() + "/database/"); + File directory = new File(FileBackend.getConversationsDirectory("Database")); // Set the input file stream up: final InputStream InputFile = new FileInputStream(directory.getPath() + "/database.bak"); //set temp file diff --git a/src/main/res/xml/file_paths.xml b/src/main/res/xml/file_paths.xml index 6ba7c695b..5cf2e6604 100644 --- a/src/main/res/xml/file_paths.xml +++ b/src/main/res/xml/file_paths.xml @@ -3,4 +3,8 @@ <external-path name="external" path="/" /> + <files-path path="Images/" name="pictures" /> + <files-path path="Videos" name="videos"/> + <files-path path="Files/" name="files" /> + <files-path path="Audios/" name="audios" /> </paths>
\ No newline at end of file |