2 * ownCloud Android client application
4 * @author Bartek Przybylski
5 * @author David A. Velasco
6 * Copyright (C) 2011 Bartek Przybylski
7 * Copyright (C) 2015 ownCloud Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 package com
.owncloud
.android
.ui
.activity
;
26 import java
.util
.ArrayList
;
28 import android
.accounts
.Account
;
29 import android
.accounts
.AccountManager
;
30 import android
.accounts
.AuthenticatorException
;
31 import android
.annotation
.TargetApi
;
32 import android
.app
.AlertDialog
;
33 import android
.content
.BroadcastReceiver
;
34 import android
.content
.ComponentName
;
35 import android
.content
.ContentResolver
;
36 import android
.content
.Context
;
37 import android
.content
.DialogInterface
;
38 import android
.content
.Intent
;
39 import android
.content
.IntentFilter
;
40 import android
.content
.ServiceConnection
;
41 import android
.content
.SharedPreferences
;
42 import android
.content
.SyncRequest
;
43 import android
.content
.res
.Configuration
;
44 import android
.content
.res
.Resources
.NotFoundException
;
45 import android
.database
.Cursor
;
46 import android
.net
.Uri
;
47 import android
.os
.Build
;
48 import android
.os
.Bundle
;
49 import android
.os
.IBinder
;
50 import android
.preference
.PreferenceManager
;
51 import android
.provider
.OpenableColumns
;
52 import android
.support
.v4
.app
.ActionBarDrawerToggle
;
53 import android
.support
.v4
.app
.Fragment
;
54 import android
.support
.v4
.app
.FragmentManager
;
55 import android
.support
.v4
.app
.FragmentTransaction
;
57 import android
.support
.v4
.view
.GravityCompat
;
58 import android
.support
.v4
.widget
.DrawerLayout
;
59 import android
.support
.v7
.app
.ActionBar
;
60 import android
.view
.Menu
;
61 import android
.view
.MenuInflater
;
62 import android
.view
.MenuItem
;
63 import android
.view
.View
;
64 import android
.view
.ViewGroup
;
65 import android
.view
.Window
;
67 import android
.widget
.AdapterView
;
68 import android
.widget
.ArrayAdapter
;
69 import android
.widget
.ImageView
;
70 import android
.widget
.LinearLayout
;
71 import android
.widget
.ListView
;
72 import android
.widget
.TextView
;
73 import android
.widget
.Toast
;
75 import com
.owncloud
.android
.BuildConfig
;
76 import com
.owncloud
.android
.MainApp
;
77 import com
.owncloud
.android
.R
;
78 import com
.owncloud
.android
.authentication
.AccountUtils
;
79 import com
.owncloud
.android
.datamodel
.OCFile
;
80 import com
.owncloud
.android
.files
.services
.FileDownloader
;
81 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
82 import com
.owncloud
.android
.files
.services
.FileUploader
;
83 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
84 import com
.owncloud
.android
.lib
.common
.OwnCloudAccount
;
85 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
86 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
87 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentials
;
88 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
.AccountNotFoundException
;
89 import com
.owncloud
.android
.lib
.common
.network
.CertificateCombinedException
;
90 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
91 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
92 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
93 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
94 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
95 import com
.owncloud
.android
.operations
.CreateShareOperation
;
96 import com
.owncloud
.android
.operations
.MoveFileOperation
;
97 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
98 import com
.owncloud
.android
.operations
.RenameFileOperation
;
99 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
100 import com
.owncloud
.android
.operations
.RefreshFolderOperation
;
101 import com
.owncloud
.android
.operations
.UnshareLinkOperation
;
102 import com
.owncloud
.android
.services
.observer
.FileObserverService
;
103 import com
.owncloud
.android
.syncadapter
.FileSyncAdapter
;
104 import com
.owncloud
.android
.ui
.NavigationDrawerItem
;
105 import com
.owncloud
.android
.ui
.adapter
.NavigationDrawerListAdapter
;
106 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
;
107 import com
.owncloud
.android
.ui
.dialog
.CreateFolderDialogFragment
;
108 import com
.owncloud
.android
.ui
.dialog
.SslUntrustedCertDialog
;
109 import com
.owncloud
.android
.ui
.dialog
.SslUntrustedCertDialog
.OnSslUntrustedCertListener
;
110 import com
.owncloud
.android
.ui
.dialog
.UploadSourceDialogFragment
;
111 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
112 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
113 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
114 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
115 import com
.owncloud
.android
.ui
.preview
.PreviewImageFragment
;
116 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
117 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
118 import com
.owncloud
.android
.utils
.DisplayUtils
;
119 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
120 import com
.owncloud
.android
.utils
.FileStorageUtils
;
121 import com
.owncloud
.android
.utils
.UriUtils
;
125 * Displays, what files the user has available in his ownCloud.
128 public class FileDisplayActivity
extends HookActivity
implements
129 FileFragment
.ContainerActivity
, ActionBar
.OnNavigationListener
,
130 OnSslUntrustedCertListener
, OnEnforceableRefreshListener
{
132 private ArrayAdapter
<String
> mDirectories
;
134 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
135 private UploadFinishReceiver mUploadFinishReceiver
;
136 private DownloadFinishReceiver mDownloadFinishReceiver
;
137 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
139 private boolean mDualPane
;
140 private View mLeftFragmentContainer
;
141 private View mRightFragmentContainer
;
143 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
144 private static final String KEY_SYNC_IN_PROGRESS
= "SYNC_IN_PROGRESS";
145 private static final String KEY_WAITING_TO_SEND
= "WAITING_TO_SEND";
147 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
149 public static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
150 public static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
151 public static final int ACTION_MOVE_FILES
= 3;
153 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
155 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
156 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
158 private OCFile mWaitingToPreview
;
160 private boolean mSyncInProgress
= false
;
162 private static String DIALOG_UNTRUSTED_CERT
= "DIALOG_UNTRUSTED_CERT";
163 private static String DIALOG_CREATE_FOLDER
= "DIALOG_CREATE_FOLDER";
164 private static String DIALOG_UPLOAD_SOURCE
= "DIALOG_UPLOAD_SOURCE";
165 private static String DIALOG_CERT_NOT_SAVED
= "DIALOG_CERT_NOT_SAVED";
167 private OCFile mWaitingToSend
;
170 private DrawerLayout mDrawerLayout
;
171 private ActionBarDrawerToggle mDrawerToggle
;
172 private ListView mDrawerList
;
175 private String
[] mDrawerTitles
;
176 private String
[] mDrawerContentDescriptions
;
178 private ArrayList
<NavigationDrawerItem
> mDrawerItems
;
180 private NavigationDrawerListAdapter mNavigationDrawerAdapter
= null
;
182 private boolean mShowAccounts
= false
;
185 protected void onCreate(Bundle savedInstanceState
) {
186 Log_OC
.v(TAG
, "onCreate() start");
187 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
189 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account
192 /// grant that FileObserverService is watching favorite files
193 if (savedInstanceState
== null
) {
194 Intent initObserversIntent
= FileObserverService
.makeInitIntent(this);
195 startService(initObserversIntent
);
198 /// Load of saved instance state
199 if(savedInstanceState
!= null
) {
200 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(
201 FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
202 mSyncInProgress
= savedInstanceState
.getBoolean(KEY_SYNC_IN_PROGRESS
);
203 mWaitingToSend
= (OCFile
) savedInstanceState
.getParcelable(
204 FileDisplayActivity
.KEY_WAITING_TO_SEND
);
207 mWaitingToPreview
= null
;
208 mSyncInProgress
= false
;
209 mWaitingToSend
= null
;
214 // Inflate and set the layout view
215 setContentView(R
.layout
.files
);
220 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
221 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
222 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
223 if (savedInstanceState
== null
) {
224 createMinFragments();
228 mDirectories
= new CustomArrayAdapter
<String
>(this,
229 R
.layout
.support_simple_spinner_dropdown_item
);
230 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS,
231 // according to the official
234 setSupportProgressBarIndeterminateVisibility(mSyncInProgress
235 /*|| mRefreshSharesInProgress*/);
236 // always AFTER setContentView(...) ; to work around bug in its implementation
238 // TODO Remove??, it is done in onPostCreate
239 mDrawerToggle
.syncState();
243 Log_OC
.v(TAG
, "onCreate() end");
246 private void initDrawer(){
247 mDrawerLayout
= (DrawerLayout
) findViewById(R
.id
.drawer_layout
);
248 // Notification Drawer
249 LinearLayout navigationDrawerLayout
= (LinearLayout
) findViewById(R
.id
.left_drawer
);
250 mDrawerList
= (ListView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_list
);
252 // load Account in the Drawer Title
254 ImageView userIcon
= (ImageView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_userIcon
);
255 userIcon
.setImageResource(DisplayUtils
.getSeasonalIconId());
258 TextView username
= (TextView
) navigationDrawerLayout
.findViewById(R
.id
.drawer_username
);
259 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
261 if (account
!= null
) {
262 int lastAtPos
= account
.name
.lastIndexOf("@");
263 username
.setText(account
.name
.substring(0, lastAtPos
));
266 // load slide menu items
267 mDrawerTitles
= getResources().getStringArray(R
.array
.drawer_items
);
269 // nav drawer content description from resources
270 mDrawerContentDescriptions
= getResources().
271 getStringArray(R
.array
.drawer_content_descriptions
);
274 mDrawerItems
= new ArrayList
<NavigationDrawerItem
>();
275 // adding nav drawer items to array
277 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[0], mDrawerContentDescriptions
[0]));
279 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[1], mDrawerContentDescriptions
[1]));
281 // TODO Enable when "On Device" is recovered
283 //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
284 // mDrawerContentDescriptions[2]));
287 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[2], mDrawerContentDescriptions
[2]));
289 if (BuildConfig
.DEBUG
) {
290 mDrawerItems
.add(new NavigationDrawerItem(mDrawerTitles
[3],
291 mDrawerContentDescriptions
[3]));
294 // setting the nav drawer list adapter
295 mNavigationDrawerAdapter
= new NavigationDrawerListAdapter(getApplicationContext(), this,
297 mDrawerList
.setAdapter(mNavigationDrawerAdapter
);
299 mDrawerToggle
= new ActionBarDrawerToggle(
302 R
.drawable
.ic_drawer
,
303 R
.string
.drawer_open
,
304 R
.string
.drawer_close
) {
306 /** Called when a drawer has settled in a completely closed state. */
307 public void onDrawerClosed(View view
) {
308 super.onDrawerClosed(view
);
309 getSupportActionBar().setDisplayShowTitleEnabled(true
);
310 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
311 initFragmentsWithFile();
312 invalidateOptionsMenu();
315 /** Called when a drawer has settled in a completely open state. */
316 public void onDrawerOpened(View drawerView
) {
317 super.onDrawerOpened(drawerView
);
318 getSupportActionBar().setTitle(R
.string
.drawer_open
);
319 getSupportActionBar().setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
320 invalidateOptionsMenu();
324 mDrawerToggle
.setDrawerIndicatorEnabled(true
);
325 // Set the list's click listener
326 mDrawerList
.setOnItemClickListener(new DrawerItemClickListener());
328 // Set the drawer toggle as the DrawerListener
329 mDrawerLayout
.setDrawerListener(mDrawerToggle
);
333 protected void onStart() {
334 Log_OC
.v(TAG
, "onStart() start");
336 getSupportActionBar().setIcon(DisplayUtils
.getSeasonalIconId());
337 Log_OC
.v(TAG
, "onStart() end");
341 protected void onPostCreate(Bundle savedInstanceState
) {
342 super.onPostCreate(savedInstanceState
);
343 // Sync the toggle state after onRestoreInstanceState has occurred.
344 mDrawerToggle
.syncState();
348 public void onConfigurationChanged(Configuration newConfig
) {
349 super.onConfigurationChanged(newConfig
);
350 mDrawerToggle
.onConfigurationChanged(newConfig
);
354 protected void onDestroy() {
355 Log_OC
.v(TAG
, "onDestroy() start");
357 Log_OC
.v(TAG
, "onDestroy() end");
361 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
364 protected void onAccountSet(boolean stateWasRecovered
) {
365 super.onAccountSet(stateWasRecovered
);
366 if (getAccount() != null
) {
367 /// Check whether the 'main' OCFile handled by the Activity is contained in the
369 OCFile file
= getFile();
370 // get parent from path
371 String parentPath
= "";
373 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
374 // upload in progress - right now, files are not inserted in the local
375 // cache until the upload is successful get parent from path
376 parentPath
= file
.getRemotePath().substring(0,
377 file
.getRemotePath().lastIndexOf(file
.getFileName()));
378 if (getStorageManager().getFileByPath(parentPath
) == null
)
379 file
= null
; // not able to know the directory where the file is uploading
381 file
= getStorageManager().getFileByPath(file
.getRemotePath());
382 // currentDir = null if not in the current Account
386 // fall back to root folder
387 file
= getStorageManager().getFileByPath(OCFile
.ROOT_PATH
); // never returns null
390 setNavigationListWithFolder(file
);
392 if (!stateWasRecovered
) {
393 Log_OC
.d(TAG
, "Initializing Fragments in onAccountChanged..");
394 initFragmentsWithFile();
395 if (file
.isFolder()) {
396 startSyncFolderOperation(file
, false
);
400 updateFragmentsVisibility(!file
.isFolder());
401 updateNavigationElementsInActionBar(file
.isFolder() ? null
: file
);
407 private void setNavigationListWithFolder(OCFile file
) {
408 mDirectories
.clear();
409 OCFile fileIt
= file
;
411 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.ROOT_PATH
) {
412 if (fileIt
.isFolder()) {
413 mDirectories
.add(fileIt
.getFileName());
415 // get parent from path
416 parentPath
= fileIt
.getRemotePath().substring(0,
417 fileIt
.getRemotePath().lastIndexOf(fileIt
.getFileName()));
418 fileIt
= getStorageManager().getFileByPath(parentPath
);
420 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
424 private void createMinFragments() {
425 OCFileListFragment listOfFiles
= new OCFileListFragment();
426 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
427 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
428 transaction
.commit();
431 private void initFragmentsWithFile() {
432 if (getAccount() != null
&& getFile() != null
) {
434 OCFileListFragment listOfFiles
= getListOfFilesFragment();
435 if (listOfFiles
!= null
) {
436 listOfFiles
.listDirectory(getCurrentDir());
437 // TODO Enable when "On Device" is recovered
438 // listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice());
440 Log_OC
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
444 OCFile file
= getFile();
445 Fragment secondFragment
= chooseInitialSecondFragment(file
);
446 if (secondFragment
!= null
) {
447 setSecondFragment(secondFragment
);
448 updateFragmentsVisibility(true
);
449 updateNavigationElementsInActionBar(file
);
452 cleanSecondFragment();
456 Log_OC
.wtf(TAG
, "initFragments() called with invalid NULLs!");
457 if (getAccount() == null
) {
458 Log_OC
.wtf(TAG
, "\t account is NULL");
460 if (getFile() == null
) {
461 Log_OC
.wtf(TAG
, "\t file is NULL");
466 private Fragment
chooseInitialSecondFragment(OCFile file
) {
467 Fragment secondFragment
= null
;
468 if (file
!= null
&& !file
.isFolder()) {
469 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
470 && file
.getLastSyncDateForProperties() > 0 // temporal fix
472 int startPlaybackPosition
=
473 getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
475 getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
476 secondFragment
= new PreviewMediaFragment(file
, getAccount(),
477 startPlaybackPosition
, autoplay
);
480 secondFragment
= new FileDetailFragment(file
, getAccount());
483 return secondFragment
;
488 * Replaces the second fragment managed by the activity with the received as
491 * Assumes never will be more than two fragments managed at the same time.
493 * @param fragment New second Fragment to set.
495 private void setSecondFragment(Fragment fragment
) {
496 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
497 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
498 transaction
.commit();
502 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
504 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
505 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
507 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
508 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
511 } else if (existsSecondFragment
) {
512 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
513 mLeftFragmentContainer
.setVisibility(View
.GONE
);
515 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
516 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
520 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
521 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
523 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
524 mRightFragmentContainer
.setVisibility(View
.GONE
);
530 private OCFileListFragment
getListOfFilesFragment() {
531 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(
532 FileDisplayActivity
.TAG_LIST_OF_FILES
);
533 if (listOfFiles
!= null
) {
534 return (OCFileListFragment
)listOfFiles
;
536 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
540 public FileFragment
getSecondFragment() {
541 Fragment second
= getSupportFragmentManager().findFragmentByTag(
542 FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
543 if (second
!= null
) {
544 return (FileFragment
)second
;
549 protected void cleanSecondFragment() {
550 Fragment second
= getSecondFragment();
551 if (second
!= null
) {
552 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
556 updateFragmentsVisibility(false
);
557 updateNavigationElementsInActionBar(null
);
560 protected void refreshListOfFilesFragment() {
561 OCFileListFragment fileListFragment
= getListOfFilesFragment();
562 if (fileListFragment
!= null
) {
563 fileListFragment
.listDirectory();
564 // TODO Enable when "On Device" is recovered ?
565 // fileListFragment.listDirectory(MainApp.getOnlyOnDevice());
569 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
,
571 FileFragment secondFragment
= getSecondFragment();
572 boolean waitedPreview
= (mWaitingToPreview
!= null
&&
573 mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
574 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
575 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
576 OCFile fileInFragment
= detailsFragment
.getFile();
577 if (fileInFragment
!= null
&&
578 !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
579 // the user browsed to other file ; forget the automatic preview
580 mWaitingToPreview
= null
;
582 } else if (downloadEvent
.equals(FileDownloader
.getDownloadAddedMessage())) {
583 // grant that the right panel updates the progress bar
584 detailsFragment
.listenForTransferProgress();
585 detailsFragment
.updateFileDetails(true
, false
);
587 } else if (downloadEvent
.equals(FileDownloader
.getDownloadFinishMessage())) {
588 // update the right panel
589 boolean detailsFragmentChanged
= false
;
592 mWaitingToPreview
= getStorageManager().getFileById(
593 mWaitingToPreview
.getFileId()); // update the file from database,
594 // for the local storage path
595 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
596 startMediaPreview(mWaitingToPreview
, 0, true
);
597 detailsFragmentChanged
= true
;
599 getFileOperationsHelper().openFile(mWaitingToPreview
);
602 mWaitingToPreview
= null
;
604 if (!detailsFragmentChanged
) {
605 detailsFragment
.updateFileDetails(false
, (success
));
612 public boolean onPrepareOptionsMenu(Menu menu
) {
613 boolean drawerOpen
= mDrawerLayout
.isDrawerOpen(GravityCompat
.START
);
614 menu
.findItem(R
.id
.action_upload
).setVisible(!drawerOpen
);
615 menu
.findItem(R
.id
.action_create_dir
).setVisible(!drawerOpen
);
616 menu
.findItem(R
.id
.action_sort
).setVisible(!drawerOpen
);
617 menu
.findItem(R
.id
.action_sync_account
).setVisible(!drawerOpen
);
619 return super.onPrepareOptionsMenu(menu
);
623 public boolean onCreateOptionsMenu(Menu menu
) {
624 MenuInflater inflater
= getMenuInflater();
625 inflater
.inflate(R
.menu
.main_menu
, menu
);
631 public boolean onOptionsItemSelected(MenuItem item
) {
632 boolean retval
= true
;
633 switch (item
.getItemId()) {
634 case R
.id
.action_create_dir
: {
635 CreateFolderDialogFragment dialog
=
636 CreateFolderDialogFragment
.newInstance(getCurrentDir());
637 dialog
.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER
);
640 case R
.id
.action_sync_account
: {
641 startSynchronization();
644 case R
.id
.action_upload
: {
645 UploadSourceDialogFragment dialog
=
646 UploadSourceDialogFragment
.newInstance(getAccount());
647 dialog
.show(getSupportFragmentManager(), DIALOG_UPLOAD_SOURCE
);
651 case android
.R
.id
.home
: {
652 if (mDrawerLayout
.isDrawerOpen(GravityCompat
.START
)) {
653 mDrawerLayout
.closeDrawer(GravityCompat
.START
);
655 mDrawerLayout
.openDrawer(GravityCompat
.START
);
659 case R
.id
.action_sort
: {
660 SharedPreferences appPreferences
= PreferenceManager
661 .getDefaultSharedPreferences(this);
663 // Read sorting order, default to sort by name ascending
664 Integer sortOrder
= appPreferences
665 .getInt("sortOrder", FileStorageUtils
.SORT_NAME
);
667 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
668 builder
.setTitle(R
.string
.actionbar_sort_title
)
669 .setSingleChoiceItems(R
.array
.actionbar_sortby
, sortOrder
,
670 new DialogInterface
.OnClickListener() {
671 public void onClick(DialogInterface dialog
, int which
) {
684 builder
.create().show();
688 retval
= super.onOptionsItemSelected(item
);
693 private void startSynchronization() {
694 Log_OC
.d(TAG
, "Got to start sync");
695 if (android
.os
.Build
.VERSION
.SDK_INT
< android
.os
.Build
.VERSION_CODES
.KITKAT
) {
696 Log_OC
.d(TAG
, "Canceling all syncs for " + MainApp
.getAuthority());
697 ContentResolver
.cancelSync(null
, MainApp
.getAuthority());
698 // cancel the current synchronizations of any ownCloud account
699 Bundle bundle
= new Bundle();
700 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
701 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_EXPEDITED
, true
);
702 Log_OC
.d(TAG
, "Requesting sync for " + getAccount().name
+ " at " +
703 MainApp
.getAuthority());
704 ContentResolver
.requestSync(
706 MainApp
.getAuthority(), bundle
);
708 Log_OC
.d(TAG
, "Requesting sync for " + getAccount().name
+ " at " +
709 MainApp
.getAuthority() + " with new API");
710 SyncRequest
.Builder builder
= new SyncRequest
.Builder();
711 builder
.setSyncAdapter(getAccount(), MainApp
.getAuthority());
712 builder
.setExpedited(true
);
713 builder
.setManual(true
);
716 // Fix bug in Android Lollipop when you click on refresh the whole account
717 Bundle extras
= new Bundle();
718 builder
.setExtras(extras
);
720 SyncRequest request
= builder
.build();
721 ContentResolver
.requestSync(request
);
727 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
728 if (itemPosition
!= 0) {
729 String targetPath
= "";
730 for (int i
=itemPosition
; i
< mDirectories
.getCount() - 1; i
++) {
731 targetPath
= mDirectories
.getItem(i
) + OCFile
.PATH_SEPARATOR
+ targetPath
;
733 targetPath
= OCFile
.PATH_SEPARATOR
+ targetPath
;
734 OCFile targetFolder
= getStorageManager().getFileByPath(targetPath
);
735 if (targetFolder
!= null
) {
736 browseTo(targetFolder
);
739 // the next operation triggers a new call to this method, but it's necessary to
740 // ensure that the name exposed in the action bar is the current directory when the
741 // user selected it in the navigation list
742 if (getSupportActionBar().getNavigationMode() == ActionBar
.NAVIGATION_MODE_LIST
&&
744 getSupportActionBar().setSelectedNavigationItem(0);
750 * Called, when the user selected something for uploading
753 @TargetApi(Build
.VERSION_CODES
.JELLY_BEAN
)
755 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
757 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
||
758 resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
759 //getClipData is only supported on api level 16+, Jelly Bean
760 if (data
.getData() == null
&& Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.JELLY_BEAN
){
761 for( int i
= 0; i
< data
.getClipData().getItemCount(); i
++){
762 Intent intent
= new Intent();
763 intent
.setData(data
.getClipData().getItemAt(i
).getUri());
764 requestSimpleUpload(intent
, resultCode
);
767 requestSimpleUpload(data
, resultCode
);
769 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
||
770 resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
771 requestMultipleUpload(data
, resultCode
);
773 } else if (requestCode
== ACTION_MOVE_FILES
&& resultCode
== RESULT_OK
){
775 final Intent fData
= data
;
776 final int fResultCode
= resultCode
;
777 getHandler().postDelayed(
781 requestMoveOperation(fData
, fResultCode
);
784 DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
788 super.onActivityResult(requestCode
, resultCode
, data
);
793 private void requestMultipleUpload(Intent data
, int resultCode
) {
794 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
795 if (filePaths
!= null
) {
796 String
[] remotePaths
= new String
[filePaths
.length
];
797 String remotePathBase
= "";
799 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
800 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
802 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
803 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
804 for (int j
= 0; j
< remotePaths
.length
; j
++) {
805 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
808 Intent i
= new Intent(this, FileUploader
.class);
809 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
810 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
811 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
812 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
813 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
814 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
818 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
819 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
),
827 private void requestSimpleUpload(Intent data
, int resultCode
) {
828 String filePath
= null
;
829 String mimeType
= null
;
831 Uri selectedImageUri
= data
.getData();
834 mimeType
= getContentResolver().getType(selectedImageUri
);
836 String fileManagerString
= selectedImageUri
.getPath();
837 String selectedImagePath
= UriUtils
.getLocalPath(selectedImageUri
, this);
839 if (selectedImagePath
!= null
)
840 filePath
= selectedImagePath
;
842 filePath
= fileManagerString
;
844 } catch (Exception e
) {
845 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of " +
846 "Intent.ACTION_GET_CONTENT", e
);
849 if (filePath
== null
) {
850 Log_OC
.e(TAG
, "Couldn't resolve path to file");
851 Toast t
= Toast
.makeText(
852 this, getString(R
.string
.filedisplay_unexpected_bad_get_content
),
860 Intent i
= new Intent(this, FileUploader
.class);
861 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
862 OCFile currentDir
= getCurrentDir();
863 String remotePath
= (currentDir
!= null
) ? currentDir
.getRemotePath() : OCFile
.ROOT_PATH
;
865 if (filePath
.startsWith(UriUtils
.URI_CONTENT_SCHEME
)) {
866 Cursor cursor
= getContentResolver().query(Uri
.parse(filePath
), null
, null
, null
, null
);
868 if (cursor
!= null
&& cursor
.moveToFirst()) {
869 String displayName
= cursor
.getString(cursor
.getColumnIndex(
870 OpenableColumns
.DISPLAY_NAME
));
871 Log_OC
.v(TAG
, "Display Name: " + displayName
);
873 displayName
.replace(File
.separatorChar
, '_');
874 displayName
.replace(File
.pathSeparatorChar
, '_');
875 remotePath
+= displayName
+ DisplayUtils
.getComposedFileExtension(filePath
);
878 // and what happens in case of error?; wrong target name for the upload
884 remotePath
+= new File(filePath
).getName();
887 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePath
);
888 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePath
);
889 i
.putExtra(FileUploader
.KEY_MIME_TYPE
, mimeType
);
890 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
891 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
892 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
897 * Request the operation for moving the file/folder from one path to another
899 * @param data Intent received
900 * @param resultCode Result code received
902 private void requestMoveOperation(Intent data
, int resultCode
) {
903 OCFile folderToMoveAt
= (OCFile
) data
.getParcelableExtra(FolderPickerActivity
.EXTRA_FOLDER
);
904 OCFile targetFile
= (OCFile
) data
.getParcelableExtra(FolderPickerActivity
.EXTRA_FILE
);
905 getFileOperationsHelper().moveFile(folderToMoveAt
, targetFile
);
909 public void onBackPressed() {
910 OCFileListFragment listOfFiles
= getListOfFilesFragment();
911 if (mDualPane
|| getSecondFragment() == null
) {
912 if (listOfFiles
!= null
) { // should never be null, indeed
913 if (mDirectories
.getCount() <= 1) {
917 int levelsUp
= listOfFiles
.onBrowseUp();
918 for (int i
=0; i
< levelsUp
&& mDirectories
.getCount() > 1 ; i
++) {
923 if (listOfFiles
!= null
) { // should never be null, indeed
924 setFile(listOfFiles
.getCurrentFile());
926 cleanSecondFragment();
931 protected void onSaveInstanceState(Bundle outState
) {
932 // responsibility of restore is preferred in onCreate() before than in
933 // onRestoreInstanceState when there are Fragments involved
934 Log_OC
.v(TAG
, "onSaveInstanceState() start");
935 super.onSaveInstanceState(outState
);
936 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
937 outState
.putBoolean(FileDisplayActivity
.KEY_SYNC_IN_PROGRESS
, mSyncInProgress
);
938 //outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS,
939 // mRefreshSharesInProgress);
940 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_SEND
, mWaitingToSend
);
942 Log_OC
.v(TAG
, "onSaveInstanceState() end");
948 protected void onResume() {
949 Log_OC
.v(TAG
, "onResume() start");
952 // refresh Navigation Drawer account list
953 mNavigationDrawerAdapter
.updateAccountList();
955 // refresh list of files
956 refreshListOfFilesFragment();
958 // Listen for sync messages
959 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncAdapter
.EVENT_FULL_SYNC_START
);
960 syncIntentFilter
.addAction(FileSyncAdapter
.EVENT_FULL_SYNC_END
);
961 syncIntentFilter
.addAction(FileSyncAdapter
.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED
);
962 syncIntentFilter
.addAction(RefreshFolderOperation
.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED
);
963 syncIntentFilter
.addAction(RefreshFolderOperation
.EVENT_SINGLE_FOLDER_SHARES_SYNCED
);
964 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
965 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
966 //LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver,
967 // syncIntentFilter);
969 // Listen for upload messages
970 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.getUploadFinishMessage());
971 mUploadFinishReceiver
= new UploadFinishReceiver();
972 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
974 // Listen for download messages
975 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.getDownloadAddedMessage());
976 downloadIntentFilter
.addAction(FileDownloader
.getDownloadFinishMessage());
977 mDownloadFinishReceiver
= new DownloadFinishReceiver();
978 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
980 Log_OC
.v(TAG
, "onResume() end");
985 protected void onPause() {
986 Log_OC
.v(TAG
, "onPause() start");
987 if (mSyncBroadcastReceiver
!= null
) {
988 unregisterReceiver(mSyncBroadcastReceiver
);
989 //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
990 mSyncBroadcastReceiver
= null
;
992 if (mUploadFinishReceiver
!= null
) {
993 unregisterReceiver(mUploadFinishReceiver
);
994 mUploadFinishReceiver
= null
;
996 if (mDownloadFinishReceiver
!= null
) {
997 unregisterReceiver(mDownloadFinishReceiver
);
998 mDownloadFinishReceiver
= null
;
1002 Log_OC
.v(TAG
, "onPause() end");
1006 * Pushes a directory to the drop down list
1007 * @param directory to push
1008 * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false.
1010 public void pushDirname(OCFile directory
) {
1011 if(!directory
.isFolder()){
1012 throw new IllegalArgumentException("Only directories may be pushed!");
1014 mDirectories
.insert(directory
.getFileName(), 0);
1019 * Pops a directory name from the drop down list
1020 * @return True, unless the stack is empty
1022 public boolean popDirname() {
1023 mDirectories
.remove(mDirectories
.getItem(0));
1024 return !mDirectories
.isEmpty();
1027 // Custom array adapter to override text colors
1028 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
1030 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
1034 public View
getView(int position
, View convertView
, ViewGroup parent
) {
1035 View v
= super.getView(position
, convertView
, parent
);
1037 ((TextView
) v
).setTextColor(getResources().getColorStateList(
1038 android
.R
.color
.white
));
1040 fixRoot((TextView
) v
);
1044 public View
getDropDownView(int position
, View convertView
,
1046 View v
= super.getDropDownView(position
, convertView
, parent
);
1048 ((TextView
) v
).setTextColor(getResources().getColorStateList(
1049 android
.R
.color
.white
));
1051 fixRoot((TextView
) v
);
1055 private void fixRoot(TextView v
) {
1056 if (v
.getText().equals(OCFile
.PATH_SEPARATOR
)) {
1057 v
.setText(R
.string
.default_display_name_for_root_folder
);
1063 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
1066 * {@link BroadcastReceiver} to enable syncing feedback in UI
1069 public void onReceive(Context context
, Intent intent
) {
1071 String event
= intent
.getAction();
1072 Log_OC
.d(TAG
, "Received broadcast " + event
);
1073 String accountName
= intent
.getStringExtra(FileSyncAdapter
.EXTRA_ACCOUNT_NAME
);
1074 String synchFolderRemotePath
=
1075 intent
.getStringExtra(FileSyncAdapter
.EXTRA_FOLDER_PATH
);
1076 RemoteOperationResult synchResult
=
1077 (RemoteOperationResult
)intent
.getSerializableExtra(
1078 FileSyncAdapter
.EXTRA_RESULT
);
1079 boolean sameAccount
= (getAccount() != null
&&
1080 accountName
.equals(getAccount().name
) && getStorageManager() != null
);
1084 if (FileSyncAdapter
.EVENT_FULL_SYNC_START
.equals(event
)) {
1085 mSyncInProgress
= true
;
1088 OCFile currentFile
= (getFile() == null
) ? null
:
1089 getStorageManager().getFileByPath(getFile().getRemotePath());
1090 OCFile currentDir
= (getCurrentDir() == null
) ? null
:
1091 getStorageManager().getFileByPath(getCurrentDir().getRemotePath());
1093 if (currentDir
== null
) {
1094 // current folder was removed from the server
1095 Toast
.makeText( FileDisplayActivity
.this,
1097 getString(R
.string
.sync_current_folder_was_removed
),
1098 mDirectories
.getItem(0)),
1104 if (currentFile
== null
&& !getFile().isFolder()) {
1105 // currently selected file was removed in the server, and now we
1107 cleanSecondFragment();
1108 currentFile
= currentDir
;
1111 if (synchFolderRemotePath
!= null
&&
1112 currentDir
.getRemotePath().equals(synchFolderRemotePath
)) {
1113 OCFileListFragment fileListFragment
= getListOfFilesFragment();
1114 if (fileListFragment
!= null
) {
1115 fileListFragment
.listDirectory();
1116 // TODO Enable when "On Device" is recovered ?
1117 // fileListFragment.listDirectory(currentDir,
1118 // MainApp.getOnlyOnDevice());
1121 setFile(currentFile
);
1124 mSyncInProgress
= (!FileSyncAdapter
.EVENT_FULL_SYNC_END
.equals(event
) &&
1125 !RefreshFolderOperation
.EVENT_SINGLE_FOLDER_SHARES_SYNCED
1128 if (RefreshFolderOperation
.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED
.
1130 /// TODO refactor and make common
1131 synchResult
!= null
&& !synchResult
.isSuccess() &&
1132 (synchResult
.getCode() == ResultCode
.UNAUTHORIZED
||
1133 synchResult
.isIdPRedirection() ||
1134 (synchResult
.isException() && synchResult
.getException()
1135 instanceof AuthenticatorException
))) {
1139 OwnCloudClient client
;
1140 OwnCloudAccount ocAccount
=
1141 new OwnCloudAccount(getAccount(), context
);
1142 client
= (OwnCloudClientManagerFactory
.getDefaultSingleton().
1143 removeClientFor(ocAccount
));
1145 if (client
!= null
) {
1146 OwnCloudCredentials cred
= client
.getCredentials();
1148 AccountManager am
= AccountManager
.get(context
);
1149 if (cred
.authTokenExpires()) {
1150 am
.invalidateAuthToken(
1155 am
.clearPassword(getAccount());
1159 requestCredentialsUpdate();
1161 } catch (AccountNotFoundException e
) {
1162 Log_OC
.e(TAG
, "Account " + getAccount() + " was removed!", e
);
1167 removeStickyBroadcast(intent
);
1168 Log_OC
.d(TAG
, "Setting progress visibility to " + mSyncInProgress
);
1169 setSupportProgressBarIndeterminateVisibility(mSyncInProgress
1170 /*|| mRefreshSharesInProgress*/);
1172 setBackgroundText();
1176 if (synchResult
!= null
) {
1177 if (synchResult
.getCode().equals(
1178 RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
1179 mLastSslUntrustedServerResult
= synchResult
;
1182 } catch (RuntimeException e
) {
1183 // avoid app crashes after changing the serial id of RemoteOperationResult
1184 // in owncloud library with broadcast notifications pending to process
1185 removeStickyBroadcast(intent
);
1191 * Show a text message on screen view for notifying user if content is
1192 * loading or folder is empty
1194 private void setBackgroundText() {
1195 OCFileListFragment ocFileListFragment
= getListOfFilesFragment();
1196 if (ocFileListFragment
!= null
) {
1197 int message
= R
.string
.file_list_loading
;
1198 if (!mSyncInProgress
) {
1199 // In case file list is empty
1200 message
= R
.string
.file_list_empty
;
1202 ocFileListFragment
.setMessageForEmptyList(getString(message
));
1204 Log_OC
.e(TAG
, "OCFileListFragment is null");
1209 * Once the file upload has finished -> update view
1211 private class UploadFinishReceiver
extends BroadcastReceiver
{
1213 * Once the file upload has finished -> update view
1214 * @author David A. Velasco
1215 * {@link BroadcastReceiver} to enable upload feedback in UI
1218 public void onReceive(Context context
, Intent intent
) {
1220 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
1221 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
1222 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
1223 OCFile currentDir
= getCurrentDir();
1224 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) &&
1225 (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
1227 if (sameAccount
&& isDescendant
) {
1228 refreshListOfFilesFragment();
1231 boolean uploadWasFine
= intent
.getBooleanExtra(FileUploader
.EXTRA_UPLOAD_RESULT
,
1233 boolean renamedInUpload
= getFile().getRemotePath().
1234 equals(intent
.getStringExtra(FileUploader
.EXTRA_OLD_REMOTE_PATH
));
1235 boolean sameFile
= getFile().getRemotePath().equals(uploadedRemotePath
) ||
1237 FileFragment details
= getSecondFragment();
1238 boolean detailFragmentIsShown
= (details
!= null
&&
1239 details
instanceof FileDetailFragment
);
1241 if (sameAccount
&& sameFile
&& detailFragmentIsShown
) {
1242 if (uploadWasFine
) {
1243 setFile(getStorageManager().getFileByPath(uploadedRemotePath
));
1245 if (renamedInUpload
) {
1246 String newName
= (new File(uploadedRemotePath
)).getName();
1247 Toast msg
= Toast
.makeText(
1250 getString(R
.string
.filedetails_renamed_in_upload_msg
),
1255 if (uploadWasFine
|| getFile().fileExists()) {
1256 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1258 cleanSecondFragment();
1261 // Force the preview if the file is an image
1262 if (uploadWasFine
&& PreviewImageFragment
.canBePreviewed(getFile())) {
1263 startImagePreview(getFile());
1264 } // TODO what about other kind of previews?
1268 if (intent
!= null
) {
1269 removeStickyBroadcast(intent
);
1279 * Class waiting for broadcast events from the {@link FileDownloader} service.
1281 * Updates the UI when a download is started or finished, provided that it is relevant for the
1284 private class DownloadFinishReceiver
extends BroadcastReceiver
{
1286 //int refreshCounter = 0;
1288 public void onReceive(Context context
, Intent intent
) {
1290 boolean sameAccount
= isSameAccount(context
, intent
);
1291 String downloadedRemotePath
=
1292 intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
1293 boolean isDescendant
= isDescendant(downloadedRemotePath
);
1295 if (sameAccount
&& isDescendant
) {
1296 String linkedToRemotePath
=
1297 intent
.getStringExtra(FileDownloader
.EXTRA_LINKED_TO_PATH
);
1298 if (linkedToRemotePath
== null
|| isAscendant(linkedToRemotePath
)) {
1299 //Log_OC.v(TAG, "refresh #" + ++refreshCounter);
1300 refreshListOfFilesFragment();
1302 refreshSecondFragment(
1304 downloadedRemotePath
,
1305 intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
)
1309 if (mWaitingToSend
!= null
) {
1311 getStorageManager().getFileByPath(mWaitingToSend
.getRemotePath());
1312 if (mWaitingToSend
.isDown()) {
1313 sendDownloadedFile();
1318 if (intent
!= null
) {
1319 removeStickyBroadcast(intent
);
1324 private boolean isDescendant(String downloadedRemotePath
) {
1325 OCFile currentDir
= getCurrentDir();
1327 currentDir
!= null
&&
1328 downloadedRemotePath
!= null
&&
1329 downloadedRemotePath
.startsWith(currentDir
.getRemotePath())
1333 private boolean isAscendant(String linkedToRemotePath
) {
1334 OCFile currentDir
= getCurrentDir();
1336 currentDir
!= null
&&
1337 currentDir
.getRemotePath().startsWith(linkedToRemotePath
)
1341 private boolean isSameAccount(Context context
, Intent intent
) {
1342 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
1343 return (accountName
!= null
&& getAccount() != null
&&
1344 accountName
.equals(getAccount().name
));
1349 public void browseToRoot() {
1350 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1351 if (listOfFiles
!= null
) { // should never be null, indeed
1352 while (mDirectories
.getCount() > 1) {
1355 OCFile root
= getStorageManager().getFileByPath(OCFile
.ROOT_PATH
);
1356 listOfFiles
.listDirectory(root
);
1357 // TODO Enable when "On Device" is recovered ?
1358 // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice());
1359 setFile(listOfFiles
.getCurrentFile());
1360 startSyncFolderOperation(root
, false
);
1362 cleanSecondFragment();
1366 public void browseTo(OCFile folder
) {
1367 if (folder
== null
|| !folder
.isFolder()) {
1368 throw new IllegalArgumentException("Trying to browse to invalid folder " + folder
);
1370 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1371 if (listOfFiles
!= null
) {
1372 setNavigationListWithFolder(folder
);
1373 listOfFiles
.listDirectory(folder
);
1374 // TODO Enable when "On Device" is recovered ?
1375 // listOfFiles.listDirectory(folder, MainApp.getOnlyOnDevice());
1376 setFile(listOfFiles
.getCurrentFile());
1377 startSyncFolderOperation(folder
, false
);
1379 Log_OC
.e(TAG
, "Unexpected null when accessing list fragment");
1381 cleanSecondFragment();
1388 * Updates action bar and second fragment, if in dual pane mode.
1391 public void onBrowsedDownTo(OCFile directory
) {
1392 pushDirname(directory
);
1393 cleanSecondFragment();
1396 startSyncFolderOperation(directory
, false
);
1401 * Shows the information of the {@link OCFile} received as a
1402 * parameter in the second fragment.
1404 * @param file {@link OCFile} whose details will be shown
1407 public void showDetails(OCFile file
) {
1408 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1409 setSecondFragment(detailFragment
);
1410 updateFragmentsVisibility(true
);
1411 updateNavigationElementsInActionBar(file
);
1419 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1420 ActionBar actionBar
= getSupportActionBar();
1422 // For adding content description tag to a title field in the action bar
1423 int actionBarTitleId
= getResources().getIdentifier("action_bar_title", "id", "android");
1425 if (chosenFile
== null
|| mDualPane
) {
1426 // only list of files - set for browsing through folders
1427 OCFile currentDir
= getCurrentDir();
1428 boolean noRoot
= (currentDir
!= null
&& currentDir
.getParentId() != 0);
1429 // actionBar.setDisplayHomeAsUpEnabled(noRoot);
1430 // actionBar.setDisplayShowTitleEnabled(!noRoot);
1431 actionBar
.setDisplayHomeAsUpEnabled(true
);
1432 actionBar
.setDisplayShowTitleEnabled(true
);
1434 actionBar
.setTitle(getString(R
.string
.default_display_name_for_root_folder
));
1435 View actionBarTitleView
= getWindow().getDecorView().findViewById(actionBarTitleId
);
1436 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
1437 actionBarTitleView
.setContentDescription(
1438 getString(R
.string
.default_display_name_for_root_folder
));
1441 actionBar
.setNavigationMode(!noRoot ? ActionBar
.NAVIGATION_MODE_STANDARD
:
1442 ActionBar
.NAVIGATION_MODE_LIST
);
1443 actionBar
.setListNavigationCallbacks(mDirectories
, this);
1444 // assuming mDirectories is updated
1447 actionBar
.setDisplayHomeAsUpEnabled(true
);
1448 actionBar
.setDisplayShowTitleEnabled(true
);
1449 actionBar
.setTitle(chosenFile
.getFileName());
1450 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1451 View actionBarTitleView
= getWindow().getDecorView().findViewById(actionBarTitleId
);
1452 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
1453 getWindow().getDecorView().findViewById(actionBarTitleId
).
1454 setContentDescription(chosenFile
.getFileName());
1461 protected ServiceConnection
newTransferenceServiceConnection() {
1462 return new ListServiceConnection();
1465 /** Defines callbacks for service binding, passed to bindService() */
1466 private class ListServiceConnection
implements ServiceConnection
{
1469 public void onServiceConnected(ComponentName component
, IBinder service
) {
1470 if (component
.equals(new ComponentName(
1471 FileDisplayActivity
.this, FileDownloader
.class))) {
1472 Log_OC
.d(TAG
, "Download service connected");
1473 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1474 if (mWaitingToPreview
!= null
)
1475 if (getStorageManager() != null
) {
1478 getStorageManager().getFileById(mWaitingToPreview
.getFileId());
1479 if (!mWaitingToPreview
.isDown()) {
1480 requestForDownload();
1484 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this,
1485 FileUploader
.class))) {
1486 Log_OC
.d(TAG
, "Upload service connected");
1487 mUploaderBinder
= (FileUploaderBinder
) service
;
1491 // a new chance to get the mDownloadBinder through
1492 // getFileDownloadBinder() - THIS IS A MESS
1493 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1494 if (listOfFiles
!= null
) {
1495 listOfFiles
.listDirectory();
1496 // TODO Enable when "On Device" is recovered ?
1497 // listOfFiles.listDirectory(MainApp.getOnlyOnDevice());
1499 FileFragment secondFragment
= getSecondFragment();
1500 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1501 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1502 detailFragment
.listenForTransferProgress();
1503 detailFragment
.updateFileDetails(false
, false
);
1508 public void onServiceDisconnected(ComponentName component
) {
1509 if (component
.equals(new ComponentName(FileDisplayActivity
.this,
1510 FileDownloader
.class))) {
1511 Log_OC
.d(TAG
, "Download service disconnected");
1512 mDownloaderBinder
= null
;
1513 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this,
1514 FileUploader
.class))) {
1515 Log_OC
.d(TAG
, "Upload service disconnected");
1516 mUploaderBinder
= null
;
1522 public void onSavedCertificate() {
1523 startSyncFolderOperation(getCurrentDir(), false
);
1528 public void onFailedSavingCertificate() {
1529 ConfirmationDialogFragment dialog
= ConfirmationDialogFragment
.newInstance(
1530 R
.string
.ssl_validator_not_saved
, new String
[]{}, R
.string
.common_ok
, -1, -1
1532 dialog
.show(getSupportFragmentManager(), DIALOG_CERT_NOT_SAVED
);
1536 public void onCancelCertificate() {
1541 * Updates the view associated to the activity after the finish of some operation over files
1542 * in the current account.
1544 * @param operation Removal operation performed.
1545 * @param result Result of the removal.
1548 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1549 super.onRemoteOperationFinish(operation
, result
);
1551 if (operation
instanceof RemoveFileOperation
) {
1552 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1554 } else if (operation
instanceof RenameFileOperation
) {
1555 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1557 } else if (operation
instanceof SynchronizeFileOperation
) {
1558 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1560 } else if (operation
instanceof CreateFolderOperation
) {
1561 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1563 } else if (operation
instanceof CreateShareOperation
) {
1564 onCreateShareOperationFinish((CreateShareOperation
) operation
, result
);
1566 } else if (operation
instanceof UnshareLinkOperation
) {
1567 onUnshareLinkOperationFinish((UnshareLinkOperation
)operation
, result
);
1569 } else if (operation
instanceof MoveFileOperation
) {
1570 onMoveFileOperationFinish((MoveFileOperation
)operation
, result
);
1576 private void onCreateShareOperationFinish(CreateShareOperation operation
,
1577 RemoteOperationResult result
) {
1578 if (result
.isSuccess()) {
1579 refreshShowDetails();
1580 refreshListOfFilesFragment();
1585 private void onUnshareLinkOperationFinish(UnshareLinkOperation operation
,
1586 RemoteOperationResult result
) {
1587 if (result
.isSuccess()) {
1588 refreshShowDetails();
1589 refreshListOfFilesFragment();
1591 } else if (result
.getCode() == ResultCode
.SHARE_NOT_FOUND
) {
1592 cleanSecondFragment();
1593 refreshListOfFilesFragment();
1597 private void refreshShowDetails() {
1598 FileFragment details
= getSecondFragment();
1599 if (details
!= null
) {
1600 OCFile file
= details
.getFile();
1602 file
= getStorageManager().getFileByPath(file
.getRemotePath());
1603 if (details
instanceof PreviewMediaFragment
) {
1604 // Refresh OCFile of the fragment
1605 ((PreviewMediaFragment
) details
).updateFile(file
);
1610 invalidateOptionsMenu();
1615 * Updates the view associated to the activity after the finish of an operation trying to
1618 * @param operation Removal operation performed.
1619 * @param result Result of the removal.
1621 private void onRemoveFileOperationFinish(RemoveFileOperation operation
,
1622 RemoteOperationResult result
) {
1623 dismissLoadingDialog();
1625 Toast msg
= Toast
.makeText(this,
1626 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
1630 if (result
.isSuccess()) {
1631 OCFile removedFile
= operation
.getFile();
1632 FileFragment second
= getSecondFragment();
1633 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1634 if (second
instanceof PreviewMediaFragment
) {
1635 ((PreviewMediaFragment
)second
).stopPreview(true
);
1637 setFile(getStorageManager().getFileById(removedFile
.getParentId()));
1638 cleanSecondFragment();
1640 if (getStorageManager().getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1641 refreshListOfFilesFragment();
1643 invalidateOptionsMenu();
1645 if (result
.isSslRecoverableException()) {
1646 mLastSslUntrustedServerResult
= result
;
1647 showUntrustedCertDialog(mLastSslUntrustedServerResult
);
1654 * Updates the view associated to the activity after the finish of an operation trying to move a
1657 * @param operation Move operation performed.
1658 * @param result Result of the move operation.
1660 private void onMoveFileOperationFinish(MoveFileOperation operation
,
1661 RemoteOperationResult result
) {
1662 if (result
.isSuccess()) {
1663 dismissLoadingDialog();
1664 refreshListOfFilesFragment();
1666 dismissLoadingDialog();
1668 Toast msg
= Toast
.makeText(FileDisplayActivity
.this,
1669 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
1673 } catch (NotFoundException e
) {
1674 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1681 * Updates the view associated to the activity after the finish of an operation trying to rename
1684 * @param operation Renaming operation performed.
1685 * @param result Result of the renaming.
1687 private void onRenameFileOperationFinish(RenameFileOperation operation
,
1688 RemoteOperationResult result
) {
1689 dismissLoadingDialog();
1690 OCFile renamedFile
= operation
.getFile();
1691 if (result
.isSuccess()) {
1692 FileFragment details
= getSecondFragment();
1693 if (details
!= null
) {
1694 if (details
instanceof FileDetailFragment
&&
1695 renamedFile
.equals(details
.getFile()) ) {
1696 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1697 showDetails(renamedFile
);
1699 } else if (details
instanceof PreviewMediaFragment
&&
1700 renamedFile
.equals(details
.getFile())) {
1701 ((PreviewMediaFragment
) details
).updateFile(renamedFile
);
1702 if (PreviewMediaFragment
.canBePreviewed(renamedFile
)) {
1703 int position
= ((PreviewMediaFragment
)details
).getPosition();
1704 startMediaPreview(renamedFile
, position
, true
);
1706 getFileOperationsHelper().openFile(renamedFile
);
1711 if (getStorageManager().getFileById(renamedFile
.getParentId()).equals(getCurrentDir())){
1712 refreshListOfFilesFragment();
1716 Toast msg
= Toast
.makeText(this,
1717 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
1721 if (result
.isSslRecoverableException()) {
1722 mLastSslUntrustedServerResult
= result
;
1723 showUntrustedCertDialog(mLastSslUntrustedServerResult
);
1728 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
,
1729 RemoteOperationResult result
) {
1730 dismissLoadingDialog();
1731 OCFile syncedFile
= operation
.getLocalFile();
1732 if (!result
.isSuccess()) {
1733 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1734 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1735 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1736 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1742 if (operation
.transferWasRequested()) {
1743 onTransferStateChanged(syncedFile
, true
, true
);
1746 Toast msg
= Toast
.makeText(this, ErrorMessageAdapter
.getErrorCauseMessage(result
,
1747 operation
, getResources()), Toast
.LENGTH_LONG
);
1754 * Updates the view associated to the activity after the finish of an operation trying create a
1757 * @param operation Creation operation performed.
1758 * @param result Result of the creation.
1760 private void onCreateFolderOperationFinish(CreateFolderOperation operation
,
1761 RemoteOperationResult result
) {
1762 if (result
.isSuccess()) {
1763 dismissLoadingDialog();
1764 refreshListOfFilesFragment();
1766 dismissLoadingDialog();
1768 Toast msg
= Toast
.makeText(FileDisplayActivity
.this,
1769 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
1773 } catch (NotFoundException e
) {
1774 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1784 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1785 refreshListOfFilesFragment();
1786 FileFragment details
= getSecondFragment();
1787 if (details
!= null
&& details
instanceof FileDetailFragment
&&
1788 file
.equals(details
.getFile()) ) {
1789 if (downloading
|| uploading
) {
1790 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1792 if (!file
.fileExists()) {
1793 cleanSecondFragment();
1795 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1803 private void requestForDownload() {
1804 Account account
= getAccount();
1805 //if (!mWaitingToPreview.isDownloading()) {
1806 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1807 Intent i
= new Intent(this, FileDownloader
.class);
1808 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1809 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1815 private OCFile
getCurrentDir() {
1816 OCFile file
= getFile();
1818 if (file
.isFolder()) {
1820 } else if (getStorageManager() != null
) {
1821 String parentPath
= file
.getRemotePath().substring(0,
1822 file
.getRemotePath().lastIndexOf(file
.getFileName()));
1823 return getStorageManager().getFileByPath(parentPath
);
1829 public void startSyncFolderOperation(OCFile folder
, boolean ignoreETag
) {
1830 long currentSyncTime
= System
.currentTimeMillis();
1832 mSyncInProgress
= true
;
1834 // perform folder synchronization
1835 RemoteOperation synchFolderOp
= new RefreshFolderOperation( folder
,
1838 getFileOperationsHelper().isSharedSupported(),
1840 getStorageManager(),
1842 getApplicationContext()
1844 synchFolderOp
.execute(getAccount(), MainApp
.getAppContext(), this, null
, null
);
1846 setSupportProgressBarIndeterminateVisibility(true
);
1848 setBackgroundText();
1852 * Show untrusted cert dialog
1854 public void showUntrustedCertDialog(RemoteOperationResult result
) {
1855 // Show a dialog with the certificate info
1856 SslUntrustedCertDialog dialog
= SslUntrustedCertDialog
.newInstanceForFullSslError(
1857 (CertificateCombinedException
) result
.getException());
1858 FragmentManager fm
= getSupportFragmentManager();
1859 FragmentTransaction ft
= fm
.beginTransaction();
1860 dialog
.show(ft
, DIALOG_UNTRUSTED_CERT
);
1863 private void requestForDownload(OCFile file
) {
1864 Account account
= getAccount();
1865 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1866 Intent i
= new Intent(this, FileDownloader
.class);
1867 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1868 i
.putExtra(FileDownloader
.EXTRA_FILE
, file
);
1873 private void sendDownloadedFile(){
1874 getFileOperationsHelper().sendDownloadedFile(mWaitingToSend
);
1875 mWaitingToSend
= null
;
1880 * Requests the download of the received {@link OCFile} , updates the UI
1881 * to monitor the download progress and prepares the activity to send the file
1882 * when the download finishes.
1884 * @param file {@link OCFile} to download and preview.
1886 public void startDownloadForSending(OCFile file
) {
1887 mWaitingToSend
= file
;
1888 requestForDownload(mWaitingToSend
);
1889 boolean hasSecondFragment
= (getSecondFragment()!= null
);
1890 updateFragmentsVisibility(hasSecondFragment
);
1894 * Opens the image gallery showing the image {@link OCFile} received as parameter.
1896 * @param file Image {@link OCFile} to show.
1898 public void startImagePreview(OCFile file
) {
1899 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
1900 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
1901 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
1902 startActivity(showDetailsIntent
);
1907 * Stars the preview of an already down media {@link OCFile}.
1909 * @param file Media {@link OCFile} to preview.
1910 * @param startPlaybackPosition Media position where the playback will be started,
1912 * @param autoplay When 'true', the playback will start without user
1915 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1916 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
,
1918 setSecondFragment(mediaFragment
);
1919 updateFragmentsVisibility(true
);
1920 updateNavigationElementsInActionBar(file
);
1925 * Requests the download of the received {@link OCFile} , updates the UI
1926 * to monitor the download progress and prepares the activity to preview
1927 * or open the file when the download finishes.
1929 * @param file {@link OCFile} to download and preview.
1931 public void startDownloadForPreview(OCFile file
) {
1932 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1933 setSecondFragment(detailFragment
);
1934 mWaitingToPreview
= file
;
1935 requestForDownload();
1936 updateFragmentsVisibility(true
);
1937 updateNavigationElementsInActionBar(file
);
1942 public void cancelTransference(OCFile file
) {
1943 getFileOperationsHelper().cancelTransference(file
);
1944 if (mWaitingToPreview
!= null
&&
1945 mWaitingToPreview
.getRemotePath().equals(file
.getRemotePath())) {
1946 mWaitingToPreview
= null
;
1948 if (mWaitingToSend
!= null
&&
1949 mWaitingToSend
.getRemotePath().equals(file
.getRemotePath())) {
1950 mWaitingToSend
= null
;
1952 onTransferStateChanged(file
, false
, false
);
1956 public void onRefresh(boolean ignoreETag
) {
1957 refreshList(ignoreETag
);
1961 public void onRefresh() {
1965 private void refreshList(boolean ignoreETag
) {
1966 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1967 if (listOfFiles
!= null
) {
1968 OCFile folder
= listOfFiles
.getCurrentFile();
1969 if (folder
!= null
) {
1970 /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
1971 listDirectory(mFile);*/
1972 startSyncFolderOperation(folder
, ignoreETag
);
1977 private void sortByDate(boolean ascending
){
1978 getListOfFilesFragment().sortByDate(ascending
);
1981 private void sortBySize(boolean ascending
){
1982 getListOfFilesFragment().sortBySize(ascending
);
1985 private void sortByName(boolean ascending
){
1986 getListOfFilesFragment().sortByName(ascending
);
1989 public void restart(){
1990 Intent i
= new Intent(this, FileDisplayActivity
.class);
1991 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
1995 public void closeDrawer() {
1996 mDrawerLayout
.closeDrawers();
1999 private class DrawerItemClickListener
implements ListView
.OnItemClickListener
{
2001 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
2002 if (mShowAccounts
&& position
> 0){
2003 position
= position
- 1;
2007 mShowAccounts
= !mShowAccounts
;
2008 mNavigationDrawerAdapter
.setShowAccounts(mShowAccounts
);
2009 mNavigationDrawerAdapter
.notifyDataSetChanged();
2012 case 1: // All Files
2013 // TODO Enable when "On Device" is recovered ?
2014 //MainApp.showOnlyFilesOnDevice(false);
2015 mDrawerLayout
.closeDrawers();
2018 // TODO Enable when "On Device" is recovered ?
2020 // MainApp.showOnlyFilesOnDevice(true);
2021 // mDrawerLayout.closeDrawers();
2025 Intent settingsIntent
= new Intent(getApplicationContext(),
2027 startActivity(settingsIntent
);
2031 Intent loggerIntent
= new Intent(getApplicationContext(),
2032 LogHistoryActivity
.class);
2033 startActivity(loggerIntent
);