From: Andy Scherzinger Date: Mon, 7 Sep 2015 09:13:04 +0000 (+0200) Subject: Merge branch 'master' of https://github.com/owncloud/android into material_fab X-Git-Tag: beta-20151202~3^2~59 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/d039bffbd171b95c6db2eff4b39c42fc731ca895?hp=-c Merge branch 'master' of https://github.com/owncloud/android into material_fab --- d039bffbd171b95c6db2eff4b39c42fc731ca895 diff --combined res/layout/file_preview.xml index dd44ed5e,f7a697a0..685f2b55 --- a/res/layout/file_preview.xml +++ b/res/layout/file_preview.xml @@@ -25,9 -25,9 +25,9 @@@ android:layout_height="match_parent" android:background="@color/background_color" android:gravity="center" - tools:context=".ui.fragment.FilePreviewFragment" > + tools:context=".ui.fragment.FilePreviewFragment"> - diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 1576a605,20bcdce4..85711d78 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -99,6 -99,7 +99,7 @@@ 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.PreviewTextFragment; import com.owncloud.android.ui.preview.PreviewVideoActivity; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; @@@ -107,7 -108,6 +108,6 @@@ import com.owncloud.android.utils.UriUt import java.io.File; - /** * Displays, what files the user has available in his ownCloud. */ @@@ -116,6 -116,8 +116,8 @@@ public class FileDisplayActivity extend implements FileFragment.ContainerActivity, OnSslUntrustedCertListener, OnEnforceableRefreshListener { + + private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; private DownloadFinishReceiver mDownloadFinishReceiver; @@@ -174,7 -176,6 +176,6 @@@ mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS); mWaitingToSend = (OCFile) savedInstanceState.getParcelable( FileDisplayActivity.KEY_WAITING_TO_SEND); - } else { mWaitingToPreview = null; mSyncInProgress = false; @@@ -212,7 -213,7 +213,7 @@@ mProgressBar.setIndeterminate(mSyncInProgress); // always AFTER setContentView(...) ; to work around bug in its implementation - + setBackgroundText(); Log_OC.v(TAG, "onCreate() end"); @@@ -264,7 -265,12 +265,7 @@@ setFile(file); if (mAccountWasSet) { - RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer); - if (navigationDrawerLayout != null && getAccount() != null) { - TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username); - int lastAtPos = getAccount().name.lastIndexOf("@"); - username.setText(getAccount().name.substring(0, lastAtPos)); - } + setUsernameInDrawer((RelativeLayout) findViewById(R.id.left_drawer), getAccount()); } if (!stateWasRecovered) { @@@ -296,6 -302,7 +297,7 @@@ listOfFiles.listDirectory(getCurrentDir()); // TODO Enable when "On Device" is recovered // listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice()); + } else { Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); } @@@ -307,9 -314,11 +309,11 @@@ setSecondFragment(secondFragment); updateFragmentsVisibility(true); updateActionBarTitleAndHomeButton(file); - + } else { cleanSecondFragment(); + if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) + startTextPreview(file); } } else { @@@ -336,9 -345,11 +340,11 @@@ secondFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay); + } else if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) { + secondFragment = null; } else { - secondFragment = FileDetailFragment.newInstance(file, getAccount()); - } + secondFragment = FileDetailFragment.newInstance(file, getAccount()); + } } return secondFragment; } @@@ -455,6 -466,9 +461,9 @@@ if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) { startMediaPreview(mWaitingToPreview, 0, true); detailsFragmentChanged = true; + } else if (PreviewTextFragment.canBePreviewed(mWaitingToPreview)) { + startTextPreview(mWaitingToPreview); + detailsFragmentChanged = true; } else { getFileOperationsHelper().openFile(mWaitingToPreview); } @@@ -492,9 -506,12 +501,10 @@@ boolean retval = true; switch (item.getItemId()) { case R.id.action_create_dir: { - CreateFolderDialogFragment dialog = - CreateFolderDialogFragment.newInstance(getCurrentDir()); - dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER); + createFolder(); break; } + case R.id.action_sync_account: { startSynchronization(); break; @@@ -503,7 -520,6 +513,6 @@@ UploadSourceDialogFragment dialog = UploadSourceDialogFragment.newInstance(getAccount()); dialog.show(getSupportFragmentManager(), DIALOG_UPLOAD_SOURCE); - break; } case android.R.id.home: { @@@ -554,34 -570,6 +563,34 @@@ return retval; } + public void createFolder() { + CreateFolderDialogFragment dialog = + CreateFolderDialogFragment.newInstance(getCurrentDir()); + dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER); + } + + public void uploadLocalFilesSelected() { + Intent action = new Intent(this, UploadFilesActivity.class); + action.putExtra( + UploadFilesActivity.EXTRA_ACCOUNT, + getAccount() + ); + startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); + } + + public void uploadFromOtherAppsSelected() { + Intent action = new Intent(Intent.ACTION_GET_CONTENT); + action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE); + //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + } + startActivityForResult( + Intent.createChooser(action, getString(R.string.upload_chooser_title)), + ACTION_SELECT_CONTENT_FROM_APPS + ); + } + private void startSynchronization() { Log_OC.d(TAG, "Got to start sync"); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) { @@@ -835,11 -823,9 +844,9 @@@ protected void onResume() { Log_OC.v(TAG, "onResume() start"); super.onResume(); - // refresh Navigation Drawer account list mNavigationDrawerAdapter.updateAccountList(); - // refresh list of files refreshListOfFilesFragment(); @@@ -867,6 -853,7 +874,7 @@@ registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); Log_OC.v(TAG, "onResume() end"); + } @@@ -910,7 -897,7 +918,7 @@@ FileSyncAdapter.EXTRA_RESULT); boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null); - + if (sameAccount) { if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) { @@@ -931,6 -918,7 +939,7 @@@ synchFolderRemotePath), Toast.LENGTH_LONG) .show(); + browseToRoot(); } else { @@@ -959,8 -947,8 +968,8 @@@ .equals(event)); if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. - equals(event) && - /// TODO refactor and make common + equals(event) &&/// TODO refactor and make common + synchResult != null && !synchResult.isSuccess() && (synchResult.getCode() == ResultCode.UNAUTHORIZED || synchResult.isIdPRedirection() || @@@ -974,7 -962,6 +983,6 @@@ new OwnCloudAccount(getAccount(), context); client = (OwnCloudClientManagerFactory.getDefaultSingleton(). removeClientFor(ocAccount)); - if (client != null) { OwnCloudCredentials cred = client.getCredentials(); if (cred != null) { @@@ -1094,10 -1081,15 +1102,15 @@@ cleanSecondFragment(); } - // Force the preview if the file is an image - if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) { - startImagePreview(getFile()); - } // TODO what about other kind of previews? + // Force the preview if the file is an image or text file + if (uploadWasFine) { + OCFile ocFile = getFile(); + if (PreviewImageFragment.canBePreviewed(ocFile)) + startImagePreview(getFile()); + else if (PreviewTextFragment.canBePreviewed(ocFile)) + startTextPreview(ocFile); + // TODO what about other kind of previews? + } } mProgressBar.setIndeterminate(false); @@@ -1146,7 -1138,7 +1159,7 @@@ if (mWaitingToSend != null) { mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); - if (mWaitingToSend.isDown()) { + if (mWaitingToSend.isDown()) { sendDownloadedFile(); } } @@@ -1194,7 -1186,6 +1207,6 @@@ startSyncFolderOperation(root, false); } cleanSecondFragment(); - } @@@ -1273,7 -1264,7 +1285,7 @@@ } // a new chance to get the mDownloadBinder through // getFileDownloadBinder() - THIS IS A MESS - OCFileListFragment listOfFiles = getListOfFilesFragment(); + OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { listOfFiles.listDirectory(); // TODO Enable when "On Device" is recovered ? @@@ -1357,8 -1348,6 +1369,6 @@@ } } - - private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { @@@ -1367,7 -1356,6 +1377,6 @@@ } } - private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { @@@ -1389,6 -1377,9 +1398,9 @@@ if (details instanceof PreviewMediaFragment) { // Refresh OCFile of the fragment ((PreviewMediaFragment) details).updateFile(file); + } else if (details instanceof PreviewTextFragment) { + // Refresh OCFile of the fragment + ((PreviewTextFragment) details).updateFile(file); } else { showDetails(file); } @@@ -1410,7 -1401,7 +1422,7 @@@ Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + Toast.LENGTH_LONG); msg.show(); if (result.isSuccess()) { @@@ -1423,7 -1414,7 +1435,7 @@@ setFile(getStorageManager().getFileById(removedFile.getParentId())); cleanSecondFragment(); } - if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) { + if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())){ refreshListOfFilesFragment(); } invalidateOptionsMenu(); @@@ -1515,6 -1506,14 +1527,14 @@@ } else { getFileOperationsHelper().openFile(renamedFile); } + } else if (details instanceof PreviewTextFragment && + renamedFile.equals(details.getFile())) { + ((PreviewTextFragment) details).updateFile(renamedFile); + if (PreviewTextFragment.canBePreviewed(renamedFile)) { + startTextPreview(renamedFile); + } else { + getFileOperationsHelper().openFile(renamedFile); + } } } @@@ -1525,7 -1524,7 +1545,7 @@@ } else { Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + Toast.LENGTH_LONG); msg.show(); if (result.isSslRecoverableException()) { @@@ -1638,6 -1637,7 +1658,7 @@@ getApplicationContext() ); synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null); + mProgressBar.setIndeterminate(true); setBackgroundText(); @@@ -1695,7 -1695,6 +1716,6 @@@ showDetailsIntent.putExtra(EXTRA_FILE, file); showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount()); startActivity(showDetailsIntent); - } /** @@@ -1717,6 -1716,23 +1737,23 @@@ } /** + * Stars the preview of a text file {@link OCFile}. + * + * @param file Text {@link OCFile} to preview. + */ + public void startTextPreview(OCFile file) { + Bundle args = new Bundle(); + args.putParcelable(EXTRA_FILE, file); + args.putParcelable(EXTRA_ACCOUNT, getAccount()); + Fragment textPreviewFragment = Fragment.instantiate(getApplicationContext(), + PreviewTextFragment.class.getName(), args); + setSecondFragment(textPreviewFragment); + updateFragmentsVisibility(true); + //updateNavigationElementsInActionBar(file); + setFile(file); + } + + /** * Requests the download of the received {@link OCFile} , updates the UI * to monitor the download progress and prepares the activity to preview * or open the file when the download finishes.