android:theme="@style/Theme.ownCloud">
<activity
android:name=".ui.activity.FileDisplayActivity"
- android:label="@string/app_name">
+ android:label="@string/app_name"
+ android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<activity android:name=".ui.activity.PreferencesNewSessionewSession" >
</activity>
- <activity android:name="com.owncloud.android.ui.preview.PreviewImageActivity" />
+ <activity android:name="com.owncloud.android.ui.preview.PreviewImageActivity" />
<activity android:name="com.owncloud.android.ui.preview.PreviewVideoActivity"
android:label="@string/app_name"
</activity>
<service
- android:name=".authenticator.AccountAuthenticatorService"
+ android:name=".authentication.AccountAuthenticatorService"
android:exported="true">
<intent-filter android:priority="100">
<action android:name="android.accounts.AccountAuthenticator" />
</provider>
<activity
- android:name=".ui.activity.AuthenticatorActivity"
+ android:name=".authentication.AuthenticatorActivity"
android:exported="true"
- android:theme="@style/Theme.ownCloud.noActionBar" >
+ android:theme="@style/Theme.ownCloud.noActionBar"
+ android:launchMode="singleTask">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:scheme="@string/oauth2_redirect_scheme" />
+ </intent-filter>
<intent-filter>
<action android:name="com.owncloud.android.workaround.accounts.CREATE" />
<category android:name="android.intent.category.DEFAULT" />
<service android:name=".files.services.FileUploader" />
<service android:name=".media.MediaService" />
- <activity android:name=".ui.activity.FileDetailActivity" />
+ <activity android:name=".ui.activity.FileDetailActivity" android:configChanges="orientation|screenSize"/>
<activity android:name=".ui.activity.PinCodeActivity" />
<activity android:name=".extensions.ExtensionsAvailableActivity"></activity>
<activity android:name=".extensions.ExtensionsListActivity"></activity>
<activity android:name=".ui.activity.LogHistoryActivity"/>
- <receiver android:name=".files.InstantUploadBroadcastReceiver">\r
- <intent-filter>\r
- <action android:name="com.android.camera.NEW_PICTURE" />\r
- <data android:mimeType="image/*" />\r
+ <receiver android:name=".files.InstantUploadBroadcastReceiver">
+ <intent-filter>
+ <action android:name="com.android.camera.NEW_PICTURE" />
+ <data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
- </intent-filter>\r
- </receiver>\r
- <receiver android:name=".files.BootupBroadcastReceiver">\r
- <intent-filter>\r
- <action android:name="android.intent.action.BOOT_COMPLETED"/>\r
- </intent-filter>\r
- </receiver>\r
- <service android:name=".files.services.FileObserverService"/>\r
- \r
- </application>\r
-\r
+ </intent-filter>
+ </receiver>
+ <receiver android:name=".files.BootupBroadcastReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"/>
+ </intent-filter>
+ </receiver>
+ <service android:name=".files.services.FileObserverService"/>
++
+ </application>
-
++
</manifest>
import android.accounts.Account;
import android.app.AlertDialog;
import android.app.ProgressDialog;
- import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.content.res.Resources.NotFoundException;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
- import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
- import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.AccountUtils;
import com.owncloud.android.Log_OC;
import com.owncloud.android.R;
- import com.owncloud.android.authenticator.AccountAuthenticator;
+ import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.datamodel.DataStorageManager;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileObserverService;
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.operations.CreateFolderOperation;
import com.owncloud.android.operations.OnRemoteOperationListener;
import com.owncloud.android.operations.RemoteOperation;
import com.owncloud.android.operations.RemoteOperationResult;
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.ui.preview.PreviewVideoActivity;
- import eu.alefzero.webdav.WebdavClient;
-
/**
* Displays, what files the user has available in his ownCloud.
*
private boolean mBackFromCreatingFirstAccount;
private static final int DIALOG_SETUP_ACCOUNT = 0;
- private static final int DIALOG_CREATE_DIR = 1;
- public static final int DIALOG_SHORT_WAIT = 3;
- private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 4;
- private static final int DIALOG_SSL_VALIDATOR = 5;
- private static final int DIALOG_CERT_NOT_SAVED = 6;
- private static final String DIALOG_CHANGELOG_TAG = "DIALOG_CHANGELOG";
-
+ public static final int DIALOG_SHORT_WAIT = 1;
+ private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 2;
+ private static final int DIALOG_SSL_VALIDATOR = 3;
+ private static final int DIALOG_CERT_NOT_SAVED = 4;
private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
private OCFile mWaitingToPreview;
private Handler mHandler;
+
+ private Configuration mNewConfigurationChangeToApplyOnStart;
+ private boolean mStarted;
@Override
public void onCreate(Bundle savedInstanceState) {
Log_OC.d(getClass().toString(), "onCreate() start");
super.onCreate(savedInstanceState);
+ mStarted = false;
+ mHandler = new Handler();
+
/// Load of parameters from received intent
Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);
if (account != null && AccountUtils.setCurrentOwnCloudAccount(this, account.name)) {
setContentView(R.layout.files);
mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
mDualPane = (findViewById(R.id.file_details_container) != null);
- if (mDualPane) {
- if (savedInstanceState == null) 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();
- }
+ if (mDualPane && savedInstanceState == null) {
+ initFileDetailsInDualPane();
}
// Action bar setup
}
+ @Override
+ public void onConfigurationChanged (Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ if (mStarted) {
+ checkConfigurationChange(newConfig);
+ } else {
+ mNewConfigurationChangeToApplyOnStart = newConfig;
+ }
+ }
+
+
/**
* Launches the account creation activity. To use when no ownCloud account is available
*/
private void createFirstAccount() {
Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
- intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });
+ intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTHORITY });
startActivity(intent); // the new activity won't be created until this.onStart() and this.onResume() are finished;
}
if (mCurrentFile != null) {
if (PreviewMediaFragment.canBePreviewed(mCurrentFile)) {
if (mCurrentFile.isDown()) {
- transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mCurrentFile, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);
+ int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
+ boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
+ transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mCurrentFile, AccountUtils.getCurrentOwnCloudAccount(this), startPlaybackPosition, autoplay), FileDetailFragment.FTAG);
} else {
transaction.replace(R.id.file_details_container, new FileDetailFragment(mCurrentFile, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);
mWaitingToPreview = mCurrentFile;
@Override
+ public void onStart() {
+ super.onStart();
+ if (mNewConfigurationChangeToApplyOnStart != null) {
+ checkConfigurationChange(mNewConfigurationChangeToApplyOnStart);
+ mNewConfigurationChangeToApplyOnStart = null;
+ }
+ mStarted = true;
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ mStarted = false;
+ }
+
+
+ private void checkConfigurationChange(Configuration newConfig) {
+ FileFragment fragment = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+ if (fragment != null
+ && fragment.getFile() != null
+ && (newConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
+ && newConfig.orientation != Configuration.ORIENTATION_LANDSCAPE) {
+
+ onFileClick(fragment.getFile(), true);
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.remove((Fragment)fragment);
+ transaction.commit();
+
+ } else {
+ finish();
+ Intent intent = new Intent(this, FileDisplayActivity.class);
+ intent.putExtra(FileDetailFragment.EXTRA_FILE, mCurrentDir);
+ intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
+ startActivity(intent);
+ }
+ }
+
+
+ @Override
public void onDestroy() {
super.onDestroy();
if (mDownloadConnection != null)
}
private void startSynchronization() {
- ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account
+ ContentResolver.cancelSync(null, AccountAuthenticator.AUTHORITY); // cancel the current synchronizations of any ownCloud account
Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(
AccountUtils.getCurrentOwnCloudAccount(this),
- AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);
+ AccountAuthenticator.AUTHORITY, bundle);
}
* Called, when the user selected something for uploading
*/
public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
requestSimpleUpload(data, resultCode);
outState.putParcelable(FileDetailActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
Log_OC.d(getClass().toString(), "onSaveInstanceState() end");
}
-
@Override
protected void onResume() {
dialog = builder.create();
break;
}
- case DIALOG_CREATE_DIR: {
- builder = new Builder(this);
- final EditText dirNameInput = new EditText(getBaseContext());
- builder.setView(dirNameInput);
- builder.setTitle(R.string.uploader_info_dirname);
- int typed_color = getResources().getColor(R.color.setup_text_typed);
- dirNameInput.setTextColor(typed_color);
- builder.setPositiveButton(android.R.string.ok,
- new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- String directoryName = dirNameInput.getText().toString();
- if (directoryName.trim().length() == 0) {
- dialog.cancel();
- return;
- }
-
- // Figure out the path where the dir needs to be created
- 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 += directoryName + OCFile.PATH_SEPARATOR;
- Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));
- thread.start();
-
- dialog.dismiss();
-
- showDialog(DIALOG_SHORT_WAIT);
- }
- });
- builder.setNegativeButton(R.string.common_cancel,
- new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- dialog = builder.create();
- break;
- }
case DIALOG_SHORT_WAIT: {
ProgressDialog working_dialog = new ProgressDialog(this);
working_dialog.setMessage(getResources().getString(
return !mDirectories.isEmpty();
}
- private class DirectoryCreator implements Runnable {
- private String mTargetPath;
- private Account mAccount;
- private Handler mHandler;
-
- public DirectoryCreator(String targetPath, Account account, Handler handler) {
- mTargetPath = targetPath;
- mAccount = account;
- mHandler = handler;
- }
-
- @Override
- public void run() {
- WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
- boolean created = wdc.createDirectory(mTargetPath);
- if (created) {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- dismissDialog(DIALOG_SHORT_WAIT);
-
- // Save new directory in local database
- OCFile newDir = new OCFile(mTargetPath);
- newDir.setMimetype("DIR");
- newDir.setParentId(mCurrentDir.getFileId());
- mStorageManager.saveFile(newDir);
-
- // Display the new folder right away
- mFileList.listDirectory();
- }
- });
-
- } else {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- dismissDialog(DIALOG_SHORT_WAIT);
- try {
- Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG);
- msg.show();
-
- } catch (NotFoundException e) {
- Log_OC.e(TAG, "Error while trying to show fail message ", e);
- }
- }
- });
- }
- }
-
- }
-
// Custom array adapter to override text colors
private class CustomArrayAdapter<T> extends ArrayAdapter<T> {
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.replace(R.id.file_details_container, new PreviewMediaFragment(mWaitingToPreview, AccountUtils.getCurrentOwnCloudAccount(this), 0, true), FileDetailFragment.FTAG);
transaction.commit();
mWaitingToPreview = null;
* {@inheritDoc}
*/
@Override
- public void onFileClick(OCFile file) {
+ public void onFileClick(OCFile file, boolean onOrientationChange) {
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
- startMediaPreview(file);
+ if (!onOrientationChange) {
+ startMediaPreview(file, 0, true, onOrientationChange);
+ } else {
+ int startPlaybackPosition = 0;
+ boolean autoplay = true;
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+ if (fragment != null && file.isVideo()) {
+ PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
+ startPlaybackPosition = videoFragment.getPosition();
+ autoplay = videoFragment.isPlaying();
+ }
+ startMediaPreview(file, startPlaybackPosition, autoplay, onOrientationChange);
+ }
} else {
// automatic download, preview on finish
- startDownloadForPreview(file);
+ startDownloadForPreview(file, onOrientationChange);
}
} else {
// details view
- startDetails(file);
+ startDetails(file, onOrientationChange);
}
}
startActivity(showDetailsIntent);
}
- private void startMediaPreview(OCFile file) {
- if (mDualPane) {
+ private void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay, boolean onOrientationChange) {
+ if (mDualPane && !onOrientationChange) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new PreviewMediaFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);
+ transaction.replace(R.id.file_details_container, new PreviewMediaFragment(file, AccountUtils.getCurrentOwnCloudAccount(this), startPlaybackPosition, autoplay), FileDetailFragment.FTAG);
transaction.commit();
} else {
Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
+ showDetailsIntent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, startPlaybackPosition);
+ showDetailsIntent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, autoplay);
startActivity(showDetailsIntent);
}
}
- private void startDownloadForPreview(OCFile file) {
- if (mDualPane) {
+ private void startDownloadForPreview(OCFile file, boolean onOrientationChange) {
+ if (mDualPane && !onOrientationChange) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);
transaction.commit();
}
- private void startDetails(OCFile file) {
- if (mDualPane && !file.isImage()) {
+ private void startDetails(OCFile file, boolean onOrientationChange) {
+ if (mDualPane && !file.isImage() && !onOrientationChange) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);
transaction.commit();
} else if (operation instanceof SynchronizeFileOperation) {
onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
+
+ } else if (operation instanceof CreateFolderOperation) {
+ onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
}
}
}
/**
+ * 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()) {
+ dismissDialog(DIALOG_SHORT_WAIT);
+ mFileList.listDirectory();
+
+ } else {
+ dismissDialog(DIALOG_SHORT_WAIT);
+ try {
+ Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG);
+ msg.show();
+
+ } catch (NotFoundException e) {
+ Log_OC.e(TAG, "Error while trying to show fail message " , e);
+ }
+ }
+ }
+
+
+ /**
* Updates the view associated to the activity after the finish of an operation trying to rename a
* file.
*
//dialog.dismiss();
if (dialog.getResult()) {
String newDirectoryName = dialog.getNewFilename().trim();
- Log.d(TAG, "'create directory' dialog dismissed with new name " + newDirectoryName);
+ Log_OC.d(TAG, "'create directory' dialog dismissed with new name " + newDirectoryName);
if (newDirectoryName.length() > 0) {
String path;
if (mCurrentDir == null) {
// Create directory
path += newDirectoryName + OCFile.PATH_SEPARATOR;
- Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));
- thread.start();
+ RemoteOperation operation = new CreateFolderOperation(path, mCurrentDir.getFileId(), mStorageManager);
+ operation.execute( AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this),
+ FileDisplayActivity.this,
+ FileDisplayActivity.this,
+ mHandler,
+ FileDisplayActivity.this);
showDialog(DIALOG_SHORT_WAIT);
}
}
}
-
+
+
private void requestForDownload() {
Account account = AccountUtils.getCurrentOwnCloudAccount(this);
if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
import java.io.File;
import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
- import org.apache.commons.httpclient.methods.GetMethod;
- import org.apache.commons.httpclient.methods.PostMethod;
- import org.apache.commons.httpclient.methods.StringRequestEntity;
- import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
- import org.apache.http.HttpStatus;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.utils.URLEncodedUtils;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.protocol.HTTP;
- import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
- import org.json.JSONObject;
-
import android.accounts.Account;
+import android.accounts.AccountManager;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
- import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
-import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragment;
- import com.owncloud.android.AccountUtils;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
import com.owncloud.android.DisplayUtils;
import com.owncloud.android.Log_OC;
- import com.owncloud.android.authenticator.AccountAuthenticator;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileObserverService;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
+import com.owncloud.android.network.OwnCloudClientUtils;
import com.owncloud.android.operations.OnRemoteOperationListener;
import com.owncloud.android.operations.RemoteOperation;
import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.dialog.EditNameDialog;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
- import com.owncloud.android.utils.OwnCloudVersion;
import com.owncloud.android.R;
import eu.alefzero.webdav.OnDatatransferProgressListener;
+import eu.alefzero.webdav.WebdavClient;
import eu.alefzero.webdav.WebdavUtils;
-
/**
* This Fragment is used to display the details about a file.
*
mProgressListener = null;
}
-
/**
* Creates a details fragment.
*
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHandler = new Handler();
+ setHasOptionsMenu(true);
}
if (mLayout == R.layout.file_details_fragment) {
mView.findViewById(R.id.fdKeepInSync).setOnClickListener(this);
- mView.findViewById(R.id.fdRenameBtn).setOnClickListener(this);
- mView.findViewById(R.id.fdDownloadBtn).setOnClickListener(this);
- mView.findViewById(R.id.fdOpenBtn).setOnClickListener(this);
- mView.findViewById(R.id.fdRemoveBtn).setOnClickListener(this);
- //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this);
ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.fdProgressBar);
mProgressListener = new ProgressListener(progressBar);
+ mView.findViewById(R.id.fdCancelBtn).setOnClickListener(this);
}
updateFileDetails(false, false);
return view;
}
-
/**
* {@inheritDoc}
*/
}
- @Override\r
- public View getView() {\r
- return super.getView() == null ? mView : super.getView();\r
- }\r
-
- \r
- @Override\r
- public void onClick(View v) {\r
- switch (v.getId()) {\r
- case R.id.fdDownloadBtn: {\r
- FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();\r
- FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();\r
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {\r
- downloaderBinder.cancel(mAccount, mFile);\r
- if (mFile.isDown()) {\r
- setButtonsForDown();\r
- } else {\r
- setButtonsForRemote();\r
- }\r
-\r
- } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {\r
- uploaderBinder.cancel(mAccount, mFile);\r
- if (!mFile.fileExists()) {\r
- // TODO make something better\r
- if (getActivity() instanceof FileDisplayActivity) {\r
- // double pane\r
- FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();\r
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment\r
- transaction.commit();\r
- mContainerActivity.onFileStateChanged();\r
- } else {\r
- getActivity().finish();\r
- }\r
- \r
- } else if (mFile.isDown()) {\r
- setButtonsForDown();\r
- } else {\r
- setButtonsForRemote();\r
- }\r
- \r
- } else {\r
- mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity());\r
- mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());\r
- \r
- // update ui \r
- boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
- getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
- setButtonsForTransferring(); // disable button immediately, although the synchronization does not result in a file transference\r
- \r
- }\r
- break;\r
- }\r
- case R.id.fdKeepInSync: {
- CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
- mFile.setKeepInSync(cb.isChecked());
- mStorageManager.saveFile(mFile);
-
- /// register the OCFile instance in the observer service to monitor local updates;
- /// if necessary, the file is download
- Intent intent = new Intent(getActivity().getApplicationContext(),
- FileObserverService.class);
- intent.putExtra(FileObserverService.KEY_FILE_CMD,
- (cb.isChecked()?
- FileObserverService.CMD_ADD_OBSERVED_FILE:
- FileObserverService.CMD_DEL_OBSERVED_FILE));
- intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
- intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
- getActivity().startService(intent);
-
- if (mFile.keepInSync()) {
- onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization
- }
- break;
+ @Override
+ public View getView() {
+ return super.getView() == null ? mView : super.getView();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ super.onCreateOptionsMenu(menu, inflater);
+ inflater.inflate(R.menu.file_actions_menu, menu);
+ MenuItem item = menu.findItem(R.id.action_see_details);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onPrepareOptionsMenu (Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+
+ List<Integer> toHide = new ArrayList<Integer>();
+ List<Integer> toShow = new ArrayList<Integer>();
+
+ FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
+ boolean downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile);
+ FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
+ boolean uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile);
+
+ if (downloading || uploading) {
+ toHide.add(R.id.action_download_file);
+ toHide.add(R.id.action_rename_file);
+ toHide.add(R.id.action_remove_file);
+ toHide.add(R.id.action_open_file_with);
+ if (!downloading) {
+ toHide.add(R.id.action_cancel_download);
+ toShow.add(R.id.action_cancel_upload);
+ } else {
+ toHide.add(R.id.action_cancel_upload);
+ toShow.add(R.id.action_cancel_download);
}
- case R.id.fdRenameBtn: {
- String fileName = mFile.getFileName();
- int extensionStart = mFile.isDirectory() ? -1 : fileName.lastIndexOf(".");
- int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
- EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
- dialog.show(getFragmentManager(), "nameeditdialog");
- break;
- }
- case R.id.fdRemoveBtn: {
- ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
- R.string.confirmation_remove_alert,
- new String[]{mFile.getFileName()},
- mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
- mFile.isDown() ? R.string.confirmation_remove_local : -1,
- R.string.common_cancel);
- confDialog.setOnConfirmationListener(this);
- confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
- break;
+
+ } else if (mFile != null && mFile.isDown()) {
+ toHide.add(R.id.action_download_file);
+ toHide.add(R.id.action_cancel_download);
+ toHide.add(R.id.action_cancel_upload);
+
+ toShow.add(R.id.action_rename_file);
+ toShow.add(R.id.action_remove_file);
+ toShow.add(R.id.action_open_file_with);
+ toShow.add(R.id.action_sync_file);
+
+ } else if (mFile != null) {
+ toHide.add(R.id.action_open_file_with);
+ toHide.add(R.id.action_cancel_download);
+ toHide.add(R.id.action_cancel_upload);
+ toHide.add(R.id.action_sync_file);
+
+ toShow.add(R.id.action_rename_file);
+ toShow.add(R.id.action_remove_file);
+ toShow.add(R.id.action_download_file);
+
+ } else {
+ toHide.add(R.id.action_open_file_with);
+ toHide.add(R.id.action_cancel_download);
+ toHide.add(R.id.action_cancel_upload);
+ toHide.add(R.id.action_sync_file);
+ toHide.add(R.id.action_download_file);
+ toHide.add(R.id.action_rename_file);
+ toHide.add(R.id.action_remove_file);
+
+ }
+
+ MenuItem item = null;
+ for (int i : toHide) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+ }
+ for (int i : toShow) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(true);
+ item.setEnabled(true);
}
- case R.id.fdOpenBtn: {
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_open_file_with: {
openFile();
-
+ return true;
+ }
+ case R.id.action_remove_file: {
+ removeFile();
+ return true;
+ }
+ case R.id.action_rename_file: {
+ renameFile();
+ return true;
+ }
+ case R.id.action_download_file:
+ case R.id.action_cancel_download:
+ case R.id.action_cancel_upload:
+ case R.id.action_sync_file: {
+ synchronizeFile();
+ return true;
+ }
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.fdKeepInSync: {
+ toggleKeepInSync();
+ break;
+ }
+ case R.id.fdCancelBtn: {
+ synchronizeFile();
break;
}
default:
Log_OC.e(TAG, "Incorrect view clicked!");
}
+ }
+
+
+ private void toggleKeepInSync() {
+ CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
+ mFile.setKeepInSync(cb.isChecked());
+ mStorageManager.saveFile(mFile);
- }\r
- \r
+ /// register the OCFile instance in the observer service to monitor local updates;
+ /// if necessary, the file is download
+ Intent intent = new Intent(getActivity().getApplicationContext(),
+ FileObserverService.class);
+ intent.putExtra(FileObserverService.KEY_FILE_CMD,
+ (cb.isChecked()?
+ FileObserverService.CMD_ADD_OBSERVED_FILE:
+ FileObserverService.CMD_DEL_OBSERVED_FILE));
+ intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
+ intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
+ getActivity().startService(intent);
+
+ if (mFile.keepInSync()) {
+ synchronizeFile(); // force an immediate synchronization
+ }
+ }
+
+
+ private void removeFile() {
+ ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
+ R.string.confirmation_remove_alert,
+ new String[]{mFile.getFileName()},
+ mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
+ mFile.isDown() ? R.string.confirmation_remove_local : -1,
+ R.string.common_cancel);
+ confDialog.setOnConfirmationListener(this);
+ confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
+ }
+
+
+ private void renameFile() {
+ String fileName = mFile.getFileName();
+ int extensionStart = mFile.isDirectory() ? -1 : fileName.lastIndexOf(".");
+ int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
+ EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
+ dialog.show(getFragmentManager(), "nameeditdialog");
+ }
+
+ private void synchronizeFile() {
+ FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
+ FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
+ if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
+ downloaderBinder.cancel(mAccount, mFile);
+ if (mFile.isDown()) {
+ setButtonsForDown();
+ } else {
+ setButtonsForRemote();
+ }
+
+ } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
+ uploaderBinder.cancel(mAccount, mFile);
+ if (!mFile.fileExists()) {
+ // TODO make something better
+ if (getActivity() instanceof FileDisplayActivity) {
+ // double pane
+ FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment
+ transaction.commit();
+ mContainerActivity.onFileStateChanged();
+ } else {
+ getActivity().finish();
+ }
+
+ } else if (mFile.isDown()) {
+ setButtonsForDown();
+ } else {
+ setButtonsForRemote();
+ }
+
+ } else {
+ mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity());
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
- mLastRemoteOperation.execute(wc, this, mHandler);
-
++ mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
++
+ // update ui
+ boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
+ getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+
+ }
+ }
+
-
/**
* Opens mFile.
*/
startActivity(i);
} catch (Throwable t) {
- Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
+ Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
boolean toastIt = true;
String mimeType = "";
try {
}
} catch (IndexOutOfBoundsException e) {
- Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
+ Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
} catch (ActivityNotFoundException e) {
- Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
+ Log_OC.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
} catch (Throwable th) {
- Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);
+ Log_OC.e(TAG, "Unexpected problem when opening: " + storagePath, th);
} finally {
if (toastIt) {
}
}
-
@Override
public void onConfirmation(String callerTag) {
if (callerTag.equals(FTAG_CONFIRMATION)) {
mLastRemoteOperation = new RemoveFileOperation( mFile,
true,
mStorageManager);
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
- mLastRemoteOperation.execute(wc, this, mHandler);
+ mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
@Override
public void onCancel(String callerTag) {
- Log.d(TAG, "REMOVAL CANCELED");
+ Log_OC.d(TAG, "REMOVAL CANCELED");
}
getView().invalidate();
}
-
/**
* Checks if the fragment is ready to show details of a OCFile
*
*/
private void setButtonsForTransferring() {
if (!isEmpty()) {
- Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
- downloadButton.setText(R.string.common_cancel);
- //downloadButton.setEnabled(false);
-
// let's protect the user from himself ;)
- ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);
- ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false);
- ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false);
getView().findViewById(R.id.fdKeepInSync).setEnabled(false);
// show the progress bar for the transfer
- ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
- progressBar.setVisibility(View.VISIBLE);
+ getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE);
TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
progressText.setVisibility(View.VISIBLE);
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
*/
private void setButtonsForDown() {
if (!isEmpty()) {
- Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
- downloadButton.setText(R.string.filedetails_sync_file);
-
- ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true);
- ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);
- ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);
getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
// hides the progress bar
- ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
- progressBar.setVisibility(View.GONE);
+ getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
progressText.setVisibility(View.GONE);
}
*/
private void setButtonsForRemote() {
if (!isEmpty()) {
- Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
- downloadButton.setText(R.string.filedetails_download);
-
- ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);
- ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);
- ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);
getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
// hides the progress bar
- ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
- progressBar.setVisibility(View.GONE);
+ getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
progressText.setVisibility(View.GONE);
}
}
- // this is a temporary class for sharing purposes, it need to be replaced in transfer service
- @SuppressWarnings("unused")
- private class ShareRunnable implements Runnable {
- private String mPath;
-
- public ShareRunnable(String path) {
- mPath = path;
- }
-
- public void run() {
- AccountManager am = AccountManager.get(getActivity());
- Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
- OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
- String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);
-
- Log.d("share", "sharing for version " + ocv.toString());
-
- if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
- String APPS_PATH = "/apps/files_sharing/";
- String SHARE_PATH = "ajax/share.php";
-
- String SHARED_PATH = "/apps/files_sharing/get.php?token=";
-
- final String WEBDAV_SCRIPT = "webdav.php";
- final String WEBDAV_FILES_LOCATION = "/files/";
-
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getActivity().getApplicationContext());
- HttpConnectionManagerParams params = new HttpConnectionManagerParams();
- params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);
-
- //wc.getParams().setParameter("http.protocol.single-cookie-header", true);
- //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
-
- PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);
-
- post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );
- post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
- List<NameValuePair> formparams = new ArrayList<NameValuePair>();
- Log.d("share", mPath+"");
- formparams.add(new BasicNameValuePair("sources",mPath));
- formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
- formparams.add(new BasicNameValuePair("permissions", "0"));
- post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));
-
- int status;
- try {
- PropFindMethod find = new PropFindMethod(url+"/");
- find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
- Log.d("sharer", ""+ url+"/");
-
- for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
- Log.d("sharer-h", a.getName() + ":"+a.getValue());
- }
-
- int status2 = wc.executeMethod(find);
-
- Log.d("sharer", "propstatus "+status2);
-
- GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
- get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
-
- status2 = wc.executeMethod(get);
-
- Log.d("sharer", "getstatus "+status2);
- Log.d("sharer", "" + get.getResponseBodyAsString());
-
- for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
- Log.d("sharer", a.getName() + ":"+a.getValue());
- }
-
- status = wc.executeMethod(post);
- for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
- Log.d("sharer-h", a.getName() + ":"+a.getValue());
- }
- for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
- Log.d("sharer", a.getName() + ":"+a.getValue());
- }
- String resp = post.getResponseBodyAsString();
- Log.d("share", ""+post.getURI().toString());
- Log.d("share", "returned status " + status);
- Log.d("share", " " +resp);
-
- if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {
- return;
- }
-
- JSONObject jsonObject = new JSONObject (resp);
- String jsonStatus = jsonObject.getString("status");
- if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");
-
- String token = jsonObject.getString("data");
- String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
- Log.d("Actions:shareFile ok", "url: " + uri);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {
-
- }
- }
- }
-
public void onDismiss(EditNameDialog dialog) {
if (dialog.getResult()) {
String newFilename = dialog.getNewFilename();
- Log.d(TAG, "name edit dialog dismissed with new name " + newFilename);
+ Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
mLastRemoteOperation = new RenameFileOperation( mFile,
mAccount,
newFilename,
new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
- mLastRemoteOperation.execute(wc, this, mHandler);
+ mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
}
}
}
-
+
public void listenForTransferProgress() {
if (mProgressListener != null) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
};
- }
+ /*
+ // this is a temporary class for sharing purposes, it need to be replaced in transfer service
+ @SuppressWarnings("unused")
+ private class ShareRunnable implements Runnable {
+ private String mPath;
+
+ public ShareRunnable(String path) {
+ mPath = path;
+ }
+
+ public void run() {
+ AccountManager am = AccountManager.get(getActivity());
+ Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+ OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
+ String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);
+
+ Log_OC.d("share", "sharing for version " + ocv.toString());
+
+ if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
+ String APPS_PATH = "/apps/files_sharing/";
+ String SHARE_PATH = "ajax/share.php";
+
+ String SHARED_PATH = "/apps/files_sharing/get.php?token=";
+
+ final String WEBDAV_SCRIPT = "webdav.php";
+ final String WEBDAV_FILES_LOCATION = "/files/";
+
+ WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getActivity().getApplicationContext());
+ HttpConnectionManagerParams params = new HttpConnectionManagerParams();
+ params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);
+
+ //wc.getParams().setParameter("http.protocol.single-cookie-header", true);
+ //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
+
+ PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);
+
+ post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );
+ post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
+ List<NameValuePair> formparams = new ArrayList<NameValuePair>();
+ Log_OC.d("share", mPath+"");
+ formparams.add(new BasicNameValuePair("sources",mPath));
+ formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
+ formparams.add(new BasicNameValuePair("permissions", "0"));
+ post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));
+
+ int status;
+ try {
+ PropFindMethod find = new PropFindMethod(url+"/");
+ find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
+ Log_OC.d("sharer", ""+ url+"/");
+
+ for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
+ Log_OC.d("sharer-h", a.getName() + ":"+a.getValue());
+ }
+
+ int status2 = wc.executeMethod(find);
+
+ Log_OC.d("sharer", "propstatus "+status2);
+
+ GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
+ get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
+
+ status2 = wc.executeMethod(get);
+
+ Log_OC.d("sharer", "getstatus "+status2);
+ Log_OC.d("sharer", "" + get.getResponseBodyAsString());
+
+ for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
+ Log_OC.d("sharer", a.getName() + ":"+a.getValue());
+ }
+
+ status = wc.executeMethod(post);
+ for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
+ Log_OC.d("sharer-h", a.getName() + ":"+a.getValue());
+ }
+ for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
+ Log_OC.d("sharer", a.getName() + ":"+a.getValue());
+ }
+ String resp = post.getResponseBodyAsString();
+ Log_OC.d("share", ""+post.getURI().toString());
+ Log_OC.d("share", "returned status " + status);
+ Log_OC.d("share", " " +resp);
+
+ if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {
+ return;
+ }
+
+ JSONObject jsonObject = new JSONObject (resp);
+ String jsonStatus = jsonObject.getString("status");
+ if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");
+
+ String token = jsonObject.getString("data");
+ String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
+ Log_OC.d("Actions:shareFile ok", "url: " + uri);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {
+
+ }
+ }
+ }
+ */
+
+ }
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
- import com.owncloud.android.network.OwnCloudClientUtils;
import com.owncloud.android.operations.OnRemoteOperationListener;
import com.owncloud.android.operations.RemoteOperation;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
- import eu.alefzero.webdav.WebdavClient;
import eu.alefzero.webdav.WebdavUtils;
import android.accounts.Account;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
- import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
mContainerActivity.onDirectoryClick(file);
} else { /// Click on a file
- mContainerActivity.onFileClick(file);
+ mContainerActivity.onFileClick(file, false);
}
} else {
toHide.add(R.id.action_download_file);
toHide.add(R.id.action_cancel_download);
toHide.add(R.id.action_cancel_upload);
+ toHide.add(R.id.action_sync_file);
toHide.add(R.id.action_see_details);
if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ||
mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ) {
if (targetFile.isDown()) {
toHide.add(R.id.action_cancel_download);
toHide.add(R.id.action_cancel_upload);
- item = menu.findItem(R.id.action_download_file);
- if (item != null) {
- item.setTitle(R.string.filedetails_sync_file);
- }
+ toHide.add(R.id.action_download_file);
+
} else {
toHide.add(R.id.action_open_file_with);
+ toHide.add(R.id.action_sync_file);
}
if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
toHide.add(R.id.action_download_file);
}
return true;
}
- case R.id.action_download_file: {
+ case R.id.action_download_file:
+ case R.id.action_sync_file: {
Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
RemoteOperation operation = new SynchronizeFileOperation(mTargetFile, null, mContainerActivity.getStorageManager(), account, true, false, getSherlockActivity());
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getSherlockActivity().getApplicationContext());
- operation.execute(wc, mContainerActivity, mHandler);
+ operation.execute(account, getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
getSherlockActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
return true;
}
*
* @param file
*/
- public void onFileClick(OCFile file);
+ public void onFileClick(OCFile file, boolean realClick);
/**
* Getter for the current DataStorageManager in the container activity
AccountUtils.getCurrentOwnCloudAccount(getActivity()),
newFilename,
mContainerActivity.getStorageManager());
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity().getApplicationContext());
- operation.execute(wc, mContainerActivity, mHandler);
+ operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
}
RemoteOperation operation = new RemoveFileOperation( mTargetFile,
true,
mContainerActivity.getStorageManager());
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity().getApplicationContext());
- operation.execute(wc, mContainerActivity, mHandler);
+ operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.os.Handler;
import android.os.IBinder;
import android.support.v4.app.FragmentTransaction;
- import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import com.owncloud.android.media.MediaControlView;
import com.owncloud.android.media.MediaService;
import com.owncloud.android.media.MediaServiceBinder;
- import com.owncloud.android.network.OwnCloudClientUtils;
import com.owncloud.android.operations.OnRemoteOperationListener;
import com.owncloud.android.operations.RemoteOperation;
import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.Log_OC;
import com.owncloud.android.R;
- import eu.alefzero.webdav.WebdavClient;
import eu.alefzero.webdav.WebdavUtils;
/**
private MediaServiceConnection mMediaServiceConnection = null;
private VideoHelper mVideoHelper;
private boolean mAutoplay;
+ public boolean mPrepared;
private static final String TAG = PreviewMediaFragment.class.getSimpleName();
* @param fileToDetail An {@link OCFile} to preview in the fragment
* @param ocAccount An ownCloud account; needed to start downloads
*/
- public PreviewMediaFragment(OCFile fileToDetail, Account ocAccount) {
+ public PreviewMediaFragment(OCFile fileToDetail, Account ocAccount, int startPlaybackPosition, boolean autoplay) {
mFile = fileToDetail;
mAccount = ocAccount;
- mSavedPlaybackPosition = 0;
+ mSavedPlaybackPosition = startPlaybackPosition;
mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
- mAutoplay = true;
+ mAutoplay = autoplay;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
+ Log_OC.e(TAG, "onCreateView");
+
mView = inflater.inflate(R.layout.file_preview, container, false);
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
+ Log_OC.e(TAG, "onAttach");
+
if (!(activity instanceof FileFragment.ContainerActivity))
throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName());
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
+ Log_OC.e(TAG, "onActivityCreated");
mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
if (savedInstanceState != null) {
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
+ Log_OC.e(TAG, "onSaveInstanceState");
+
outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, mFile);
outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount);
@Override
public void onStart() {
super.onStart();
+ Log_OC.e(TAG, "onStart");
if (mFile != null) {
if (mFile.isAudio()) {
toHide.add(R.id.action_cancel_download);
toHide.add(R.id.action_cancel_upload);
toHide.add(R.id.action_download_file);
+ toHide.add(R.id.action_sync_file);
toHide.add(R.id.action_rename_file); // by now
for (int i : toHide) {
*/
@Override
public void onPrepared(MediaPlayer vp) {
- Log.e(TAG, "onPrepared");
+ Log_OC.e(TAG, "onPrepared");
mVideoPreview.seekTo(mSavedPlaybackPosition);
if (mAutoplay) {
mVideoPreview.start();
}
mMediaController.setEnabled(true);
mMediaController.updatePausePlay();
+ mPrepared = true;
}
*/
@Override
public void onCompletion(MediaPlayer mp) {
- Log.e(TAG, "completed");
+ Log_OC.e(TAG, "completed");
if (mp != null) {
mVideoPreview.seekTo(0);
// next lines are necessary to work around undesired video loops
@Override
+ public void onPause() {
+ super.onPause();
+ Log_OC.e(TAG, "onPause");
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ Log_OC.e(TAG, "onResume");
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ Log_OC.e(TAG, "onDestroy");
+ }
+
+ @Override
public void onStop() {
+ Log_OC.e(TAG, "onStop");
super.onStop();
-
+
+ mPrepared = false;
if (mMediaServiceConnection != null) {
- Log.d(TAG, "Unbinding from MediaService ...");
+ Log_OC.d(TAG, "Unbinding from MediaService ...");
if (mMediaServiceBinder != null && mMediaController != null) {
mMediaServiceBinder.unregisterMediaController(mMediaController);
}
startActivityForResult(i, 0);
}
+ @Override
+ public void onConfigurationChanged (Configuration newConfig) {
+ Log_OC.e(TAG, "onConfigurationChanged " + this);
+ }
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
+ Log_OC.e(TAG, "onActivityResult " + this);
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
mSavedPlaybackPosition = data.getExtras().getInt(PreviewVideoActivity.EXTRA_START_POSITION);
private void playAudio() {
if (!mMediaServiceBinder.isPlaying(mFile)) {
- Log.d(TAG, "starting playback of " + mFile.getStoragePath());
+ Log_OC.d(TAG, "starting playback of " + mFile.getStoragePath());
mMediaServiceBinder.start(mAccount, mFile, mAutoplay, mSavedPlaybackPosition);
} else {
private void bindMediaService() {
- Log.d(TAG, "Binding to MediaService...");
+ Log_OC.d(TAG, "Binding to MediaService...");
if (mMediaServiceConnection == null) {
mMediaServiceConnection = new MediaServiceConnection();
}
@Override
public void onServiceConnected(ComponentName component, IBinder service) {
if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
- Log.d(TAG, "Media service connected");
+ Log_OC.d(TAG, "Media service connected");
mMediaServiceBinder = (MediaServiceBinder) service;
if (mMediaServiceBinder != null) {
prepareMediaController();
playAudio(); // do not wait for the touch of nobody to play audio
- Log.d(TAG, "Successfully bound to MediaService, MediaController ready");
+ Log_OC.d(TAG, "Successfully bound to MediaService, MediaController ready");
} else {
- Log.e(TAG, "Unexpected response from MediaService while binding");
+ Log_OC.e(TAG, "Unexpected response from MediaService while binding");
}
}
}
@Override
public void onServiceDisconnected(ComponentName component) {
if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
- Log.e(TAG, "Media service suddenly disconnected");
+ Log_OC.e(TAG, "Media service suddenly disconnected");
if (mMediaController != null) {
mMediaController.setMediaPlayer(null);
} else {
startActivity(i);
} catch (Throwable t) {
- Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
+ Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
boolean toastIt = true;
String mimeType = "";
try {
}
} catch (IndexOutOfBoundsException e) {
- Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
+ Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
} catch (ActivityNotFoundException e) {
- Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
+ Log_OC.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
} catch (Throwable th) {
- Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);
+ Log_OC.e(TAG, "Unexpected problem when opening: " + storagePath, th);
} finally {
if (toastIt) {
mLastRemoteOperation = new RemoveFileOperation( mFile, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
true,
mStorageManager);
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
- mLastRemoteOperation.execute(wc, this, mHandler);
+ mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
container.finish();
}
}
+
+
+ public int getPosition() {
+ if (mPrepared) {
+ mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
+ }
+ Log_OC.e(TAG, "getting position: " + mSavedPlaybackPosition);
+ return mSavedPlaybackPosition;
+ }
+
+ public boolean isPlaying() {
+ if (mPrepared) {
+ mAutoplay = mVideoPreview.isPlaying();
+ }
+ return mAutoplay;
+ }
}