diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 22505c81c3..9a269f2df2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.178B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/src/eu/alefzero/owncloud/datamodel/OCFile.java b/src/eu/alefzero/owncloud/datamodel/OCFile.java index 7284604c23..b23abf9a02 100644 --- a/src/eu/alefzero/owncloud/datamodel/OCFile.java +++ b/src/eu/alefzero/owncloud/datamodel/OCFile.java @@ -156,20 +156,6 @@ public class OCFile implements Parcelable, Comparable { return false; } - /** - * Use this to check if this file is downloading - * - * @return true if it is in a download in progress - */ - public boolean isDownloading() { - if (mLocalPath != null && mLocalPath.length() > 0) { - String savePath = FileDownloader.getSavePath(); - File file = new File(FileDownloader.getTemporalPath() + mLocalPath.substring(savePath.length())); - return (file.exists()); - } - return false; - } - /** * The path, where the file is stored locally * diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java index e5316b3e57..c147c9d282 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/src/eu/alefzero/owncloud/files/services/FileDownloader.java @@ -2,6 +2,9 @@ package eu.alefzero.owncloud.files.services; import java.io.File; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import android.accounts.Account; import android.accounts.AccountManager; @@ -48,7 +51,27 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis private long mTotalDownloadSize; private long mCurrentDownlodSize; private Notification mNotification; + + /** + * Static map with the files being download and the path to the temporal file were are download + */ + private static Map mDownloadsInProgress = Collections.synchronizedMap(new HashMap()); + + /** + * Returns True when the file referred by 'remotePath' in the ownCloud account 'account' is downloading + */ + public static boolean isDownloading(Account account, String remotePath) { + return (mDownloadsInProgress.get(buildRemoteName(account.name, remotePath)) != null); + } + + /** + * Builds a key for mDownloadsInProgress from the accountName and remotePath + */ + private static String buildRemoteName(String accountName, String remotePath) { + return accountName + remotePath; + } + private final class ServiceHandler extends Handler { public ServiceHandler(Looper looper) { super(looper); @@ -141,6 +164,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis // download in a temporal file File tmpFile = new File(getTemporalPath() + mAccount.name + mFilePath); tmpFile.getParentFile().mkdirs(); + mDownloadsInProgress.put(buildRemoteName(mAccount.name, mRemotePath), tmpFile.getAbsolutePath()); boolean download_result = false; File newFile = null; @@ -164,6 +188,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } } + mDownloadsInProgress.remove(buildRemoteName(mAccount.name, mRemotePath)); + mNotificationMngr.cancel(1); Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE); end.putExtra(EXTRA_DOWNLOAD_RESULT, download_result); diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java index 9c7960384c..bcdce7937f 100644 --- a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java +++ b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java @@ -19,11 +19,14 @@ package eu.alefzero.owncloud.ui.adapter; import java.util.Vector; +import eu.alefzero.owncloud.AccountUtils; import eu.alefzero.owncloud.DisplayUtils; import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.datamodel.DataStorageManager; import eu.alefzero.owncloud.datamodel.OCFile; +import eu.alefzero.owncloud.files.services.FileDownloader; +import android.accounts.Account; import android.content.Context; import android.database.DataSetObserver; import android.util.Log; @@ -46,6 +49,7 @@ public class FileListListAdapter implements ListAdapter { private OCFile mFile; private Vector mFiles; private DataStorageManager mStorageManager; + private Account mAccount; public FileListListAdapter(OCFile file, DataStorageManager storage_man, Context context) { @@ -53,6 +57,7 @@ public class FileListListAdapter implements ListAdapter { mStorageManager = storage_man; mFiles = mStorageManager.getDirectoryContent(mFile); mContext = context; + mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); } @Override @@ -111,7 +116,7 @@ public class FileListListAdapter implements ListAdapter { } ImageView downloaded = (ImageView) view.findViewById(R.id.imageView2); ImageView downloading = (ImageView) view.findViewById(R.id.imageView4); - if (file.isDownloading()) { + if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) { downloaded.setVisibility(View.INVISIBLE); downloading.setVisibility(View.VISIBLE); } else if (file.isDown()) { diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index ed986352a5..7101dd0634 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -362,7 +362,7 @@ public class FileDetailFragment extends SherlockFragment implements cb.setChecked(mFile.keepInSync()); // configure UI for depending upon local state of the file - if (mFile.isDownloading()) { + if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) { setButtonsForDownloading(); } else if (mFile.isDown()) {