From: David A. Velasco Date: Mon, 6 May 2013 08:48:43 +0000 (+0200) Subject: Merge branch 'develop' into file_browsing_refactoring X-Git-Tag: oc-android-1.4.3~27^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b36914df88ff9abd04c19b422889de894df3a714?ds=inline;hp=-c Merge branch 'develop' into file_browsing_refactoring Conflicts: AndroidManifest.xml src/com/owncloud/android/ui/activity/FileDisplayActivity.java src/com/owncloud/android/ui/fragment/FileDetailFragment.java --- b36914df88ff9abd04c19b422889de894df3a714 diff --combined AndroidManifest.xml index 255b7aad,ba32f6cf..b047f918 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@@ -49,8 -49,7 +49,8 @@@ android:theme="@style/Theme.ownCloud"> + android:label="@string/app_name" + android:configChanges="orientation|screenSize"> @@@ -91,7 -90,7 +91,7 @@@ - + @@@ -131,9 -130,16 +131,16 @@@ + android:theme="@style/Theme.ownCloud.noActionBar" + android:launchMode="singleTask"> + + + + + + @@@ -144,7 -150,7 +151,7 @@@ - + @@@ -155,21 -161,22 +162,22 @@@ - - - - + + + + - - - - - - - - - - - + + + + + + + + ++ + - ++ diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index d87aabd4,6fd51a9a..7ffe9000 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -23,7 -23,6 +23,6 @@@ import java.io.File 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; @@@ -35,7 -34,6 +34,7 @@@ import android.content.Intent 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; @@@ -46,11 -44,9 +45,9 @@@ import android.preference.PreferenceMan 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; @@@ -64,7 -60,7 +61,7 @@@ import com.actionbarsherlock.view.Windo 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; @@@ -73,7 -69,7 +70,7 @@@ import com.owncloud.android.files.servi 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; @@@ -92,10 -88,7 +89,8 @@@ import com.owncloud.android.ui.fragment 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. * @@@ -125,13 -118,10 +120,10 @@@ public class FileDisplayActivity extend 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; @@@ -140,16 -130,14 +132,18 @@@ 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)) { @@@ -209,8 -197,21 +203,8 @@@ 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 @@@ -229,23 -230,12 +223,23 @@@ } + @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; } @@@ -288,9 -278,7 +282,9 @@@ 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; @@@ -309,45 -297,6 +303,45 @@@ @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) @@@ -400,12 -349,12 +394,12 @@@ } 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); } @@@ -427,7 -376,6 +421,7 @@@ * 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); @@@ -560,7 -508,6 +554,6 @@@ outState.putParcelable(FileDetailActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview); Log_OC.d(getClass().toString(), "onSaveInstanceState() end"); } - @Override protected void onResume() { @@@ -666,53 -613,6 +659,6 @@@ 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( @@@ -833,57 -733,6 +779,6 @@@ 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 extends ArrayAdapter { @@@ -1051,7 -900,7 +946,7 @@@ 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; @@@ -1097,7 -946,7 +992,7 @@@ * {@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); @@@ -1105,28 -954,16 +1000,28 @@@ } 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); } } @@@ -1137,24 -974,22 +1032,24 @@@ 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(); @@@ -1170,8 -1005,8 +1065,8 @@@ } - 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(); @@@ -1312,6 -1147,9 +1207,9 @@@ } else if (operation instanceof SynchronizeFileOperation) { onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result); + + } else if (operation instanceof CreateFolderOperation) { + onCreateFolderOperationFinish((CreateFolderOperation)operation, result); } } @@@ -1352,6 -1190,30 +1250,30 @@@ } /** + * 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. * @@@ -1459,7 -1321,7 +1381,7 @@@ //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) { @@@ -1474,14 -1336,19 +1396,19 @@@ // 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)) { diff --combined src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 2bf9b734,ec20f869..6d24c596 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@@ -19,23 -19,8 +19,11 @@@ package com.owncloud.android.ui.fragmen 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; @@@ -46,12 -31,12 +34,11 @@@ import android.net.Uri 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; @@@ -59,20 -44,14 +46,18 @@@ import android.widget.TextView import android.widget.Toast; import com.actionbarsherlock.app.SherlockFragment; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuInflater; +import com.actionbarsherlock.view.MenuItem; - import com.owncloud.android.AccountUtils; 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; @@@ -85,15 -64,12 +70,13 @@@ import com.owncloud.android.ui.activity 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. * @@@ -140,7 -116,6 +123,6 @@@ public class FileDetailFragment extend mProgressListener = null; } - /** * Creates a details fragment. * @@@ -162,7 -137,6 +144,7 @@@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); + setHasOptionsMenu(true); } @@@ -186,15 -160,20 +168,15 @@@ 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} */ @@@ -262,239 -241,109 +244,236 @@@ } - @Override - public View getView() { - return super.getView() == null ? mView : super.getView(); - } - - - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.fdDownloadBtn: { - 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()); - 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); - setButtonsForTransferring(); // disable button immediately, although the synchronization does not result in a file transference - - } - break; - } - 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 toHide = new ArrayList(); + List toShow = new ArrayList(); + + 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); - } - + /// 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. */ @@@ -509,7 -358,7 +488,7 @@@ 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 { @@@ -528,13 -377,13 +507,13 @@@ } } 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) { @@@ -545,7 -394,6 +524,6 @@@ } } - @Override public void onConfirmation(String callerTag) { if (callerTag.equals(FTAG_CONFIRMATION)) { @@@ -553,8 -401,7 +531,7 @@@ 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); @@@ -575,7 -422,7 +552,7 @@@ @Override public void onCancel(String callerTag) { - Log.d(TAG, "REMOVAL CANCELED"); + Log_OC.d(TAG, "REMOVAL CANCELED"); } @@@ -666,7 -513,6 +643,6 @@@ getView().invalidate(); } - /** * Checks if the fragment is ready to show details of a OCFile * @@@ -743,11 -589,19 +719,11 @@@ */ 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(); @@@ -765,10 -619,17 +741,10 @@@ */ 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); } @@@ -779,10 -640,17 +755,10 @@@ */ 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); } @@@ -846,120 -714,15 +822,15 @@@ } - // 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 formparams = new ArrayList(); - 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); } @@@ -1075,7 -838,7 +946,7 @@@ } } - + public void listenForTransferProgress() { if (mProgressListener != null) { if (mContainerActivity.getFileDownloaderBinder() != null) { @@@ -1134,4 -897,110 +1005,110 @@@ }; - } + /* + // 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 formparams = new ArrayList(); + 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) { + + } + } + } + */ + + } diff --combined src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 8af801c1,f8728032..f0d074fd --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -28,7 -28,6 +28,6 @@@ import com.owncloud.android.datamodel.D 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; @@@ -42,7 -41,6 +41,6 @@@ import com.owncloud.android.ui.dialog.E 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; @@@ -52,7 -50,6 +50,6 @@@ import android.content.Intent 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; @@@ -144,7 -141,7 +141,7 @@@ public class OCFileListFragment extend mContainerActivity.onDirectoryClick(file); } else { /// Click on a file - mContainerActivity.onFileClick(file); + mContainerActivity.onFileClick(file, false); } } else { @@@ -173,7 -170,6 +170,7 @@@ 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) ) { @@@ -187,11 -183,12 +184,11 @@@ 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); @@@ -314,12 -311,10 +311,11 @@@ } 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; } @@@ -440,7 -435,7 +436,7 @@@ * * @param file */ - public void onFileClick(OCFile file); + public void onFileClick(OCFile file, boolean realClick); /** * Getter for the current DataStorageManager in the container activity @@@ -485,8 -480,7 +481,7 @@@ 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); } } @@@ -499,8 -493,7 +494,7 @@@ 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); } diff --combined src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 85575d16,c26d8c74..164fe04a --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@@ -29,7 -29,6 +29,7 @@@ import android.content.Context 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; @@@ -40,7 -39,6 +40,6 @@@ import android.os.Bundle 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; @@@ -60,7 -58,6 +59,6 @@@ import com.owncloud.android.datamodel.O 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; @@@ -73,7 -70,6 +71,6 @@@ import com.owncloud.android.ui.fragment import com.owncloud.android.Log_OC; import com.owncloud.android.R; - import eu.alefzero.webdav.WebdavClient; import eu.alefzero.webdav.WebdavUtils; /** @@@ -110,7 -106,6 +107,7 @@@ public class PreviewMediaFragment exten private MediaServiceConnection mMediaServiceConnection = null; private VideoHelper mVideoHelper; private boolean mAutoplay; + public boolean mPrepared; private static final String TAG = PreviewMediaFragment.class.getSimpleName(); @@@ -123,12 -118,12 +120,12 @@@ * @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; } @@@ -166,8 -161,6 +163,8 @@@ 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); @@@ -187,8 -180,6 +184,8 @@@ @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()); } @@@ -200,7 -191,6 +197,7 @@@ @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + Log_OC.e(TAG, "onActivityCreated"); mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); if (savedInstanceState != null) { @@@ -238,8 -228,6 +235,8 @@@ @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); @@@ -258,7 -246,6 +255,7 @@@ @Override public void onStart() { super.onStart(); + Log_OC.e(TAG, "onStart"); if (mFile != null) { if (mFile.isAudio()) { @@@ -293,7 -280,6 +290,7 @@@ 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) { @@@ -366,14 -352,13 +363,14 @@@ */ @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; } @@@ -386,7 -371,7 +383,7 @@@ */ @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 @@@ -437,31 -422,11 +434,31 @@@ @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); } @@@ -491,14 -456,9 +488,14 @@@ 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); @@@ -509,7 -469,7 +506,7 @@@ 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 { @@@ -522,7 -482,7 +519,7 @@@ private void bindMediaService() { - Log.d(TAG, "Binding to MediaService..."); + Log_OC.d(TAG, "Binding to MediaService..."); if (mMediaServiceConnection == null) { mMediaServiceConnection = new MediaServiceConnection(); } @@@ -539,16 -499,16 +536,16 @@@ @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"); } } } @@@ -565,7 -525,7 +562,7 @@@ @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 { @@@ -597,7 -557,7 +594,7 @@@ 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 { @@@ -616,13 -576,13 +613,13 @@@ } } 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) { @@@ -662,8 -622,7 +659,7 @@@ 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); @@@ -789,21 -748,5 +785,21 @@@ 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; + } }