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
.lib
.resources
.files
.FileUtils
;
71 import com
.owncloud
.android
.operations
.CreateShareOperation
;
72 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
73 import com
.owncloud
.android
.operations
.UnshareLinkOperation
;
74 import com
.owncloud
.android
.services
.OperationsService
;
75 import com
.owncloud
.android
.services
.OperationsService
.OperationsServiceBinder
;
76 import com
.owncloud
.android
.ui
.NavigationDrawerItem
;
77 import com
.owncloud
.android
.ui
.adapter
.NavigationDrawerListAdapter
;
78 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
79 import com
.owncloud
.android
.ui
.dialog
.SharePasswordDialogFragment
;
80 import com
.owncloud
.android
.utils
.DisplayUtils
;
81 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
83 import java
.util
.ArrayList
;
87 * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud
90 public class FileActivity
extends ActionBarActivity
91 implements OnRemoteOperationListener
, ComponentsGetter
{
93 public static final String EXTRA_FILE
= "com.owncloud.android.ui.activity.FILE";
94 public static final String EXTRA_ACCOUNT
= "com.owncloud.android.ui.activity.ACCOUNT";
95 public static final String EXTRA_WAITING_TO_PREVIEW
=
96 "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
97 public static final String EXTRA_FROM_NOTIFICATION
=
98 "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
100 public static final String TAG
= FileActivity
.class.getSimpleName();
102 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
103 private static final String KEY_WAITING_FOR_OP_ID
= "WAITING_FOR_OP_ID";
104 private static final String DIALOG_SHARE_PASSWORD
= "DIALOG_SHARE_PASSWORD";
105 private static final String KEY_TRY_SHARE_AGAIN
= "TRY_SHARE_AGAIN";
107 protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
= 200;
110 /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
111 private Account mAccount
;
113 /** Main {@link OCFile} handled by the activity.*/
114 private OCFile mFile
;
116 /** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud
118 private boolean mRedirectingToSetupAccount
= false
;
120 /** Flag to signal when the value of mAccount was set */
121 protected boolean mAccountWasSet
;
123 /** Flag to signal when the value of mAccount was restored from a saved state */
124 protected boolean mAccountWasRestored
;
126 /** Flag to signal if the activity is launched by a notification */
127 private boolean mFromNotification
;
129 /** Messages handler associated to the main thread and the life cycle of the activity */
130 private Handler mHandler
;
132 /** Access point to the cached database for the current ownCloud {@link Account} */
133 private FileDataStorageManager mStorageManager
= null
;
135 private FileOperationsHelper mFileOperationsHelper
;
137 private ServiceConnection mOperationsServiceConnection
= null
;
139 private OperationsServiceBinder mOperationsServiceBinder
= null
;
141 protected FileDownloaderBinder mDownloaderBinder
= null
;
142 protected FileUploaderBinder mUploaderBinder
= null
;
143 private ServiceConnection mDownloadServiceConnection
, mUploadServiceConnection
= null
;
145 private boolean mTryShareAgain
= false
;
148 protected DrawerLayout mDrawerLayout
;
149 protected ActionBarDrawerToggle mDrawerToggle
;
150 protected ListView mDrawerList
;
153 protected String
[] mDrawerTitles
;
154 protected String
[] mDrawerContentDescriptions
;
156 protected ArrayList
<NavigationDrawerItem
> mDrawerItems
;
158 protected NavigationDrawerListAdapter mNavigationDrawerAdapter
= null
;
160 protected boolean mShowAccounts
= false
;
163 * Loads the ownCloud {@link Account} and main {@link OCFile} to be handled by the instance of
164 * the {@link FileActivity}.
166 * Grants that a valid ownCloud {@link Account} is associated to the instance, or that the user
167 * is requested to create a new one.
170 protected void onCreate(Bundle savedInstanceState
) {
171 super.onCreate(savedInstanceState
);
172 mHandler
= new Handler();
173 mFileOperationsHelper
= new FileOperationsHelper(this);
174 Account account
= null
;
175 if(savedInstanceState
!= null
) {
176 mFile
= savedInstanceState
.getParcelable(FileActivity
.EXTRA_FILE
);
177 mFromNotification
= savedInstanceState
.getBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
);
178 mFileOperationsHelper
.setOpIdWaitingFor(
179 savedInstanceState
.getLong(KEY_WAITING_FOR_OP_ID
, Long
.MAX_VALUE
)
181 mTryShareAgain
= savedInstanceState
.getBoolean(KEY_TRY_SHARE_AGAIN
);
183 account
= getIntent().getParcelableExtra(FileActivity
.EXTRA_ACCOUNT
);
184 mFile
= getIntent().getParcelableExtra(FileActivity
.EXTRA_FILE
);
185 mFromNotification
= getIntent().getBooleanExtra(FileActivity
.EXTRA_FROM_NOTIFICATION
,
189 AccountUtils
.updateAccountVersion(this); // best place, before any access to AccountManager
192 setAccount(account
, savedInstanceState
!= null
);
194 mOperationsServiceConnection
= new OperationsServiceConnection();
195 bindService(new Intent(this, OperationsService
.class), mOperationsServiceConnection
,
196 Context
.BIND_AUTO_CREATE
);
198 mDownloadServiceConnection
= newTransferenceServiceConnection();
199 if (mDownloadServiceConnection
!= null
) {
200 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
201 Context
.BIND_AUTO_CREATE
);
203 mUploadServiceConnection
= newTransferenceServiceConnection();
204 if (mUploadServiceConnection
!= null
) {
205 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
206 Context
.BIND_AUTO_CREATE
);
212 protected void onNewIntent (Intent intent
) {
213 Log_OC
.v(TAG
, "onNewIntent() start");
214 Account current
= AccountUtils
.getCurrentOwnCloudAccount(this);
215 if (current
!= null
&& mAccount
!= null
&& !mAccount
.name
.equals(current
.name
)) {
218 Log_OC
.v(TAG
, "onNewIntent() stop");
222 * Since ownCloud {@link Account}s can be managed from the system setting menu,
223 * the existence of the {@link Account} associated to the instance must be checked
224 * every time it is restarted.
227 protected void onRestart() {
228 Log_OC
.v(TAG
, "onRestart() start");
230 boolean validAccount
= (mAccount
!= null
&& AccountUtils
.exists(mAccount
, this));
232 swapToDefaultAccount();
234 Log_OC
.v(TAG
, "onRestart() end");
239 protected void onStart() {
242 if (mAccountWasSet
) {
243 onAccountSet(mAccountWasRestored
);
248 protected void onResume() {
251 if (mOperationsServiceBinder
!= null
) {
252 doOnResumeAndBound();
257 protected void onPause() {
258 if (mOperationsServiceBinder
!= null
) {
259 mOperationsServiceBinder
.removeOperationListener(this);
267 protected void onDestroy() {
268 if (mOperationsServiceConnection
!= null
) {
269 unbindService(mOperationsServiceConnection
);
270 mOperationsServiceBinder
= null
;
272 if (mDownloadServiceConnection
!= null
) {
273 unbindService(mDownloadServiceConnection
);
274 mDownloadServiceConnection
= null
;
276 if (mUploadServiceConnection
!= null
) {
277 unbindService(mUploadServiceConnection
);
278 mUploadServiceConnection
= null
;
285 protected void onPostCreate(Bundle savedInstanceState
) {
286 super.onPostCreate(savedInstanceState
);
287 // Sync the toggle state after onRestoreInstanceState has occurred.
288 if (mDrawerToggle
!= null
) {
289 mDrawerToggle
.syncState();
294 public void onConfigurationChanged(Configuration newConfig
) {
295 super.onConfigurationChanged(newConfig
);
296 if (mDrawerToggle
!= null
) {
297 mDrawerToggle
.onConfigurationChanged(newConfig
);
301 protected void initDrawer(){
302 mDrawerLayout
= (DrawerLayout
) findViewById(R
.id
.drawer_layout
);
303 // Notification Drawer
304 LinearLayout navigationDrawerLayout
= (LinearLayout
) findViewById(R
.id
.left_drawer
);
305 mDrawerList
= (ListView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_list
);
307 // load Account in the Drawer Title
309 ImageView userIcon
= (ImageView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_userIcon
);
310 userIcon
.setImageResource(DisplayUtils
.getSeasonalIconId());
313 TextView username
= (TextView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_username
);
314 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
316 if (account
!= null
) {
317 int lastAtPos
= account
.name
.lastIndexOf("@");
318 username
.setText(account
.name
.substring(0, lastAtPos
));
321 // load slide menu items
322 mDrawerTitles
= getResources().getStringArray(R
.array
.drawer_items
);
324 // nav drawer content description from resources
325 mDrawerContentDescriptions
= getResources().
326 getStringArray(R
.array
.drawer_content_descriptions
);
329 mDrawerItems
= new ArrayList
<NavigationDrawerItem
>();
330 // adding nav drawer items to array
332 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[0], mDrawerContentDescriptions
[0]));
334 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[1], mDrawerContentDescriptions
[1]));
336 // TODO Enable when "On Device" is recovered
338 //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
339 // mDrawerContentDescriptions[2]));
342 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[2], mDrawerContentDescriptions
[2]));
344 if (BuildConfig
.DEBUG
) {
345 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[3],
346 mDrawerContentDescriptions
[3]));
349 // setting the nav drawer list adapter
350 mNavigationDrawerAdapter
= new NavigationDrawerListAdapter(getApplicationContext(), this,
352 mDrawerList
.setAdapter(mNavigationDrawerAdapter
);
354 mDrawerToggle
= new ActionBarDrawerToggle(
357 R
.drawable
.ic_drawer
,
358 R
.string
.drawer_open
,
359 R
.string
.drawer_close
) {
361 /** Called when a drawer has settled in a completely closed state. */
362 public void onDrawerClosed(View view
) {
363 super.onDrawerClosed(view
);
364 updateActionBarTitle();
365 getSupportActionBar().setDisplayShowTitleEnabled(true
);
366 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
367 invalidateOptionsMenu();
370 /** Called when a drawer has settled in a completely open state. */
371 public void onDrawerOpened(View drawerView
) {
372 super.onDrawerOpened(drawerView
);
373 getSupportActionBar().setTitle(R
.string
.drawer_open
);
374 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
375 invalidateOptionsMenu();
379 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
380 // Set the list's click listener
381 mDrawerList
.setOnItemClickListener(new DrawerItemClickListener());
383 // Set the drawer toggle as the DrawerListener
384 mDrawerLayout
.setDrawerListener(mDrawerToggle
);
387 protected void updateActionBarTitle(){
388 if (mFile
.getParentId() == 0) {
389 getSupportActionBar().setTitle(getString(
390 R
.string
.default_display_name_for_root_folder
));
391 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
393 getSupportActionBar().setTitle(mFile
.getFileName().toString());
394 mDrawerToggle
.setDrawerIndicatorEnabled(false
);
398 * Sets and validates the ownCloud {@link Account} associated to the Activity.
400 * If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
402 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
404 * @param account New {@link Account} to set.
405 * @param savedAccount When 'true', account was retrieved from a saved instance state.
407 protected void setAccount(Account account
, boolean savedAccount
) {
408 Account oldAccount
= mAccount
;
409 boolean validAccount
=
410 (account
!= null
&& AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(),
414 mAccountWasSet
= true
;
415 mAccountWasRestored
= (savedAccount
|| mAccount
.equals(oldAccount
));
418 swapToDefaultAccount();
424 * Tries to swap the current ownCloud {@link Account} for other valid and existing.
426 * If no valid ownCloud {@link Account} exists, the the user is requested
427 * to create a new ownCloud {@link Account}.
429 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
431 private void swapToDefaultAccount() {
432 // default to the most recently used account
433 Account newAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
434 if (newAccount
== null
) {
435 /// no account available: force account creation
436 createFirstAccount();
437 mRedirectingToSetupAccount
= true
;
438 mAccountWasSet
= false
;
439 mAccountWasRestored
= false
;
442 mAccountWasSet
= true
;
443 mAccountWasRestored
= (newAccount
.equals(mAccount
));
444 mAccount
= newAccount
;
450 * Launches the account creation activity. To use when no ownCloud account is available
452 private void createFirstAccount() {
453 AccountManager am
= AccountManager
.get(getApplicationContext());
454 am
.addAccount(MainApp
.getAccountType(),
459 new AccountCreationCallback(),
468 protected void onSaveInstanceState(Bundle outState
) {
469 super.onSaveInstanceState(outState
);
470 outState
.putParcelable(FileActivity
.EXTRA_FILE
, mFile
);
471 outState
.putBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
, mFromNotification
);
472 outState
.putLong(KEY_WAITING_FOR_OP_ID
, mFileOperationsHelper
.getOpIdWaitingFor());
473 outState
.putBoolean(KEY_TRY_SHARE_AGAIN
, mTryShareAgain
);
478 * Getter for the main {@link OCFile} handled by the activity.
480 * @return Main {@link OCFile} handled by the activity.
482 public OCFile
getFile() {
488 * Setter for the main {@link OCFile} handled by the activity.
490 * @param file Main {@link OCFile} to be handled by the activity.
492 public void setFile(OCFile file
) {
498 * Getter for the ownCloud {@link Account} where the main {@link OCFile} handled by the activity
501 * @return OwnCloud {@link Account} where the main {@link OCFile} handled by the activity
504 public Account
getAccount() {
508 protected void setAccount(Account account
) {
513 * @return Value of mFromNotification: True if the Activity is launched by a notification
515 public boolean fromNotification() {
516 return mFromNotification
;
520 * @return 'True' when the Activity is finishing to enforce the setup of a new account.
522 protected boolean isRedirectingToSetupAccount() {
523 return mRedirectingToSetupAccount
;
526 public boolean isTryShareAgain(){
527 return mTryShareAgain
;
530 public void setTryShareAgain(boolean tryShareAgain
) {
531 mTryShareAgain
= tryShareAgain
;
534 public OperationsServiceBinder
getOperationsServiceBinder() {
535 return mOperationsServiceBinder
;
538 protected ServiceConnection
newTransferenceServiceConnection() {
543 * Helper class handling a callback from the {@link AccountManager} after the creation of
544 * a new ownCloud {@link Account} finished, successfully or not.
546 * At this moment, only called after the creation of the first account.
548 public class AccountCreationCallback
implements AccountManagerCallback
<Bundle
> {
551 public void run(AccountManagerFuture
<Bundle
> future
) {
552 FileActivity
.this.mRedirectingToSetupAccount
= false
;
553 boolean accountWasSet
= false
;
554 if (future
!= null
) {
557 result
= future
.getResult();
558 String name
= result
.getString(AccountManager
.KEY_ACCOUNT_NAME
);
559 String type
= result
.getString(AccountManager
.KEY_ACCOUNT_TYPE
);
560 if (AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(), name
)) {
561 setAccount(new Account(name
, type
), false
);
562 accountWasSet
= true
;
564 } catch (OperationCanceledException e
) {
565 Log_OC
.d(TAG
, "Account creation canceled");
567 } catch (Exception e
) {
568 Log_OC
.e(TAG
, "Account creation finished in exception: ", e
);
572 Log_OC
.e(TAG
, "Account creation callback with null bundle");
574 if (!accountWasSet
) {
575 moveTaskToBack(true
);
583 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
585 * Child classes must grant that state depending on the {@link Account} is updated.
587 protected void onAccountSet(boolean stateWasRecovered
) {
588 if (getAccount() != null
) {
589 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
592 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
597 public FileDataStorageManager
getStorageManager() {
598 return mStorageManager
;
602 public OnRemoteOperationListener
getRemoteOperationListener() {
607 public Handler
getHandler() {
611 public FileOperationsHelper
getFileOperationsHelper() {
612 return mFileOperationsHelper
;
617 * @param operation Removal operation performed.
618 * @param result Result of the removal.
621 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
622 Log_OC
.d(TAG
, "Received result of operation in FileActivity - common behaviour for all the "
623 + "FileActivities ");
625 mFileOperationsHelper
.setOpIdWaitingFor(Long
.MAX_VALUE
);
627 if (!result
.isSuccess() && (
628 result
.getCode() == ResultCode
.UNAUTHORIZED
||
629 result
.isIdPRedirection() ||
630 (result
.isException() && result
.getException() instanceof AuthenticatorException
)
633 requestCredentialsUpdate();
635 if (result
.getCode() == ResultCode
.UNAUTHORIZED
) {
636 dismissLoadingDialog();
637 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
638 operation
, getResources()),
642 mTryShareAgain
= false
;
644 } else if (operation
instanceof CreateShareOperation
) {
645 onCreateShareOperationFinish((CreateShareOperation
) operation
, result
);
647 } else if (operation
instanceof UnshareLinkOperation
) {
648 onUnshareLinkOperationFinish((UnshareLinkOperation
)operation
, result
);
650 } else if (operation
instanceof SynchronizeFolderOperation
) {
651 onSynchronizeFolderOperationFinish((SynchronizeFolderOperation
)operation
, result
);
656 protected void requestCredentialsUpdate() {
657 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
658 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, getAccount());
659 updateAccountCredentials
.putExtra(
660 AuthenticatorActivity
.EXTRA_ACTION
,
661 AuthenticatorActivity
.ACTION_UPDATE_EXPIRED_TOKEN
);
662 updateAccountCredentials
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
663 startActivity(updateAccountCredentials
);
667 private void onCreateShareOperationFinish(CreateShareOperation operation
,
668 RemoteOperationResult result
) {
669 dismissLoadingDialog();
670 if (result
.isSuccess()) {
671 mTryShareAgain
= false
;
674 Intent sendIntent
= operation
.getSendIntent();
675 startActivity(sendIntent
);
677 // Detect Failure (403) --> needs Password
678 if (result
.getCode() == ResultCode
.SHARE_FORBIDDEN
) {
679 if (!isTryShareAgain()) {
680 SharePasswordDialogFragment dialog
=
681 SharePasswordDialogFragment
.newInstance(new OCFile(operation
.getPath()),
682 operation
.getSendIntent());
683 dialog
.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD
);
685 Toast t
= Toast
.makeText(this,
686 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
689 mTryShareAgain
= false
;
692 Toast t
= Toast
.makeText(this,
693 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
701 private void onUnshareLinkOperationFinish(UnshareLinkOperation operation
,
702 RemoteOperationResult result
) {
703 dismissLoadingDialog();
705 if (result
.isSuccess()){
709 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
710 operation
, getResources()), Toast
.LENGTH_LONG
);
715 private void onSynchronizeFolderOperationFinish(
716 SynchronizeFolderOperation operation
, RemoteOperationResult result
718 if (!result
.isSuccess() && result
.getCode() != ResultCode
.CANCELLED
){
719 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
720 operation
, getResources()), Toast
.LENGTH_LONG
);
725 protected void updateFileFromDB(){
726 OCFile file
= getFile();
728 file
= getStorageManager().getFileByPath(file
.getRemotePath());
734 * Show loading dialog
736 public void showLoadingDialog() {
738 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
739 FragmentManager fm
= getSupportFragmentManager();
740 FragmentTransaction ft
= fm
.beginTransaction();
741 loading
.show(ft
, DIALOG_WAIT_TAG
);
747 * Dismiss loading dialog
749 public void dismissLoadingDialog(){
750 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
752 LoadingDialog loading
= (LoadingDialog
) frag
;
758 private void doOnResumeAndBound() {
759 mOperationsServiceBinder
.addOperationListener(FileActivity
.this, mHandler
);
760 long waitingForOpId
= mFileOperationsHelper
.getOpIdWaitingFor();
761 if (waitingForOpId
<= Integer
.MAX_VALUE
) {
762 boolean wait
= mOperationsServiceBinder
.dispatchResultIfFinished((int)waitingForOpId
,
765 dismissLoadingDialog();
772 * Implements callback methods for service binding. Passed as a parameter to {
774 private class OperationsServiceConnection
implements ServiceConnection
{
777 public void onServiceConnected(ComponentName component
, IBinder service
) {
778 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
779 Log_OC
.d(TAG
, "Operations service connected");
780 mOperationsServiceBinder
= (OperationsServiceBinder
) service
;
781 /*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
782 dismissLoadingDialog();
784 doOnResumeAndBound();
793 public void onServiceDisconnected(ComponentName component
) {
794 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
795 Log_OC
.d(TAG
, "Operations service disconnected");
796 mOperationsServiceBinder
= null
;
797 // TODO whatever could be waiting for the service is unbound
804 public FileDownloaderBinder
getFileDownloaderBinder() {
805 return mDownloaderBinder
;
810 public FileUploaderBinder
getFileUploaderBinder() {
811 return mUploaderBinder
;
815 public void restart(){
816 Intent i
= new Intent(this, FileDisplayActivity
.class);
817 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
821 public void closeDrawer() {
822 mDrawerLayout
.closeDrawers();
825 public void allFilesOption(){
829 private class DrawerItemClickListener
implements ListView
.OnItemClickListener
{
831 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
832 if (mShowAccounts
&& position
> 0){
833 position
= position
- 1;
837 mShowAccounts
= !mShowAccounts
;
838 mNavigationDrawerAdapter
.setShowAccounts(mShowAccounts
);
839 mNavigationDrawerAdapter
.notifyDataSetChanged();
844 mDrawerLayout
.closeDrawers();
847 // TODO Enable when "On Device" is recovered ?
849 // MainApp.showOnlyFilesOnDevice(true);
850 // mDrawerLayout.closeDrawers();
854 Intent settingsIntent
= new Intent(getApplicationContext(),
856 startActivity(settingsIntent
);
860 Intent loggerIntent
= new Intent(getApplicationContext(),
861 LogHistoryActivity
.class);
862 startActivity(loggerIntent
);