2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2011 Bartek Przybylski
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.ui
.activity
;
24 import android
.accounts
.Account
;
25 import android
.accounts
.AccountManager
;
26 import android
.accounts
.AccountManagerCallback
;
27 import android
.accounts
.AccountManagerFuture
;
28 import android
.accounts
.AuthenticatorException
;
29 import android
.accounts
.OperationCanceledException
;
30 import android
.content
.ComponentName
;
31 import android
.content
.Context
;
32 import android
.content
.Intent
;
33 import android
.content
.ServiceConnection
;
34 import android
.content
.res
.Configuration
;
35 import android
.os
.Bundle
;
36 import android
.os
.Handler
;
37 import android
.os
.IBinder
;
38 import android
.support
.v4
.app
.ActionBarDrawerToggle
;
39 import android
.support
.v4
.app
.Fragment
;
40 import android
.support
.v4
.app
.FragmentManager
;
41 import android
.support
.v4
.app
.FragmentTransaction
;
42 import android
.support
.v4
.widget
.DrawerLayout
;
43 import android
.support
.v7
.app
.ActionBar
;
44 import android
.support
.v7
.app
.ActionBarActivity
;
45 import android
.view
.View
;
46 import android
.widget
.AdapterView
;
47 import android
.widget
.ImageView
;
48 import android
.widget
.LinearLayout
;
49 import android
.widget
.ListView
;
50 import android
.widget
.TextView
;
51 import android
.widget
.Toast
;
53 import com
.owncloud
.android
.BuildConfig
;
54 import com
.owncloud
.android
.MainApp
;
55 import com
.owncloud
.android
.R
;
56 import com
.owncloud
.android
.authentication
.AccountUtils
;
57 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
58 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
59 import com
.owncloud
.android
.datamodel
.OCFile
;
60 import com
.owncloud
.android
.files
.FileOperationsHelper
;
61 import com
.owncloud
.android
.files
.services
.FileDownloader
;
62 import com
.owncloud
.android
.files
.services
.FileUploader
;
63 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
64 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
65 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
66 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
67 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
68 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
69 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
70 import com
.owncloud
.android
.operations
.CreateShareOperation
;
71 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
72 import com
.owncloud
.android
.operations
.UnshareLinkOperation
;
73 import com
.owncloud
.android
.services
.OperationsService
;
74 import com
.owncloud
.android
.services
.OperationsService
.OperationsServiceBinder
;
75 import com
.owncloud
.android
.ui
.NavigationDrawerItem
;
76 import com
.owncloud
.android
.ui
.adapter
.NavigationDrawerListAdapter
;
77 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
78 import com
.owncloud
.android
.ui
.dialog
.SharePasswordDialogFragment
;
79 import com
.owncloud
.android
.utils
.DisplayUtils
;
80 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
82 import java
.util
.ArrayList
;
86 * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud
89 public class FileActivity
extends ActionBarActivity
90 implements OnRemoteOperationListener
, ComponentsGetter
{
92 public static final String EXTRA_FILE
= "com.owncloud.android.ui.activity.FILE";
93 public static final String EXTRA_ACCOUNT
= "com.owncloud.android.ui.activity.ACCOUNT";
94 public static final String EXTRA_WAITING_TO_PREVIEW
=
95 "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
96 public static final String EXTRA_FROM_NOTIFICATION
=
97 "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
99 public static final String TAG
= FileActivity
.class.getSimpleName();
101 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
102 private static final String KEY_WAITING_FOR_OP_ID
= "WAITING_FOR_OP_ID";
103 private static final String DIALOG_SHARE_PASSWORD
= "DIALOG_SHARE_PASSWORD";
104 private static final String KEY_TRY_SHARE_AGAIN
= "TRY_SHARE_AGAIN";
106 protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
= 200;
109 /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
110 private Account mAccount
;
112 /** Main {@link OCFile} handled by the activity.*/
113 private OCFile mFile
;
115 /** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud
117 private boolean mRedirectingToSetupAccount
= false
;
119 /** Flag to signal when the value of mAccount was set */
120 protected boolean mAccountWasSet
;
122 /** Flag to signal when the value of mAccount was restored from a saved state */
123 protected boolean mAccountWasRestored
;
125 /** Flag to signal if the activity is launched by a notification */
126 private boolean mFromNotification
;
128 /** Messages handler associated to the main thread and the life cycle of the activity */
129 private Handler mHandler
;
131 /** Access point to the cached database for the current ownCloud {@link Account} */
132 private FileDataStorageManager mStorageManager
= null
;
134 private FileOperationsHelper mFileOperationsHelper
;
136 private ServiceConnection mOperationsServiceConnection
= null
;
138 private OperationsServiceBinder mOperationsServiceBinder
= null
;
140 protected FileDownloaderBinder mDownloaderBinder
= null
;
141 protected FileUploaderBinder mUploaderBinder
= null
;
142 private ServiceConnection mDownloadServiceConnection
, mUploadServiceConnection
= null
;
144 private boolean mTryShareAgain
= false
;
147 protected DrawerLayout mDrawerLayout
;
148 protected ActionBarDrawerToggle mDrawerToggle
;
149 protected ListView mDrawerList
;
152 protected String
[] mDrawerTitles
;
153 protected String
[] mDrawerContentDescriptions
;
155 protected ArrayList
<NavigationDrawerItem
> mDrawerItems
;
157 protected NavigationDrawerListAdapter mNavigationDrawerAdapter
= null
;
159 protected boolean mShowAccounts
= false
;
162 * Loads the ownCloud {@link Account} and main {@link OCFile} to be handled by the instance of
163 * the {@link FileActivity}.
165 * Grants that a valid ownCloud {@link Account} is associated to the instance, or that the user
166 * is requested to create a new one.
169 protected void onCreate(Bundle savedInstanceState
) {
170 super.onCreate(savedInstanceState
);
171 mHandler
= new Handler();
172 mFileOperationsHelper
= new FileOperationsHelper(this);
173 Account account
= null
;
174 if(savedInstanceState
!= null
) {
175 mFile
= savedInstanceState
.getParcelable(FileActivity
.EXTRA_FILE
);
176 mFromNotification
= savedInstanceState
.getBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
);
177 mFileOperationsHelper
.setOpIdWaitingFor(
178 savedInstanceState
.getLong(KEY_WAITING_FOR_OP_ID
, Long
.MAX_VALUE
)
180 mTryShareAgain
= savedInstanceState
.getBoolean(KEY_TRY_SHARE_AGAIN
);
182 account
= getIntent().getParcelableExtra(FileActivity
.EXTRA_ACCOUNT
);
183 mFile
= getIntent().getParcelableExtra(FileActivity
.EXTRA_FILE
);
184 mFromNotification
= getIntent().getBooleanExtra(FileActivity
.EXTRA_FROM_NOTIFICATION
,
188 AccountUtils
.updateAccountVersion(this); // best place, before any access to AccountManager
191 setAccount(account
, savedInstanceState
!= null
);
193 mOperationsServiceConnection
= new OperationsServiceConnection();
194 bindService(new Intent(this, OperationsService
.class), mOperationsServiceConnection
,
195 Context
.BIND_AUTO_CREATE
);
197 mDownloadServiceConnection
= newTransferenceServiceConnection();
198 if (mDownloadServiceConnection
!= null
) {
199 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
200 Context
.BIND_AUTO_CREATE
);
202 mUploadServiceConnection
= newTransferenceServiceConnection();
203 if (mUploadServiceConnection
!= null
) {
204 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
205 Context
.BIND_AUTO_CREATE
);
211 protected void onNewIntent (Intent intent
) {
212 Log_OC
.v(TAG
, "onNewIntent() start");
213 Account current
= AccountUtils
.getCurrentOwnCloudAccount(this);
214 if (current
!= null
&& mAccount
!= null
&& !mAccount
.name
.equals(current
.name
)) {
217 Log_OC
.v(TAG
, "onNewIntent() stop");
221 * Since ownCloud {@link Account}s can be managed from the system setting menu,
222 * the existence of the {@link Account} associated to the instance must be checked
223 * every time it is restarted.
226 protected void onRestart() {
227 Log_OC
.v(TAG
, "onRestart() start");
229 boolean validAccount
= (mAccount
!= null
&& AccountUtils
.exists(mAccount
, this));
231 swapToDefaultAccount();
233 Log_OC
.v(TAG
, "onRestart() end");
238 protected void onStart() {
241 if (mAccountWasSet
) {
242 onAccountSet(mAccountWasRestored
);
247 protected void onResume() {
250 if (mOperationsServiceBinder
!= null
) {
251 doOnResumeAndBound();
256 protected void onPause() {
257 if (mOperationsServiceBinder
!= null
) {
258 mOperationsServiceBinder
.removeOperationListener(this);
266 protected void onDestroy() {
267 if (mOperationsServiceConnection
!= null
) {
268 unbindService(mOperationsServiceConnection
);
269 mOperationsServiceBinder
= null
;
271 if (mDownloadServiceConnection
!= null
) {
272 unbindService(mDownloadServiceConnection
);
273 mDownloadServiceConnection
= null
;
275 if (mUploadServiceConnection
!= null
) {
276 unbindService(mUploadServiceConnection
);
277 mUploadServiceConnection
= null
;
284 protected void onPostCreate(Bundle savedInstanceState
) {
285 super.onPostCreate(savedInstanceState
);
286 // Sync the toggle state after onRestoreInstanceState has occurred.
287 if (mDrawerToggle
!= null
) {
288 mDrawerToggle
.syncState();
293 public void onConfigurationChanged(Configuration newConfig
) {
294 super.onConfigurationChanged(newConfig
);
295 if (mDrawerToggle
!= null
) {
296 mDrawerToggle
.onConfigurationChanged(newConfig
);
300 protected void initDrawer(){
301 mDrawerLayout
= (DrawerLayout
) findViewById(R
.id
.drawer_layout
);
302 // Notification Drawer
303 LinearLayout navigationDrawerLayout
= (LinearLayout
) findViewById(R
.id
.left_drawer
);
304 mDrawerList
= (ListView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_list
);
306 // load Account in the Drawer Title
308 ImageView userIcon
= (ImageView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_userIcon
);
309 userIcon
.setImageResource(DisplayUtils
.getSeasonalIconId());
312 TextView username
= (TextView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_username
);
313 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
315 if (account
!= null
) {
316 int lastAtPos
= account
.name
.lastIndexOf("@");
317 username
.setText(account
.name
.substring(0, lastAtPos
));
320 // load slide menu items
321 mDrawerTitles
= getResources().getStringArray(R
.array
.drawer_items
);
323 // nav drawer content description from resources
324 mDrawerContentDescriptions
= getResources().
325 getStringArray(R
.array
.drawer_content_descriptions
);
328 mDrawerItems
= new ArrayList
<NavigationDrawerItem
>();
329 // adding nav drawer items to array
331 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[0], mDrawerContentDescriptions
[0]));
333 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[1], mDrawerContentDescriptions
[1]));
335 // TODO Enable when "On Device" is recovered
337 //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
338 // mDrawerContentDescriptions[2]));
341 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[2], mDrawerContentDescriptions
[2]));
343 if (BuildConfig
.DEBUG
) {
344 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[3],
345 mDrawerContentDescriptions
[3]));
348 // setting the nav drawer list adapter
349 mNavigationDrawerAdapter
= new NavigationDrawerListAdapter(getApplicationContext(), this,
351 mDrawerList
.setAdapter(mNavigationDrawerAdapter
);
353 mDrawerToggle
= new ActionBarDrawerToggle(
356 R
.drawable
.ic_drawer
,
357 R
.string
.drawer_open
,
358 R
.string
.drawer_close
) {
360 /** Called when a drawer has settled in a completely closed state. */
361 public void onDrawerClosed(View view
) {
362 super.onDrawerClosed(view
);
363 getSupportActionBar().setDisplayShowTitleEnabled(true
);
364 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
365 //initFragmentsWithFile();
366 invalidateOptionsMenu();
369 /** Called when a drawer has settled in a completely open state. */
370 public void onDrawerOpened(View drawerView
) {
371 super.onDrawerOpened(drawerView
);
372 getSupportActionBar().setTitle(R
.string
.drawer_open
);
373 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
374 invalidateOptionsMenu();
378 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
379 // Set the list's click listener
380 mDrawerList
.setOnItemClickListener(new DrawerItemClickListener());
382 // Set the drawer toggle as the DrawerListener
383 mDrawerLayout
.setDrawerListener(mDrawerToggle
);
387 * Sets and validates the ownCloud {@link Account} associated to the Activity.
389 * If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
391 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
393 * @param account New {@link Account} to set.
394 * @param savedAccount When 'true', account was retrieved from a saved instance state.
396 protected void setAccount(Account account
, boolean savedAccount
) {
397 Account oldAccount
= mAccount
;
398 boolean validAccount
=
399 (account
!= null
&& AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(),
403 mAccountWasSet
= true
;
404 mAccountWasRestored
= (savedAccount
|| mAccount
.equals(oldAccount
));
407 swapToDefaultAccount();
413 * Tries to swap the current ownCloud {@link Account} for other valid and existing.
415 * If no valid ownCloud {@link Account} exists, the the user is requested
416 * to create a new ownCloud {@link Account}.
418 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
420 private void swapToDefaultAccount() {
421 // default to the most recently used account
422 Account newAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
423 if (newAccount
== null
) {
424 /// no account available: force account creation
425 createFirstAccount();
426 mRedirectingToSetupAccount
= true
;
427 mAccountWasSet
= false
;
428 mAccountWasRestored
= false
;
431 mAccountWasSet
= true
;
432 mAccountWasRestored
= (newAccount
.equals(mAccount
));
433 mAccount
= newAccount
;
439 * Launches the account creation activity. To use when no ownCloud account is available
441 private void createFirstAccount() {
442 AccountManager am
= AccountManager
.get(getApplicationContext());
443 am
.addAccount(MainApp
.getAccountType(),
448 new AccountCreationCallback(),
457 protected void onSaveInstanceState(Bundle outState
) {
458 super.onSaveInstanceState(outState
);
459 outState
.putParcelable(FileActivity
.EXTRA_FILE
, mFile
);
460 outState
.putBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
, mFromNotification
);
461 outState
.putLong(KEY_WAITING_FOR_OP_ID
, mFileOperationsHelper
.getOpIdWaitingFor());
462 outState
.putBoolean(KEY_TRY_SHARE_AGAIN
, mTryShareAgain
);
467 * Getter for the main {@link OCFile} handled by the activity.
469 * @return Main {@link OCFile} handled by the activity.
471 public OCFile
getFile() {
477 * Setter for the main {@link OCFile} handled by the activity.
479 * @param file Main {@link OCFile} to be handled by the activity.
481 public void setFile(OCFile file
) {
487 * Getter for the ownCloud {@link Account} where the main {@link OCFile} handled by the activity
490 * @return OwnCloud {@link Account} where the main {@link OCFile} handled by the activity
493 public Account
getAccount() {
497 protected void setAccount(Account account
) {
502 * @return Value of mFromNotification: True if the Activity is launched by a notification
504 public boolean fromNotification() {
505 return mFromNotification
;
509 * @return 'True' when the Activity is finishing to enforce the setup of a new account.
511 protected boolean isRedirectingToSetupAccount() {
512 return mRedirectingToSetupAccount
;
515 public boolean isTryShareAgain(){
516 return mTryShareAgain
;
519 public void setTryShareAgain(boolean tryShareAgain
) {
520 mTryShareAgain
= tryShareAgain
;
523 public OperationsServiceBinder
getOperationsServiceBinder() {
524 return mOperationsServiceBinder
;
527 protected ServiceConnection
newTransferenceServiceConnection() {
532 * Helper class handling a callback from the {@link AccountManager} after the creation of
533 * a new ownCloud {@link Account} finished, successfully or not.
535 * At this moment, only called after the creation of the first account.
537 public class AccountCreationCallback
implements AccountManagerCallback
<Bundle
> {
540 public void run(AccountManagerFuture
<Bundle
> future
) {
541 FileActivity
.this.mRedirectingToSetupAccount
= false
;
542 boolean accountWasSet
= false
;
543 if (future
!= null
) {
546 result
= future
.getResult();
547 String name
= result
.getString(AccountManager
.KEY_ACCOUNT_NAME
);
548 String type
= result
.getString(AccountManager
.KEY_ACCOUNT_TYPE
);
549 if (AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(), name
)) {
550 setAccount(new Account(name
, type
), false
);
551 accountWasSet
= true
;
553 } catch (OperationCanceledException e
) {
554 Log_OC
.d(TAG
, "Account creation canceled");
556 } catch (Exception e
) {
557 Log_OC
.e(TAG
, "Account creation finished in exception: ", e
);
561 Log_OC
.e(TAG
, "Account creation callback with null bundle");
563 if (!accountWasSet
) {
564 moveTaskToBack(true
);
572 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
574 * Child classes must grant that state depending on the {@link Account} is updated.
576 protected void onAccountSet(boolean stateWasRecovered
) {
577 if (getAccount() != null
) {
578 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
581 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
586 public FileDataStorageManager
getStorageManager() {
587 return mStorageManager
;
591 public OnRemoteOperationListener
getRemoteOperationListener() {
596 public Handler
getHandler() {
600 public FileOperationsHelper
getFileOperationsHelper() {
601 return mFileOperationsHelper
;
606 * @param operation Removal operation performed.
607 * @param result Result of the removal.
610 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
611 Log_OC
.d(TAG
, "Received result of operation in FileActivity - common behaviour for all the " +
614 mFileOperationsHelper
.setOpIdWaitingFor(Long
.MAX_VALUE
);
616 if (!result
.isSuccess() && (
617 result
.getCode() == ResultCode
.UNAUTHORIZED
||
618 result
.isIdPRedirection() ||
619 (result
.isException() && result
.getException() instanceof AuthenticatorException
)
622 requestCredentialsUpdate();
624 if (result
.getCode() == ResultCode
.UNAUTHORIZED
) {
625 dismissLoadingDialog();
626 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
627 operation
, getResources()),
631 mTryShareAgain
= false
;
633 } else if (operation
instanceof CreateShareOperation
) {
634 onCreateShareOperationFinish((CreateShareOperation
) operation
, result
);
636 } else if (operation
instanceof UnshareLinkOperation
) {
637 onUnshareLinkOperationFinish((UnshareLinkOperation
)operation
, result
);
639 } else if (operation
instanceof SynchronizeFolderOperation
) {
640 onSynchronizeFolderOperationFinish((SynchronizeFolderOperation
)operation
, result
);
645 protected void requestCredentialsUpdate() {
646 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
647 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, getAccount());
648 updateAccountCredentials
.putExtra(
649 AuthenticatorActivity
.EXTRA_ACTION
,
650 AuthenticatorActivity
.ACTION_UPDATE_EXPIRED_TOKEN
);
651 updateAccountCredentials
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
652 startActivity(updateAccountCredentials
);
656 private void onCreateShareOperationFinish(CreateShareOperation operation
,
657 RemoteOperationResult result
) {
658 dismissLoadingDialog();
659 if (result
.isSuccess()) {
660 mTryShareAgain
= false
;
663 Intent sendIntent
= operation
.getSendIntent();
664 startActivity(sendIntent
);
666 // Detect Failure (403) --> needs Password
667 if (result
.getCode() == ResultCode
.SHARE_FORBIDDEN
) {
668 if (!isTryShareAgain()) {
669 SharePasswordDialogFragment dialog
=
670 SharePasswordDialogFragment
.newInstance(new OCFile(operation
.getPath()),
671 operation
.getSendIntent());
672 dialog
.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD
);
674 Toast t
= Toast
.makeText(this,
675 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
678 mTryShareAgain
= false
;
681 Toast t
= Toast
.makeText(this,
682 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
690 private void onUnshareLinkOperationFinish(UnshareLinkOperation operation
,
691 RemoteOperationResult result
) {
692 dismissLoadingDialog();
694 if (result
.isSuccess()){
698 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
699 operation
, getResources()), Toast
.LENGTH_LONG
);
704 private void onSynchronizeFolderOperationFinish(
705 SynchronizeFolderOperation operation
, RemoteOperationResult result
707 if (!result
.isSuccess() && result
.getCode() != ResultCode
.CANCELLED
){
708 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
709 operation
, getResources()), Toast
.LENGTH_LONG
);
714 protected void updateFileFromDB(){
715 OCFile file
= getFile();
717 file
= getStorageManager().getFileByPath(file
.getRemotePath());
723 * Show loading dialog
725 public void showLoadingDialog() {
727 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
728 FragmentManager fm
= getSupportFragmentManager();
729 FragmentTransaction ft
= fm
.beginTransaction();
730 loading
.show(ft
, DIALOG_WAIT_TAG
);
736 * Dismiss loading dialog
738 public void dismissLoadingDialog(){
739 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
741 LoadingDialog loading
= (LoadingDialog
) frag
;
747 private void doOnResumeAndBound() {
748 mOperationsServiceBinder
.addOperationListener(FileActivity
.this, mHandler
);
749 long waitingForOpId
= mFileOperationsHelper
.getOpIdWaitingFor();
750 if (waitingForOpId
<= Integer
.MAX_VALUE
) {
751 boolean wait
= mOperationsServiceBinder
.dispatchResultIfFinished((int)waitingForOpId
,
754 dismissLoadingDialog();
761 * Implements callback methods for service binding. Passed as a parameter to {
763 private class OperationsServiceConnection
implements ServiceConnection
{
766 public void onServiceConnected(ComponentName component
, IBinder service
) {
767 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
768 Log_OC
.d(TAG
, "Operations service connected");
769 mOperationsServiceBinder
= (OperationsServiceBinder
) service
;
770 /*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
771 dismissLoadingDialog();
773 doOnResumeAndBound();
782 public void onServiceDisconnected(ComponentName component
) {
783 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
784 Log_OC
.d(TAG
, "Operations service disconnected");
785 mOperationsServiceBinder
= null
;
786 // TODO whatever could be waiting for the service is unbound
793 public FileDownloaderBinder
getFileDownloaderBinder() {
794 return mDownloaderBinder
;
799 public FileUploaderBinder
getFileUploaderBinder() {
800 return mUploaderBinder
;
804 public void restart(){
805 Intent i
= new Intent(this, FileDisplayActivity
.class);
806 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
810 public void closeDrawer() {
811 mDrawerLayout
.closeDrawers();
814 private class DrawerItemClickListener
implements ListView
.OnItemClickListener
{
816 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
817 if (mShowAccounts
&& position
> 0){
818 position
= position
- 1;
822 mShowAccounts
= !mShowAccounts
;
823 mNavigationDrawerAdapter
.setShowAccounts(mShowAccounts
);
824 mNavigationDrawerAdapter
.notifyDataSetChanged();
828 // TODO Enable when "On Device" is recovered ?
829 //MainApp.showOnlyFilesOnDevice(false);
830 mDrawerLayout
.closeDrawers();
833 // TODO Enable when "On Device" is recovered ?
835 // MainApp.showOnlyFilesOnDevice(true);
836 // mDrawerLayout.closeDrawers();
840 Intent settingsIntent
= new Intent(getApplicationContext(),
842 startActivity(settingsIntent
);
846 Intent loggerIntent
= new Intent(getApplicationContext(),
847 LogHistoryActivity
.class);
848 startActivity(loggerIntent
);