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
;
158 // TODO re-enable when "Accounts" is available in Navigation Drawer
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
);
181 getSupportActionBar().setTitle(savedInstanceState
.getString(KEY_ACTION_BAR_TITLE
));
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();
290 if (mDrawerLayout
.isDrawerOpen(GravityCompat
.START
)) {
291 getSupportActionBar().setTitle(R
.string
.app_name
);
292 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
298 public void onConfigurationChanged(Configuration newConfig
) {
299 super.onConfigurationChanged(newConfig
);
300 if (mDrawerToggle
!= null
) {
301 mDrawerToggle
.onConfigurationChanged(newConfig
);
305 protected void initDrawer(){
306 mDrawerLayout
= (DrawerLayout
) findViewById(R
.id
.drawer_layout
);
307 // Notification Drawer
308 LinearLayout navigationDrawerLayout
= (LinearLayout
) findViewById(R
.id
.left_drawer
);
309 mDrawerList
= (ListView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_list
);
311 // TODO re-enable when "Accounts" is available in Navigation Drawer
312 // // load Account in the Drawer Title
314 // ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon);
315 // userIcon.setImageResource(DisplayUtils.getSeasonalIconId());
318 // TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
319 // Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
321 // if (account != null) {
322 // int lastAtPos = account.name.lastIndexOf("@");
323 // username.setText(account.name.substring(0, lastAtPos));
326 // load slide menu items
327 mDrawerTitles
= getResources().getStringArray(R
.array
.drawer_items
);
329 // nav drawer content description from resources
330 mDrawerContentDescriptions
= getResources().
331 getStringArray(R
.array
.drawer_content_descriptions
);
334 mDrawerItems
= new ArrayList
<NavigationDrawerItem
>();
335 // adding nav drawer items to array
336 // TODO re-enable when "Accounts" is available in Navigation Drawer
338 // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
339 // mDrawerContentDescriptions[0]));
341 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[0], mDrawerContentDescriptions
[0]));
343 // TODO Enable when "On Device" is recovered
345 //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
346 // mDrawerContentDescriptions[2]));
349 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[1], mDrawerContentDescriptions
[1]));
351 if (BuildConfig
.DEBUG
) {
352 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[2],
353 mDrawerContentDescriptions
[2]));
356 // setting the nav drawer list adapter
357 mNavigationDrawerAdapter
= new NavigationDrawerListAdapter(getApplicationContext(), this,
359 mDrawerList
.setAdapter(mNavigationDrawerAdapter
);
361 mDrawerToggle
= new ActionBarDrawerToggle(
364 R
.drawable
.ic_drawer
,
366 R
.string
.drawer_close
) {
368 /** Called when a drawer has settled in a completely closed state. */
369 public void onDrawerClosed(View view
) {
370 super.onDrawerClosed(view
);
371 updateActionBarTitleAndHomeButton();
372 getSupportActionBar().setDisplayShowTitleEnabled(true
);
373 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
374 invalidateOptionsMenu();
377 /** Called when a drawer has settled in a completely open state. */
378 public void onDrawerOpened(View drawerView
) {
379 super.onDrawerOpened(drawerView
);
380 getSupportActionBar().setTitle(R
.string
.app_name
);
381 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
382 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
383 invalidateOptionsMenu();
387 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
388 // Set the list's click listener
389 mDrawerList
.setOnItemClickListener(new DrawerItemClickListener());
391 // Set the drawer toggle as the DrawerListener
392 mDrawerLayout
.setDrawerListener(mDrawerToggle
);
395 protected void updateActionBarTitleAndHomeButton(){
396 if (mFile
.getParentId() == 0) {
397 getSupportActionBar().setTitle(getString(
398 R
.string
.default_display_name_for_root_folder
));
399 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
401 getSupportActionBar().setTitle(mFile
.getFileName().toString());
402 mDrawerToggle
.setDrawerIndicatorEnabled(false
);
406 * Sets and validates the ownCloud {@link Account} associated to the Activity.
408 * If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
410 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
412 * @param account New {@link Account} to set.
413 * @param savedAccount When 'true', account was retrieved from a saved instance state.
415 protected void setAccount(Account account
, boolean savedAccount
) {
416 Account oldAccount
= mAccount
;
417 boolean validAccount
=
418 (account
!= null
&& AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(),
422 mAccountWasSet
= true
;
423 mAccountWasRestored
= (savedAccount
|| mAccount
.equals(oldAccount
));
426 swapToDefaultAccount();
432 * Tries to swap the current ownCloud {@link Account} for other valid and existing.
434 * If no valid ownCloud {@link Account} exists, the the user is requested
435 * to create a new ownCloud {@link Account}.
437 * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
439 private void swapToDefaultAccount() {
440 // default to the most recently used account
441 Account newAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
442 if (newAccount
== null
) {
443 /// no account available: force account creation
444 createFirstAccount();
445 mRedirectingToSetupAccount
= true
;
446 mAccountWasSet
= false
;
447 mAccountWasRestored
= false
;
450 mAccountWasSet
= true
;
451 mAccountWasRestored
= (newAccount
.equals(mAccount
));
452 mAccount
= newAccount
;
458 * Launches the account creation activity. To use when no ownCloud account is available
460 private void createFirstAccount() {
461 AccountManager am
= AccountManager
.get(getApplicationContext());
462 am
.addAccount(MainApp
.getAccountType(),
467 new AccountCreationCallback(),
476 protected void onSaveInstanceState(Bundle outState
) {
477 super.onSaveInstanceState(outState
);
478 outState
.putParcelable(FileActivity
.EXTRA_FILE
, mFile
);
479 outState
.putBoolean(FileActivity
.EXTRA_FROM_NOTIFICATION
, mFromNotification
);
480 outState
.putLong(KEY_WAITING_FOR_OP_ID
, mFileOperationsHelper
.getOpIdWaitingFor());
481 outState
.putBoolean(KEY_TRY_SHARE_AGAIN
, mTryShareAgain
);
482 outState
.putString(KEY_ACTION_BAR_TITLE
, getSupportActionBar().getTitle().toString());
487 * Getter for the main {@link OCFile} handled by the activity.
489 * @return Main {@link OCFile} handled by the activity.
491 public OCFile
getFile() {
497 * Setter for the main {@link OCFile} handled by the activity.
499 * @param file Main {@link OCFile} to be handled by the activity.
501 public void setFile(OCFile file
) {
507 * Getter for the ownCloud {@link Account} where the main {@link OCFile} handled by the activity
510 * @return OwnCloud {@link Account} where the main {@link OCFile} handled by the activity
513 public Account
getAccount() {
517 protected void setAccount(Account account
) {
522 * @return Value of mFromNotification: True if the Activity is launched by a notification
524 public boolean fromNotification() {
525 return mFromNotification
;
529 * @return 'True' when the Activity is finishing to enforce the setup of a new account.
531 protected boolean isRedirectingToSetupAccount() {
532 return mRedirectingToSetupAccount
;
535 public boolean isTryShareAgain(){
536 return mTryShareAgain
;
539 public void setTryShareAgain(boolean tryShareAgain
) {
540 mTryShareAgain
= tryShareAgain
;
543 public OperationsServiceBinder
getOperationsServiceBinder() {
544 return mOperationsServiceBinder
;
547 protected ServiceConnection
newTransferenceServiceConnection() {
552 * Helper class handling a callback from the {@link AccountManager} after the creation of
553 * a new ownCloud {@link Account} finished, successfully or not.
555 * At this moment, only called after the creation of the first account.
557 public class AccountCreationCallback
implements AccountManagerCallback
<Bundle
> {
560 public void run(AccountManagerFuture
<Bundle
> future
) {
561 FileActivity
.this.mRedirectingToSetupAccount
= false
;
562 boolean accountWasSet
= false
;
563 if (future
!= null
) {
566 result
= future
.getResult();
567 String name
= result
.getString(AccountManager
.KEY_ACCOUNT_NAME
);
568 String type
= result
.getString(AccountManager
.KEY_ACCOUNT_TYPE
);
569 if (AccountUtils
.setCurrentOwnCloudAccount(getApplicationContext(), name
)) {
570 setAccount(new Account(name
, type
), false
);
571 accountWasSet
= true
;
573 } catch (OperationCanceledException e
) {
574 Log_OC
.d(TAG
, "Account creation canceled");
576 } catch (Exception e
) {
577 Log_OC
.e(TAG
, "Account creation finished in exception: ", e
);
581 Log_OC
.e(TAG
, "Account creation callback with null bundle");
583 if (!accountWasSet
) {
584 moveTaskToBack(true
);
592 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
594 * Child classes must grant that state depending on the {@link Account} is updated.
596 protected void onAccountSet(boolean stateWasRecovered
) {
597 if (getAccount() != null
) {
598 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
601 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
606 public FileDataStorageManager
getStorageManager() {
607 return mStorageManager
;
611 public OnRemoteOperationListener
getRemoteOperationListener() {
616 public Handler
getHandler() {
620 public FileOperationsHelper
getFileOperationsHelper() {
621 return mFileOperationsHelper
;
626 * @param operation Removal operation performed.
627 * @param result Result of the removal.
630 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
631 Log_OC
.d(TAG
, "Received result of operation in FileActivity - common behaviour for all the "
632 + "FileActivities ");
634 mFileOperationsHelper
.setOpIdWaitingFor(Long
.MAX_VALUE
);
636 if (!result
.isSuccess() && (
637 result
.getCode() == ResultCode
.UNAUTHORIZED
||
638 result
.isIdPRedirection() ||
639 (result
.isException() && result
.getException() instanceof AuthenticatorException
)
642 requestCredentialsUpdate();
644 if (result
.getCode() == ResultCode
.UNAUTHORIZED
) {
645 dismissLoadingDialog();
646 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
647 operation
, getResources()),
651 mTryShareAgain
= false
;
653 } else if (operation
instanceof CreateShareOperation
) {
654 onCreateShareOperationFinish((CreateShareOperation
) operation
, result
);
656 } else if (operation
instanceof UnshareLinkOperation
) {
657 onUnshareLinkOperationFinish((UnshareLinkOperation
)operation
, result
);
659 } else if (operation
instanceof SynchronizeFolderOperation
) {
660 onSynchronizeFolderOperationFinish((SynchronizeFolderOperation
)operation
, result
);
665 protected void requestCredentialsUpdate() {
666 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
667 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, getAccount());
668 updateAccountCredentials
.putExtra(
669 AuthenticatorActivity
.EXTRA_ACTION
,
670 AuthenticatorActivity
.ACTION_UPDATE_EXPIRED_TOKEN
);
671 updateAccountCredentials
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
672 startActivity(updateAccountCredentials
);
676 private void onCreateShareOperationFinish(CreateShareOperation operation
,
677 RemoteOperationResult result
) {
678 dismissLoadingDialog();
679 if (result
.isSuccess()) {
680 mTryShareAgain
= false
;
683 Intent sendIntent
= operation
.getSendIntent();
684 startActivity(sendIntent
);
686 // Detect Failure (403) --> needs Password
687 if (result
.getCode() == ResultCode
.SHARE_FORBIDDEN
) {
688 if (!isTryShareAgain()) {
689 SharePasswordDialogFragment dialog
=
690 SharePasswordDialogFragment
.newInstance(new OCFile(operation
.getPath()),
691 operation
.getSendIntent());
692 dialog
.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD
);
694 Toast t
= Toast
.makeText(this,
695 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
698 mTryShareAgain
= false
;
701 Toast t
= Toast
.makeText(this,
702 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
710 private void onUnshareLinkOperationFinish(UnshareLinkOperation operation
,
711 RemoteOperationResult result
) {
712 dismissLoadingDialog();
714 if (result
.isSuccess()){
718 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
719 operation
, getResources()), Toast
.LENGTH_LONG
);
724 private void onSynchronizeFolderOperationFinish(
725 SynchronizeFolderOperation operation
, RemoteOperationResult result
727 if (!result
.isSuccess() && result
.getCode() != ResultCode
.CANCELLED
){
728 Toast t
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
729 operation
, getResources()), Toast
.LENGTH_LONG
);
734 protected void updateFileFromDB(){
735 OCFile file
= getFile();
737 file
= getStorageManager().getFileByPath(file
.getRemotePath());
743 * Show loading dialog
745 public void showLoadingDialog() {
747 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
748 FragmentManager fm
= getSupportFragmentManager();
749 FragmentTransaction ft
= fm
.beginTransaction();
750 loading
.show(ft
, DIALOG_WAIT_TAG
);
756 * Dismiss loading dialog
758 public void dismissLoadingDialog(){
759 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
761 LoadingDialog loading
= (LoadingDialog
) frag
;
767 private void doOnResumeAndBound() {
768 mOperationsServiceBinder
.addOperationListener(FileActivity
.this, mHandler
);
769 long waitingForOpId
= mFileOperationsHelper
.getOpIdWaitingFor();
770 if (waitingForOpId
<= Integer
.MAX_VALUE
) {
771 boolean wait
= mOperationsServiceBinder
.dispatchResultIfFinished((int)waitingForOpId
,
774 dismissLoadingDialog();
781 * Implements callback methods for service binding. Passed as a parameter to {
783 private class OperationsServiceConnection
implements ServiceConnection
{
786 public void onServiceConnected(ComponentName component
, IBinder service
) {
787 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
788 Log_OC
.d(TAG
, "Operations service connected");
789 mOperationsServiceBinder
= (OperationsServiceBinder
) service
;
790 /*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
791 dismissLoadingDialog();
793 doOnResumeAndBound();
802 public void onServiceDisconnected(ComponentName component
) {
803 if (component
.equals(new ComponentName(FileActivity
.this, OperationsService
.class))) {
804 Log_OC
.d(TAG
, "Operations service disconnected");
805 mOperationsServiceBinder
= null
;
806 // TODO whatever could be waiting for the service is unbound
813 public FileDownloaderBinder
getFileDownloaderBinder() {
814 return mDownloaderBinder
;
819 public FileUploaderBinder
getFileUploaderBinder() {
820 return mUploaderBinder
;
824 public void restart(){
825 Intent i
= new Intent(this, FileDisplayActivity
.class);
826 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
830 // TODO re-enable when "Accounts" is available in Navigation Drawer
831 // public void closeDrawer() {
832 // mDrawerLayout.closeDrawers();
835 public void allFilesOption(){
839 private class DrawerItemClickListener
implements ListView
.OnItemClickListener
{
841 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
842 // TODO re-enable when "Accounts" is available in Navigation Drawer
843 // if (mShowAccounts && position > 0){
844 // position = position - 1;
847 // TODO re-enable when "Accounts" is available in Navigation Drawer
848 // case 0: // Accounts
849 // mShowAccounts = !mShowAccounts;
850 // mNavigationDrawerAdapter.setShowAccounts(mShowAccounts);
851 // mNavigationDrawerAdapter.notifyDataSetChanged();
856 mDrawerLayout
.closeDrawers();
859 // TODO Enable when "On Device" is recovered ?
861 // MainApp.showOnlyFilesOnDevice(true);
862 // mDrawerLayout.closeDrawers();
866 Intent settingsIntent
= new Intent(getApplicationContext(),
868 startActivity(settingsIntent
);
872 Intent loggerIntent
= new Intent(getApplicationContext(),
873 LogHistoryActivity
.class);
874 startActivity(loggerIntent
);