X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ff2271a8c531efe4c2602c63934eca568c397510..e4bc3bdadc47c01e88dd1de94a4666d3753ee90e:/src/com/owncloud/android/ui/fragment/FileDetailFragment.java diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 01fc1866..9338b93f 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -113,6 +113,7 @@ public class FileDetailFragment extends SherlockFragment implements private View mView; private OCFile mFile; private Account mAccount; + private FileDataStorageManager mStorageManager; private ImageView mPreview; private DownloadFinishReceiver mDownloadFinishReceiver; @@ -134,6 +135,7 @@ public class FileDetailFragment extends SherlockFragment implements public FileDetailFragment() { mFile = null; mAccount = null; + mStorageManager = null; mLayout = R.layout.file_details_empty; } @@ -149,6 +151,7 @@ public class FileDetailFragment extends SherlockFragment implements public FileDetailFragment(OCFile fileToDetail, Account ocAccount) { mFile = fileToDetail; mAccount = ocAccount; + mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment mLayout = R.layout.file_details_empty; if(fileToDetail != null && ocAccount != null) { @@ -205,6 +208,18 @@ public class FileDetailFragment extends SherlockFragment implements throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getSimpleName()); } } + + + /** + * {@inheritDoc} + */ + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + if (mAccount != null) { + mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());; + } + } @Override @@ -257,7 +272,6 @@ public class FileDetailFragment extends SherlockFragment implements @Override public void onClick(View v) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); switch (v.getId()) { case R.id.fdDownloadBtn: { //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) { @@ -292,7 +306,7 @@ public class FileDetailFragment extends SherlockFragment implements } } else { - mLastRemoteOperation = new SynchronizeFileOperation(mFile.getRemotePath(), fdsm, mAccount, true, false, getActivity()); + mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity()); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); mLastRemoteOperation.execute(wc, this, mHandler); @@ -307,20 +321,7 @@ public class FileDetailFragment extends SherlockFragment implements case R.id.fdKeepInSync: { CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); mFile.setKeepInSync(cb.isChecked()); - fdsm.saveFile(mFile); - - /* NOT HERE - * now that FileObserverService is involved, the easiest way to coordinate it with the download service - * in every possible case is let the FileObserverService decide if the download should be started at - * this moment or not - * - * see changes at FileObserverService#addObservedFile - - if (mFile.keepInSync()) { - onClick(getView().findViewById(R.id.fdDownloadBtn)); - } else { - mContainerActivity.onFileStateChanged(); // put inside 'else' to not call it twice (here, and in the virtual click on fdDownloadBtn) - }*/ + mStorageManager.saveFile(mFile); /// register the OCFile instance in the observer service to monitor local updates; /// if necessary, the file is download @@ -335,7 +336,9 @@ public class FileDetailFragment extends SherlockFragment implements Log.e(TAG, "starting observer service"); getActivity().startService(intent); - mContainerActivity.onFileStateChanged(); + if (mFile.keepInSync()) { + onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization + } break; } case R.id.fdRenameBtn: { @@ -410,11 +413,10 @@ public class FileDetailFragment extends SherlockFragment implements @Override public void onConfirmation(String callerTag) { if (callerTag.equals(FTAG_CONFIRMATION)) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - if (fdsm.getFileById(mFile.getFileId()) != null) { + if (mStorageManager.getFileById(mFile.getFileId()) != null) { mLastRemoteOperation = new RemoveFileOperation( mFile, true, - new FileDataStorageManager(mAccount, getActivity().getContentResolver())); + mStorageManager); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); mLastRemoteOperation.execute(wc, this, mHandler); @@ -426,12 +428,11 @@ public class FileDetailFragment extends SherlockFragment implements @Override public void onNeutral(String callerTag) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); File f = null; if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) { f.delete(); mFile.setStoragePath(null); - fdsm.saveFile(mFile); + mStorageManager.saveFile(mFile); updateFileDetails(mFile, mAccount); } } @@ -467,6 +468,12 @@ public class FileDetailFragment extends SherlockFragment implements */ public void updateFileDetails(OCFile file, Account ocAccount) { mFile = file; + if (ocAccount != null && ( + mStorageManager == null || + (mAccount != null && !mAccount.equals(ocAccount)) + )) { + mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver()); + } mAccount = ocAccount; updateFileDetails(); } @@ -594,7 +601,7 @@ public class FileDetailFragment extends SherlockFragment implements private void setButtonsForDown() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - downloadButton.setText(R.string.filedetails_redownload); + downloadButton.setText(R.string.filedetails_sync_file); //downloadButton.setEnabled(true); ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true); @@ -678,7 +685,7 @@ public class FileDetailFragment extends SherlockFragment implements String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); if (mFile.getRemotePath().equals(downloadedRemotePath)) { if (downloadWasFine) { - mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); // updates the local object without accessing the database again + mFile = mStorageManager.getFileByPath(downloadedRemotePath); } updateFileDetails(); // it updates the buttons; must be called although !downloadWasFine } @@ -700,15 +707,22 @@ public class FileDetailFragment extends SherlockFragment implements private class UploadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + Log.d(TAG, "Received broacast! : " + intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH)); String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); if (!isEmpty() && accountName.equals(mAccount.name)) { boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false); String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH); - if (mFile.getRemotePath().equals(uploadRemotePath)) { + boolean renamedInUpload = mFile.getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH)); + if (mFile.getRemotePath().equals(uploadRemotePath) || + renamedInUpload) { if (uploadWasFine) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); - mFile = fdsm.getFileByPath(mFile.getRemotePath()); + mFile = mStorageManager.getFileByPath(mFile.getRemotePath()); + } + if (renamedInUpload) { + String newName = (new File(uploadRemotePath)).getName(); + Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG); + msg.show(); } updateFileDetails(); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server } @@ -985,10 +999,8 @@ public class FileDetailFragment extends SherlockFragment implements if (!result.isSuccess()) { if (result.getCode() == ResultCode.SYNC_CONFLICT) { Intent i = new Intent(getActivity(), ConflictsResolveActivity.class); - //i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); - i.putExtra("remotepath", mFile.getRemotePath()); - i.putExtra("localpath", mFile.getStoragePath()); - i.putExtra("account", mAccount); + i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile); + i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount); startActivity(i); } else { @@ -996,6 +1008,13 @@ public class FileDetailFragment extends SherlockFragment implements msg.show(); } + if (mFile.isDown()) { + setButtonsForDown(); + + } else { + setButtonsForRemote(); + } + } else { if (operation.transferWasRequested()) { mContainerActivity.onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so