import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.CreateShareOperation;
+import com.owncloud.android.operations.MoveFileOperation;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
*/
public class FileDisplayActivity extends HookActivity implements
-FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener {
-
+FileFragment.ContainerActivity, OnNavigationListener,
+OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
+
private ArrayAdapter<String> mDirectories;
private SyncBroadcastReceiver mSyncBroadcastReceiver;
private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
+ public static final int ACTION_MOVE_FILES = 3;
private static final String TAG = FileDisplayActivity.class.getSimpleName();
getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation
setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); // always AFTER setContentView(...) ; to work around bug in its implementation
- showMessageView();
+ setBackgroundText();
Log_OC.d(TAG, "onCreate() end");
}
} else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
requestMultipleUpload(data, resultCode);
+ } else if (requestCode == ACTION_MOVE_FILES && (resultCode == RESULT_OK ||
+ resultCode == MoveActivity.RESULT_OK_AND_MOVE)){
+ requestMoveOperation(data, resultCode);
}
}
startService(i);
}
+ /**
+ * Request the operation for moving the file/folder from one path to another
+ *
+ * @param data Intent received
+ * @param resultCode Result code received
+ */
+ private void requestMoveOperation(Intent data, int resultCode) {
+ OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(MoveActivity.EXTRA_CURRENT_FOLDER);
+ getFileOperationsHelper().moveFile(folderToMoveAt, getCurrentDir());
+ }
+
@Override
public void onBackPressed() {
OCFileListFragment listOfFiles = getListOfFilesFragment();
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
- showMessageView();
+ setBackgroundText();
}
* Show a text message on screen view for notifying user if content is
* loading or folder is empty
*/
- private void showMessageView() {
+ private void setBackgroundText() {
OCFileListFragment ocFileListFragment = getListOfFilesFragment();
if (ocFileListFragment != null) {
int message = R.string.file_list_loading;
// In case file list is empty
message = R.string.file_list_empty;
}
- ocFileListFragment.setMessageforEmptyView(message);
+ ocFileListFragment.setMessageForEmptyList(getString(message));
} else {
Log.e(TAG, "OCFileListFragment is null");
}
} else if (operation instanceof UnshareLinkOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
- }
+ } else if (operation instanceof MoveFileOperation) {
+ onMoveFileOperationFinish((MoveFileOperation)operation, result);
+ }
}
/**
- * Updates the view associated to the activity after the finish of an operation trying create a new folder
+ * Updates the view associated to the activity after the finish of an operation trying to move a
+ * file.
*
- * @param operation Creation operation performed.
- * @param result Result of the creation.
+ * @param operation Move operation performed.
+ * @param result Result of the move operation.
*/
- private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {
+ private void onMoveFileOperationFinish(MoveFileOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
dismissLoadingDialog();
refreshListOfFilesFragment();
}
}
+ /**
+ * Updates the view associated to the activity after the finish of an operation trying create a new folder
+ *
+ * @param operation Creation operation performed.
+ * @param result Result of the creation.
+ */
+ private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {
+ if (result.isSuccess()) {
+ dismissLoadingDialog();
+ refreshListOfFilesFragment();
+ } else {
+ dismissLoadingDialog();
+ try {
+ Toast msg = Toast.makeText(FileDisplayActivity.this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ msg.show();
+
+ } catch (NotFoundException e) {
+ Log_OC.e(TAG, "Error while trying to show fail message " , e);
+ }
+ }
+ }
+
/**
* {@inheritDoc}
setSupportProgressBarIndeterminateVisibility(true);
- showMessageView();
+ setBackgroundText();
}
/**
}
onTransferStateChanged(file, false, false);
}
-
+
+ @Override
+ public void onRefresh() {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ OCFile folder = listOfFiles.getCurrentFile();
+ if (folder != null) {
+ /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
+ listDirectory(mFile);*/
+ startSyncFolderOperation(folder);
+ }
+ }
+ }
+
}