From e5fbfbab0d0b04247d7decacae7a1a02369e4914 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Wed, 25 Jan 2017 21:18:53 +0100 Subject: reworked FileBackend --- .../pixart/messenger/persistance/FileBackend.java | 42 ++++++++-------------- .../messenger/services/ExportLogsService.java | 4 +-- .../pixart/messenger/ui/ConversationFragment.java | 2 +- .../de/pixart/messenger/ui/RecordingActivity.java | 2 +- .../de/pixart/messenger/ui/WelcomeActivity.java | 6 ++-- 5 files changed, 22 insertions(+), 34 deletions(-) (limited to 'src/main/java/de/pixart') 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 -- cgit v1.2.3