Cleaned stuff , add a history delete button and renamed
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 package com.owncloud.android.ui.activity;
21
22 import java.io.File;
23
24 import android.accounts.Account;
25 import android.app.AlertDialog;
26 import android.app.AlertDialog.Builder;
27 import android.app.Dialog;
28 import android.app.ProgressDialog;
29 import android.content.BroadcastReceiver;
30 import android.content.ComponentName;
31 import android.content.ContentResolver;
32 import android.content.Context;
33 import android.content.DialogInterface;
34 import android.content.DialogInterface.OnClickListener;
35 import android.content.Intent;
36 import android.content.IntentFilter;
37 import android.content.ServiceConnection;
38 import android.content.SharedPreferences;
39 import android.content.SharedPreferences.Editor;
40 import android.content.pm.PackageInfo;
41 import android.content.pm.PackageManager.NameNotFoundException;
42 import android.content.res.Resources.NotFoundException;
43 import android.database.Cursor;
44 import android.graphics.Bitmap;
45 import android.graphics.drawable.BitmapDrawable;
46 import android.net.Uri;
47 import android.os.Bundle;
48 import android.os.Handler;
49 import android.os.IBinder;
50 import android.preference.PreferenceManager;
51 import android.provider.MediaStore;
52 import android.support.v4.app.FragmentTransaction;
53 import android.util.Log;
54 import android.view.View;
55 import android.view.ViewGroup;
56 import android.widget.ArrayAdapter;
57 import android.widget.EditText;
58 import android.widget.TextView;
59 import android.widget.Toast;
60
61 import com.actionbarsherlock.app.ActionBar;
62 import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
63 import com.actionbarsherlock.app.SherlockFragmentActivity;
64 import com.actionbarsherlock.view.Menu;
65 import com.actionbarsherlock.view.MenuInflater;
66 import com.actionbarsherlock.view.MenuItem;
67 import com.actionbarsherlock.view.Window;
68 import com.owncloud.android.AccountUtils;
69 import com.owncloud.android.Log_OC;
70 import com.owncloud.android.R;
71 import com.owncloud.android.authenticator.AccountAuthenticator;
72 import com.owncloud.android.datamodel.DataStorageManager;
73 import com.owncloud.android.datamodel.FileDataStorageManager;
74 import com.owncloud.android.datamodel.OCFile;
75 import com.owncloud.android.files.services.FileDownloader;
76 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
77 import com.owncloud.android.files.services.FileObserverService;
78 import com.owncloud.android.files.services.FileUploader;
79 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
80 import com.owncloud.android.network.OwnCloudClientUtils;
81 import com.owncloud.android.operations.OnRemoteOperationListener;
82 import com.owncloud.android.operations.RemoteOperation;
83 import com.owncloud.android.operations.RemoteOperationResult;
84 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
85 import com.owncloud.android.operations.RemoveFileOperation;
86 import com.owncloud.android.operations.RenameFileOperation;
87 import com.owncloud.android.operations.SynchronizeFileOperation;
88 import com.owncloud.android.syncadapter.FileSyncService;
89 import com.owncloud.android.ui.dialog.ChangelogDialog;
90 import com.owncloud.android.ui.dialog.SslValidatorDialog;
91 import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;
92 import com.owncloud.android.ui.fragment.FileDetailFragment;
93 import com.owncloud.android.ui.fragment.OCFileListFragment;
94
95 import eu.alefzero.webdav.WebdavClient;
96
97 /**
98 * Displays, what files the user has available in his ownCloud.
99 *
100 * @author Bartek Przybylski
101 *
102 */
103
104 public class FileDisplayActivity extends SherlockFragmentActivity implements OCFileListFragment.ContainerActivity,
105 FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener {
106
107 private ArrayAdapter<String> mDirectories;
108 private OCFile mCurrentDir = null;
109 private OCFile mCurrentFile = null;
110
111 private DataStorageManager mStorageManager;
112 private SyncBroadcastReceiver mSyncBroadcastReceiver;
113 private UploadFinishReceiver mUploadFinishReceiver;
114 private DownloadFinishReceiver mDownloadFinishReceiver;
115 private FileDownloaderBinder mDownloaderBinder = null;
116 private FileUploaderBinder mUploaderBinder = null;
117 private ServiceConnection mDownloadConnection = null, mUploadConnection = null;
118 private RemoteOperationResult mLastSslUntrustedServerResult = null;
119
120 private OCFileListFragment mFileList;
121
122 private boolean mDualPane;
123
124 private static final int DIALOG_SETUP_ACCOUNT = 0;
125 private static final int DIALOG_CREATE_DIR = 1;
126 public static final int DIALOG_SHORT_WAIT = 3;
127 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 4;
128 private static final int DIALOG_SSL_VALIDATOR = 5;
129 private static final int DIALOG_CERT_NOT_SAVED = 6;
130 private static final String DIALOG_CHANGELOG_TAG = "DIALOG_CHANGELOG";
131
132
133 private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
134 private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
135 private static final int ACTION_SELECT_FAILED_INSTANT_UPLOAD = 2;
136
137 private static final String TAG = "FileDisplayActivity";
138
139
140 @Override
141 public void onCreate(Bundle savedInstanceState) {
142 Log_OC.d(getClass().toString(), "onCreate() start");
143 super.onCreate(savedInstanceState);
144
145 /// Load of parameters from received intent
146 mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent
147 Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);
148 if (account != null)
149 AccountUtils.setCurrentOwnCloudAccount(this, account.name);
150
151 /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
152 if(savedInstanceState != null) {
153 // TODO - test if savedInstanceState should take precedence over file in the intent ALWAYS (now), NEVER, or SOME TIMES
154 mCurrentDir = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);
155 }
156
157 if (!AccountUtils.accountsAreSetup(this)) {
158 /// no account available: FORCE ACCOUNT CREATION
159 mStorageManager = null;
160 createFirstAccount();
161
162 } else { // / at least an account is available
163
164 initDataFromCurrentAccount(); // it checks mCurrentDir and
165 // mCurrentFile with the current
166 // account
167
168 }
169
170 mUploadConnection = new ListServiceConnection();
171 mDownloadConnection = new ListServiceConnection();
172 bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);
173 bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
174
175 // PIN CODE request ; best location is to decide, let's try this first
176 if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {
177 requestPinCode();
178 }
179
180 // file observer
181 Intent observer_intent = new Intent(this, FileObserverService.class);
182 observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST);
183 startService(observer_intent);
184
185
186 /// USER INTERFACE
187 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
188
189 // Drop-down navigation
190 mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
191 OCFile currFile = mCurrentDir;
192 while (currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
193 mDirectories.add(currFile.getFileName());
194 currFile = mStorageManager.getFileById(currFile.getParentId());
195 }
196 mDirectories.add(OCFile.PATH_SEPARATOR);
197
198 // Inflate and set the layout view
199 setContentView(R.layout.files);
200 mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
201 mDualPane = (findViewById(R.id.file_details_container) != null);
202 if (mDualPane) {
203 initFileDetailsInDualPane();
204 }
205
206 // Action bar setup
207 ActionBar actionBar = getSupportActionBar();
208 actionBar.setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation
209 actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getParentId() != 0);
210 actionBar.setDisplayShowTitleEnabled(false);
211 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
212 actionBar.setListNavigationCallbacks(mDirectories, this);
213 setSupportProgressBarIndeterminateVisibility(false); // always AFTER setContentView(...) ; to workaround bug in its implementation
214
215
216 // show changelog, if needed
217 showChangeLog();
218
219 Log_OC.d(getClass().toString(), "onCreate() end");
220 }
221
222
223 /**
224 * Shows a dialog with the change log of the current version after each app update
225 *
226 * TODO make it permanent; by now, only to advice the workaround app for 4.1.x
227 */
228 private void showChangeLog() {
229 if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.JELLY_BEAN) {
230 final String KEY_VERSION = "version";
231 SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
232 int currentVersionNumber = 0;
233 int savedVersionNumber = sharedPref.getInt(KEY_VERSION, 0);
234 try {
235 PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
236 currentVersionNumber = pi.versionCode;
237 } catch (Exception e) {}
238
239 if (currentVersionNumber > savedVersionNumber) {
240 ChangelogDialog.newInstance(true).show(getSupportFragmentManager(), DIALOG_CHANGELOG_TAG);
241 Editor editor = sharedPref.edit();
242 editor.putInt(KEY_VERSION, currentVersionNumber);
243 editor.commit();
244 }
245 }
246 }
247
248
249 /**
250 * Launches the account creation activity. To use when no ownCloud account is available
251 */
252 private void createFirstAccount() {
253 Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
254 intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });
255 startActivity(intent); // the new activity won't be created until this.onStart() and this.onResume() are finished;
256 }
257
258
259 /**
260 * Load of state dependent of the existence of an ownCloud account
261 */
262 private void initDataFromCurrentAccount() {
263 /// Storage manager initialization - access to local database
264 mStorageManager = new FileDataStorageManager(
265 AccountUtils.getCurrentOwnCloudAccount(this),
266 getContentResolver());
267
268 /// Check if mCurrentDir is a directory
269 if(mCurrentDir != null && !mCurrentDir.isDirectory()) {
270 mCurrentFile = mCurrentDir;
271 mCurrentDir = mStorageManager.getFileById(mCurrentDir.getParentId());
272 }
273
274 /// Check if mCurrentDir and mCurrentFile are in the current account, and update them
275 if (mCurrentDir != null) {
276 mCurrentDir = mStorageManager.getFileByPath(mCurrentDir.getRemotePath()); // mCurrentDir == null if it is not in the current account
277 }
278 if (mCurrentFile != null) {
279 if (mCurrentFile.fileExists()) {
280 mCurrentFile = mStorageManager.getFileByPath(mCurrentFile.getRemotePath()); // mCurrentFile == null if it is not in the current account
281 } // else : keep mCurrentFile with the received value; this is currently the case of an upload in progress, when the user presses the status notification in a landscape tablet
282 }
283
284 /// Default to root if mCurrentDir was not found
285 if (mCurrentDir == null) {
286 mCurrentDir = mStorageManager.getFileByPath("/"); // will be NULL if the database was never synchronized
287 }
288 }
289
290
291 private void initFileDetailsInDualPane() {
292 if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {
293 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
294 if (mCurrentFile != null) {
295 transaction.replace(R.id.file_details_container,
296 new FileDetailFragment(mCurrentFile, AccountUtils.getCurrentOwnCloudAccount(this)),
297 FileDetailFragment.FTAG); // empty FileDetailFragment
298 mCurrentFile = null;
299 } else {
300 transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null),
301 FileDetailFragment.FTAG); // empty FileDetailFragment
302 }
303 transaction.commit();
304 }
305 }
306
307
308 @Override
309 public void onDestroy() {
310 super.onDestroy();
311 if (mDownloadConnection != null)
312 unbindService(mDownloadConnection);
313 if (mUploadConnection != null)
314 unbindService(mUploadConnection);
315 }
316
317
318 @Override
319 public boolean onCreateOptionsMenu(Menu menu) {
320 MenuInflater inflater = getSherlock().getMenuInflater();
321 inflater.inflate(R.menu.menu, menu);
322 return true;
323 }
324
325 @Override
326 public boolean onOptionsItemSelected(MenuItem item) {
327 boolean retval = true;
328 switch (item.getItemId()) {
329 case R.id.createDirectoryItem: {
330 showDialog(DIALOG_CREATE_DIR);
331 break;
332 }
333 case R.id.startSync: {
334 startSynchronization();
335 break;
336 }
337 case R.id.action_upload: {
338 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE);
339 break;
340 }
341 case R.id.action_settings: {
342 Intent settingsIntent = new Intent(this, Preferences.class);
343 startActivity(settingsIntent);
344 break;
345 }
346 case android.R.id.home: {
347 if (mCurrentDir != null && mCurrentDir.getParentId() != 0) {
348 onBackPressed();
349 }
350 break;
351 }
352 default:
353 retval = super.onOptionsItemSelected(item);
354 }
355 return retval;
356 }
357
358 private void startSynchronization() {
359 ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account
360 Bundle bundle = new Bundle();
361 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
362 ContentResolver.requestSync(
363 AccountUtils.getCurrentOwnCloudAccount(this),
364 AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);
365 }
366
367
368 @Override
369 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
370 int i = itemPosition;
371 while (i-- != 0) {
372 onBackPressed();
373 }
374 // the next operation triggers a new call to this method, but it's necessary to
375 // ensure that the name exposed in the action bar is the current directory when the
376 // user selected it in the navigation list
377 if (itemPosition != 0)
378 getSupportActionBar().setSelectedNavigationItem(0);
379 return true;
380 }
381
382 /**
383 * Called, when the user selected something for uploading
384 */
385 public void onActivityResult(int requestCode, int resultCode, Intent data) {
386
387 if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS
388 && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
389 requestSimpleUpload(data, resultCode);
390
391 } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES
392 && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
393 requestMultipleUpload(data, resultCode);
394
395 }
396 }
397
398 private void requestMultipleUpload(Intent data, int resultCode) {
399 String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
400 if (filePaths != null) {
401 String[] remotePaths = new String[filePaths.length];
402 String remotePathBase = "";
403 for (int j = mDirectories.getCount() - 2; j >= 0; --j) {
404 remotePathBase += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);
405 }
406 if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR))
407 remotePathBase += OCFile.PATH_SEPARATOR;
408 for (int j = 0; j < remotePaths.length; j++) {
409 remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
410 }
411
412 Intent i = new Intent(this, FileUploader.class);
413 i.putExtra(FileUploader.KEY_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
414 i.putExtra(FileUploader.KEY_LOCAL_FILE, filePaths);
415 i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
416 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
417 if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
418 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
419 startService(i);
420
421 } else {
422 Log_OC.d("FileDisplay", "User clicked on 'Update' with no selection");
423 Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected), Toast.LENGTH_LONG);
424 t.show();
425 return;
426 }
427 }
428
429
430 private void requestSimpleUpload(Intent data, int resultCode) {
431 String filepath = null;
432 try {
433 Uri selectedImageUri = data.getData();
434
435 String filemanagerstring = selectedImageUri.getPath();
436 String selectedImagePath = getPath(selectedImageUri);
437
438 if (selectedImagePath != null)
439 filepath = selectedImagePath;
440 else
441 filepath = filemanagerstring;
442
443 } catch (Exception e) {
444 Log_OC.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);
445 e.printStackTrace();
446
447 } finally {
448 if (filepath == null) {
449 Log_OC.e("FileDisplay", "Couldnt resolve path to file");
450 Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);
451 t.show();
452 return;
453 }
454 }
455
456 Intent i = new Intent(this, FileUploader.class);
457 i.putExtra(FileUploader.KEY_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
458 String remotepath = new String();
459 for (int j = mDirectories.getCount() - 2; j >= 0; --j) {
460 remotepath += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);
461 }
462 if (!remotepath.endsWith(OCFile.PATH_SEPARATOR))
463 remotepath += OCFile.PATH_SEPARATOR;
464 remotepath += new File(filepath).getName();
465
466 i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);
467 i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);
468 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
469 if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
470 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
471 startService(i);
472 }
473
474
475 @Override
476 public void onBackPressed() {
477 if (mDirectories.getCount() <= 1) {
478 finish();
479 return;
480 }
481 popDirname();
482 mFileList.onNavigateUp();
483 mCurrentDir = mFileList.getCurrentFile();
484
485 if (mDualPane) {
486 // Resets the FileDetailsFragment on Tablets so that it always
487 // displays
488 FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(
489 FileDetailFragment.FTAG);
490 if (fileDetails != null && !fileDetails.isEmpty()) {
491 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
492 transaction.remove(fileDetails);
493 transaction.add(R.id.file_details_container, new FileDetailFragment(null, null),
494 FileDetailFragment.FTAG);
495 transaction.commit();
496 }
497 }
498
499 if (mCurrentDir.getParentId() == 0) {
500 ActionBar actionBar = getSupportActionBar();
501 actionBar.setDisplayHomeAsUpEnabled(false);
502 }
503 }
504
505 @Override
506 protected void onSaveInstanceState(Bundle outState) {
507 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
508 Log_OC.d(getClass().toString(), "onSaveInstanceState() start");
509 super.onSaveInstanceState(outState);
510 outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir);
511 if (mDualPane) {
512 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
513 if (fragment != null) {
514 OCFile file = fragment.getDisplayedFile();
515 if (file != null) {
516 outState.putParcelable(FileDetailFragment.EXTRA_FILE, file);
517 }
518 }
519 }
520 Log_OC.d(getClass().toString(), "onSaveInstanceState() end");
521 }
522
523 @Override
524 protected void onResume() {
525 Log_OC.d(getClass().toString(), "onResume() start");
526 super.onResume();
527
528 if (AccountUtils.accountsAreSetup(this)) {
529
530 if (mStorageManager == null) {
531 // this is necessary for handling the come back to FileDisplayActivity when the first ownCloud account is created
532 initDataFromCurrentAccount();
533 if (mDualPane) {
534 initFileDetailsInDualPane();
535 }
536 }
537
538 // Listen for sync messages
539 IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);
540 mSyncBroadcastReceiver = new SyncBroadcastReceiver();
541 registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
542
543 // Listen for upload messages
544 IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);
545 mUploadFinishReceiver = new UploadFinishReceiver();
546 registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
547
548 // Listen for download messages
549 IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
550 mDownloadFinishReceiver = new DownloadFinishReceiver();
551 registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
552
553 // List current directory
554 mFileList.listDirectory(mCurrentDir); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
555
556 } else {
557
558 mStorageManager = null; // an invalid object will be there if all the ownCloud accounts are removed
559 showDialog(DIALOG_SETUP_ACCOUNT);
560
561 }
562 Log_OC.d(getClass().toString(), "onResume() end");
563 }
564
565
566 @Override
567 protected void onPause() {
568 Log_OC.d(getClass().toString(), "onPause() start");
569 super.onPause();
570 if (mSyncBroadcastReceiver != null) {
571 unregisterReceiver(mSyncBroadcastReceiver);
572 mSyncBroadcastReceiver = null;
573 }
574 if (mUploadFinishReceiver != null) {
575 unregisterReceiver(mUploadFinishReceiver);
576 mUploadFinishReceiver = null;
577 }
578 if (mDownloadFinishReceiver != null) {
579 unregisterReceiver(mDownloadFinishReceiver);
580 mDownloadFinishReceiver = null;
581 }
582 if (!AccountUtils.accountsAreSetup(this)) {
583 dismissDialog(DIALOG_SETUP_ACCOUNT);
584 }
585
586 Log_OC.d(getClass().toString(), "onPause() end");
587 }
588
589
590 @Override
591 protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
592 if (id == DIALOG_SSL_VALIDATOR && mLastSslUntrustedServerResult != null) {
593 ((SslValidatorDialog)dialog).updateResult(mLastSslUntrustedServerResult);
594 }
595 }
596
597
598 @Override
599 protected Dialog onCreateDialog(int id) {
600 Dialog dialog = null;
601 AlertDialog.Builder builder;
602 switch (id) {
603 case DIALOG_SETUP_ACCOUNT: {
604 builder = new AlertDialog.Builder(this);
605 builder.setTitle(R.string.main_tit_accsetup);
606 builder.setMessage(R.string.main_wrn_accsetup);
607 builder.setCancelable(false);
608 builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
609 public void onClick(DialogInterface dialog, int which) {
610 createFirstAccount();
611 dialog.dismiss();
612 }
613 });
614 String message = String.format(getString(R.string.common_exit), getString(R.string.app_name));
615 builder.setNegativeButton(message, new OnClickListener() {
616 public void onClick(DialogInterface dialog, int which) {
617 dialog.dismiss();
618 finish();
619 }
620 });
621 //builder.setNegativeButton(android.R.string.cancel, this);
622 dialog = builder.create();
623 break;
624 }
625 case DIALOG_CREATE_DIR: {
626 builder = new Builder(this);
627 final EditText dirNameInput = new EditText(getBaseContext());
628 builder.setView(dirNameInput);
629 builder.setTitle(R.string.uploader_info_dirname);
630 int typed_color = getResources().getColor(R.color.setup_text_typed);
631 dirNameInput.setTextColor(typed_color);
632 builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
633 public void onClick(DialogInterface dialog, int which) {
634 String directoryName = dirNameInput.getText().toString();
635 if (directoryName.trim().length() == 0) {
636 dialog.cancel();
637 return;
638 }
639
640 // Figure out the path where the dir needs to be created
641 String path;
642 if (mCurrentDir == null) {
643 // this is just a patch; we should ensure that
644 // mCurrentDir never is null
645 if (!mStorageManager.fileExists(OCFile.PATH_SEPARATOR)) {
646 OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
647 mStorageManager.saveFile(file);
648 }
649 mCurrentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
650 }
651 path = FileDisplayActivity.this.mCurrentDir.getRemotePath();
652
653 // Create directory
654 path += directoryName + OCFile.PATH_SEPARATOR;
655 Thread thread = new Thread(new DirectoryCreator(path, AccountUtils
656 .getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));
657 thread.start();
658
659 dialog.dismiss();
660
661 showDialog(DIALOG_SHORT_WAIT);
662 }
663 });
664 builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
665 public void onClick(DialogInterface dialog, int which) {
666 dialog.cancel();
667 }
668 });
669 dialog = builder.create();
670 break;
671 }
672 case DIALOG_SHORT_WAIT: {
673 ProgressDialog working_dialog = new ProgressDialog(this);
674 working_dialog.setMessage(getResources().getString(R.string.wait_a_moment));
675 working_dialog.setIndeterminate(true);
676 working_dialog.setCancelable(false);
677 dialog = working_dialog;
678 break;
679 }
680 case DIALOG_CHOOSE_UPLOAD_SOURCE: {
681 final String[] items = { getString(R.string.actionbar_upload_files),
682 getString(R.string.actionbar_upload_from_apps), getString(R.string.actionbar_failed_instant_upload) };
683 builder = new AlertDialog.Builder(this);
684 builder.setTitle(R.string.actionbar_upload);
685 builder.setItems(items, new DialogInterface.OnClickListener() {
686 public void onClick(DialogInterface dialog, int item) {
687 if (item == 0) {
688 // if (!mDualPane) {
689 Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
690 action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT,
691 AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this));
692 startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
693 // } else {
694 // TODO create and handle new fragment
695 // LocalFileListFragment
696 // }
697 } else if (item == 1) {
698 Intent action = new Intent(Intent.ACTION_GET_CONTENT);
699 action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
700 startActivityForResult(Intent.createChooser(action, getString(R.string.upload_chooser_title)),
701 ACTION_SELECT_CONTENT_FROM_APPS);
702 } else if (item == 2) {
703 Account account = AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this);
704 Intent action = new Intent(FileDisplayActivity.this, InstantUploadActivity.class);
705 action.putExtra(FileUploader.KEY_ACCOUNT, account);
706 startActivity(action);
707 }
708 }
709 });
710 dialog = builder.create();
711 break;
712 }
713 case DIALOG_SSL_VALIDATOR: {
714 dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
715 break;
716 }
717 case DIALOG_CERT_NOT_SAVED: {
718 builder = new AlertDialog.Builder(this);
719 builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
720 builder.setCancelable(false);
721 builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
722 @Override
723 public void onClick(DialogInterface dialog, int which) {
724 dialog.dismiss();
725 };
726 });
727 dialog = builder.create();
728 break;
729 }
730 default:
731 dialog = null;
732 }
733
734 return dialog;
735 }
736
737
738 /**
739 * Translates a content URI of an image to a physical path
740 * on the disk
741 * @param uri The URI to resolve
742 * @return The path to the image or null if it could not be found
743 */
744 public String getPath(Uri uri) {
745 String[] projection = { MediaStore.Images.Media.DATA };
746 Cursor cursor = managedQuery(uri, projection, null, null, null);
747 if (cursor != null) {
748 int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
749 cursor.moveToFirst();
750 return cursor.getString(column_index);
751 }
752 return null;
753 }
754
755 /**
756 * Pushes a directory to the drop down list
757 * @param directory to push
758 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
759 */
760 public void pushDirname(OCFile directory) {
761 if(!directory.isDirectory()){
762 throw new IllegalArgumentException("Only directories may be pushed!");
763 }
764 mDirectories.insert(directory.getFileName(), 0);
765 mCurrentDir = directory;
766 }
767
768 /**
769 * Pops a directory name from the drop down list
770 * @return True, unless the stack is empty
771 */
772 public boolean popDirname() {
773 mDirectories.remove(mDirectories.getItem(0));
774 return !mDirectories.isEmpty();
775 }
776
777 private class DirectoryCreator implements Runnable {
778 private String mTargetPath;
779 private Account mAccount;
780 private Handler mHandler;
781
782 public DirectoryCreator(String targetPath, Account account, Handler handler) {
783 mTargetPath = targetPath;
784 mAccount = account;
785 mHandler = handler;
786 }
787
788 @Override
789 public void run() {
790 WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
791 boolean created = wdc.createDirectory(mTargetPath);
792 if (created) {
793 mHandler.post(new Runnable() {
794 @Override
795 public void run() {
796 dismissDialog(DIALOG_SHORT_WAIT);
797
798 // Save new directory in local database
799 OCFile newDir = new OCFile(mTargetPath);
800 newDir.setMimetype("DIR");
801 newDir.setParentId(mCurrentDir.getFileId());
802 mStorageManager.saveFile(newDir);
803
804 // Display the new folder right away
805 mFileList.listDirectory();
806 }
807 });
808
809 } else {
810 mHandler.post(new Runnable() {
811 @Override
812 public void run() {
813 dismissDialog(DIALOG_SHORT_WAIT);
814 try {
815 Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg,
816 Toast.LENGTH_LONG);
817 msg.show();
818
819 } catch (NotFoundException e) {
820 Log_OC.e(TAG, "Error while trying to show fail message ", e);
821 }
822 }
823 });
824 }
825 }
826
827 }
828
829 // Custom array adapter to override text colors
830 private class CustomArrayAdapter<T> extends ArrayAdapter<T> {
831
832 public CustomArrayAdapter(FileDisplayActivity ctx, int view) {
833 super(ctx, view);
834 }
835
836 public View getView(int position, View convertView, ViewGroup parent) {
837 View v = super.getView(position, convertView, parent);
838
839 ((TextView) v).setTextColor(getResources().getColorStateList(android.R.color.white));
840 return v;
841 }
842
843 public View getDropDownView(int position, View convertView, ViewGroup parent) {
844 View v = super.getDropDownView(position, convertView, parent);
845
846 ((TextView) v).setTextColor(getResources().getColorStateList(android.R.color.white));
847
848 return v;
849 }
850
851 }
852
853 private class SyncBroadcastReceiver extends BroadcastReceiver {
854
855 /**
856 * {@link BroadcastReceiver} to enable syncing feedback in UI
857 */
858 @Override
859 public void onReceive(Context context, Intent intent) {
860 boolean inProgress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);
861 String accountName = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);
862
863 Log_OC.d("FileDisplay", "sync of account " + accountName + " is in_progress: " + inProgress);
864
865 if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) {
866
867 String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH);
868
869 boolean fillBlankRoot = false;
870 if (mCurrentDir == null) {
871 mCurrentDir = mStorageManager.getFileByPath("/");
872 fillBlankRoot = (mCurrentDir != null);
873 }
874
875 if ((synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath()
876 .equals(synchFolderRemotePath))) || fillBlankRoot) {
877 if (!fillBlankRoot)
878 mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath);
879 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()
880 .findFragmentById(R.id.fileList);
881 if (fileListFragment != null) {
882 fileListFragment.listDirectory(mCurrentDir);
883 }
884 }
885
886 setSupportProgressBarIndeterminateVisibility(inProgress);
887 removeStickyBroadcast(intent);
888
889 }
890
891 RemoteOperationResult synchResult = (RemoteOperationResult) intent
892 .getSerializableExtra(FileSyncService.SYNC_RESULT);
893 if (synchResult != null) {
894 if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
895 mLastSslUntrustedServerResult = synchResult;
896 showDialog(DIALOG_SSL_VALIDATOR);
897 }
898 }
899 }
900 }
901
902
903 private class UploadFinishReceiver extends BroadcastReceiver {
904 /**
905 * Once the file upload has finished -> update view
906 * @author David A. Velasco
907 * {@link BroadcastReceiver} to enable upload feedback in UI
908 */
909 @Override
910 public void onReceive(Context context, Intent intent) {
911 String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
912 String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
913 boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);
914 boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null)
915 && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath()));
916 if (sameAccount && isDescendant) {
917 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()
918 .findFragmentById(R.id.fileList);
919 if (fileListFragment != null) {
920 fileListFragment.listDirectory();
921 }
922 }
923 }
924
925 }
926
927
928 /**
929 * Once the file download has finished -> update view
930 */
931 private class DownloadFinishReceiver extends BroadcastReceiver {
932 @Override
933 public void onReceive(Context context, Intent intent) {
934 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
935 String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
936 boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);
937 boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null)
938 && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath()));
939 if (sameAccount && isDescendant) {
940 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()
941 .findFragmentById(R.id.fileList);
942 if (fileListFragment != null) {
943 fileListFragment.listDirectory();
944 }
945 }
946 }
947 }
948
949
950
951
952 /**
953 * {@inheritDoc}
954 */
955 @Override
956 public DataStorageManager getStorageManager() {
957 return mStorageManager;
958 }
959
960
961 /**
962 * {@inheritDoc}
963 */
964 @Override
965 public void onDirectoryClick(OCFile directory) {
966 pushDirname(directory);
967 ActionBar actionBar = getSupportActionBar();
968 actionBar.setDisplayHomeAsUpEnabled(true);
969
970 if (mDualPane) {
971 // Resets the FileDetailsFragment on Tablets so that it always displays
972 FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
973 if (fileDetails != null && !fileDetails.isEmpty()) {
974 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
975 transaction.remove(fileDetails);
976 transaction.add(R.id.file_details_container, new FileDetailFragment(null, null),
977 FileDetailFragment.FTAG);
978 transaction.commit();
979 }
980 }
981 }
982
983
984 /**
985 * {@inheritDoc}
986 */
987 @Override
988 public void onFileClick(OCFile file) {
989
990 // If we are on a large device -> update fragment
991 if (mDualPane) {
992 // buttons in the details view are problematic when trying to reuse an existing fragment; create always a new one solves some of them, BUT no all; downloads are 'dangerous'
993 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
994 transaction
995 .replace(R.id.file_details_container,
996 new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)),
997 FileDetailFragment.FTAG);
998 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
999 transaction.commit();
1000
1001 } else { // small or medium screen device -> new Activity
1002 Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
1003 showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
1004 showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
1005 startActivity(showDetailsIntent);
1006 }
1007 }
1008
1009
1010 /**
1011 * {@inheritDoc}
1012 */
1013 @Override
1014 public OCFile getInitialDirectory() {
1015 return mCurrentDir;
1016 }
1017
1018
1019 /**
1020 * {@inheritDoc}
1021 */
1022 @Override
1023 public void onFileStateChanged() {
1024 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(
1025 R.id.fileList);
1026 if (fileListFragment != null) {
1027 fileListFragment.listDirectory();
1028 }
1029 }
1030
1031
1032 /**
1033 * {@inheritDoc}
1034 */
1035 @Override
1036 public FileDownloaderBinder getFileDownloaderBinder() {
1037 return mDownloaderBinder;
1038 }
1039
1040
1041 /**
1042 * {@inheritDoc}
1043 */
1044 @Override
1045 public FileUploaderBinder getFileUploaderBinder() {
1046 return mUploaderBinder;
1047 }
1048
1049
1050 /** Defines callbacks for service binding, passed to bindService() */
1051 private class ListServiceConnection implements ServiceConnection {
1052
1053 @Override
1054 public void onServiceConnected(ComponentName component, IBinder service) {
1055 if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
1056 Log_OC.d(TAG, "Download service connected");
1057 mDownloaderBinder = (FileDownloaderBinder) service;
1058 } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
1059 Log_OC.d(TAG, "Upload service connected");
1060 mUploaderBinder = (FileUploaderBinder) service;
1061 } else {
1062 return;
1063 }
1064 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1065 if (mFileList != null)
1066 mFileList.listDirectory();
1067 if (mDualPane) {
1068 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(
1069 FileDetailFragment.FTAG);
1070 if (fragment != null)
1071 fragment.updateFileDetails(false);
1072 }
1073 }
1074
1075 @Override
1076 public void onServiceDisconnected(ComponentName component) {
1077 if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
1078 Log_OC.d(TAG, "Download service disconnected");
1079 mDownloaderBinder = null;
1080 } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
1081 Log_OC.d(TAG, "Upload service disconnected");
1082 mUploaderBinder = null;
1083 }
1084 }
1085 };
1086
1087
1088
1089 /**
1090 * Launch an intent to request the PIN code to the user before letting him use the app
1091 */
1092 private void requestPinCode() {
1093 boolean pinStart = false;
1094 SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
1095 pinStart = appPrefs.getBoolean("set_pincode", false);
1096 if (pinStart) {
1097 Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);
1098 i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
1099 startActivity(i);
1100 }
1101 }
1102
1103
1104 @Override
1105 public void onSavedCertificate() {
1106 startSynchronization();
1107 }
1108
1109 @Override
1110 public void onFailedSavingCertificate() {
1111 showDialog(DIALOG_CERT_NOT_SAVED);
1112 }
1113
1114
1115 /**
1116 * Updates the view associated to the activity after the finish of some operation over files
1117 * in the current account.
1118 *
1119 * @param operation Removal operation performed.
1120 * @param result Result of the removal.
1121 */
1122 @Override
1123 public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
1124 if (operation instanceof RemoveFileOperation) {
1125 onRemoveFileOperationFinish((RemoveFileOperation) operation, result);
1126
1127 } else if (operation instanceof RenameFileOperation) {
1128 onRenameFileOperationFinish((RenameFileOperation) operation, result);
1129
1130 } else if (operation instanceof SynchronizeFileOperation) {
1131 onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result);
1132 }
1133 }
1134
1135
1136 /**
1137 * Updates the view associated to the activity after the finish of an operation trying to remove a
1138 * file.
1139 *
1140 * @param operation Removal operation performed.
1141 * @param result Result of the removal.
1142 */
1143 private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
1144 dismissDialog(DIALOG_SHORT_WAIT);
1145 if (result.isSuccess()) {
1146 Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
1147 msg.show();
1148 OCFile removedFile = operation.getFile();
1149 if (mDualPane) {
1150 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(
1151 FileDetailFragment.FTAG);
1152 if (details != null && removedFile.equals(details.getDisplayedFile())) {
1153 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
1154 transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty
1155 // FileDetailFragment
1156 transaction.commit();
1157 }
1158 }
1159 if (mStorageManager.getFileById(removedFile.getParentId()).equals(mCurrentDir)) {
1160 mFileList.listDirectory();
1161 }
1162
1163 } else {
1164 Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG);
1165 msg.show();
1166 if (result.isSslRecoverableException()) {
1167 mLastSslUntrustedServerResult = result;
1168 showDialog(DIALOG_SSL_VALIDATOR);
1169 }
1170 }
1171 }
1172
1173 /**
1174 * Updates the view associated to the activity after the finish of an operation trying to rename a
1175 * file.
1176 *
1177 * @param operation Renaming operation performed.
1178 * @param result Result of the renaming.
1179 */
1180 private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
1181 dismissDialog(DIALOG_SHORT_WAIT);
1182 OCFile renamedFile = operation.getFile();
1183 if (result.isSuccess()) {
1184 if (mDualPane) {
1185 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(
1186 FileDetailFragment.FTAG);
1187 if (details != null && renamedFile.equals(details.getDisplayedFile())) {
1188 details.updateFileDetails(renamedFile, AccountUtils.getCurrentOwnCloudAccount(this));
1189 }
1190 }
1191 if (mStorageManager.getFileById(renamedFile.getParentId()).equals(mCurrentDir)) {
1192 mFileList.listDirectory();
1193 }
1194
1195 } else {
1196 if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
1197 Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
1198 msg.show();
1199 // TODO throw again the new rename dialog
1200 } else {
1201 Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
1202 msg.show();
1203 if (result.isSslRecoverableException()) {
1204 mLastSslUntrustedServerResult = result;
1205 showDialog(DIALOG_SSL_VALIDATOR);
1206 }
1207 }
1208 }
1209 }
1210
1211 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
1212 dismissDialog(DIALOG_SHORT_WAIT);
1213 OCFile syncedFile = operation.getLocalFile();
1214 if (!result.isSuccess()) {
1215 if (result.getCode() == ResultCode.SYNC_CONFLICT) {
1216 Intent i = new Intent(this, ConflictsResolveActivity.class);
1217 i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);
1218 i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
1219 startActivity(i);
1220
1221 } else {
1222 Toast msg = Toast.makeText(this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG);
1223 msg.show();
1224 }
1225
1226 } else {
1227 if (operation.transferWasRequested()) {
1228 mFileList.listDirectory();
1229 onTransferStateChanged(syncedFile, true, true);
1230
1231 } else {
1232 Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
1233 msg.show();
1234 }
1235 }
1236 }
1237
1238
1239 /**
1240 * {@inheritDoc}
1241 */
1242 @Override
1243 public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
1244 /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1245 if (fileListFragment != null) {
1246 fileListFragment.listDirectory();
1247 }*/
1248 if (mDualPane) {
1249 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(
1250 FileDetailFragment.FTAG);
1251 if (details != null && file.equals(details.getDisplayedFile())) {
1252 if (downloading || uploading) {
1253 details.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));
1254 } else {
1255 details.updateFileDetails(downloading || uploading);
1256 }
1257 }
1258 }
1259 }
1260
1261
1262
1263
1264
1265 }