X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b22ad95e2fe78bc03a43c83dfef6232a187d8fdd..a70c4c658fa261a1944c7ca12ee3cea3e58e7ad5:/src/eu/alefzero/owncloud/files/services/FileDownloader.java diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java index 323faf46..9c9b3eff 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/src/eu/alefzero/owncloud/files/services/FileDownloader.java @@ -11,7 +11,6 @@ import android.app.PendingIntent; import android.app.Service; import android.content.ContentValues; import android.content.Intent; -import android.net.Uri; import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; @@ -21,18 +20,15 @@ import android.os.Message; import android.os.Process; import android.util.Log; import android.widget.RemoteViews; -import eu.alefzero.owncloud.AccountUtils; import eu.alefzero.owncloud.R; -import eu.alefzero.owncloud.R.drawable; import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta; import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener; -import eu.alefzero.owncloud.ui.activity.FileDisplayActivity; -import eu.alefzero.owncloud.utils.OwnCloudVersion; import eu.alefzero.webdav.WebdavClient; public class FileDownloader extends Service implements OnDatatransferProgressListener { public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH"; + public static final String EXTRA_DOWNLOAD_RESULT = "RESULT"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; public static final String EXTRA_FILE_PATH = "FILE_PATH"; public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH"; @@ -99,13 +95,9 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis void downloadFile() { AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE); - String oc_base_url = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); - OwnCloudVersion ocv = new OwnCloudVersion(am - .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); - String webdav_path = AccountUtils.getWebdavPath(ocv); - Uri oc_url = Uri.parse(oc_base_url+webdav_path); - WebdavClient wdc = new WebdavClient(Uri.parse(oc_base_url + webdav_path)); + + WebdavClient wdc = new WebdavClient(mAccount, getApplicationContext()); String username = mAccount.name.split("@")[0]; String password = ""; @@ -135,15 +127,9 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis File sdCard = Environment.getExternalStorageDirectory(); File file = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + mFilePath); - try { - file.getParentFile().mkdirs(); - file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } + file.getParentFile().mkdirs(); - Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString()); - Log.e(TAG, mFilePath+""); + boolean download_result = false; if (wdc.downloadFile(mRemotePath, file)) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath()); @@ -155,10 +141,13 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis new String[] { mFilePath.substring(mFilePath.lastIndexOf('/') + 1), mAccount.name }); + download_result = true; } + mNotificationMngr.cancel(1); Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE); end.putExtra(EXTRA_FILE_PATH, file.getAbsolutePath()); + end.putExtra(EXTRA_DOWNLOAD_RESULT, download_result); sendBroadcast(end); }