aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-03-11 18:59:09 +0100
committerChristian Schneppe <christian@pix-art.de>2017-03-11 20:14:57 +0100
commit7ea55c47aa7f787dbd1f753aa848c585de266988 (patch)
tree1a60b2bf5d4874e075a530a2fada08f7b856adef /src/main
parent36d6885162566e2b3041d470b45fac0206334d01 (diff)
rename media directories
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java56
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java36
-rw-r--r--src/main/java/de/pixart/messenger/services/ExportLogsService.java4
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java1
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/RecordingActivity.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/UpdaterActivity.java6
-rw-r--r--src/main/java/de/pixart/messenger/ui/WelcomeActivity.java6
8 files changed, 84 insertions, 29 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
index 66e1297d7..1b7d09663 100644
--- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
@@ -7,6 +7,7 @@ import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import android.os.Environment;
import android.util.Base64;
import android.util.Log;
import android.util.Pair;
@@ -22,6 +23,7 @@ import org.whispersystems.libaxolotl.state.SessionRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.IOException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
@@ -55,7 +57,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
public static final String DATABASE_NAME = "history";
- public static final int DATABASE_VERSION = 35;
+ public static final int DATABASE_VERSION = 36;
private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@@ -398,6 +400,58 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (oldVersion < 35 && newVersion >= 35) {
db.execSQL(CREATE_MESSAGE_CONVERSATION_INDEX);
}
+ if (oldVersion < 36 && newVersion >= 36) {
+ // only rename videos, images, audios and other files directories
+ final File oldPicturesDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Images/");
+ final File oldFilesDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Files/");
+ final File oldAudiosDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Audios/");
+ final File oldVideosDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Videos/");
+
+ if (oldPicturesDirectory.exists() && oldPicturesDirectory.isDirectory()) {
+ final File newPicturesDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/Pix-Art Messenger Images/");
+ newPicturesDirectory.getParentFile().mkdirs();
+ final File[] files = oldPicturesDirectory.listFiles();
+ if (files == null) {
+ return;
+ }
+ if (oldPicturesDirectory.renameTo(newPicturesDirectory)) {
+ Log.d(Config.LOGTAG,"moved " + oldPicturesDirectory.getAbsolutePath() + " to " + newPicturesDirectory.getAbsolutePath());
+ }
+ }
+ if (oldFilesDirectory.exists() && oldFilesDirectory.isDirectory()) {
+ final File newFilesDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/Pix-Art Messenger Files/");
+ newFilesDirectory.mkdirs();
+ final File[] files = oldFilesDirectory.listFiles();
+ if (files == null) {
+ return;
+ }
+ if (oldFilesDirectory.renameTo(newFilesDirectory)) {
+ Log.d(Config.LOGTAG,"moved " + oldFilesDirectory.getAbsolutePath() + " to " + newFilesDirectory.getAbsolutePath());
+ }
+ }
+ if (oldAudiosDirectory.exists() && oldAudiosDirectory.isDirectory()) {
+ final File newAudiosDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/Pix-Art Messenger Audios/");
+ newAudiosDirectory.mkdirs();
+ final File[] files = oldAudiosDirectory.listFiles();
+ if (files == null) {
+ return;
+ }
+ if (oldAudiosDirectory.renameTo(newAudiosDirectory)) {
+ Log.d(Config.LOGTAG,"moved " + oldAudiosDirectory.getAbsolutePath() + " to " + newAudiosDirectory.getAbsolutePath());
+ }
+ }
+ if (oldVideosDirectory.exists() && oldVideosDirectory.isDirectory()) {
+ final File newVideosDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/Pix-Art Messenger Videos/");
+ newVideosDirectory.mkdirs();
+ final File[] files = oldVideosDirectory.listFiles();
+ if (files == null) {
+ return;
+ }
+ if (oldVideosDirectory.renameTo(newVideosDirectory)) {
+ Log.d(Config.LOGTAG,"moved " + oldVideosDirectory.getAbsolutePath() + " to " + newVideosDirectory.getAbsolutePath());
+ }
+ }
+ }
}
private static ContentValues createFingerprintStatusContentValues(FingerprintStatus.Trust trust, boolean active) {
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 3fc35ab1b..7f367f2b7 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -74,8 +74,8 @@ public class FileBackend {
}
private void createNoMedia() {
- final File nomedia_files = new File(getConversationsDirectory("Files") + ".nomedia");
- final File nomedia_audios = new File(getConversationsDirectory("Audios") + ".nomedia");
+ final File nomedia_files = new File(getConversationsDirectory("Files", true) + ".nomedia");
+ final File nomedia_audios = new File(getConversationsDirectory("Audios", true) + ".nomedia");
if (!nomedia_files.exists()) {
try {
nomedia_files.createNewFile();
@@ -93,8 +93,8 @@ public class FileBackend {
}
public void updateMediaScanner(File file) {
- if (file.getAbsolutePath().startsWith(getConversationsDirectory("Images"))
- || file.getAbsolutePath().startsWith(getConversationsDirectory("Videos"))) {
+ if (file.getAbsolutePath().startsWith(getConversationsDirectory("Images", true))
+ || file.getAbsolutePath().startsWith(getConversationsDirectory("Videos", true))) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
mXmppConnectionService.sendBroadcast(intent);
@@ -132,17 +132,17 @@ public class FileBackend {
} else {
String mime = message.getMimeType();
if (mime != null && mime.startsWith("image")) {
- file = new DownloadableFile(getConversationsDirectory("Images") + path);
+ file = new DownloadableFile(getConversationsDirectory("Images", true) + path);
} else if (mime != null && mime.startsWith("video")) {
- file = new DownloadableFile(getConversationsDirectory("Videos") + path);
+ file = new DownloadableFile(getConversationsDirectory("Videos", true) + path);
} else if (mime != null && mime.startsWith("audio")) {
- file = new DownloadableFile(getConversationsDirectory("Audios") + path);
+ file = new DownloadableFile(getConversationsDirectory("Audios", true) + path);
} else {
- file = new DownloadableFile(getConversationsDirectory("Files") + path);
+ file = new DownloadableFile(getConversationsDirectory("Files", true) + path);
}
}
if (encrypted) {
- return new DownloadableFile(getConversationsDirectory("Files") + file.getName() + ".pgp");
+ return new DownloadableFile(getConversationsDirectory("Files", true) + file.getName() + ".pgp");
} else {
return file;
}
@@ -177,20 +177,24 @@ public class FileBackend {
return true;
}
- public static String getDirectoryName(final String type) {
+ public static String getDirectoryName(final String type, final boolean isMedia) {
+ String media = "";
+ if (isMedia) {
+ media = "Media/Pix-Art Messenger ";
+ }
if (type == "null" || type == null) {
return "/Pix-Art Messenger/";
} else {
- return "/Pix-Art Messenger" + "/" + type + "/";
+ return "/Pix-Art Messenger" + "/" + media + type + "/";
}
}
- public static String getConversationsDirectory(final String type) {
+ public static String getConversationsDirectory(final String type, final boolean isMedia) {
String DirName = null;
if (type != "null" || type != null) {
DirName = type;
}
- String path = Environment.getExternalStorageDirectory().getAbsolutePath() + getDirectoryName(DirName);
+ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + getDirectoryName(DirName, isMedia);
File createFolders = new File(path);
if (!createFolders.exists()) {
Log.d(Config.LOGTAG, "creating directory " + createFolders);
@@ -266,7 +270,7 @@ public class FileBackend {
if (path == null) {
return false;
}
- if (path.contains(getDirectoryName("null"))) {
+ if (path.contains(getDirectoryName("null", true))) {
Log.d(Config.LOGTAG, "File " + path + " is in our directory, sending as is");
return true;
}
@@ -577,8 +581,6 @@ public class FileBackend {
return null;
} catch (IOException e) {
return null;
- } catch (OutOfMemoryError e) {
- return null;
}
}
@@ -695,8 +697,6 @@ public class FileBackend {
return null; // happens for example on Android 6.0 if contacts permissions get revoked
} catch (FileNotFoundException e) {
return null;
- } catch (OutOfMemoryError e) {
- return null;
} finally {
close(is);
}
diff --git a/src/main/java/de/pixart/messenger/services/ExportLogsService.java b/src/main/java/de/pixart/messenger/services/ExportLogsService.java
index 61d8a921d..ab1d223db 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", false) + "%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);
@@ -181,7 +181,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", false));
// Create the folder if it doesn't exist:
if (!directory.exists()) {
directory.mkdirs();
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 48c816f03..ce839766d 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -346,6 +346,7 @@ public class XmppConnectionService extends Service {
if (!conversation.startOtrIfNeeded()) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": couldn't start OTR with " + conversation.getContact().getJid() + " when needed");
}
+ checkDeletedFiles(conversation);
sendUnsentMessages(conversation);
resendFailedFileMessages(conversation);
}
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 069708b26..47d3ea2c5 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -681,7 +681,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("null"))) {
+ if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory("null", false))) {
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 dab401309..29fcf6a5b 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.getConversationsDirectory("Audios") + "/"
+ return new File(FileBackend.getConversationsDirectory("Audios", true) + "/"
+ dateFormat.format(new Date())
+ ".m4a");
}
diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
index 066a2fd39..b043c3db7 100644
--- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
@@ -52,7 +52,7 @@ public class UpdaterActivity extends Activity {
//check if the broadcast message is for our Enqueued download
long referenceId = intent.getExtras().getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
if (downloadReference == referenceId) {
- File file = new File(FileBackend.getConversationsDirectory("Update"), FileName);
+ File file = new File(FileBackend.getConversationsDirectory("Update", false), FileName);
//start the installation of the latest localVersion
Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
installIntent.setDataAndType(FileBackend.getUriForFile(UpdaterActivity.this, file), "application/vnd.android.package-archive");
@@ -267,7 +267,7 @@ public class UpdaterActivity extends Activity {
//check if we need to upgrade?
if (checkVersion(remoteVersion, localVersion) >= 1) {
//delete old downloaded localVersion files
- File dir = new File(FileBackend.getConversationsDirectory("Update"));
+ File dir = new File(FileBackend.getConversationsDirectory("Update", false));
if (dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
@@ -296,7 +296,7 @@ public class UpdaterActivity extends Activity {
Uri Download_Uri = Uri.parse(appURI);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
request.setTitle("Pix-Art Messenger Update");
- request.setDestinationInExternalPublicDir(FileBackend.getDirectoryName("Update"), FileName);
+ request.setDestinationInExternalPublicDir(FileBackend.getDirectoryName("Update", false), FileName);
downloadReference = downloadManager.enqueue(request);
Toast.makeText(getApplicationContext(),
getText(R.string.download_started),
diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
index 0c37515cd..da5972666 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", false) + "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", false));
// 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", false));
// Set the input file stream up:
final InputStream InputFile = new FileInputStream(directory.getPath() + "/database.bak");
//set temp file