X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c6b553f635c7cbb4f21d41a6fa82e204447c16cf..a032bdeebc51a6e81d1bd5c558944f96fc55eacb:/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 45f7c77d..163fea42 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -48,6 +48,7 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.OnNavigationListener; @@ -88,6 +89,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private DataStorageManager mStorageManager; private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; + private DownloadFinishReceiver mDownloadFinishReceiver; private View mLayoutView = null; private FileListFragment mFileList; @@ -223,20 +225,29 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ACTION_SELECT_FILE) { if (resultCode == RESULT_OK) { - Uri selectedImageUri = data.getData(); - - String filemanagerstring = selectedImageUri.getPath(); - String selectedImagePath = getPath(selectedImageUri); - String filepath; - - if (selectedImagePath != null) - filepath = selectedImagePath; - else - filepath = filemanagerstring; - - if (filepath == null) { - Log.e("FileDisplay", "Couldnt resolve path to file"); - return; + String filepath = null; + try { + Uri selectedImageUri = data.getData(); + + String filemanagerstring = selectedImageUri.getPath(); + String selectedImagePath = getPath(selectedImageUri); + + if (selectedImagePath != null) + filepath = selectedImagePath; + else + filepath = filemanagerstring; + + } catch (Exception e) { + Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e); + e.printStackTrace(); + + } finally { + if (filepath == null) { + Log.e("FileDisplay", "Couldnt resolve path to file"); + Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG); + t.show(); + return; + } } Intent i = new Intent(this, FileUploader.class); @@ -319,6 +330,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE); mUploadFinishReceiver = new UploadFinishReceiver(); registerReceiver(mUploadFinishReceiver, uploadIntentFilter); + + // Listen for download messages + IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE); + mDownloadFinishReceiver = new DownloadFinishReceiver(); + registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); // Storage manager initialization mStorageManager = new FileDataStorageManager( @@ -400,6 +416,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements unregisterReceiver(mUploadFinishReceiver); mUploadFinishReceiver = null; } + if (mDownloadFinishReceiver != null) { + unregisterReceiver(mDownloadFinishReceiver); + mDownloadFinishReceiver = null; + } + getIntent().putExtra(FileDetailFragment.EXTRA_FILE, mCurrentDir); Log.i(getClass().toString(), "onPause() end"); } @@ -618,13 +639,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onReceive(Context context, Intent intent) { boolean inProgress = intent.getBooleanExtra( FileSyncService.IN_PROGRESS, false); - String account_name = intent + String accountName = intent .getStringExtra(FileSyncService.ACCOUNT_NAME); - Log.d("FileDisplay", "sync of account " + account_name + Log.d("FileDisplay", "sync of account " + accountName + " is in_progress: " + inProgress); - if (account_name.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) { + if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) { String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); @@ -634,10 +655,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements fillBlankRoot = (mCurrentDir != null); } - if (synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath) || fillBlankRoot) ) { + if ((synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath))) + || fillBlankRoot ) { + if (!fillBlankRoot) + mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath); FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager() .findFragmentById(R.id.fileList); - mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath); if (fileListFragment != null) { fileListFragment.listDirectory(mCurrentDir); } @@ -660,10 +683,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onReceive(Context context, Intent intent) { long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1); OCFile parentDir = mStorageManager.getFileById(parentDirId); - - if (parentDir != null && ( - (mCurrentDir == null && parentDir.getFileName().equals("/")) || - parentDir.equals(mCurrentDir)) + String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); + + if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && + parentDir != null && + ( (mCurrentDir == null && parentDir.getFileName().equals("/")) || + parentDir.equals(mCurrentDir) + ) ) { FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { @@ -673,6 +699,26 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } } + + + /** + * Once the file download has finished -> update view + */ + private class DownloadFinishReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); + String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); + + if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && + mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) { + FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + } + } + } + } @Override