X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/7fead3cb22a70f8b2bb23a7e981c5ee3708dd523..d6ccd4c9600822b08141ecaa7d19aed614ca2ed5:/src/com/owncloud/android/ui/activity/FileDisplayActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 3d8f22cf..77612e3a 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -69,6 +69,7 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader; +import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.network.OwnCloudClientUtils; import com.owncloud.android.syncadapter.FileSyncService; import com.owncloud.android.ui.fragment.FileDetailFragment; @@ -96,6 +97,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private UploadFinishReceiver mUploadFinishReceiver; private DownloadFinishReceiver mDownloadFinishReceiver; private FileDownloaderBinder mDownloaderBinder = null; + private FileUploaderBinder mUploaderBinder = null; + private ServiceConnection mDownloadConnection = null, mUploadConnection = null; private OCFileListFragment mFileList; @@ -140,7 +143,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } - bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE); + mUploadConnection = new ListServiceConnection(); + mDownloadConnection = new ListServiceConnection(); + bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE); + bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE); // PIN CODE request ; best location is to decide, let's try this first if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) { @@ -216,7 +222,9 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements mCurrentDir = mStorageManager.getFileByPath(mCurrentDir.getRemotePath()); // mCurrentDir == null if it is not in the current account } if (mCurrentFile != null) { - mCurrentFile = mStorageManager.getFileByPath(mCurrentFile.getRemotePath()); // mCurrentFile == null if it is not in the current account + if (mCurrentFile.fileExists()) { + mCurrentFile = mStorageManager.getFileByPath(mCurrentFile.getRemotePath()); // mCurrentFile == null if it is not in the current account + } // else : keep mCurrentFile with the received value; this is currently the case of an upload in progress, when the user presses the status notification in a landscape tablet } /// Default to root if mCurrentDir was not found @@ -243,7 +251,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements @Override public void onDestroy() { super.onDestroy(); - unbindService(mConnection); + if (mDownloadConnection != null) + unbindService(mDownloadConnection); + if (mUploadConnection != null) + unbindService(mUploadConnection); } @@ -433,9 +444,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir); if (mDualPane) { FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); - OCFile file = fragment.getDisplayedFile(); - if (file != null) { - outState.putParcelable(FileDetailFragment.EXTRA_FILE, file); + if (fragment != null) { + OCFile file = fragment.getDisplayedFile(); + if (file != null) { + outState.putParcelable(FileDetailFragment.EXTRA_FILE, file); + } } } Log.d(getClass().toString(), "onSaveInstanceState() end"); @@ -932,15 +945,32 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public FileDownloaderBinder getFileDownloaderBinder() { return mDownloaderBinder; } + + + /** + * {@inheritDoc} + */ + @Override + public FileUploaderBinder getFileUploaderBinder() { + return mUploaderBinder; + } /** Defines callbacks for service binding, passed to bindService() */ - private ServiceConnection mConnection = new ServiceConnection() { + private class ListServiceConnection implements ServiceConnection { @Override - public void onServiceConnected(ComponentName className, IBinder service) { - mDownloaderBinder = (FileDownloaderBinder) service; - // a new chance to get the mDownloadBinder through getDownloadBinder() - THIS IS A MESS + public void onServiceConnected(ComponentName component, IBinder service) { + if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) { + Log.d(TAG, "Download service connected"); + mDownloaderBinder = (FileDownloaderBinder) service; + } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) { + Log.d(TAG, "Upload service connected"); + mUploaderBinder = (FileUploaderBinder) service; + } else { + return; + } + // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS if (mFileList != null) mFileList.listDirectory(); if (mDualPane) { @@ -951,8 +981,14 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } @Override - public void onServiceDisconnected(ComponentName arg0) { - mDownloaderBinder = null; + public void onServiceDisconnected(ComponentName component) { + if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) { + Log.d(TAG, "Download service disconnected"); + mDownloaderBinder = null; + } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) { + Log.d(TAG, "Upload service disconnected"); + mUploaderBinder = null; + } } };