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 // TODO re-enable when "Accounts" is available in Navigation Drawer
161 // protected boolean mShowAccounts = false;
164 * Loads the ownCloud {@link Account} and main {@link OCFile} to be handled by the instance of
165 * the {@link FileActivity}.
167 * Grants that a valid ownCloud {@link Account} is associated to the instance, or that the user
168 * is requested to create a new one.
171 protected void onCreate(Bundle savedInstanceState
) {
172 super.onCreate(savedInstanceState
);
173 mHandler
= new Handler();
174 mFileOperationsHelper
= new FileOperationsHelper(this);
175 Account account
= null
;
176 if(savedInstanceState
!= null
) {
177 mFile
= savedInstanceState
.getParcelable(FileActivity
.EXTRA_FILE
);
178 mFromNotification
= savedInstanceState
.getBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
);
179 mFileOperationsHelper
.setOpIdWaitingFor(
180 savedInstanceState
.getLong(KEY_WAITING_FOR_OP_ID
, Long
.MAX_VALUE
)
182 mTryShareAgain
= savedInstanceState
.getBoolean(KEY_TRY_SHARE_AGAIN
);
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();
295 public void onConfigurationChanged(Configuration newConfig
) {
296 super.onConfigurationChanged(newConfig
);
297 if (mDrawerToggle
!= null
) {
298 mDrawerToggle
.onConfigurationChanged(newConfig
);
302 protected void initDrawer(){
303 mDrawerLayout
= (DrawerLayout
) findViewById(R
.id
.drawer_layout
);
304 // Notification Drawer
305 LinearLayout navigationDrawerLayout
= (LinearLayout
) findViewById(R
.id
.left_drawer
);
306 mDrawerList
= (ListView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_list
);
308 // TODO re-enable when "Accounts" is available in Navigation Drawer
309 // // load Account in the Drawer Title
311 // ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon);
312 // userIcon.setImageResource(DisplayUtils.getSeasonalIconId());
315 // TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
316 // Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
318 // if (account != null) {
319 // int lastAtPos = account.name.lastIndexOf("@");
320 // username.setText(account.name.substring(0, lastAtPos));
323 // load slide menu items
324 mDrawerTitles
= getResources().getStringArray(R
.array
.drawer_items
);
326 // nav drawer content description from resources
327 mDrawerContentDescriptions
= getResources().
328 getStringArray(R
.array
.drawer_content_descriptions
);
331 mDrawerItems
= new ArrayList
<NavigationDrawerItem
>();
332 // adding nav drawer items to array
333 // TODO re-enable when "Accounts" is available in Navigation Drawer
335 // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
336 // mDrawerContentDescriptions[0]));
338 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[0], mDrawerContentDescriptions
[0]));
340 // TODO Enable when "On Device" is recovered
342 //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
343 // mDrawerContentDescriptions[2]));
346 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[1], mDrawerContentDescriptions
[1]));
348 if (BuildConfig
.DEBUG
) {
349 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[2],
350 mDrawerContentDescriptions
[2]));
353 // setting the nav drawer list adapter
354 mNavigationDrawerAdapter
= new NavigationDrawerListAdapter(getApplicationContext(), this,
356 mDrawerList
.setAdapter(mNavigationDrawerAdapter
);
358 mDrawerToggle
= new ActionBarDrawerToggle(
361 R
.drawable
.ic_drawer
,
362 R
.string
.drawer_open
,
363 R
.string
.drawer_close
) {
365 /** Called when a drawer has settled in a completely closed state. */
366 public void onDrawerClosed(View view
) {
367 super.onDrawerClosed(view
);
368 updateActionBarTitle();
369 getSupportActionBar().setDisplayShowTitleEnabled(true
);
370 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
371 invalidateOptionsMenu();
374 /** Called when a drawer has settled in a completely open state. */
375 public void onDrawerOpened(View drawerView
) {
376 super.onDrawerOpened(drawerView
);
377 getSupportActionBar().setTitle(R
.string
.drawer_open
);
378 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
379 invalidateOptionsMenu();
383 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
384 // Set the list's click listener
385 mDrawerList
.setOnItemClickListener(new DrawerItemClickListener());
387 // Set the drawer toggle as the DrawerListener
388 mDrawerLayout
.setDrawerListener(mDrawerToggle
);
391 protected void updateActionBarTitle(){
392 if (mFile
.getParentId() == 0) {
393 getSupportActionBar().setTitle(getString(
394 R
.string
.default_display_name_for_root_folder
));
395 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
397 getSupportActionBar().setTitle(mFile
.getFileName().toString());
398 mDrawerToggle
.setDrawerIndicatorEnabled(false
);
402 * Sets and validates the ownCloud {@link Account} associated to the Activity.
404 * If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
406 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
408 * @param account New {@link Account} to set.
409 * @param savedAccount When 'true', account was retrieved from a saved instance state.
411 protected void setAccount(Account account
, boolean savedAccount
) {
412 Account oldAccount
= mAccount
;
413 boolean validAccount
=
414 (account
!= null
&& AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(),
418 mAccountWasSet
= true
;
419 mAccountWasRestored
= (savedAccount
|| mAccount
.equals(oldAccount
));
422 swapToDefaultAccount();
428 * Tries to swap the current ownCloud {@link Account} for other valid and existing.
430 * If no valid ownCloud {@link Account} exists, the the user is requested
431 * to create a new ownCloud {@link Account}.
433 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
435 private void swapToDefaultAccount() {
436 // default to the most recently used account
437 Account newAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
438 if (newAccount
== null
) {
439 /// no account available: force account creation
440 createFirstAccount();
441 mRedirectingToSetupAccount
= true
;
442 mAccountWasSet
= false
;
443 mAccountWasRestored
= false
;
446 mAccountWasSet
= true
;
447 mAccountWasRestored
= (newAccount
.equals(mAccount
));
448 mAccount
= newAccount
;
454 * Launches the account creation activity. To use when no ownCloud account is available
456 private void createFirstAccount() {
457 AccountManager am
= AccountManager
.get(getApplicationContext());
458 am
.addAccount(MainApp
.getAccountType(),
463 new AccountCreationCallback(),
472 protected void onSaveInstanceState(Bundle outState
) {
473 super.onSaveInstanceState(outState
);
474 outState
.putParcelable(FileActivity
.EXTRA_FILE
, mFile
);
475 outState
.putBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
, mFromNotification
);
476 outState
.putLong(KEY_WAITING_FOR_OP_ID
, mFileOperationsHelper
.getOpIdWaitingFor());
477 outState
.putBoolean(KEY_TRY_SHARE_AGAIN
, mTryShareAgain
);
482 * Getter for the main {@link OCFile} handled by the activity.
484 * @return Main {@link OCFile} handled by the activity.
486 public OCFile
getFile() {
492 * Setter for the main {@link OCFile} handled by the activity.
494 * @param file Main {@link OCFile} to be handled by the activity.
496 public void setFile(OCFile file
) {
502 * Getter for the ownCloud {@link Account} where the main {@link OCFile} handled by the activity
505 * @return OwnCloud {@link Account} where the main {@link OCFile} handled by the activity
508 public Account
getAccount() {
512 protected void setAccount(Account account
) {
517 * @return Value of mFromNotification: True if the Activity is launched by a notification
519 public boolean fromNotification() {
520 return mFromNotification
;
524 * @return 'True' when the Activity is finishing to enforce the setup of a new account.
526 protected boolean isRedirectingToSetupAccount() {
527 return mRedirectingToSetupAccount
;
530 public boolean isTryShareAgain(){
531 return mTryShareAgain
;
534 public void setTryShareAgain(boolean tryShareAgain
) {
535 mTryShareAgain
= tryShareAgain
;
538 public OperationsServiceBinder
getOperationsServiceBinder() {
539 return mOperationsServiceBinder
;
542 protected ServiceConnection
newTransferenceServiceConnection() {
547 * Helper class handling a callback from the {@link AccountManager} after the creation of
548 * a new ownCloud {@link Account} finished, successfully or not.
550 * At this moment, only called after the creation of the first account.
552 public class AccountCreationCallback
implements AccountManagerCallback
<Bundle
> {
555 public void run(AccountManagerFuture
<Bundle
> future
) {
556 FileActivity
.this.mRedirectingToSetupAccount
= false
;
557 boolean accountWasSet
= false
;
558 if (future
!= null
) {
561 result
= future
.getResult();
562 String name
= result
.getString(AccountManager
.KEY_ACCOUNT_NAME
);
563 String type
= result
.getString(AccountManager
.KEY_ACCOUNT_TYPE
);
564 if (AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(), name
)) {
565 setAccount(new Account(name
, type
), false
);
566 accountWasSet
= true
;
568 } catch (OperationCanceledException e
) {
569 Log_OC
.d(TAG
, "Account creation canceled");
571 } catch (Exception e
) {
572 Log_OC
.e(TAG
, "Account creation finished in exception: ", e
);
576 Log_OC
.e(TAG
, "Account creation callback with null bundle");
578 if (!accountWasSet
) {
579 moveTaskToBack(true
);
587 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
589 * Child classes must grant that state depending on the {@link Account} is updated.
591 protected void onAccountSet(boolean stateWasRecovered
) {
592 if (getAccount() != null
) {
593 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
596 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
601 public FileDataStorageManager
getStorageManager() {
602 return mStorageManager
;
606 public OnRemoteOperationListener
getRemoteOperationListener() {
611 public Handler
getHandler() {
615 public FileOperationsHelper
getFileOperationsHelper() {
616 return mFileOperationsHelper
;
621 * @param operation Removal operation performed.
622 * @param result Result of the removal.
625 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
626 Log_OC
.d(TAG
, "Received result of operation in FileActivity - common behaviour for all the "
627 + "FileActivities ");
629 mFileOperationsHelper
.setOpIdWaitingFor(Long
.MAX_VALUE
);
631 if (!result
.isSuccess() && (
632 result
.getCode() == ResultCode
.UNAUTHORIZED
||
633 result
.isIdPRedirection() ||
634 (result
.isException() && result
.getException() instanceof AuthenticatorException
)
637 requestCredentialsUpdate();
639 if (result
.getCode() == ResultCode
.UNAUTHORIZED
) {
640 dismissLoadingDialog();
641 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
642 operation
, getResources()),
646 mTryShareAgain
= false
;
648 } else if (operation
instanceof CreateShareOperation
) {
649 onCreateShareOperationFinish((CreateShareOperation
) operation
, result
);
651 } else if (operation
instanceof UnshareLinkOperation
) {
652 onUnshareLinkOperationFinish((UnshareLinkOperation
)operation
, result
);
654 } else if (operation
instanceof SynchronizeFolderOperation
) {
655 onSynchronizeFolderOperationFinish((SynchronizeFolderOperation
)operation
, result
);
660 protected void requestCredentialsUpdate() {
661 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
662 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, getAccount());
663 updateAccountCredentials
.putExtra(
664 AuthenticatorActivity
.EXTRA_ACTION
,
665 AuthenticatorActivity
.ACTION_UPDATE_EXPIRED_TOKEN
);
666 updateAccountCredentials
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
667 startActivity(updateAccountCredentials
);
671 private void onCreateShareOperationFinish(CreateShareOperation operation
,
672 RemoteOperationResult result
) {
673 dismissLoadingDialog();
674 if (result
.isSuccess()) {
675 mTryShareAgain
= false
;
678 Intent sendIntent
= operation
.getSendIntent();
679 startActivity(sendIntent
);
681 // Detect Failure (403) --> needs Password
682 if (result
.getCode() == ResultCode
.SHARE_FORBIDDEN
) {
683 if (!isTryShareAgain()) {
684 SharePasswordDialogFragment dialog
=
685 SharePasswordDialogFragment
.newInstance(new OCFile(operation
.getPath()),
686 operation
.getSendIntent());
687 dialog
.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD
);
689 Toast t
= Toast
.makeText(this,
690 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
693 mTryShareAgain
= false
;
696 Toast t
= Toast
.makeText(this,
697 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
705 private void onUnshareLinkOperationFinish(UnshareLinkOperation operation
,
706 RemoteOperationResult result
) {
707 dismissLoadingDialog();
709 if (result
.isSuccess()){
713 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
714 operation
, getResources()), Toast
.LENGTH_LONG
);
719 private void onSynchronizeFolderOperationFinish(
720 SynchronizeFolderOperation operation
, RemoteOperationResult result
722 if (!result
.isSuccess() && result
.getCode() != ResultCode
.CANCELLED
){
723 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
724 operation
, getResources()), Toast
.LENGTH_LONG
);
729 protected void updateFileFromDB(){
730 OCFile file
= getFile();
732 file
= getStorageManager().getFileByPath(file
.getRemotePath());
738 * Show loading dialog
740 public void showLoadingDialog() {
742 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
743 FragmentManager fm
= getSupportFragmentManager();
744 FragmentTransaction ft
= fm
.beginTransaction();
745 loading
.show(ft
, DIALOG_WAIT_TAG
);
751 * Dismiss loading dialog
753 public void dismissLoadingDialog(){
754 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
756 LoadingDialog loading
= (LoadingDialog
) frag
;
762 private void doOnResumeAndBound() {
763 mOperationsServiceBinder
.addOperationListener(FileActivity
.this, mHandler
);
764 long waitingForOpId
= mFileOperationsHelper
.getOpIdWaitingFor();
765 if (waitingForOpId
<= Integer
.MAX_VALUE
) {
766 boolean wait
= mOperationsServiceBinder
.dispatchResultIfFinished((int)waitingForOpId
,
769 dismissLoadingDialog();
776 * Implements callback methods for service binding. Passed as a parameter to {
778 private class OperationsServiceConnection
implements ServiceConnection
{
781 public void onServiceConnected(ComponentName component
, IBinder service
) {
782 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
783 Log_OC
.d(TAG
, "Operations service connected");
784 mOperationsServiceBinder
= (OperationsServiceBinder
) service
;
785 /*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
786 dismissLoadingDialog();
788 doOnResumeAndBound();
797 public void onServiceDisconnected(ComponentName component
) {
798 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
799 Log_OC
.d(TAG
, "Operations service disconnected");
800 mOperationsServiceBinder
= null
;
801 // TODO whatever could be waiting for the service is unbound
808 public FileDownloaderBinder
getFileDownloaderBinder() {
809 return mDownloaderBinder
;
814 public FileUploaderBinder
getFileUploaderBinder() {
815 return mUploaderBinder
;
819 public void restart(){
820 Intent i
= new Intent(this, FileDisplayActivity
.class);
821 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
825 // TODO re-enable when "Accounts" is available in Navigation Drawer
826 // public void closeDrawer() {
827 // mDrawerLayout.closeDrawers();
830 public void allFilesOption(){
834 private class DrawerItemClickListener
implements ListView
.OnItemClickListener
{
836 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
837 // TODO re-enable when "Accounts" is available in Navigation Drawer
838 // if (mShowAccounts && position > 0){
839 // position = position - 1;
842 // TODO re-enable when "Accounts" is available in Navigation Drawer
843 // case 0: // Accounts
844 // mShowAccounts = !mShowAccounts;
845 // mNavigationDrawerAdapter.setShowAccounts(mShowAccounts);
846 // mNavigationDrawerAdapter.notifyDataSetChanged();
851 mDrawerLayout
.closeDrawers();
854 // TODO Enable when "On Device" is recovered ?
856 // MainApp.showOnlyFilesOnDevice(true);
857 // mDrawerLayout.closeDrawers();
861 Intent settingsIntent
= new Intent(getApplicationContext(),
863 startActivity(settingsIntent
);
867 Intent loggerIntent
= new Intent(getApplicationContext(),
868 LogHistoryActivity
.class);
869 startActivity(loggerIntent
);