X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/2f1aaa8b15cac2e5fe8fdae3b9a3d5214d7df2f0..a11e7fd9004d8672077d6e3db7d69b74ea46e163:/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 57667aa1..6d1524f7 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1,5 +1,6 @@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski + * Copyright (C) 2012-2013 ownCloud Inc. * * 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 @@ -21,7 +22,6 @@ package com.owncloud.android.ui.activity; import java.io.File; import android.accounts.Account; -import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.app.AlertDialog.Builder; @@ -86,12 +86,15 @@ import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.syncadapter.FileSyncService; import com.owncloud.android.ui.dialog.ChangelogDialog; +import com.owncloud.android.ui.dialog.EditNameDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog; +import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.OCFileListFragment; import com.owncloud.android.ui.preview.PreviewImageActivity; +import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; import com.owncloud.android.R; @@ -101,11 +104,11 @@ import eu.alefzero.webdav.WebdavClient; * Displays, what files the user has available in his ownCloud. * * @author Bartek Przybylski - * + * @author David A. Velasco */ public class FileDisplayActivity extends SherlockFragmentActivity implements - OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener { + OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener, EditNameDialogListener { private ArrayAdapter mDirectories; private OCFile mCurrentDir = null; @@ -123,6 +126,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private OCFileListFragment mFileList; private boolean mDualPane; + private boolean mBackFromCreatingFirstAccount; private static final int DIALOG_SETUP_ACCOUNT = 0; private static final int DIALOG_CREATE_DIR = 1; @@ -151,10 +155,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements super.onCreate(savedInstanceState); /// Load of parameters from received intent - mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT); - if (account != null) - AccountUtils.setCurrentOwnCloudAccount(this, account.name); + if (account != null && AccountUtils.setCurrentOwnCloudAccount(this, account.name)) { + mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); + } /// Load of saved instance state: keep this always before initDataFromCurrentAccount() if(savedInstanceState != null) { @@ -199,7 +203,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // Drop-down navigation mDirectories = new CustomArrayAdapter(this, R.layout.sherlock_spinner_dropdown_item); OCFile currFile = mCurrentDir; - while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) { + while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) { mDirectories.add(currFile.getFileName()); currFile = mStorageManager.getFileById(currFile.getParentId()); } @@ -211,6 +215,19 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements mDualPane = (findViewById(R.id.file_details_container) != null); if (mDualPane) { initFileDetailsInDualPane(); + } else { + // quick patchES to fix problem in turn from landscape to portrait, when a file is selected in the right pane + // TODO serious refactorization in activities and fragments providing file browsing and handling + if (mCurrentFile != null) { + onFileClick(mCurrentFile); + mCurrentFile = null; + } + Fragment rightPanel = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + if (rightPanel != null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.remove(rightPanel); + transaction.commit(); + } } // Action bar setup @@ -224,7 +241,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // show changelog, if needed - showChangeLog(); + //showChangeLog(); + mBackFromCreatingFirstAccount = false; Log.d(getClass().toString(), "onCreate() end"); } @@ -265,7 +283,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements startActivity(intent); // the new activity won't be created until this.onStart() and this.onResume() are finished; } - + /** * Load of state dependent of the existence of an ownCloud account */ @@ -367,7 +385,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements boolean retval = true; switch (item.getItemId()) { case R.id.action_create_dir: { - showDialog(DIALOG_CREATE_DIR); + EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.uploader_info_dirname), "", this); + dialog.show(getSupportFragmentManager(), "createdirdialog"); break; } case R.id.action_sync_account: { @@ -561,7 +580,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } @Override - protected void onResume() { + public void onResume() { Log.d(getClass().toString(), "onResume() start"); super.onResume(); @@ -573,6 +592,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements if (mDualPane) { initFileDetailsInDualPane(); } + mBackFromCreatingFirstAccount = true; } // Listen for sync messages @@ -587,7 +607,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // Listen for download messages IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_ADDED_MESSAGE); - //downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE); + downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE); mDownloadFinishReceiver = new DownloadFinishReceiver(); registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); @@ -605,7 +625,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements @Override - protected void onPause() { + public void onPause() { Log.d(getClass().toString(), "onPause() start"); super.onPause(); if (mSyncBroadcastReceiver != null) { @@ -736,27 +756,45 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements break; } case DIALOG_CHOOSE_UPLOAD_SOURCE: { - final String [] items = { getString(R.string.actionbar_upload_files), - getString(R.string.actionbar_upload_from_apps) }; + + String[] items = null; + + String[] allTheItems = { getString(R.string.actionbar_upload_files), + getString(R.string.actionbar_upload_from_apps), + getString(R.string.actionbar_failed_instant_upload) }; + + String[] commonItems = { getString(R.string.actionbar_upload_files), + getString(R.string.actionbar_upload_from_apps) }; + + if (InstantUploadActivity.IS_ENABLED) + items = allTheItems; + else + items = commonItems; + builder = new AlertDialog.Builder(this); builder.setTitle(R.string.actionbar_upload); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { - //if (!mDualPane) { - Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class); - action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this)); - startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); - //} else { - // TODO create and handle new fragment LocalFileListFragment - //} + // if (!mDualPane) { + Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class); + action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, + AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this)); + startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); + // } else { + // TODO create and handle new fragment + // LocalFileListFragment + // } } else if (item == 1) { Intent action = new Intent(Intent.ACTION_GET_CONTENT); - action = action.setType("*/*") - .addCategory(Intent.CATEGORY_OPENABLE); - startActivityForResult( - Intent.createChooser(action, getString(R.string.upload_chooser_title)), + action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE); + startActivityForResult(Intent.createChooser(action, getString(R.string.upload_chooser_title)), ACTION_SELECT_CONTENT_FROM_APPS); + } else if (item == 2 && InstantUploadActivity.IS_ENABLED) { + Account account = AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this); + Intent action = new Intent(FileDisplayActivity.this, InstantUploadActivity.class); + action.putExtra(FileUploader.KEY_ACCOUNT, account); + startActivity(action); } } }); @@ -943,6 +981,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } setSupportProgressBarIndeterminateVisibility(inProgress); + if (mBackFromCreatingFirstAccount) { + // awful patch to fix problem with visibility of progress circle with the first refresh of the first account + // TODO - kill this Activity when the first account has to be created instead of stack the account creation on it + getSupportActionBar().hide(); + getSupportActionBar().show(); + mBackFromCreatingFirstAccount = false; + } removeStickyBroadcast(intent); } @@ -982,42 +1027,78 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements /** - * Once the file download has finished -> update view + * Class waiting for broadcast events from the {@link FielDownloader} service. + * + * Updates the UI when a download is started or finished, provided that it is relevant for the + * current folder. */ private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + boolean sameAccount = isSameAccount(context, intent); String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); - String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); - if (accountName != null && AccountUtils.getCurrentOwnCloudAccount(context) != null) { - boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); - boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath())); - if (sameAccount && isDescendant) { - OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); - if (fileListFragment != null) { - fileListFragment.listDirectory(); - if ( mWaitingToPreview != null && - mWaitingToPreview.getRemotePath().equals(downloadedRemotePath) && - intent.getAction().equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE) ) { - - Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); - if (fragment != null && fragment instanceof FileDetailFragment ) { - FileDetailFragment detailFragment = (FileDetailFragment) fragment; - if (detailFragment.getFile().getRemotePath().equals(downloadedRemotePath)) { - detailFragment.listenForTransferProgress(); - detailFragment.updateFileDetails(true); - } - } - } - } + boolean isDescendant = isDescendant(downloadedRemotePath); + + if (sameAccount && isDescendant) { + updateLeftPanel(); + if (mDualPane) { + updateRightPanel(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)); } } + + removeStickyBroadcast(intent); + } + + private boolean isDescendant(String downloadedRemotePath) { + return (mCurrentDir != null && downloadedRemotePath != null && downloadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + } + + private boolean isSameAccount(Context context, Intent intent) { + String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); + return (accountName != null && accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)); } } - - + protected void updateLeftPanel() { + OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + } + } + + protected void updateRightPanel(String downloadEvent, String downloadedRemotePath, boolean success) { + Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + boolean waitedPreview = (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(downloadedRemotePath)); + if (fragment != null && fragment instanceof FileDetailFragment) { + FileDetailFragment detailsFragment = (FileDetailFragment) fragment; + OCFile fileInFragment = detailsFragment.getFile(); + if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) { + // the user browsed to other file ; forget the automatic preview + mWaitingToPreview = null; + + } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) { + // grant that the right panel updates the progress bar + detailsFragment.listenForTransferProgress(); + detailsFragment.updateFileDetails(true, false); + + } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) { + // update the right panel + if (success && waitedPreview) { + mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId()); // update the file from database, for the local storage path + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mWaitingToPreview, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG); + transaction.commit(); + mWaitingToPreview = null; + + } else { + detailsFragment.updateFileDetails(false, (success)); + } + } + } + } + + /** * {@inheritDoc} */ @@ -1026,7 +1107,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements return mStorageManager; } - + /** * {@inheritDoc} */ @@ -1053,15 +1134,14 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements */ @Override public void onFileClick(OCFile file) { - - if (file != null && PreviewMediaFragment.canBePreviewed(file)) { - if (file.isImage()) { - // preview image - it handles the download, if needed - startPreviewImage(file); - - } else if (file.isDown()) { + if (file != null && PreviewImageFragment.canBePreviewed(file)) { + // preview image - it handles the download, if needed + startPreviewImage(file); + + } else if (file != null && PreviewMediaFragment.canBePreviewed(file)) { + if (file.isDown()) { // general preview - startOtherPreview(file); + startMediaPreview(file); } else { // automatic download, preview on finish @@ -1081,7 +1161,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements startActivity(showDetailsIntent); } - private void startOtherPreview(OCFile file) { + private void startMediaPreview(OCFile file) { if (mDualPane) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.file_details_container, new PreviewMediaFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG); @@ -1191,7 +1271,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements if (fragment != null && fragment instanceof FileDetailFragment) { FileDetailFragment detailFragment = (FileDetailFragment)fragment; detailFragment.listenForTransferProgress(); - detailFragment.updateFileDetails(false); + detailFragment.updateFileDetails(false, false); } } } @@ -1374,7 +1454,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements if (downloading || uploading) { ((FileDetailFragment)details).updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this)); } else { - ((FileDetailFragment)details).updateFileDetails(downloading || uploading); + ((FileDetailFragment)details).updateFileDetails(false, true); } } } @@ -1397,21 +1477,33 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } } - - @Override - public void notifySuccessfulDownload(OCFile file, Intent intent, boolean success) { - if (success) { - if (mWaitingToPreview != null) { - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - transaction.replace(R.id.file_details_container, new PreviewMediaFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG); - transaction.commit(); - mWaitingToPreview = null; + public void onDismiss(EditNameDialog dialog) { + //dialog.dismiss(); + if (dialog.getResult()) { + String newDirectoryName = dialog.getNewFilename().trim(); + Log.d(TAG, "'create directory' dialog dismissed with new name " + newDirectoryName); + if (newDirectoryName.length() > 0) { + String path; + if (mCurrentDir == null) { + // this is just a patch; we should ensure that mCurrentDir never is null + if (!mStorageManager.fileExists(OCFile.PATH_SEPARATOR)) { + OCFile file = new OCFile(OCFile.PATH_SEPARATOR); + mStorageManager.saveFile(file); + } + mCurrentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR); + } + path = FileDisplayActivity.this.mCurrentDir.getRemotePath(); + + // Create directory + path += newDirectoryName + OCFile.PATH_SEPARATOR; + Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler())); + thread.start(); + + showDialog(DIALOG_SHORT_WAIT); } } - mDownloadFinishReceiver.onReceive(this, intent); } - private void requestForDownload() { Account account = AccountUtils.getCurrentOwnCloudAccount(this); if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) { @@ -1424,3 +1516,4 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } +