mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Fixed issue 1205: Attachment storage location setting now takes effect immediatly. LocalStore is also better at handling when attachment are stored in a mix of internal and external storage (migration state after a setting change)
This commit is contained in:
parent
f2f3b4263d
commit
e435d9d616
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,7 @@ public class LocalStore extends Store implements Serializable
|
|||||||
private static final int DB_VERSION = 33;
|
private static final int DB_VERSION = 33;
|
||||||
private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.X_DESTROYED, Flag.SEEN };
|
private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.X_DESTROYED, Flag.SEEN };
|
||||||
|
|
||||||
private Account mAccount;
|
private boolean mStoreAttachmentsOnSdCard;
|
||||||
private String mPath;
|
private String mPath;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
private File mInternalAttachmentsDir = null;
|
private File mInternalAttachmentsDir = null;
|
||||||
@ -70,23 +70,6 @@ public class LocalStore extends Store implements Serializable
|
|||||||
{
|
{
|
||||||
mApplication = application;
|
mApplication = application;
|
||||||
|
|
||||||
//Store should be passed their store
|
|
||||||
//but let's not break the interface now
|
|
||||||
for (Account account : Preferences.getPreferences(mApplication).getAccounts())
|
|
||||||
{
|
|
||||||
if (_uri.equals(account.getLocalStoreUri()))
|
|
||||||
{
|
|
||||||
mAccount = account;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mAccount == null)
|
|
||||||
{
|
|
||||||
//Should not happend
|
|
||||||
throw new IllegalArgumentException("No account found: uri=" + _uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
URI uri = null;
|
URI uri = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -124,14 +107,24 @@ public class LocalStore extends Store implements Serializable
|
|||||||
|
|
||||||
String externalAttachmentsPath = "/sdcard" + mPath.substring("//data".length());
|
String externalAttachmentsPath = "/sdcard" + mPath.substring("//data".length());
|
||||||
mExternalAttachmentsDir = new File(externalAttachmentsPath + "_att");
|
mExternalAttachmentsDir = new File(externalAttachmentsPath + "_att");
|
||||||
if (mAccount.isStoreAttachmentOnSdCard()
|
Account account = null;
|
||||||
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
|
for (Account aAccount : Preferences.getPreferences(mApplication).getAccounts())
|
||||||
{
|
{
|
||||||
if (!mExternalAttachmentsDir.exists())
|
if (_uri.equals(aAccount.getLocalStoreUri()))
|
||||||
{
|
{
|
||||||
mExternalAttachmentsDir.mkdirs();
|
account = aAccount;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (account == null)
|
||||||
|
{
|
||||||
|
//Should not happend
|
||||||
|
throw new IllegalArgumentException("No account found: uri=" + _uri);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.setStoreAttachmentsOnSdCard(account.isStoreAttachmentOnSdCard());
|
||||||
|
}
|
||||||
|
|
||||||
mDb = SQLiteDatabase.openOrCreateDatabase(mPath, null);
|
mDb = SQLiteDatabase.openOrCreateDatabase(mPath, null);
|
||||||
if (mDb.getVersion() != DB_VERSION)
|
if (mDb.getVersion() != DB_VERSION)
|
||||||
@ -269,7 +262,7 @@ public class LocalStore extends Store implements Serializable
|
|||||||
long attachmentLength = 0;
|
long attachmentLength = 0;
|
||||||
|
|
||||||
attachmentLength =+ getSize(mInternalAttachmentsDir);
|
attachmentLength =+ getSize(mInternalAttachmentsDir);
|
||||||
if (usesExternalAttachmentDir())
|
if (isExternalAttachmentsDirReady())
|
||||||
{
|
{
|
||||||
attachmentLength =+ getSize(mExternalAttachmentsDir);
|
attachmentLength =+ getSize(mExternalAttachmentsDir);
|
||||||
}
|
}
|
||||||
@ -429,7 +422,7 @@ public class LocalStore extends Store implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(mInternalAttachmentsDir);
|
delete(mInternalAttachmentsDir);
|
||||||
if (usesExternalAttachmentDir())
|
if (isExternalAttachmentsDirReady())
|
||||||
{
|
{
|
||||||
delete(mExternalAttachmentsDir);
|
delete(mExternalAttachmentsDir);
|
||||||
}
|
}
|
||||||
@ -486,7 +479,7 @@ public class LocalStore extends Store implements Serializable
|
|||||||
mDb.update("attachments", cv, null, null);
|
mDb.update("attachments", cv, null, null);
|
||||||
}
|
}
|
||||||
pruneCachedAttachments(force, mInternalAttachmentsDir);
|
pruneCachedAttachments(force, mInternalAttachmentsDir);
|
||||||
if (usesExternalAttachmentDir())
|
if (isExternalAttachmentsDirReady())
|
||||||
{
|
{
|
||||||
pruneCachedAttachments(force, mExternalAttachmentsDir);
|
pruneCachedAttachments(force, mExternalAttachmentsDir);
|
||||||
}
|
}
|
||||||
@ -2624,35 +2617,70 @@ public class LocalStore extends Store implements Serializable
|
|||||||
|
|
||||||
private File getAttachmentsDir()
|
private File getAttachmentsDir()
|
||||||
{
|
{
|
||||||
if (usesExternalAttachmentDir())
|
if (mStoreAttachmentsOnSdCard)
|
||||||
{
|
{
|
||||||
if (!mExternalAttachmentsDir.exists())
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
|
||||||
{
|
{
|
||||||
mExternalAttachmentsDir.mkdirs();
|
if (!mExternalAttachmentsDir.exists())
|
||||||
|
{
|
||||||
|
mExternalAttachmentsDir.mkdirs();
|
||||||
|
}
|
||||||
|
return mExternalAttachmentsDir;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("SD card not mounted");
|
||||||
}
|
}
|
||||||
return mExternalAttachmentsDir;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return mInternalAttachmentsDir;
|
return mInternalAttachmentsDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean usesExternalAttachmentDir()
|
public boolean isStoreAttachmentsOnSdCard()
|
||||||
{
|
{
|
||||||
if (mAccount.isStoreAttachmentOnSdCard()) {
|
return mStoreAttachmentsOnSdCard;
|
||||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
|
}
|
||||||
{
|
|
||||||
throw new IllegalStateException("SDCard not mounted");
|
|
||||||
|
|
||||||
}
|
public void setStoreAttachmentsOnSdCard(boolean storeAttachmentsOnSdCard)
|
||||||
else
|
{
|
||||||
{
|
this.mStoreAttachmentsOnSdCard = storeAttachmentsOnSdCard;
|
||||||
return true;
|
if (K9.DEBUG)
|
||||||
}
|
{
|
||||||
|
Log.v(K9.LOG_TAG, "mStoreAttachmentsOnSdCard: " + mStoreAttachmentsOnSdCard);
|
||||||
}
|
}
|
||||||
else
|
if (storeAttachmentsOnSdCard
|
||||||
|
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
|
||||||
|
&& !mExternalAttachmentsDir.exists())
|
||||||
|
{
|
||||||
|
mExternalAttachmentsDir.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the dir is eardy to use and if we need it.
|
||||||
|
*
|
||||||
|
* @exception IllegalStateException If the dir is not ready (SD card not mounted)
|
||||||
|
* and we expect it to be (mStoreAttachmentsOnSdCard is true)
|
||||||
|
*/
|
||||||
|
private boolean isExternalAttachmentsDirReady()
|
||||||
|
{
|
||||||
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
|
||||||
|
{
|
||||||
|
if (!mExternalAttachmentsDir.exists())
|
||||||
|
{
|
||||||
|
mExternalAttachmentsDir.mkdirs();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (!mStoreAttachmentsOnSdCard)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("SD card not mounted");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user