import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
-import com.owncloud.android.files.services.FileDownloader;
+import com.owncloud.android.utils.FileStorageUtils;
import android.accounts.Account;
import android.content.ContentProviderClient;
.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
if (file.getStoragePath() == null) {
// try to find existing file and bind it with current account
- File f = new File(FileDownloader.getSavePath(mAccount.name) + file.getRemotePath());
+ File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
if (f.exists())
file.setStoragePath(f.getAbsolutePath());
}
DataStorageManager mStorage;
Account mOCAccount;
OCFile mFile;
- static Context mContext;
+ static Context mContext; // ISSUE 4: why is this static?
List<FileObserverStatusListener> mListeners;
public OwnCloudFileObserver(String path) {
import android.app.Service;\r
import android.content.ContentValues;\r
import android.content.Intent;\r
-import android.net.Uri;\r
import android.os.Binder;\r
-import android.os.Environment;\r
import android.os.Handler;\r
import android.os.HandlerThread;\r
import android.os.IBinder;\r
private String buildRemoteName(Account account, OCFile file) {\r
return account.name + file.getRemotePath();\r
}\r
- \r
- public static final String getSavePath(String accountName) {\r
- File sdCard = Environment.getExternalStorageDirectory();\r
- return sdCard.getAbsolutePath() + "/owncloud/" + Uri.encode(accountName, "@"); \r
- // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B\r
- }\r
- \r
- public static final String getTemporalPath(String accountName) {\r
- File sdCard = Environment.getExternalStorageDirectory();\r
- return sdCard.getAbsolutePath() + "/owncloud/tmp/" + Uri.encode(accountName, "@");\r
- // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B\r
- }\r
\r
\r
/**\r
public final static int CMD_DEL_OBSERVED_FILE = 3;
public final static int CMD_ADD_DOWNLOADING_FILE = 4;
- private static String TAG = "FileObserverService";
+ private static String TAG = FileObserverService.class.getSimpleName();
private static List<OwnCloudFileObserver> mObservers;
private static List<DownloadCompletedReceiver> mDownloadReceivers;
private static Object mReceiverListLock = new Object();
if (path == null) return;
if (mObservers == null) {
initializeObservedList();
- return;
+ return; // ISSUE 2: why return? ; the file still has to be removed of the mObservers !
}
for (int i = 0; i < mObservers.size(); ++i) {
OwnCloudFileObserver observer = mObservers.get(i);
switch (status) {
case CONFLICT:
{
+ // ISSUE 5: if the user is not running the app (this is a service!), this can be very intrusive; a notification should be preferred
Intent i = new Intent(getApplicationContext(), ConflictsResolveActivity.class);
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("remotepath", remotePath);
@Override
public void onReceive(Context context, Intent intent) {
- if (mPath.equals(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH))) {
+ if (mPath.equals(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH))) { // ISSUE 3: this condition will be false if the download failed; in that case, the download won't ever be retried
context.unregisterReceiver(this);
removeReceiverFromList(this);
mObserver.startWatching();
import org.apache.http.HttpStatus;
import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.operations.RemoteOperation;
import com.owncloud.android.operations.RemoteOperationResult;
+import com.owncloud.android.utils.FileStorageUtils;
import eu.alefzero.webdav.OnDatatransferProgressListener;
import eu.alefzero.webdav.WebdavClient;
}
public String getSavePath() {
- return FileDownloader.getSavePath(mAccount.name) + mFile.getRemotePath();
+ String path = mFile.getStoragePath(); // re-downloads should be done over the original file
+ if (path != null && path.length() > 0) {
+ return path;
+ }
+ return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
}
public String getTmpPath() {
- return FileDownloader.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+ return FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
}
public String getRemotePath() {
import com.owncloud.android.datamodel.DataStorageManager;
import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.utils.FileStorageUtils;
import eu.alefzero.webdav.WebdavClient;
import eu.alefzero.webdav.WebdavUtils;
return false;
}
// create a test file
- String tmpFolder = FileDownloader.getTemporalPath("");
+ String tmpFolder = FileStorageUtils.getTemporalPath("");
File testFile = new File(tmpFolder + mNewName);
try {
testFile.createNewFile(); // return value is ignored; it could be 'false' because the file already existed, that doesn't invalidate the name
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.files.services.FileObserverService;
+import com.owncloud.android.utils.FileStorageUtils;
import eu.alefzero.webdav.WebdavClient;
import eu.alefzero.webdav.WebdavEntry;
// removal of obsolete files
mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId));
OCFile file;
- String currentSavePath = FileDownloader.getSavePath(mAccount.name);
+ String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
for (int i=0; i < mChildren.size(); ) {
file = mChildren.get(i);
if (file.getLastSyncDate() != mCurrentSyncTime) {
import com.owncloud.android.ui.activity.TransferServiceGetter;\r
import com.owncloud.android.ui.dialog.EditNameDialog;\r
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;\r
+import com.owncloud.android.utils.FileStorageUtils;\r
import com.owncloud.android.utils.OwnCloudVersion;\r
\r
import com.owncloud.android.R;\r
}\r
\r
} else {\r
+ // ISSUE 6: this button should be promoted to 'synchronize' if the file is DOWN, not just redownload\r
Intent i = new Intent(getActivity(), FileDownloader.class);\r
i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);\r
i.putExtra(FileDownloader.EXTRA_FILE, mFile);\r
(cb.isChecked()?\r
FileObserverService.CMD_ADD_OBSERVED_FILE:\r
FileObserverService.CMD_DEL_OBSERVED_FILE));\r
- intent.putExtra(FileObserverService.KEY_CMD_ARG, mFile.getStoragePath());\r
+ String localPath = mFile.getStoragePath();\r
+ if (localPath == null || localPath.length() <= 0) {\r
+ localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);\r
+ }\r
+ intent.putExtra(FileObserverService.KEY_CMD_ARG, localPath);\r
Log.e(TAG, "starting observer service");\r
getActivity().startService(intent);\r
\r
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012 Bartek Przybylski
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.utils;
+
+import java.io.File;
+
+import android.net.Uri;
+import android.os.Environment;
+import com.owncloud.android.datamodel.OCFile;
+
+
+public class FileStorageUtils {
+
+ public static final String getSavePath(String accountName) {
+ File sdCard = Environment.getExternalStorageDirectory();
+ return sdCard.getAbsolutePath() + "/owncloud/" + Uri.encode(accountName, "@");
+ // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B
+ }
+
+ public static final String getDefaultSavePathFor(String accountName, OCFile file) {
+ return getSavePath(accountName) + file.getRemotePath();
+ }
+
+ public static final String getTemporalPath(String accountName) {
+ File sdCard = Environment.getExternalStorageDirectory();
+ return sdCard.getAbsolutePath() + "/owncloud/tmp/" + Uri.encode(accountName, "@");
+ // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B
+ }
+
+
+}
\ No newline at end of file