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
.view
.GravityCompat
;
43 import android
.support
.v4
.widget
.DrawerLayout
;
44 import android
.support
.v7
.app
.ActionBar
;
45 import android
.support
.v7
.app
.ActionBarActivity
;
46 import android
.view
.View
;
47 import android
.widget
.AdapterView
;
48 import android
.widget
.LinearLayout
;
49 import android
.widget
.ListView
;
50 import android
.widget
.Toast
;
52 import com
.owncloud
.android
.BuildConfig
;
53 import com
.owncloud
.android
.MainApp
;
54 import com
.owncloud
.android
.R
;
55 import com
.owncloud
.android
.authentication
.AccountUtils
;
56 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
57 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
58 import com
.owncloud
.android
.datamodel
.OCFile
;
59 import com
.owncloud
.android
.files
.FileOperationsHelper
;
60 import com
.owncloud
.android
.files
.services
.FileDownloader
;
61 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
62 import com
.owncloud
.android
.files
.services
.FileUploader
;
63 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
64 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
65 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
66 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
67 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
68 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
69 import com
.owncloud
.android
.operations
.CreateShareOperation
;
70 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
71 import com
.owncloud
.android
.operations
.UnshareLinkOperation
;
72 import com
.owncloud
.android
.services
.OperationsService
;
73 import com
.owncloud
.android
.services
.OperationsService
.OperationsServiceBinder
;
74 import com
.owncloud
.android
.ui
.NavigationDrawerItem
;
75 import com
.owncloud
.android
.ui
.adapter
.NavigationDrawerListAdapter
;
76 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
77 import com
.owncloud
.android
.ui
.dialog
.SharePasswordDialogFragment
;
78 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
80 import java
.util
.ArrayList
;
84 * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud
87 public class FileActivity
extends ActionBarActivity
88 implements OnRemoteOperationListener
, ComponentsGetter
{
90 public static final String EXTRA_FILE
= "com.owncloud.android.ui.activity.FILE";
91 public static final String EXTRA_ACCOUNT
= "com.owncloud.android.ui.activity.ACCOUNT";
92 public static final String EXTRA_WAITING_TO_PREVIEW
=
93 "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
94 public static final String EXTRA_FROM_NOTIFICATION
=
95 "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
97 public static final String TAG
= FileActivity
.class.getSimpleName();
99 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
100 private static final String KEY_WAITING_FOR_OP_ID
= "WAITING_FOR_OP_ID";
101 private static final String DIALOG_SHARE_PASSWORD
= "DIALOG_SHARE_PASSWORD";
102 private static final String KEY_TRY_SHARE_AGAIN
= "TRY_SHARE_AGAIN";
103 private static final String KEY_ACTION_BAR_TITLE
= "ACTION_BAR_TITLE";
105 protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
= 200;
108 /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
109 private Account mAccount
;
111 /** Main {@link OCFile} handled by the activity.*/
112 private OCFile mFile
;
114 /** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud
116 private boolean mRedirectingToSetupAccount
= false
;
118 /** Flag to signal when the value of mAccount was set */
119 protected boolean mAccountWasSet
;
121 /** Flag to signal when the value of mAccount was restored from a saved state */
122 protected boolean mAccountWasRestored
;
124 /** Flag to signal if the activity is launched by a notification */
125 private boolean mFromNotification
;
127 /** Messages handler associated to the main thread and the life cycle of the activity */
128 private Handler mHandler
;
130 /** Access point to the cached database for the current ownCloud {@link Account} */
131 private FileDataStorageManager mStorageManager
= null
;
133 private FileOperationsHelper mFileOperationsHelper
;
135 private ServiceConnection mOperationsServiceConnection
= null
;
137 private OperationsServiceBinder mOperationsServiceBinder
= null
;
139 protected FileDownloaderBinder mDownloaderBinder
= null
;
140 protected FileUploaderBinder mUploaderBinder
= null
;
141 private ServiceConnection mDownloadServiceConnection
, mUploadServiceConnection
= null
;
143 private boolean mTryShareAgain
= false
;
146 protected DrawerLayout mDrawerLayout
;
147 protected ActionBarDrawerToggle mDrawerToggle
;
148 protected ListView mDrawerList
;
151 protected String
[] mDrawerTitles
;
152 protected String
[] mDrawerContentDescriptions
;
154 protected ArrayList
<NavigationDrawerItem
> mDrawerItems
;
156 protected NavigationDrawerListAdapter mNavigationDrawerAdapter
= null
;
159 // TODO re-enable when "Accounts" is available in Navigation Drawer
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
);
182 getSupportActionBar().setTitle(savedInstanceState
.getString(KEY_ACTION_BAR_TITLE
));
184 account
= getIntent().getParcelableExtra(FileActivity
.EXTRA_ACCOUNT
);
185 mFile
= getIntent().getParcelableExtra(FileActivity
.EXTRA_FILE
);
186 mFromNotification
= getIntent().getBooleanExtra(FileActivity
.EXTRA_FROM_NOTIFICATION
,
190 AccountUtils
.updateAccountVersion(this); // best place, before any access to AccountManager
193 setAccount(account
, savedInstanceState
!= null
);
195 mOperationsServiceConnection
= new OperationsServiceConnection();
196 bindService(new Intent(this, OperationsService
.class), mOperationsServiceConnection
,
197 Context
.BIND_AUTO_CREATE
);
199 mDownloadServiceConnection
= newTransferenceServiceConnection();
200 if (mDownloadServiceConnection
!= null
) {
201 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
202 Context
.BIND_AUTO_CREATE
);
204 mUploadServiceConnection
= newTransferenceServiceConnection();
205 if (mUploadServiceConnection
!= null
) {
206 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
207 Context
.BIND_AUTO_CREATE
);
213 protected void onNewIntent (Intent intent
) {
214 Log_OC
.v(TAG
, "onNewIntent() start");
215 Account current
= AccountUtils
.getCurrentOwnCloudAccount(this);
216 if (current
!= null
&& mAccount
!= null
&& !mAccount
.name
.equals(current
.name
)) {
219 Log_OC
.v(TAG
, "onNewIntent() stop");
223 * Since ownCloud {@link Account}s can be managed from the system setting menu,
224 * the existence of the {@link Account} associated to the instance must be checked
225 * every time it is restarted.
228 protected void onRestart() {
229 Log_OC
.v(TAG
, "onRestart() start");
231 boolean validAccount
= (mAccount
!= null
&& AccountUtils
.exists(mAccount
, this));
233 swapToDefaultAccount();
235 Log_OC
.v(TAG
, "onRestart() end");
240 protected void onStart() {
243 if (mAccountWasSet
) {
244 onAccountSet(mAccountWasRestored
);
249 protected void onResume() {
252 if (mOperationsServiceBinder
!= null
) {
253 doOnResumeAndBound();
258 protected void onPause() {
259 if (mOperationsServiceBinder
!= null
) {
260 mOperationsServiceBinder
.removeOperationListener(this);
268 protected void onDestroy() {
269 if (mOperationsServiceConnection
!= null
) {
270 unbindService(mOperationsServiceConnection
);
271 mOperationsServiceBinder
= null
;
273 if (mDownloadServiceConnection
!= null
) {
274 unbindService(mDownloadServiceConnection
);
275 mDownloadServiceConnection
= null
;
277 if (mUploadServiceConnection
!= null
) {
278 unbindService(mUploadServiceConnection
);
279 mUploadServiceConnection
= null
;
286 protected void onPostCreate(Bundle savedInstanceState
) {
287 super.onPostCreate(savedInstanceState
);
288 // Sync the toggle state after onRestoreInstanceState has occurred.
289 if (mDrawerToggle
!= null
) {
290 mDrawerToggle
.syncState();
291 if (mDrawerLayout
.isDrawerOpen(GravityCompat
.START
)) {
292 getSupportActionBar().setTitle(R
.string
.app_name
);
293 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
299 public void onConfigurationChanged(Configuration newConfig
) {
300 super.onConfigurationChanged(newConfig
);
301 if (mDrawerToggle
!= null
) {
302 mDrawerToggle
.onConfigurationChanged(newConfig
);
306 protected void initDrawer(){
307 // constant settings for action bar when navigation drawer is inited
308 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
311 mDrawerLayout
= (DrawerLayout
) findViewById(R
.id
.drawer_layout
);
312 // Notification Drawer
313 LinearLayout navigationDrawerLayout
= (LinearLayout
) findViewById(R
.id
.left_drawer
);
314 mDrawerList
= (ListView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_list
);
316 // TODO re-enable when "Accounts" is available in Navigation Drawer
317 // // load Account in the Drawer Title
319 // ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon);
320 // userIcon.setImageResource(DisplayUtils.getSeasonalIconId());
323 // TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
324 // Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
326 // if (account != null) {
327 // int lastAtPos = account.name.lastIndexOf("@");
328 // username.setText(account.name.substring(0, lastAtPos));
331 // load slide menu items
332 mDrawerTitles
= getResources().getStringArray(R
.array
.drawer_items
);
334 // nav drawer content description from resources
335 mDrawerContentDescriptions
= getResources().
336 getStringArray(R
.array
.drawer_content_descriptions
);
339 mDrawerItems
= new ArrayList
<NavigationDrawerItem
>();
340 // adding nav drawer items to array
341 // TODO re-enable when "Accounts" is available in Navigation Drawer
343 // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
344 // mDrawerContentDescriptions[0]));
346 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[0], mDrawerContentDescriptions
[0]));
348 // TODO Enable when "On Device" is recovered
350 //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
351 // mDrawerContentDescriptions[2]));
354 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[1], mDrawerContentDescriptions
[1]));
356 if (BuildConfig
.DEBUG
) {
357 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[2],
358 mDrawerContentDescriptions
[2]));
361 // setting the nav drawer list adapter
362 mNavigationDrawerAdapter
= new NavigationDrawerListAdapter(getApplicationContext(), this,
364 mDrawerList
.setAdapter(mNavigationDrawerAdapter
);
366 mDrawerToggle
= new ActionBarDrawerToggle(
369 R
.drawable
.ic_drawer
,
371 R
.string
.drawer_close
) {
373 /** Called when a drawer has settled in a completely closed state. */
374 public void onDrawerClosed(View view
) {
375 super.onDrawerClosed(view
);
376 updateActionBarTitleAndHomeButton(null
);
377 invalidateOptionsMenu();
380 /** Called when a drawer has settled in a completely open state. */
381 public void onDrawerOpened(View drawerView
) {
382 super.onDrawerOpened(drawerView
);
383 getSupportActionBar().setTitle(R
.string
.app_name
);
384 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
385 invalidateOptionsMenu();
389 //mDrawerToggle.setDrawerIndicatorEnabled(true);
390 // Set the list's click listener
391 mDrawerList
.setOnItemClickListener(new DrawerItemClickListener());
393 // Set the drawer toggle as the DrawerListener
394 mDrawerLayout
.setDrawerListener(mDrawerToggle
);
398 * Updates title bar and home buttons (state and icon).
400 * Assumes that navigation drawer is NOT visible.
402 protected void updateActionBarTitleAndHomeButton(OCFile chosenFile
) {
403 String title
= getString(R
.string
.default_display_name_for_root_folder
); // default
406 /// choose the appropiate title
407 if (chosenFile
== null
) {
408 // mFile determines the title
409 inRoot
= (mFile
== null
|| mFile
.getParentId() == 0);
411 title
= mFile
.getFileName();
414 } else if (chosenFile
.getParentId() != 0){
415 // chosenFile determines the title, instead of mFile
416 title
= chosenFile
.getFileName();
423 /// set the chosen title
424 ActionBar actionBar
= getSupportActionBar();
425 actionBar
.setTitle(title
);
426 /// also as content description
427 View actionBarTitleView
= getWindow().getDecorView().findViewById(
428 getResources().getIdentifier("action_bar_title", "id", "android")
430 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
431 actionBarTitleView
.setContentDescription(title
);
434 /// set home button properties
435 mDrawerToggle
.setDrawerIndicatorEnabled(inRoot
);
436 actionBar
.setDisplayHomeAsUpEnabled(true
);
437 actionBar
.setDisplayShowTitleEnabled(true
);
443 * Sets and validates the ownCloud {@link Account} associated to the Activity.
445 * If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
447 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
449 * @param account New {@link Account} to set.
450 * @param savedAccount When 'true', account was retrieved from a saved instance state.
452 protected void setAccount(Account account
, boolean savedAccount
) {
453 Account oldAccount
= mAccount
;
454 boolean validAccount
=
455 (account
!= null
&& AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(),
459 mAccountWasSet
= true
;
460 mAccountWasRestored
= (savedAccount
|| mAccount
.equals(oldAccount
));
463 swapToDefaultAccount();
469 * Tries to swap the current ownCloud {@link Account} for other valid and existing.
471 * If no valid ownCloud {@link Account} exists, the the user is requested
472 * to create a new ownCloud {@link Account}.
474 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
476 private void swapToDefaultAccount() {
477 // default to the most recently used account
478 Account newAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
479 if (newAccount
== null
) {
480 /// no account available: force account creation
481 createFirstAccount();
482 mRedirectingToSetupAccount
= true
;
483 mAccountWasSet
= false
;
484 mAccountWasRestored
= false
;
487 mAccountWasSet
= true
;
488 mAccountWasRestored
= (newAccount
.equals(mAccount
));
489 mAccount
= newAccount
;
495 * Launches the account creation activity. To use when no ownCloud account is available
497 private void createFirstAccount() {
498 AccountManager am
= AccountManager
.get(getApplicationContext());
499 am
.addAccount(MainApp
.getAccountType(),
504 new AccountCreationCallback(),
513 protected void onSaveInstanceState(Bundle outState
) {
514 super.onSaveInstanceState(outState
);
515 outState
.putParcelable(FileActivity
.EXTRA_FILE
, mFile
);
516 outState
.putBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
, mFromNotification
);
517 outState
.putLong(KEY_WAITING_FOR_OP_ID
, mFileOperationsHelper
.getOpIdWaitingFor());
518 outState
.putBoolean(KEY_TRY_SHARE_AGAIN
, mTryShareAgain
);
519 outState
.putString(KEY_ACTION_BAR_TITLE
, getSupportActionBar().getTitle().toString());
524 * Getter for the main {@link OCFile} handled by the activity.
526 * @return Main {@link OCFile} handled by the activity.
528 public OCFile
getFile() {
534 * Setter for the main {@link OCFile} handled by the activity.
536 * @param file Main {@link OCFile} to be handled by the activity.
538 public void setFile(OCFile file
) {
544 * Getter for the ownCloud {@link Account} where the main {@link OCFile} handled by the activity
547 * @return OwnCloud {@link Account} where the main {@link OCFile} handled by the activity
550 public Account
getAccount() {
554 protected void setAccount(Account account
) {
559 * @return Value of mFromNotification: True if the Activity is launched by a notification
561 public boolean fromNotification() {
562 return mFromNotification
;
566 * @return 'True' when the Activity is finishing to enforce the setup of a new account.
568 protected boolean isRedirectingToSetupAccount() {
569 return mRedirectingToSetupAccount
;
572 public boolean isTryShareAgain(){
573 return mTryShareAgain
;
576 public void setTryShareAgain(boolean tryShareAgain
) {
577 mTryShareAgain
= tryShareAgain
;
580 public OperationsServiceBinder
getOperationsServiceBinder() {
581 return mOperationsServiceBinder
;
584 protected ServiceConnection
newTransferenceServiceConnection() {
589 * Helper class handling a callback from the {@link AccountManager} after the creation of
590 * a new ownCloud {@link Account} finished, successfully or not.
592 * At this moment, only called after the creation of the first account.
594 public class AccountCreationCallback
implements AccountManagerCallback
<Bundle
> {
597 public void run(AccountManagerFuture
<Bundle
> future
) {
598 FileActivity
.this.mRedirectingToSetupAccount
= false
;
599 boolean accountWasSet
= false
;
600 if (future
!= null
) {
603 result
= future
.getResult();
604 String name
= result
.getString(AccountManager
.KEY_ACCOUNT_NAME
);
605 String type
= result
.getString(AccountManager
.KEY_ACCOUNT_TYPE
);
606 if (AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(), name
)) {
607 setAccount(new Account(name
, type
), false
);
608 accountWasSet
= true
;
610 } catch (OperationCanceledException e
) {
611 Log_OC
.d(TAG
, "Account creation canceled");
613 } catch (Exception e
) {
614 Log_OC
.e(TAG
, "Account creation finished in exception: ", e
);
618 Log_OC
.e(TAG
, "Account creation callback with null bundle");
620 if (!accountWasSet
) {
621 moveTaskToBack(true
);
629 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
631 * Child classes must grant that state depending on the {@link Account} is updated.
633 protected void onAccountSet(boolean stateWasRecovered
) {
634 if (getAccount() != null
) {
635 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
638 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
643 public FileDataStorageManager
getStorageManager() {
644 return mStorageManager
;
648 public OnRemoteOperationListener
getRemoteOperationListener() {
653 public Handler
getHandler() {
657 public FileOperationsHelper
getFileOperationsHelper() {
658 return mFileOperationsHelper
;
663 * @param operation Removal operation performed.
664 * @param result Result of the removal.
667 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
668 Log_OC
.d(TAG
, "Received result of operation in FileActivity - common behaviour for all the "
669 + "FileActivities ");
671 mFileOperationsHelper
.setOpIdWaitingFor(Long
.MAX_VALUE
);
673 if (!result
.isSuccess() && (
674 result
.getCode() == ResultCode
.UNAUTHORIZED
||
675 result
.isIdPRedirection() ||
676 (result
.isException() && result
.getException() instanceof AuthenticatorException
)
679 requestCredentialsUpdate();
681 if (result
.getCode() == ResultCode
.UNAUTHORIZED
) {
682 dismissLoadingDialog();
683 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
684 operation
, getResources()),
688 mTryShareAgain
= false
;
690 } else if (operation
instanceof CreateShareOperation
) {
691 onCreateShareOperationFinish((CreateShareOperation
) operation
, result
);
693 } else if (operation
instanceof UnshareLinkOperation
) {
694 onUnshareLinkOperationFinish((UnshareLinkOperation
)operation
, result
);
696 } else if (operation
instanceof SynchronizeFolderOperation
) {
697 onSynchronizeFolderOperationFinish((SynchronizeFolderOperation
)operation
, result
);
702 protected void requestCredentialsUpdate() {
703 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
704 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, getAccount());
705 updateAccountCredentials
.putExtra(
706 AuthenticatorActivity
.EXTRA_ACTION
,
707 AuthenticatorActivity
.ACTION_UPDATE_EXPIRED_TOKEN
);
708 updateAccountCredentials
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
709 startActivity(updateAccountCredentials
);
713 private void onCreateShareOperationFinish(CreateShareOperation operation
,
714 RemoteOperationResult result
) {
715 dismissLoadingDialog();
716 if (result
.isSuccess()) {
717 mTryShareAgain
= false
;
720 Intent sendIntent
= operation
.getSendIntent();
721 startActivity(sendIntent
);
723 // Detect Failure (403) --> needs Password
724 if (result
.getCode() == ResultCode
.SHARE_FORBIDDEN
) {
725 if (!isTryShareAgain()) {
726 SharePasswordDialogFragment dialog
=
727 SharePasswordDialogFragment
.newInstance(new OCFile(operation
.getPath()),
728 operation
.getSendIntent());
729 dialog
.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD
);
731 Toast t
= Toast
.makeText(this,
732 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
735 mTryShareAgain
= false
;
738 Toast t
= Toast
.makeText(this,
739 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
747 private void onUnshareLinkOperationFinish(UnshareLinkOperation operation
,
748 RemoteOperationResult result
) {
749 dismissLoadingDialog();
751 if (result
.isSuccess()){
755 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
756 operation
, getResources()), Toast
.LENGTH_LONG
);
761 private void onSynchronizeFolderOperationFinish(
762 SynchronizeFolderOperation operation
, RemoteOperationResult result
764 if (!result
.isSuccess() && result
.getCode() != ResultCode
.CANCELLED
){
765 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
766 operation
, getResources()), Toast
.LENGTH_LONG
);
771 protected void updateFileFromDB(){
772 OCFile file
= getFile();
774 file
= getStorageManager().getFileByPath(file
.getRemotePath());
780 * Show loading dialog
782 public void showLoadingDialog() {
784 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
785 FragmentManager fm
= getSupportFragmentManager();
786 FragmentTransaction ft
= fm
.beginTransaction();
787 loading
.show(ft
, DIALOG_WAIT_TAG
);
793 * Dismiss loading dialog
795 public void dismissLoadingDialog(){
796 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
798 LoadingDialog loading
= (LoadingDialog
) frag
;
804 private void doOnResumeAndBound() {
805 mOperationsServiceBinder
.addOperationListener(FileActivity
.this, mHandler
);
806 long waitingForOpId
= mFileOperationsHelper
.getOpIdWaitingFor();
807 if (waitingForOpId
<= Integer
.MAX_VALUE
) {
808 boolean wait
= mOperationsServiceBinder
.dispatchResultIfFinished((int)waitingForOpId
,
811 dismissLoadingDialog();
818 * Implements callback methods for service binding. Passed as a parameter to {
820 private class OperationsServiceConnection
implements ServiceConnection
{
823 public void onServiceConnected(ComponentName component
, IBinder service
) {
824 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
825 Log_OC
.d(TAG
, "Operations service connected");
826 mOperationsServiceBinder
= (OperationsServiceBinder
) service
;
827 /*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
828 dismissLoadingDialog();
830 doOnResumeAndBound();
839 public void onServiceDisconnected(ComponentName component
) {
840 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
841 Log_OC
.d(TAG
, "Operations service disconnected");
842 mOperationsServiceBinder
= null
;
843 // TODO whatever could be waiting for the service is unbound
850 public FileDownloaderBinder
getFileDownloaderBinder() {
851 return mDownloaderBinder
;
856 public FileUploaderBinder
getFileUploaderBinder() {
857 return mUploaderBinder
;
861 public void restart(){
862 Intent i
= new Intent(this, FileDisplayActivity
.class);
863 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
867 // TODO re-enable when "Accounts" is available in Navigation Drawer
868 // public void closeDrawer() {
869 // mDrawerLayout.closeDrawers();
872 public void allFilesOption(){
876 private class DrawerItemClickListener
implements ListView
.OnItemClickListener
{
878 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
879 // TODO re-enable when "Accounts" is available in Navigation Drawer
880 // if (mShowAccounts && position > 0){
881 // position = position - 1;
884 // TODO re-enable when "Accounts" is available in Navigation Drawer
885 // case 0: // Accounts
886 // mShowAccounts = !mShowAccounts;
887 // mNavigationDrawerAdapter.setShowAccounts(mShowAccounts);
888 // mNavigationDrawerAdapter.notifyDataSetChanged();
893 mDrawerLayout
.closeDrawers();
896 // TODO Enable when "On Device" is recovered ?
898 // MainApp.showOnlyFilesOnDevice(true);
899 // mDrawerLayout.closeDrawers();
903 Intent settingsIntent
= new Intent(getApplicationContext(),
905 startActivity(settingsIntent
);
906 mDrawerLayout
.closeDrawers();
910 Intent loggerIntent
= new Intent(getApplicationContext(),
911 LogHistoryActivity
.class);
912 startActivity(loggerIntent
);
913 mDrawerLayout
.closeDrawers();