import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SyncRequest;
+import android.content.res.Configuration;
import android.content.res.Resources.NotFoundException;
import android.database.Cursor;
import android.net.Uri;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.operations.CreateFolderOperation;
-import com.owncloud.android.lib.operations.common.RemoteOperation;
-import com.owncloud.android.lib.operations.common.RemoteOperationResult;
-import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
+import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.EditNameDialog;
* @author David A. Velasco
*/
-public class FileDisplayActivity extends FileActivity implements
+public class FileDisplayActivity extends HookActivity implements
OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, EditNameDialogListener {
private ArrayAdapter<String> mDirectories;
private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
- private static final String KEY_REFRESH_SHARES_IN_PROGRESS = "SHARES_IN_PROGRESS";
+ //private static final String KEY_REFRESH_SHARES_IN_PROGRESS = "SHARES_IN_PROGRESS";
+ private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND";
public static final int DIALOG_SHORT_WAIT = 0;
private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
private boolean mSyncInProgress = false;
//private boolean mRefreshSharesInProgress = false;
+ private OCFile mWaitingToSend;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreate() start");
mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
//mRefreshSharesInProgress = savedInstanceState.getBoolean(KEY_REFRESH_SHARES_IN_PROGRESS);
+ mWaitingToSend = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND);
} else {
mWaitingToPreview = null;
mSyncInProgress = false;
//mRefreshSharesInProgress = false;
+ mWaitingToSend = null;
}
/// USER INTERFACE
mRightFragmentContainer = findViewById(R.id.right_fragment_container);
if (savedInstanceState == null) {
createMinFragments();
+ } else {
+ Log_OC.d(TAG, "Init the secondFragment again");
+ if (mDualPane) {
+ initFragmentsWithFile();
+ }
}
// Action bar setup
protected void onStart() {
super.onStart();
getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
+ refeshListOfFilesFragment();
}
@Override
unbindService(mUploadConnection);
}
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ }
/**
* Called when the ownCloud {@link Account} associated to the Activity was just updated.
transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
transaction.commit();
}
-
+
private void initFragmentsWithFile() {
if (getAccount() != null && getFile() != null) {
/// First fragment
// the next operation triggers a new call to this method, but it's necessary to
// ensure that the name exposed in the action bar is the current directory when the
// user selected it in the navigation list
- getSupportActionBar().setSelectedNavigationItem(0);
+ if (getSupportActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST && itemPosition != 0)
+ getSupportActionBar().setSelectedNavigationItem(0);
}
return true;
}
outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress);
//outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS, mRefreshSharesInProgress);
+ outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend);
Log_OC.d(TAG, "onSaveInstanceState() end");
}
((TextView) v).setTextColor(getResources().getColorStateList(
android.R.color.white));
+
+ fixRoot((TextView) v );
return v;
}
((TextView) v).setTextColor(getResources().getColorStateList(
android.R.color.white));
+ fixRoot((TextView) v );
return v;
}
+ private void fixRoot(TextView v) {
+ if (v.getText().equals(OCFile.PATH_SEPARATOR)) {
+ v.setText(R.string.default_display_name_for_root_folder);
+ }
+ }
+
}
private class SyncBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String event = intent.getAction();
+ Log_OC.d(TAG, "Received broadcast " + event);
String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncAdapter.EXTRA_RESULT);
if (sameAccount) {
- if (!FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
+ if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
+ mSyncInProgress = true;
+
+ } else {
OCFile currentFile = (getFile() == null) ? null : getStorageManager().getFileByPath(getFile().getRemotePath());
OCFile currentDir = (getCurrentDir() == null) ? null : getStorageManager().getFileByPath(getCurrentDir().getRemotePath());
}
removeStickyBroadcast(intent);
+ Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
}
refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
}
+ if (mWaitingToSend != null) {
+ mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); // Update the file to send
+ if (mWaitingToSend.isDown()) {
+ sendDownloadedFile();
+ }
+ }
+
removeStickyBroadcast(intent);
}
if (chosenFile == null || mDualPane) {
// only list of files - set for browsing through folders
OCFile currentDir = getCurrentDir();
- actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0);
- actionBar.setDisplayShowTitleEnabled(false);
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ boolean noRoot = (currentDir != null && currentDir.getParentId() != 0);
+ actionBar.setDisplayHomeAsUpEnabled(noRoot);
+ actionBar.setDisplayShowTitleEnabled(!noRoot);
+ if (!noRoot) {
+ actionBar.setTitle(getString(R.string.default_display_name_for_root_folder));
+ }
+ actionBar.setNavigationMode(!noRoot ? ActionBar.NAVIGATION_MODE_STANDARD : ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(mDirectories, this); // assuming mDirectories is updated
} else {
} else if (operation instanceof CreateFolderOperation) {
onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
-
+
} else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
- }
+
+ } else if (operation instanceof UnshareLinkOperation) {
+ onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
+
+ }
}
-
+
private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
+ refreshShowDetails();
refeshListOfFilesFragment();
}
}
+ private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
+ if (result.isSuccess()) {
+ refreshShowDetails();
+ refeshListOfFilesFragment();
+ } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ cleanSecondFragment();
+ refeshListOfFilesFragment();
+ }
+ }
+
+ private void refreshShowDetails() {
+ FileFragment details = getSecondFragment();
+ if (details != null) {
+ OCFile file = details.getFile();
+ if (file != null) {
+ file = getStorageManager().getFileByPath(file.getRemotePath());
+ if (details instanceof PreviewMediaFragment) {
+ // Refresh OCFile of the fragment
+ ((PreviewMediaFragment) details).updateFile(file);
+ } else {
+ showDetails(file);
+ }
+ }
+ invalidateOptionsMenu();
+ }
+ }
+
/**
* Updates the view associated to the activity after the finish of an operation trying to remove a
* file.
RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
currentSyncTime,
false,
+ getFileOperationsHelper().isSharedSupported(this),
getStorageManager(),
getAccount(),
getApplicationContext()
}
*/
+ /**
+ * Requests the download of the received {@link OCFile} , updates the UI
+ * to monitor the download progress and prepares the activity to send the file
+ * when the download finishes.
+ *
+ * @param file {@link OCFile} to download and preview.
+ */
+ @Override
+ public void startDownloadForSending(OCFile file) {
+ mWaitingToSend = file;
+ requestForDownload(mWaitingToSend);
+ boolean hasSecondFragment = (getSecondFragment()!= null);
+ updateFragmentsVisibility(hasSecondFragment);
+ }
+
+ private void requestForDownload(OCFile file) {
+ Account account = getAccount();
+ if (!mDownloaderBinder.isDownloading(account, file)) {
+ Intent i = new Intent(this, FileDownloader.class);
+ i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
+ i.putExtra(FileDownloader.EXTRA_FILE, file);
+ startService(i);
+ }
+ }
+
+ private void sendDownloadedFile(){
+ getFileOperationsHelper().sendDownloadedFile(mWaitingToSend, this);
+ mWaitingToSend = null;
+ }
+
}