1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2014 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.ui
.fragment
;
21 import java
.util
.ArrayList
;
22 import java
.util
.List
;
24 import com
.owncloud
.android
.R
;
25 import com
.owncloud
.android
.authentication
.AccountUtils
;
26 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
27 import com
.owncloud
.android
.datamodel
.FileListCursorLoader
;
28 import com
.owncloud
.android
.datamodel
.OCFile
;
29 import com
.owncloud
.android
.db
.ProviderMeta
.ProviderTableMeta
;
30 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
31 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
32 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
33 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
34 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
35 import com
.owncloud
.android
.operations
.RenameFileOperation
;
36 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
37 import com
.owncloud
.android
.ui
.activity
.FileActivity
;
38 import com
.owncloud
.android
.ui
.ExtendedListView
;
39 import com
.owncloud
.android
.ui
.activity
.TransferServiceGetter
;
40 import com
.owncloud
.android
.ui
.adapter
.FileListListAdapter
;
41 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
;
42 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
43 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
;
44 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
45 import com
.owncloud
.android
.ui
.preview
.PreviewImageFragment
;
46 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
47 import com
.owncloud
.android
.utils
.Log_OC
;
49 import android
.accounts
.Account
;
50 import android
.app
.Activity
;
51 import android
.database
.Cursor
;
52 import android
.net
.Uri
;
53 import android
.os
.Bundle
;
54 import android
.os
.Handler
;
55 import android
.support
.v4
.app
.LoaderManager
;
56 import android
.support
.v4
.app
.LoaderManager
.LoaderCallbacks
;
57 import android
.support
.v4
.content
.Loader
;
58 import android
.view
.ContextMenu
;
59 import android
.view
.MenuInflater
;
60 import android
.view
.MenuItem
;
61 import android
.view
.View
;
62 import android
.widget
.AdapterView
;
63 import android
.widget
.AdapterView
.AdapterContextMenuInfo
;
66 * A Fragment that lists all files and folders in a given path.
68 * @author Bartek Przybylski
71 public class OCFileListFragment
extends ExtendedListFragment
72 implements EditNameDialogListener
, ConfirmationDialogFragmentListener
,
73 LoaderCallbacks
<Cursor
>{
75 private static final String TAG
= OCFileListFragment
.class.getSimpleName();
77 private static final String MY_PACKAGE
= OCFileListFragment
.class.getPackage() != null ? OCFileListFragment
.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
78 private static final String EXTRA_FILE
= MY_PACKAGE
+ ".extra.FILE";
80 private static final String KEY_INDEXES
= "INDEXES";
81 private static final String KEY_FIRST_POSITIONS
= "FIRST_POSITIONS";
82 private static final String KEY_TOPS
= "TOPS";
83 private static final String KEY_HEIGHT_CELL
= "HEIGHT_CELL";
85 private static final int LOADER_ID
= 0;
87 private OCFileListFragment
.ContainerActivity mContainerActivity
;
89 private OCFile mFile
= null
;
90 private FileListListAdapter mAdapter
;
91 private LoaderManager mLoaderManager
;
92 private FileListCursorLoader mCursorLoader
;
94 private Handler mHandler
;
95 private OCFile mTargetFile
;
97 // Save the state of the scroll in browsing
98 private ArrayList
<Integer
> mIndexes
;
99 private ArrayList
<Integer
> mFirstPositions
;
100 private ArrayList
<Integer
> mTops
;
102 private int mHeightCell
= 0;
108 public void onAttach(Activity activity
) {
109 super.onAttach(activity
);
110 Log_OC
.e(TAG
, "onAttach");
112 mContainerActivity
= (ContainerActivity
) activity
;
113 } catch (ClassCastException e
) {
114 throw new ClassCastException(activity
.toString() + " must implement " + OCFileListFragment
.ContainerActivity
.class.getSimpleName());
123 public void onActivityCreated(Bundle savedInstanceState
) {
124 super.onActivityCreated(savedInstanceState
);
125 Log_OC
.e(TAG
, "onActivityCreated() start");
127 mAdapter
= new FileListListAdapter(getSherlockActivity(), mContainerActivity
);
128 mLoaderManager
= getLoaderManager();
130 if (savedInstanceState
!= null
) {
131 mFile
= savedInstanceState
.getParcelable(EXTRA_FILE
);
132 mIndexes
= savedInstanceState
.getIntegerArrayList(KEY_INDEXES
);
133 mFirstPositions
= savedInstanceState
.getIntegerArrayList(KEY_FIRST_POSITIONS
);
134 mTops
= savedInstanceState
.getIntegerArrayList(KEY_TOPS
);
135 mHeightCell
= savedInstanceState
.getInt(KEY_HEIGHT_CELL
);
138 mIndexes
= new ArrayList
<Integer
>();
139 mFirstPositions
= new ArrayList
<Integer
>();
140 mTops
= new ArrayList
<Integer
>();
145 // Initialize loaderManager and makes it active
146 mLoaderManager
.initLoader(LOADER_ID
, null
, this);
148 setListAdapter(mAdapter
);
150 registerForContextMenu(getListView());
151 getListView().setOnCreateContextMenuListener(this);
153 mHandler
= new Handler();
159 * Saves the current listed folder.
162 public void onSaveInstanceState (Bundle outState
) {
163 super.onSaveInstanceState(outState
);
164 outState
.putParcelable(EXTRA_FILE
, mFile
);
165 outState
.putIntegerArrayList(KEY_INDEXES
, mIndexes
);
166 outState
.putIntegerArrayList(KEY_FIRST_POSITIONS
, mFirstPositions
);
167 outState
.putIntegerArrayList(KEY_TOPS
, mTops
);
168 outState
.putInt(KEY_HEIGHT_CELL
, mHeightCell
);
172 * Call this, when the user presses the up button.
174 * Tries to move up the current folder one level. If the parent folder was removed from the database,
175 * it continues browsing up until finding an existing folders.
177 * return Count of folder levels browsed up.
179 public int onBrowseUp() {
180 OCFile parentDir
= null
;
184 FileDataStorageManager storageManager
=
185 ((FileActivity
)getSherlockActivity()).getStorageManager();
187 String parentPath
= null
;
188 if (mFile
.getParentId() != FileDataStorageManager
.ROOT_PARENT_ID
) {
189 parentPath
= new File(mFile
.getRemotePath()).getParent();
190 parentPath
= parentPath
.endsWith(OCFile
.PATH_SEPARATOR
) ? parentPath
: parentPath
+ OCFile
.PATH_SEPARATOR
;
191 parentDir
= storageManager
.getFileByPath(parentPath
);
194 parentDir
= storageManager
.getFileByPath(OCFile
.ROOT_PATH
); // never returns null; keep the path in root folder
196 while (parentDir
== null
) {
197 parentPath
= new File(parentPath
).getParent();
198 parentPath
= parentPath
.endsWith(OCFile
.PATH_SEPARATOR
) ? parentPath
: parentPath
+ OCFile
.PATH_SEPARATOR
;
199 parentDir
= storageManager
.getFileByPath(parentPath
);
201 } // exit is granted because storageManager.getFileByPath("/") never returns null
206 listDirectory(mFile
);
208 mContainerActivity
.startSyncFolderOperation(mFile
);
210 // restore index and top position
211 restoreIndexAndTopPosition();
213 } // else - should never happen now
219 * Restore index and position
221 private void restoreIndexAndTopPosition() {
222 if (mIndexes
.size() > 0) {
223 // needs to be checked; not every browse-up had a browse-down before
225 int index
= mIndexes
.remove(mIndexes
.size() - 1);
227 int firstPosition
= mFirstPositions
.remove(mFirstPositions
.size() -1);
229 int top
= mTops
.remove(mTops
.size() - 1);
231 ExtendedListView list
= (ExtendedListView
) getListView();
232 list
.setSelectionFromTop(firstPosition
, top
);
234 // Move the scroll if the selection is not visible
235 int indexPosition
= mHeightCell
*index
;
236 int height
= list
.getHeight();
238 if (indexPosition
> height
) {
239 if (android
.os
.Build
.VERSION
.SDK_INT
>= 11)
241 list
.smoothScrollToPosition(index
);
243 else if (android
.os
.Build
.VERSION
.SDK_INT
>= 8)
245 list
.setSelectionFromTop(index
, 0);
253 * Save index and top position
255 private void saveIndexAndTopPosition(int index
) {
259 ExtendedListView list
= (ExtendedListView
) getListView();
261 int firstPosition
= list
.getFirstVisiblePosition();
262 mFirstPositions
.add(firstPosition
);
264 View view
= list
.getChildAt(0);
265 int top
= (view
== null
) ?
0 : view
.getTop() ;
269 // Save the height of a cell
270 mHeightCell
= (view
== null
|| mHeightCell
!= 0) ? mHeightCell
: view
.getHeight();
274 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
275 OCFile file
= ((FileActivity
)getSherlockActivity()).getStorageManager().createFileInstance(
276 (Cursor
) mAdapter
.getItem(position
));
278 if (file
.isFolder()) {
279 // update state and view of this fragment
281 // then, notify parent activity to let it update its state and view, and other fragments
282 mContainerActivity
.onBrowsedDownTo(file
);
283 // save index and top position
284 saveIndexAndTopPosition(position
);
286 } else { /// Click on a file
287 if (PreviewImageFragment
.canBePreviewed(file
)) {
288 // preview image - it handles the download, if needed
289 mContainerActivity
.startImagePreview(file
);
291 } else if (file
.isDown()) {
292 if (PreviewMediaFragment
.canBePreviewed(file
)) {
294 mContainerActivity
.startMediaPreview(file
, 0, true
);
296 FileActivity activity
= (FileActivity
) getSherlockActivity();
297 activity
.getFileOperationsHelper().openFile(file
, activity
);
301 // automatic download, preview on finish
302 mContainerActivity
.startDownloadForPreview(file
);
308 Log_OC
.d(TAG
, "Null object in ListAdapter!!");
317 public void onCreateContextMenu (ContextMenu menu
, View v
, ContextMenu
.ContextMenuInfo menuInfo
) {
318 super.onCreateContextMenu(menu
, v
, menuInfo
);
319 MenuInflater inflater
= getSherlockActivity().getMenuInflater();
320 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
321 AdapterContextMenuInfo info
= (AdapterContextMenuInfo
) menuInfo
;
322 OCFile targetFile
= ((FileActivity
)getSherlockActivity()).getStorageManager().createFileInstance(
323 (Cursor
) mAdapter
.getItem(info
.position
));
324 List
<Integer
> toHide
= new ArrayList
<Integer
>();
325 List
<Integer
> toDisable
= new ArrayList
<Integer
>();
327 MenuItem item
= null
;
328 if (targetFile
.isFolder()) {
329 // contextual menu for folders
330 toHide
.add(R
.id
.action_open_file_with
);
331 toHide
.add(R
.id
.action_download_file
);
332 toHide
.add(R
.id
.action_cancel_download
);
333 toHide
.add(R
.id
.action_cancel_upload
);
334 toHide
.add(R
.id
.action_sync_file
);
335 toHide
.add(R
.id
.action_see_details
);
336 toHide
.add(R
.id
.action_send_file
);
337 if ( mContainerActivity
.getFileDownloaderBinder().isDownloading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
) ||
338 mContainerActivity
.getFileUploaderBinder().isUploading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
) ) {
339 toDisable
.add(R
.id
.action_rename_file
);
340 toDisable
.add(R
.id
.action_remove_file
);
345 // contextual menu for regular files
347 // new design: 'download' and 'open with' won't be available anymore in context menu
348 toHide
.add(R
.id
.action_download_file
);
349 toHide
.add(R
.id
.action_open_file_with
);
351 if (targetFile
.isDown()) {
352 toHide
.add(R
.id
.action_cancel_download
);
353 toHide
.add(R
.id
.action_cancel_upload
);
356 toHide
.add(R
.id
.action_sync_file
);
358 if ( mContainerActivity
.getFileDownloaderBinder().isDownloading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
)) {
359 toHide
.add(R
.id
.action_cancel_upload
);
360 toDisable
.add(R
.id
.action_rename_file
);
361 toDisable
.add(R
.id
.action_remove_file
);
363 } else if ( mContainerActivity
.getFileUploaderBinder().isUploading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
)) {
364 toHide
.add(R
.id
.action_cancel_download
);
365 toDisable
.add(R
.id
.action_rename_file
);
366 toDisable
.add(R
.id
.action_remove_file
);
369 toHide
.add(R
.id
.action_cancel_download
);
370 toHide
.add(R
.id
.action_cancel_upload
);
375 if (!targetFile
.isShareByLink()) {
376 toHide
.add(R
.id
.action_unshare_file
);
380 boolean sendEnabled
= getString(R
.string
.send_files_to_other_apps
).equalsIgnoreCase("on");
382 toHide
.add(R
.id
.action_send_file
);
385 for (int i
: toHide
) {
386 item
= menu
.findItem(i
);
388 item
.setVisible(false
);
389 item
.setEnabled(false
);
393 for (int i
: toDisable
) {
394 item
= menu
.findItem(i
);
396 item
.setEnabled(false
);
406 public boolean onContextItemSelected (MenuItem item
) {
407 AdapterContextMenuInfo info
= (AdapterContextMenuInfo
) item
.getMenuInfo();
408 mTargetFile
= ((FileActivity
)getSherlockActivity()).getStorageManager().createFileInstance(
409 (Cursor
) mAdapter
.getItem(info
.position
));
410 switch (item
.getItemId()) {
411 case R
.id
.action_share_file
: {
412 FileActivity activity
= (FileActivity
) getSherlockActivity();
413 activity
.getFileOperationsHelper().shareFileWithLink(mTargetFile
, activity
);
416 case R
.id
.action_unshare_file
: {
417 FileActivity activity
= (FileActivity
) getSherlockActivity();
418 activity
.getFileOperationsHelper().unshareFileWithLink(mTargetFile
, activity
);
421 case R
.id
.action_rename_file
: {
422 String fileName
= mTargetFile
.getFileName();
423 int extensionStart
= mTargetFile
.isFolder() ?
-1 : fileName
.lastIndexOf(".");
424 int selectionEnd
= (extensionStart
>= 0) ? extensionStart
: fileName
.length();
425 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.rename_dialog_title
), fileName
, 0, selectionEnd
, this);
426 dialog
.show(getFragmentManager(), EditNameDialog
.TAG
);
429 case R
.id
.action_remove_file
: {
430 int messageStringId
= R
.string
.confirmation_remove_alert
;
431 int posBtnStringId
= R
.string
.confirmation_remove_remote
;
432 int neuBtnStringId
= -1;
433 if (mTargetFile
.isFolder()) {
434 messageStringId
= R
.string
.confirmation_remove_folder_alert
;
435 posBtnStringId
= R
.string
.confirmation_remove_remote_and_local
;
436 neuBtnStringId
= R
.string
.confirmation_remove_folder_local
;
437 } else if (mTargetFile
.isDown()) {
438 posBtnStringId
= R
.string
.confirmation_remove_remote_and_local
;
439 neuBtnStringId
= R
.string
.confirmation_remove_local
;
441 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
443 new String
[]{mTargetFile
.getFileName()},
446 R
.string
.common_cancel
);
447 confDialog
.setOnConfirmationListener(this);
448 confDialog
.show(getFragmentManager(), FileDetailFragment
.FTAG_CONFIRMATION
);
451 case R
.id
.action_sync_file
: {
452 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity());
453 RemoteOperation operation
= new SynchronizeFileOperation(
456 ((FileActivity
)getSherlockActivity()).getStorageManager(),
459 getSherlockActivity());
460 operation
.execute(account
, getSherlockActivity(), mContainerActivity
, mHandler
, getSherlockActivity());
461 ((FileActivity
) getSherlockActivity()).showLoadingDialog();
464 case R
.id
.action_cancel_download
: {
465 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
466 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity());
467 if (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(account
, mTargetFile
)) {
468 downloaderBinder
.cancel(account
, mTargetFile
);
470 mContainerActivity
.onTransferStateChanged(mTargetFile
, false
, false
);
474 case R
.id
.action_cancel_upload
: {
475 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
476 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity());
477 if (uploaderBinder
!= null
&& uploaderBinder
.isUploading(account
, mTargetFile
)) {
478 uploaderBinder
.cancel(account
, mTargetFile
);
480 mContainerActivity
.onTransferStateChanged(mTargetFile
, false
, false
);
484 case R
.id
.action_see_details
: {
485 ((FileFragment
.ContainerActivity
)getSherlockActivity()).showDetails(mTargetFile
);
488 case R
.id
.action_send_file
: {
490 if (!mTargetFile
.isDown()) { // Download the file
491 Log_OC
.d(TAG
, mTargetFile
.getRemotePath() + " : File must be downloaded");
492 mContainerActivity
.startDownloadForSending(mTargetFile
);
496 FileActivity activity
= (FileActivity
) getSherlockActivity();
497 activity
.getFileOperationsHelper().sendDownloadedFile(mTargetFile
, activity
);
502 return super.onContextItemSelected(item
);
508 * Use this to query the {@link OCFile} that is currently
509 * being displayed by this fragment
510 * @return The currently viewed OCFile
512 public OCFile
getCurrentFile(){
517 * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter
519 public void listDirectory(){
524 * Lists the given directory on the view. When the input parameter is null,
525 * it will either refresh the last known directory. list the root
526 * if there never was a directory.
528 * @param directory File to be listed
530 public void listDirectory(OCFile directory
) {
531 FileDataStorageManager storageManager
= ((FileActivity
)getSherlockActivity()).getStorageManager();
532 if (storageManager
!= null
) {
534 // Check input parameters for null
535 if(directory
== null
){
539 directory
= storageManager
.getFileByPath("/");
540 if (directory
== null
) return; // no files, wait for sync
545 // If that's not a directory -> List its parent
546 if(!directory
.isFolder()){
547 Log_OC
.w(TAG
, "You see, that is not a directory -> " + directory
.toString());
548 directory
= storageManager
.getFileById(directory
.getParentId());
551 swapDirectory(directory
.getFileId(), storageManager
);
553 if (mFile
== null
|| !mFile
.equals(directory
)) {
554 ((ExtendedListView
) getListView()).setSelectionFromTop(0, 0);
562 * Change the adapted directory for a new one
563 * @param folder New file to adapt. Can be NULL, meaning "no content to adapt".
564 * @param updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
566 public void swapDirectory(long parentId
, FileDataStorageManager updatedStorageManager
) {
567 FileDataStorageManager storageManager
= null
;
568 if (updatedStorageManager
!= null
&& updatedStorageManager
!= storageManager
) {
569 storageManager
= updatedStorageManager
;
571 Cursor newCursor
= null
;
572 if (storageManager
!= null
) {
573 mAdapter
.setStorageManager(storageManager
);
574 mCursorLoader
.setParentId(parentId
);
575 newCursor
= mCursorLoader
.loadInBackground();//storageManager.getContent(folder.getFileId());
576 Uri uri
= Uri
.withAppendedPath(
577 ProviderTableMeta
.CONTENT_URI_DIR
,
578 String
.valueOf(parentId
));
579 Log_OC
.d(TAG
, "swapDirectory Uri " + uri
);
580 //newCursor.setNotificationUri(getSherlockActivity().getContentResolver(), uri);
583 Cursor oldCursor
= mAdapter
.swapCursor(newCursor
);
584 if (oldCursor
!= null
){
587 mAdapter
.notifyDataSetChanged();
592 * Interface to implement by any Activity that includes some instance of FileListFragment
594 * @author David A. Velasco
596 public interface ContainerActivity
extends TransferServiceGetter
, OnRemoteOperationListener
{
599 * Callback method invoked when a the user browsed into a different folder through the list of files
603 public void onBrowsedDownTo(OCFile folder
);
605 public void startDownloadForPreview(OCFile file
);
607 public void startMediaPreview(OCFile file
, int i
, boolean b
);
609 public void startImagePreview(OCFile file
);
611 public void startSyncFolderOperation(OCFile folder
);
614 * Callback method invoked when a the 'transfer state' of a file changes.
616 * This happens when a download or upload is started or ended for a file.
618 * This method is necessary by now to update the user interface of the double-pane layout in tablets
619 * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
620 * won't provide the needed response before the method where this is called finishes.
622 * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
624 * @param file OCFile which state changed.
625 * @param downloading Flag signaling if the file is now downloading.
626 * @param uploading Flag signaling if the file is now uploading.
628 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
);
630 public void startDownloadForSending(OCFile file
);
636 public void onDismiss(EditNameDialog dialog
) {
637 if (dialog
.getResult()) {
638 String newFilename
= dialog
.getNewFilename();
639 Log_OC
.d(TAG
, "name edit dialog dismissed with new name " + newFilename
);
640 RemoteOperation operation
=
641 new RenameFileOperation(
643 AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()),
645 ((FileActivity
)getSherlockActivity()).getStorageManager());
646 operation
.execute(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity
, mHandler
, getSherlockActivity());
647 ((FileActivity
) getSherlockActivity()).showLoadingDialog();
653 public void onConfirmation(String callerTag
) {
654 if (callerTag
.equals(FileDetailFragment
.FTAG_CONFIRMATION
)) {
655 FileDataStorageManager storageManager
=
656 ((FileActivity
)getSherlockActivity()).getStorageManager();
657 if (storageManager
.getFileById(mTargetFile
.getFileId()) != null
) {
658 RemoteOperation operation
= new RemoveFileOperation( mTargetFile
,
661 operation
.execute(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity
, mHandler
, getSherlockActivity());
663 ((FileActivity
) getSherlockActivity()).showLoadingDialog();
669 public void onNeutral(String callerTag
) {
670 ((FileActivity
)getSherlockActivity()).getStorageManager().removeFile(mTargetFile
, false
, true
); // TODO perform in background task / new thread
672 mContainerActivity
.onTransferStateChanged(mTargetFile
, false
, false
);
676 public void onCancel(String callerTag
) {
677 Log_OC
.d(TAG
, "REMOVAL CANCELED");
681 * LoaderManager.LoaderCallbacks<Cursor>
685 * Instantiate and return a new Loader for the given ID. This is where the cursor is created.
688 public Loader
<Cursor
> onCreateLoader(int id
, Bundle bundle
) {
689 Log_OC
.d(TAG
, "onCreateLoader start");
690 mCursorLoader
= new FileListCursorLoader((FileActivity
)getSherlockActivity(),
691 ((FileActivity
)getSherlockActivity()).getStorageManager());
693 mCursorLoader
.setParentId(mFile
.getFileId());
695 mCursorLoader
.setParentId(1);
697 Log_OC
.d(TAG
, "onCreateLoader end");
698 return mCursorLoader
;
703 * Called when a previously created loader has finished its load. Here, you can start using the cursor.
706 public void onLoadFinished(Loader
<Cursor
> loader
, Cursor cursor
) {
707 Log_OC
.d(TAG
, "onLoadFinished start");
709 FileDataStorageManager storageManager
= ((FileActivity
)getSherlockActivity()).getStorageManager();
710 if (storageManager
!= null
) {
711 mCursorLoader
.setStorageManager(storageManager
);
713 mCursorLoader
.setParentId(mFile
.getFileId());
715 mCursorLoader
.setParentId(1);
717 mAdapter
.swapCursor(mCursorLoader
.loadInBackground());
720 // if(mAdapter != null && cursor != null)
721 // mAdapter.swapCursor(cursor); //swap the new cursor in.
723 // Log_OC.d(TAG,"OnLoadFinished: mAdapter is null");
725 Log_OC
.d(TAG
, "onLoadFinished end");
730 * Called when a previously created loader is being reset, thus making its data unavailable.
731 * It is being reset in order to create a new cursor to query different data.
732 * This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
733 * We need to make sure we are no longer using it.
736 public void onLoaderReset(Loader
<Cursor
> loader
) {
737 Log_OC
.d(TAG
, "onLoadReset start");
739 mAdapter
.swapCursor(null
);
741 Log_OC
.d(TAG
,"OnLoadFinished: mAdapter is null");
742 Log_OC
.d(TAG
, "onLoadReset end");