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