2157d99daf96e5fee9787322dbe2c3b60eb8c064
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / FileDownloadFragment.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package com.owncloud.android.ui.fragment;
19
20 import java.io.File;
21 import java.lang.ref.WeakReference;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.commons.httpclient.methods.GetMethod;
26 import org.apache.commons.httpclient.methods.PostMethod;
27 import org.apache.commons.httpclient.methods.StringRequestEntity;
28 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
29 import org.apache.http.HttpStatus;
30 import org.apache.http.NameValuePair;
31 import org.apache.http.client.utils.URLEncodedUtils;
32 import org.apache.http.entity.FileEntity;
33 import org.apache.http.message.BasicNameValuePair;
34 import org.apache.http.protocol.HTTP;
35 import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
36 import org.json.JSONObject;
37
38 import android.accounts.Account;
39 import android.accounts.AccountManager;
40 import android.annotation.SuppressLint;
41 import android.app.Activity;
42 import android.content.ActivityNotFoundException;
43 import android.content.BroadcastReceiver;
44 import android.content.ComponentName;
45 import android.content.Context;
46 import android.content.Intent;
47 import android.content.IntentFilter;
48 import android.content.ServiceConnection;
49 import android.graphics.Bitmap;
50 import android.graphics.BitmapFactory;
51 import android.graphics.BitmapFactory.Options;
52 import android.graphics.Point;
53 import android.net.Uri;
54 import android.os.AsyncTask;
55 import android.os.Bundle;
56 import android.os.Handler;
57 import android.os.IBinder;
58 import android.support.v4.app.DialogFragment;
59 import android.support.v4.app.FragmentTransaction;
60 import android.util.Log;
61 import android.view.Display;
62 import android.view.LayoutInflater;
63 import android.view.MotionEvent;
64 import android.view.View;
65 import android.view.View.OnClickListener;
66 import android.view.View.OnTouchListener;
67 import android.view.ViewGroup;
68 import android.webkit.MimeTypeMap;
69 import android.webkit.WebView.FindListener;
70 import android.widget.Button;
71 import android.widget.CheckBox;
72 import android.widget.ImageView;
73 import android.widget.MediaController;
74 import android.widget.ProgressBar;
75 import android.widget.TextView;
76 import android.widget.Toast;
77 import android.widget.VideoView;
78
79 import com.actionbarsherlock.app.SherlockFragment;
80 import com.owncloud.android.AccountUtils;
81 import com.owncloud.android.DisplayUtils;
82 import com.owncloud.android.authenticator.AccountAuthenticator;
83 import com.owncloud.android.datamodel.FileDataStorageManager;
84 import com.owncloud.android.datamodel.OCFile;
85 import com.owncloud.android.files.services.FileDownloader;
86 import com.owncloud.android.files.services.FileObserverService;
87 import com.owncloud.android.files.services.FileUploader;
88 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
89 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
90 import com.owncloud.android.media.MediaService;
91 import com.owncloud.android.media.MediaServiceBinder;
92 import com.owncloud.android.network.OwnCloudClientUtils;
93 import com.owncloud.android.operations.OnRemoteOperationListener;
94 import com.owncloud.android.operations.RemoteOperation;
95 import com.owncloud.android.operations.RemoteOperationResult;
96 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
97 import com.owncloud.android.operations.RemoveFileOperation;
98 import com.owncloud.android.operations.RenameFileOperation;
99 import com.owncloud.android.operations.SynchronizeFileOperation;
100 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
101 import com.owncloud.android.ui.activity.FileDetailActivity;
102 import com.owncloud.android.ui.activity.FileDisplayActivity;
103 import com.owncloud.android.ui.OnSwipeTouchListener;
104 import com.owncloud.android.ui.activity.TransferServiceGetter;
105 import com.owncloud.android.ui.activity.PreviewVideoActivity;
106 import com.owncloud.android.ui.dialog.EditNameDialog;
107 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
108 import com.owncloud.android.utils.OwnCloudVersion;
109
110 import com.owncloud.android.R;
111
112 import eu.alefzero.webdav.OnDatatransferProgressListener;
113 import eu.alefzero.webdav.WebdavClient;
114 import eu.alefzero.webdav.WebdavUtils;
115
116 /**
117 * This Fragment is used to display the details about a file.
118 *
119 * @author Bartek Przybylski
120 * @author David A. Velasco
121 */
122 public class FileDownloadFragment extends SherlockFragment implements
123 OnClickListener,
124 ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener,
125 FileFragment {
126
127 public static final String EXTRA_FILE = "FILE";
128 public static final String EXTRA_ACCOUNT = "ACCOUNT";
129
130 private FileFragment.ContainerActivity mContainerActivity;
131
132 private int mLayout;
133 private View mView;
134 private OCFile mFile;
135 private Account mAccount;
136 private FileDataStorageManager mStorageManager;
137
138 private DownloadFinishReceiver mDownloadFinishReceiver;
139 private UploadFinishReceiver mUploadFinishReceiver;
140 public ProgressListener mProgressListener;
141
142 private Handler mHandler;
143 private RemoteOperation mLastRemoteOperation;
144
145 private MediaServiceBinder mMediaServiceBinder = null;
146 private MediaController mMediaController = null;
147 private MediaServiceConnection mMediaServiceConnection = null;
148
149 private static final String TAG = FileDownloadFragment.class.getSimpleName();
150 public static final String FTAG = "FileDetails";
151 public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";
152
153
154 /**
155 * Creates an empty details fragment.
156 *
157 * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
158 */
159 public FileDownloadFragment() {
160 mFile = null;
161 mAccount = null;
162 mStorageManager = null;
163 mLayout = R.layout.file_details_empty;
164 mProgressListener = null;
165 }
166
167
168 /**
169 * Creates a details fragment.
170 *
171 * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before).
172 *
173 * @param fileToDetail An {@link OCFile} to show in the fragment
174 * @param ocAccount An ownCloud account; needed to start downloads
175 */
176 public FileDownloadFragment(OCFile fileToDetail, Account ocAccount) {
177 mFile = fileToDetail;
178 mAccount = ocAccount;
179 mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
180 mLayout = R.layout.file_details_empty;
181 mProgressListener = null;
182 }
183
184
185 @Override
186 public void onCreate(Bundle savedInstanceState) {
187 super.onCreate(savedInstanceState);
188 Log.e(TAG, "PREVIEW_DOWNLOAD_FRAGMENT ONCREATE " + ((mFile == null)? "(NULL)" : mFile.getFileName()));
189
190 mHandler = new Handler();
191 }
192
193
194 @Override
195 public View onCreateView(LayoutInflater inflater, ViewGroup container,
196 Bundle savedInstanceState) {
197 super.onCreateView(inflater, container, savedInstanceState);
198
199 if (savedInstanceState != null) {
200 mFile = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE);
201 mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT);
202 }
203
204 if(mFile != null && mAccount != null) {
205 //mLayout = R.layout.file_details_fragment;
206 }
207
208 View view = null;
209 view = inflater.inflate(mLayout, container, false);
210 mView = view;
211
212 if (mLayout == R.layout.file_details_fragment) {
213 mView.findViewById(R.id.fdKeepInSync).setOnClickListener(this);
214 mView.findViewById(R.id.fdRenameBtn).setOnClickListener(this);
215 mView.findViewById(R.id.fdDownloadBtn).setOnClickListener(this);
216 mView.findViewById(R.id.fdOpenBtn).setOnClickListener(this);
217 mView.findViewById(R.id.fdRemoveBtn).setOnClickListener(this);
218 //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this);
219 ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.fdProgressBar);
220 mProgressListener = new ProgressListener(progressBar);
221 }
222
223 updateFileDetails(false);
224 return view;
225 }
226
227
228 /**
229 * {@inheritDoc}
230 */
231 @Override
232 public void onAttach(Activity activity) {
233 super.onAttach(activity);
234 try {
235 mContainerActivity = (ContainerActivity) activity;
236
237 } catch (ClassCastException e) {
238 throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getSimpleName());
239 }
240 }
241
242
243 /**
244 * {@inheritDoc}
245 */
246 @Override
247 public void onActivityCreated(Bundle savedInstanceState) {
248 super.onActivityCreated(savedInstanceState);
249 if (mAccount != null) {
250 mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
251 mView.setOnTouchListener(new OnSwipeTouchListener(getActivity()));
252 }
253 }
254
255
256 @Override
257 public void onSaveInstanceState(Bundle outState) {
258 super.onSaveInstanceState(outState);
259 outState.putParcelable(FileDownloadFragment.EXTRA_FILE, mFile);
260 outState.putParcelable(FileDownloadFragment.EXTRA_ACCOUNT, mAccount);
261 }
262
263 @Override
264 public void onStart() {
265 super.onStart();
266 Log.e(TAG, "FILE_DOWNLOAD_FRAGMENT ONSTART " + mFile.getFileName());
267 if (mFile != null && mFile.isAudio()) {
268 bindMediaService();
269 }
270 listenForTransferProgress();
271 }
272
273 @Override
274 public void onResume() {
275 Log.e(TAG, "PREVIEW_DOWNLOAD_FRAGMENT ONRESUME " + mFile.getFileName());
276 super.onResume();
277
278 mDownloadFinishReceiver = new DownloadFinishReceiver();
279 IntentFilter filter = new IntentFilter(
280 FileDownloader.DOWNLOAD_FINISH_MESSAGE);
281 getActivity().registerReceiver(mDownloadFinishReceiver, filter);
282
283 mUploadFinishReceiver = new UploadFinishReceiver();
284 filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);
285 getActivity().registerReceiver(mUploadFinishReceiver, filter);
286
287 }
288
289
290 @Override
291 public void onPause() {
292 super.onPause();
293 Log.e(TAG, "PREVIEW_DOWNLOAD_FRAGMENT ONPAUSE " + mFile.getFileName());
294
295 getActivity().unregisterReceiver(mDownloadFinishReceiver);
296 mDownloadFinishReceiver = null;
297
298 getActivity().unregisterReceiver(mUploadFinishReceiver);
299 mUploadFinishReceiver = null;
300 }
301
302
303 @Override
304 public void onStop() {
305 super.onStop();
306 Log.e(TAG, "FILE_DOWNLOAD_FRAGMENT ONSTOP " + mFile.getFileName());
307 if (mMediaServiceConnection != null) {
308 Log.d(TAG, "Unbinding from MediaService ...");
309 if (mMediaServiceBinder != null && mMediaController != null) {
310 mMediaServiceBinder.unregisterMediaController(mMediaController);
311 }
312 getActivity().unbindService(mMediaServiceConnection);
313 mMediaServiceBinder = null;
314 if (mMediaController != null) {
315 mMediaController.hide();
316 mMediaController = null;
317 }
318 }
319 leaveTransferProgress();
320 }
321
322 @Override
323 public void onDestroy() {
324 super.onDestroy();
325 Log.e(TAG, "FILE_DOWNLOAD_FRAGMENT ONDESTROY " + mFile.getFileName());
326 }
327
328
329 @Override
330 public View getView() {
331 return super.getView() == null ? mView : super.getView();
332 }
333
334
335 @Override
336 public void onClick(View v) {
337 switch (v.getId()) {
338 case R.id.fdDownloadBtn: {
339 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
340 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
341 if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
342 downloaderBinder.cancel(mAccount, mFile);
343 if (mFile.isDown()) {
344 setButtonsForDown();
345 } else {
346 setButtonsForRemote();
347 }
348
349 } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
350 uploaderBinder.cancel(mAccount, mFile);
351 if (!mFile.fileExists()) {
352 // TODO make something better
353 if (getActivity() instanceof FileDisplayActivity) {
354 // double pane
355 FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
356 transaction.replace(R.id.file_details_container, new FileDownloadFragment(null, null), FTAG); // empty FileDetailFragment
357 transaction.commit();
358 mContainerActivity.onFileStateChanged();
359 } else {
360 getActivity().finish();
361 }
362
363 } else if (mFile.isDown()) {
364 setButtonsForDown();
365 } else {
366 setButtonsForRemote();
367 }
368
369 } else {
370 mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity());
371 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
372 mLastRemoteOperation.execute(wc, this, mHandler);
373
374 // update ui
375 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
376 getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
377
378 }
379 break;
380 }
381 case R.id.fdKeepInSync: {
382 CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
383 mFile.setKeepInSync(cb.isChecked());
384 mStorageManager.saveFile(mFile);
385
386 /// register the OCFile instance in the observer service to monitor local updates;
387 /// if necessary, the file is download
388 Intent intent = new Intent(getActivity().getApplicationContext(),
389 FileObserverService.class);
390 intent.putExtra(FileObserverService.KEY_FILE_CMD,
391 (cb.isChecked()?
392 FileObserverService.CMD_ADD_OBSERVED_FILE:
393 FileObserverService.CMD_DEL_OBSERVED_FILE));
394 intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
395 intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
396 getActivity().startService(intent);
397
398 if (mFile.keepInSync()) {
399 onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization
400 }
401 break;
402 }
403 case R.id.fdRenameBtn: {
404 EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this);
405 dialog.show(getFragmentManager(), "nameeditdialog");
406 break;
407 }
408 case R.id.fdRemoveBtn: {
409 ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
410 R.string.confirmation_remove_alert,
411 new String[]{mFile.getFileName()},
412 mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
413 mFile.isDown() ? R.string.confirmation_remove_local : -1,
414 R.string.common_cancel);
415 confDialog.setOnConfirmationListener(this);
416 confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
417 break;
418 }
419 case R.id.fdOpenBtn: {
420 openFile();
421 break;
422 }
423 default:
424 Log.e(TAG, "Incorrect view clicked!");
425 }
426
427 /* else if (v.getId() == R.id.fdShareBtn) {
428 Thread t = new Thread(new ShareRunnable(mFile.getRemotePath()));
429 t.start();
430 }*/
431 }
432
433
434 private void startVideoActivity() {
435 Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
436 i.putExtra(PreviewVideoActivity.EXTRA_FILE, mFile);
437 i.putExtra(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount);
438 startActivity(i);
439 }
440
441
442 private void bindMediaService() {
443 Log.d(TAG, "Binding to MediaService...");
444 if (mMediaServiceConnection == null) {
445 mMediaServiceConnection = new MediaServiceConnection();
446 }
447 getActivity().bindService( new Intent(getActivity(),
448 MediaService.class),
449 mMediaServiceConnection,
450 Context.BIND_AUTO_CREATE);
451 // follow the flow in MediaServiceConnection#onServiceConnected(...)
452 }
453
454 /** Defines callbacks for service binding, passed to bindService() */
455 private class MediaServiceConnection implements ServiceConnection {
456
457 @Override
458 public void onServiceConnected(ComponentName component, IBinder service) {
459 if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
460 Log.d(TAG, "Media service connected");
461 mMediaServiceBinder = (MediaServiceBinder) service;
462 if (mMediaServiceBinder != null) {
463 if (mMediaController == null) {
464 mMediaController = new MediaController(getSherlockActivity());
465 }
466 prepareMediaController();
467
468 Log.d(TAG, "Successfully bound to MediaService, MediaController ready");
469
470 } else {
471 Log.e(TAG, "Unexpected response from MediaService while binding");
472 }
473 }
474 }
475
476 private void prepareMediaController() {
477 mMediaServiceBinder.registerMediaController(mMediaController);
478 mMediaController.setMediaPlayer(mMediaServiceBinder);
479 mMediaController.setAnchorView(getView());
480 mMediaController.setEnabled(mMediaServiceBinder.isInPlaybackState());
481 }
482
483 @Override
484 public void onServiceDisconnected(ComponentName component) {
485 if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
486 Log.e(TAG, "Media service suddenly disconnected");
487 if (mMediaController != null) {
488 mMediaController.hide();
489 mMediaController.setMediaPlayer(null);
490 mMediaController = null;
491 }
492 mMediaServiceBinder = null;
493 mMediaServiceConnection = null;
494 }
495 }
496 }
497
498
499 /**
500 * Opens mFile.
501 */
502 private void openFile() {
503
504 String storagePath = mFile.getStoragePath();
505 String encodedStoragePath = WebdavUtils.encodePath(storagePath);
506 try {
507 Intent i = new Intent(Intent.ACTION_VIEW);
508 i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());
509 i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
510 startActivity(i);
511
512 } catch (Throwable t) {
513 Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
514 boolean toastIt = true;
515 String mimeType = "";
516 try {
517 Intent i = new Intent(Intent.ACTION_VIEW);
518 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
519 if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
520 if (mimeType != null) {
521 i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
522 } else {
523 // desperate try
524 i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*/*");
525 }
526 i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
527 startActivity(i);
528 toastIt = false;
529 }
530
531 } catch (IndexOutOfBoundsException e) {
532 Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
533
534 } catch (ActivityNotFoundException e) {
535 Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
536
537 } catch (Throwable th) {
538 Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);
539
540 } finally {
541 if (toastIt) {
542 Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();
543 }
544 }
545
546 }
547 }
548
549
550 @Override
551 public void onConfirmation(String callerTag) {
552 if (callerTag.equals(FTAG_CONFIRMATION)) {
553 if (mStorageManager.getFileById(mFile.getFileId()) != null) {
554 mLastRemoteOperation = new RemoveFileOperation( mFile,
555 true,
556 mStorageManager);
557 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
558 mLastRemoteOperation.execute(wc, this, mHandler);
559
560 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
561 getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
562 }
563 }
564 }
565
566 @Override
567 public void onNeutral(String callerTag) {
568 File f = null;
569 if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) {
570 f.delete();
571 mFile.setStoragePath(null);
572 mStorageManager.saveFile(mFile);
573 updateFileDetails(mFile, mAccount);
574 }
575 }
576
577 @Override
578 public void onCancel(String callerTag) {
579 Log.d(TAG, "REMOVAL CANCELED");
580 }
581
582
583 /**
584 * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.
585 *
586 * @return True when the fragment was created with the empty layout.
587 */
588 public boolean isEmpty() {
589 return (mLayout == R.layout.file_details_empty || mFile == null || mAccount == null);
590 }
591
592
593 /**
594 * {@inheritDoc}
595 */
596 public OCFile getFile(){
597 return mFile;
598 }
599
600 /**
601 * Use this method to signal this Activity that it shall update its view.
602 *
603 * @param file : An {@link OCFile}
604 */
605 public void updateFileDetails(OCFile file, Account ocAccount) {
606 mFile = file;
607 if (ocAccount != null && (
608 mStorageManager == null ||
609 (mAccount != null && !mAccount.equals(ocAccount))
610 )) {
611 mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
612 }
613 mAccount = ocAccount;
614 updateFileDetails(false);
615 }
616
617
618 /**
619 * Updates the view with all relevant details about that file.
620 *
621 * TODO Remove parameter when the transferring state of files is kept in database.
622 *
623 * TODO REFACTORING! this method called 5 times before every time the fragment is shown!
624 *
625 * @param transferring Flag signaling if the file should be considered as downloading or uploading,
626 * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and
627 * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
628 *
629 */
630 public void updateFileDetails(boolean transferring) {
631
632 if (readyToShow()) {
633
634 // set file details
635 setFilename(mFile.getFileName());
636 setFiletype(mFile.getMimetype());
637 setFilesize(mFile.getFileLength());
638 if(ocVersionSupportsTimeCreated()){
639 setTimeCreated(mFile.getCreationTimestamp());
640 }
641
642 setTimeModified(mFile.getModificationTimestamp());
643
644 CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);
645 cb.setChecked(mFile.keepInSync());
646
647 // configure UI for depending upon local state of the file
648 //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {
649 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
650 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
651 if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {
652 setButtonsForTransferring();
653
654 } else if (mFile.isDown()) {
655
656 setButtonsForDown();
657
658 } else {
659 // TODO load default preview image; when the local file is removed, the preview remains there
660 setButtonsForRemote();
661 }
662 }
663 getView().invalidate();
664 }
665
666
667 /**
668 * Checks if the fragment is ready to show details of a OCFile
669 *
670 * @return 'True' when the fragment is ready to show details of a file
671 */
672 private boolean readyToShow() {
673 return (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment);
674 }
675
676
677
678 /**
679 * Updates the filename in view
680 * @param filename to set
681 */
682 private void setFilename(String filename) {
683 TextView tv = (TextView) getView().findViewById(R.id.fdFilename);
684 if (tv != null)
685 tv.setText(filename);
686 }
687
688 /**
689 * Updates the MIME type in view
690 * @param mimetype to set
691 */
692 private void setFiletype(String mimetype) {
693 TextView tv = (TextView) getView().findViewById(R.id.fdType);
694 if (tv != null) {
695 String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);;
696 tv.setText(printableMimetype);
697 }
698 ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon);
699 if (iv != null) {
700 iv.setImageResource(DisplayUtils.getResourceId(mimetype));
701 }
702 }
703
704 /**
705 * Updates the file size in view
706 * @param filesize in bytes to set
707 */
708 private void setFilesize(long filesize) {
709 TextView tv = (TextView) getView().findViewById(R.id.fdSize);
710 if (tv != null)
711 tv.setText(DisplayUtils.bytesToHumanReadable(filesize));
712 }
713
714 /**
715 * Updates the time that the file was created in view
716 * @param milliseconds Unix time to set
717 */
718 private void setTimeCreated(long milliseconds){
719 TextView tv = (TextView) getView().findViewById(R.id.fdCreated);
720 TextView tvLabel = (TextView) getView().findViewById(R.id.fdCreatedLabel);
721 if(tv != null){
722 tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));
723 tv.setVisibility(View.VISIBLE);
724 tvLabel.setVisibility(View.VISIBLE);
725 }
726 }
727
728 /**
729 * Updates the time that the file was last modified
730 * @param milliseconds Unix time to set
731 */
732 private void setTimeModified(long milliseconds){
733 TextView tv = (TextView) getView().findViewById(R.id.fdModified);
734 if(tv != null){
735 tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));
736 }
737 }
738
739 /**
740 * Enables or disables buttons for a file being downloaded
741 */
742 private void setButtonsForTransferring() {
743 if (!isEmpty()) {
744 Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
745 downloadButton.setText(R.string.common_cancel);
746 //downloadButton.setEnabled(false);
747
748 // let's protect the user from himself ;)
749 ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);
750 ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false);
751 ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false);
752 getView().findViewById(R.id.fdKeepInSync).setEnabled(false);
753
754 // show the progress bar for the transfer
755 ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
756 progressBar.setVisibility(View.VISIBLE);
757 TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
758 progressText.setVisibility(View.VISIBLE);
759 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
760 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
761 if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
762 progressText.setText(R.string.downloader_download_in_progress_ticker);
763 } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
764 progressText.setText(R.string.uploader_upload_in_progress_ticker);
765 }
766 }
767 }
768
769
770 /**
771 * Enables or disables buttons for a file locally available
772 */
773 private void setButtonsForDown() {
774 if (!isEmpty()) {
775 Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
776 downloadButton.setText(R.string.filedetails_sync_file);
777
778 ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true);
779 ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);
780 ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);
781 getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
782
783 // hides the progress bar
784 ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
785 progressBar.setVisibility(View.GONE);
786 TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
787 progressText.setVisibility(View.GONE);
788 }
789 }
790
791 /**
792 * Enables or disables buttons for a file not locally available
793 */
794 private void setButtonsForRemote() {
795 if (!isEmpty()) {
796 Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
797 downloadButton.setText(R.string.filedetails_download);
798
799 ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);
800 ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);
801 ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);
802 getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
803
804 // hides the progress bar
805 ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
806 progressBar.setVisibility(View.GONE);
807 TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
808 progressText.setVisibility(View.GONE);
809 }
810 }
811
812
813 /**
814 * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return
815 * the time that the file was created. There is a chance that this will
816 * be fixed in future versions. Use this method to check if this version of
817 * ownCloud has this fix.
818 * @return True, if ownCloud the ownCloud version is supporting creation time
819 */
820 private boolean ocVersionSupportsTimeCreated(){
821 /*if(mAccount != null){
822 AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);
823 OwnCloudVersion ocVersion = new OwnCloudVersion(accManager
824 .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));
825 if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) {
826 return true;
827 }
828 }*/
829 return false;
830 }
831
832
833 /**
834 * Once the file download has finished -> update view
835 * @author Bartek Przybylski
836 */
837 private class DownloadFinishReceiver extends BroadcastReceiver {
838 @Override
839 public void onReceive(Context context, Intent intent) {
840 String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
841
842 if (!isEmpty() && accountName.equals(mAccount.name)) {
843 boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
844 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
845 if (mFile.getRemotePath().equals(downloadedRemotePath)) {
846 if (downloadWasFine) {
847 mFile = mStorageManager.getFileByPath(downloadedRemotePath);
848 }
849 mContainerActivity.notifySuccessfulDownload(mFile, intent, downloadWasFine);
850 getActivity().removeStickyBroadcast(intent);
851 updateFileDetails(false); // it updates the buttons; must be called although !downloadWasFine
852 }
853 }
854 }
855 }
856
857
858 /**
859 * Once the file upload has finished -> update view
860 *
861 * Being notified about the finish of an upload is necessary for the next sequence:
862 * 1. Upload a big file.
863 * 2. Force a synchronization; if it finished before the upload, the file in transfer will be included in the local database and in the file list
864 * of its containing folder; the the server includes it in the PROPFIND requests although it's not fully upload.
865 * 3. Click the file in the list to see its details.
866 * 4. Wait for the upload finishes; at this moment, the details view must be refreshed to enable the action buttons.
867 */
868 private class UploadFinishReceiver extends BroadcastReceiver {
869 @Override
870 public void onReceive(Context context, Intent intent) {
871 String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
872
873 if (!isEmpty() && accountName.equals(mAccount.name)) {
874 boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
875 String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
876 boolean renamedInUpload = mFile.getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
877 if (mFile.getRemotePath().equals(uploadRemotePath) ||
878 renamedInUpload) {
879 if (uploadWasFine) {
880 mFile = mStorageManager.getFileByPath(uploadRemotePath);
881 }
882 if (renamedInUpload) {
883 String newName = (new File(uploadRemotePath)).getName();
884 Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG);
885 msg.show();
886 }
887 getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done
888 updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server
889 }
890 }
891 }
892 }
893
894
895 // this is a temporary class for sharing purposes, it need to be replaced in transfer service
896 @SuppressWarnings("unused")
897 private class ShareRunnable implements Runnable {
898 private String mPath;
899
900 public ShareRunnable(String path) {
901 mPath = path;
902 }
903
904 public void run() {
905 AccountManager am = AccountManager.get(getActivity());
906 Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
907 OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
908 String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);
909
910 Log.d("share", "sharing for version " + ocv.toString());
911
912 if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
913 String APPS_PATH = "/apps/files_sharing/";
914 String SHARE_PATH = "ajax/share.php";
915
916 String SHARED_PATH = "/apps/files_sharing/get.php?token=";
917
918 final String WEBDAV_SCRIPT = "webdav.php";
919 final String WEBDAV_FILES_LOCATION = "/files/";
920
921 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getActivity().getApplicationContext());
922 HttpConnectionManagerParams params = new HttpConnectionManagerParams();
923 params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);
924
925 //wc.getParams().setParameter("http.protocol.single-cookie-header", true);
926 //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
927
928 PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);
929
930 post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );
931 post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
932 List<NameValuePair> formparams = new ArrayList<NameValuePair>();
933 Log.d("share", mPath+"");
934 formparams.add(new BasicNameValuePair("sources",mPath));
935 formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
936 formparams.add(new BasicNameValuePair("permissions", "0"));
937 post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));
938
939 int status;
940 try {
941 PropFindMethod find = new PropFindMethod(url+"/");
942 find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
943 Log.d("sharer", ""+ url+"/");
944
945 for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
946 Log.d("sharer-h", a.getName() + ":"+a.getValue());
947 }
948
949 int status2 = wc.executeMethod(find);
950
951 Log.d("sharer", "propstatus "+status2);
952
953 GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
954 get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
955
956 status2 = wc.executeMethod(get);
957
958 Log.d("sharer", "getstatus "+status2);
959 Log.d("sharer", "" + get.getResponseBodyAsString());
960
961 for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
962 Log.d("sharer", a.getName() + ":"+a.getValue());
963 }
964
965 status = wc.executeMethod(post);
966 for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
967 Log.d("sharer-h", a.getName() + ":"+a.getValue());
968 }
969 for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
970 Log.d("sharer", a.getName() + ":"+a.getValue());
971 }
972 String resp = post.getResponseBodyAsString();
973 Log.d("share", ""+post.getURI().toString());
974 Log.d("share", "returned status " + status);
975 Log.d("share", " " +resp);
976
977 if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {
978 return;
979 }
980
981 JSONObject jsonObject = new JSONObject (resp);
982 String jsonStatus = jsonObject.getString("status");
983 if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");
984
985 String token = jsonObject.getString("data");
986 String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
987 Log.d("Actions:shareFile ok", "url: " + uri);
988
989 } catch (Exception e) {
990 e.printStackTrace();
991 }
992
993 } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {
994
995 }
996 }
997 }
998
999 public void onDismiss(EditNameDialog dialog) {
1000 if (dialog.getResult()) {
1001 String newFilename = dialog.getNewFilename();
1002 Log.d(TAG, "name edit dialog dismissed with new name " + newFilename);
1003 mLastRemoteOperation = new RenameFileOperation( mFile,
1004 mAccount,
1005 newFilename,
1006 new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
1007 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
1008 mLastRemoteOperation.execute(wc, this, mHandler);
1009 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1010 getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1011 }
1012 }
1013
1014
1015 /**
1016 * {@inheritDoc}
1017 */
1018 @Override
1019 public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
1020 if (operation.equals(mLastRemoteOperation)) {
1021 if (operation instanceof RemoveFileOperation) {
1022 onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
1023
1024 } else if (operation instanceof RenameFileOperation) {
1025 onRenameFileOperationFinish((RenameFileOperation)operation, result);
1026
1027 } else if (operation instanceof SynchronizeFileOperation) {
1028 onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
1029 }
1030 }
1031 }
1032
1033
1034 private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
1035 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1036 getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1037
1038 if (result.isSuccess()) {
1039 Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
1040 msg.show();
1041 if (inDisplayActivity) {
1042 // double pane
1043 FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
1044 transaction.replace(R.id.file_details_container, new FileDownloadFragment(null, null)); // empty FileDetailFragment
1045 transaction.commit();
1046 mContainerActivity.onFileStateChanged();
1047 } else {
1048 getActivity().finish();
1049 }
1050
1051 } else {
1052 Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG);
1053 msg.show();
1054 if (result.isSslRecoverableException()) {
1055 // TODO show the SSL warning dialog
1056 }
1057 }
1058 }
1059
1060 private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
1061 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1062 getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1063
1064 if (result.isSuccess()) {
1065 updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
1066 mContainerActivity.onFileStateChanged();
1067
1068 } else {
1069 if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
1070 Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
1071 msg.show();
1072 // TODO throw again the new rename dialog
1073 } else {
1074 Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
1075 msg.show();
1076 if (result.isSslRecoverableException()) {
1077 // TODO show the SSL warning dialog
1078 }
1079 }
1080 }
1081 }
1082
1083 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
1084 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1085 getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1086
1087 if (!result.isSuccess()) {
1088 if (result.getCode() == ResultCode.SYNC_CONFLICT) {
1089 Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);
1090 i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile);
1091 i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
1092 startActivity(i);
1093
1094 } else {
1095 Toast msg = Toast.makeText(getActivity(), R.string.sync_file_fail_msg, Toast.LENGTH_LONG);
1096 msg.show();
1097 }
1098
1099 if (mFile.isDown()) {
1100 setButtonsForDown();
1101
1102 } else {
1103 setButtonsForRemote();
1104 }
1105
1106 } else {
1107 if (operation.transferWasRequested()) {
1108 setButtonsForTransferring();
1109 mContainerActivity.onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so
1110 // checking the service to see if the file is downloading results in FALSE
1111 } else {
1112 Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
1113 msg.show();
1114 if (mFile.isDown()) {
1115 setButtonsForDown();
1116
1117 } else {
1118 setButtonsForRemote();
1119 }
1120 }
1121 }
1122 }
1123
1124
1125 public void listenForTransferProgress() {
1126 if (mProgressListener != null) {
1127 if (mContainerActivity.getFileDownloaderBinder() != null) {
1128 mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
1129 }
1130 if (mContainerActivity.getFileUploaderBinder() != null) {
1131 mContainerActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
1132 }
1133 }
1134 }
1135
1136
1137 public void leaveTransferProgress() {
1138 if (mProgressListener != null) {
1139 if (mContainerActivity.getFileDownloaderBinder() != null) {
1140 mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
1141 }
1142 if (mContainerActivity.getFileUploaderBinder() != null) {
1143 mContainerActivity.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
1144 }
1145 }
1146 }
1147
1148
1149
1150 /**
1151 * Helper class responsible for updating the progress bar shown for file uploading or downloading
1152 *
1153 * @author David A. Velasco
1154 */
1155 private class ProgressListener implements OnDatatransferProgressListener {
1156 int mLastPercent = 0;
1157 WeakReference<ProgressBar> mProgressBar = null;
1158
1159 ProgressListener(ProgressBar progressBar) {
1160 mProgressBar = new WeakReference<ProgressBar>(progressBar);
1161 }
1162
1163 @Override
1164 public void onTransferProgress(long progressRate) {
1165 // old method, nothing here
1166 };
1167
1168 @Override
1169 public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String filename) {
1170 int percent = (int)(100.0*((double)totalTransferredSoFar)/((double)totalToTransfer));
1171 if (percent != mLastPercent) {
1172 ProgressBar pb = mProgressBar.get();
1173 if (pb != null) {
1174 pb.setProgress(percent);
1175 pb.postInvalidate();
1176 }
1177 }
1178 mLastPercent = percent;
1179 }
1180
1181 };
1182
1183
1184
1185 }