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 onCreateLoader(LOADER_ID
, null
);
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
);
173 * Call this, when the user presses the up button.
175 * Tries to move up the current folder one level. If the parent folder was removed from the database,
176 * it continues browsing up until finding an existing folders.
178 * return Count of folder levels browsed up.
180 public int onBrowseUp() {
181 OCFile parentDir
= null
;
185 FileDataStorageManager storageManager
=
186 ((FileActivity
)getSherlockActivity()).getStorageManager();
188 String parentPath
= null
;
189 if (mFile
.getParentId() != FileDataStorageManager
.ROOT_PARENT_ID
) {
190 parentPath
= new File(mFile
.getRemotePath()).getParent();
191 parentPath
= parentPath
.endsWith(OCFile
.PATH_SEPARATOR
) ? parentPath
: parentPath
+ OCFile
.PATH_SEPARATOR
;
192 parentDir
= storageManager
.getFileByPath(parentPath
);
195 parentDir
= storageManager
.getFileByPath(OCFile
.ROOT_PATH
); // never returns null; keep the path in root folder
197 while (parentDir
== null
) {
198 parentPath
= new File(parentPath
).getParent();
199 parentPath
= parentPath
.endsWith(OCFile
.PATH_SEPARATOR
) ? parentPath
: parentPath
+ OCFile
.PATH_SEPARATOR
;
200 parentDir
= storageManager
.getFileByPath(parentPath
);
202 } // exit is granted because storageManager.getFileByPath("/") never returns null
207 listDirectory(mFile
);
209 mContainerActivity
.startSyncFolderOperation(mFile
);
211 // restore index and top position
212 restoreIndexAndTopPosition();
214 } // else - should never happen now
220 * Restore index and position
222 private void restoreIndexAndTopPosition() {
223 if (mIndexes
.size() > 0) {
224 // needs to be checked; not every browse-up had a browse-down before
226 int index
= mIndexes
.remove(mIndexes
.size() - 1);
228 int firstPosition
= mFirstPositions
.remove(mFirstPositions
.size() -1);
230 int top
= mTops
.remove(mTops
.size() - 1);
232 ExtendedListView list
= (ExtendedListView
) getListView();
233 list
.setSelectionFromTop(firstPosition
, top
);
235 // Move the scroll if the selection is not visible
236 int indexPosition
= mHeightCell
*index
;
237 int height
= list
.getHeight();
239 if (indexPosition
> height
) {
240 if (android
.os
.Build
.VERSION
.SDK_INT
>= 11)
242 list
.smoothScrollToPosition(index
);
244 else if (android
.os
.Build
.VERSION
.SDK_INT
>= 8)
246 list
.setSelectionFromTop(index
, 0);
254 * Save index and top position
256 private void saveIndexAndTopPosition(int index
) {
260 ExtendedListView list
= (ExtendedListView
) getListView();
262 int firstPosition
= list
.getFirstVisiblePosition();
263 mFirstPositions
.add(firstPosition
);
265 View view
= list
.getChildAt(0);
266 int top
= (view
== null
) ?
0 : view
.getTop() ;
270 // Save the height of a cell
271 mHeightCell
= (view
== null
|| mHeightCell
!= 0) ? mHeightCell
: view
.getHeight();
275 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
276 OCFile file
= ((FileActivity
)getSherlockActivity()).getStorageManager().createFileInstance(
277 (Cursor
) mAdapter
.getItem(position
));
279 if (file
.isFolder()) {
280 // update state and view of this fragment
282 // then, notify parent activity to let it update its state and view, and other fragments
283 mContainerActivity
.onBrowsedDownTo(file
);
284 // save index and top position
285 saveIndexAndTopPosition(position
);
287 } else { /// Click on a file
288 if (PreviewImageFragment
.canBePreviewed(file
)) {
289 // preview image - it handles the download, if needed
290 mContainerActivity
.startImagePreview(file
);
292 } else if (file
.isDown()) {
293 if (PreviewMediaFragment
.canBePreviewed(file
)) {
295 mContainerActivity
.startMediaPreview(file
, 0, true
);
297 FileActivity activity
= (FileActivity
) getSherlockActivity();
298 activity
.getFileOperationsHelper().openFile(file
, activity
);
302 // automatic download, preview on finish
303 mContainerActivity
.startDownloadForPreview(file
);
309 Log_OC
.d(TAG
, "Null object in ListAdapter!!");
318 public void onCreateContextMenu (ContextMenu menu
, View v
, ContextMenu
.ContextMenuInfo menuInfo
) {
319 super.onCreateContextMenu(menu
, v
, menuInfo
);
320 MenuInflater inflater
= getSherlockActivity().getMenuInflater();
321 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
322 AdapterContextMenuInfo info
= (AdapterContextMenuInfo
) menuInfo
;
323 OCFile targetFile
= ((FileActivity
)getSherlockActivity()).getStorageManager().createFileInstance(
324 (Cursor
) mAdapter
.getItem(info
.position
));
325 List
<Integer
> toHide
= new ArrayList
<Integer
>();
326 List
<Integer
> toDisable
= new ArrayList
<Integer
>();
328 MenuItem item
= null
;
329 if (targetFile
.isFolder()) {
330 // contextual menu for folders
331 toHide
.add(R
.id
.action_open_file_with
);
332 toHide
.add(R
.id
.action_download_file
);
333 toHide
.add(R
.id
.action_cancel_download
);
334 toHide
.add(R
.id
.action_cancel_upload
);
335 toHide
.add(R
.id
.action_sync_file
);
336 toHide
.add(R
.id
.action_see_details
);
337 toHide
.add(R
.id
.action_send_file
);
338 if ( mContainerActivity
.getFileDownloaderBinder().isDownloading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
) ||
339 mContainerActivity
.getFileUploaderBinder().isUploading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
) ) {
340 toDisable
.add(R
.id
.action_rename_file
);
341 toDisable
.add(R
.id
.action_remove_file
);
346 // contextual menu for regular files
348 // new design: 'download' and 'open with' won't be available anymore in context menu
349 toHide
.add(R
.id
.action_download_file
);
350 toHide
.add(R
.id
.action_open_file_with
);
352 if (targetFile
.isDown()) {
353 toHide
.add(R
.id
.action_cancel_download
);
354 toHide
.add(R
.id
.action_cancel_upload
);
357 toHide
.add(R
.id
.action_sync_file
);
359 if ( mContainerActivity
.getFileDownloaderBinder().isDownloading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
)) {
360 toHide
.add(R
.id
.action_cancel_upload
);
361 toDisable
.add(R
.id
.action_rename_file
);
362 toDisable
.add(R
.id
.action_remove_file
);
364 } else if ( mContainerActivity
.getFileUploaderBinder().isUploading(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile
)) {
365 toHide
.add(R
.id
.action_cancel_download
);
366 toDisable
.add(R
.id
.action_rename_file
);
367 toDisable
.add(R
.id
.action_remove_file
);
370 toHide
.add(R
.id
.action_cancel_download
);
371 toHide
.add(R
.id
.action_cancel_upload
);
376 if (!targetFile
.isShareByLink()) {
377 toHide
.add(R
.id
.action_unshare_file
);
381 boolean sendEnabled
= getString(R
.string
.send_files_to_other_apps
).equalsIgnoreCase("on");
383 toHide
.add(R
.id
.action_send_file
);
386 for (int i
: toHide
) {
387 item
= menu
.findItem(i
);
389 item
.setVisible(false
);
390 item
.setEnabled(false
);
394 for (int i
: toDisable
) {
395 item
= menu
.findItem(i
);
397 item
.setEnabled(false
);
407 public boolean onContextItemSelected (MenuItem item
) {
408 AdapterContextMenuInfo info
= (AdapterContextMenuInfo
) item
.getMenuInfo();
409 mTargetFile
= ((FileActivity
)getSherlockActivity()).getStorageManager().createFileInstance(
410 (Cursor
) mAdapter
.getItem(info
.position
));
411 switch (item
.getItemId()) {
412 case R
.id
.action_share_file
: {
413 FileActivity activity
= (FileActivity
) getSherlockActivity();
414 activity
.getFileOperationsHelper().shareFileWithLink(mTargetFile
, activity
);
417 case R
.id
.action_unshare_file
: {
418 FileActivity activity
= (FileActivity
) getSherlockActivity();
419 activity
.getFileOperationsHelper().unshareFileWithLink(mTargetFile
, activity
);
422 case R
.id
.action_rename_file
: {
423 String fileName
= mTargetFile
.getFileName();
424 int extensionStart
= mTargetFile
.isFolder() ?
-1 : fileName
.lastIndexOf(".");
425 int selectionEnd
= (extensionStart
>= 0) ? extensionStart
: fileName
.length();
426 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.rename_dialog_title
), fileName
, 0, selectionEnd
, this);
427 dialog
.show(getFragmentManager(), EditNameDialog
.TAG
);
430 case R
.id
.action_remove_file
: {
431 int messageStringId
= R
.string
.confirmation_remove_alert
;
432 int posBtnStringId
= R
.string
.confirmation_remove_remote
;
433 int neuBtnStringId
= -1;
434 if (mTargetFile
.isFolder()) {
435 messageStringId
= R
.string
.confirmation_remove_folder_alert
;
436 posBtnStringId
= R
.string
.confirmation_remove_remote_and_local
;
437 neuBtnStringId
= R
.string
.confirmation_remove_folder_local
;
438 } else if (mTargetFile
.isDown()) {
439 posBtnStringId
= R
.string
.confirmation_remove_remote_and_local
;
440 neuBtnStringId
= R
.string
.confirmation_remove_local
;
442 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
444 new String
[]{mTargetFile
.getFileName()},
447 R
.string
.common_cancel
);
448 confDialog
.setOnConfirmationListener(this);
449 confDialog
.show(getFragmentManager(), FileDetailFragment
.FTAG_CONFIRMATION
);
452 case R
.id
.action_sync_file
: {
453 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity());
454 RemoteOperation operation
= new SynchronizeFileOperation(
457 ((FileActivity
)getSherlockActivity()).getStorageManager(),
460 getSherlockActivity());
461 operation
.execute(account
, getSherlockActivity(), mContainerActivity
, mHandler
, getSherlockActivity());
462 ((FileActivity
) getSherlockActivity()).showLoadingDialog();
465 case R
.id
.action_cancel_download
: {
466 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
467 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity());
468 if (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(account
, mTargetFile
)) {
469 downloaderBinder
.cancel(account
, mTargetFile
);
471 mContainerActivity
.onTransferStateChanged(mTargetFile
, false
, false
);
475 case R
.id
.action_cancel_upload
: {
476 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
477 Account account
= AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity());
478 if (uploaderBinder
!= null
&& uploaderBinder
.isUploading(account
, mTargetFile
)) {
479 uploaderBinder
.cancel(account
, mTargetFile
);
481 mContainerActivity
.onTransferStateChanged(mTargetFile
, false
, false
);
485 case R
.id
.action_see_details
: {
486 ((FileFragment
.ContainerActivity
)getSherlockActivity()).showDetails(mTargetFile
);
489 case R
.id
.action_send_file
: {
491 if (!mTargetFile
.isDown()) { // Download the file
492 Log_OC
.d(TAG
, mTargetFile
.getRemotePath() + " : File must be downloaded");
493 mContainerActivity
.startDownloadForSending(mTargetFile
);
497 FileActivity activity
= (FileActivity
) getSherlockActivity();
498 activity
.getFileOperationsHelper().sendDownloadedFile(mTargetFile
, activity
);
503 return super.onContextItemSelected(item
);
509 * Use this to query the {@link OCFile} that is currently
510 * being displayed by this fragment
511 * @return The currently viewed OCFile
513 public OCFile
getCurrentFile(){
518 * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter
520 public void listDirectory(){
525 * Lists the given directory on the view. When the input parameter is null,
526 * it will either refresh the last known directory. list the root
527 * if there never was a directory.
529 * @param directory File to be listed
531 public void listDirectory(OCFile directory
) {
532 FileDataStorageManager storageManager
= ((FileActivity
)getSherlockActivity()).getStorageManager();
533 if (storageManager
!= null
) {
535 // Check input parameters for null
536 if(directory
== null
){
540 directory
= storageManager
.getFileByPath("/");
541 if (directory
== null
) return; // no files, wait for sync
546 // If that's not a directory -> List its parent
547 if(!directory
.isFolder()){
548 Log_OC
.w(TAG
, "You see, that is not a directory -> " + directory
.toString());
549 directory
= storageManager
.getFileById(directory
.getParentId());
552 swapDirectory(directory
.getFileId(), storageManager
);
554 if (mFile
== null
|| !mFile
.equals(directory
)) {
555 ((ExtendedListView
) getListView()).setSelectionFromTop(0, 0);
563 * Change the adapted directory for a new one
564 * @param folder New file to adapt. Can be NULL, meaning "no content to adapt".
565 * @param updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
567 public void swapDirectory(long parentId
, FileDataStorageManager updatedStorageManager
) {
568 FileDataStorageManager storageManager
= null
;
569 if (updatedStorageManager
!= null
&& updatedStorageManager
!= storageManager
) {
570 storageManager
= updatedStorageManager
;
572 Cursor newCursor
= null
;
573 if (storageManager
!= null
) {
574 mAdapter
.setStorageManager(storageManager
);
575 mCursorLoader
.setParentId(parentId
);
576 mCursorLoader
.setStorageManager(storageManager
);
577 newCursor
= mCursorLoader
.loadInBackground();//storageManager.getContent(folder.getFileId());
578 Uri uri
= Uri
.withAppendedPath(
579 ProviderTableMeta
.CONTENT_URI_DIR
,
580 String
.valueOf(parentId
));
581 Log_OC
.d(TAG
, "swapDirectory Uri " + uri
);
582 //newCursor.setNotificationUri(getSherlockActivity().getContentResolver(), uri);
585 Cursor oldCursor
= mAdapter
.swapCursor(newCursor
);
586 if (oldCursor
!= null
){
589 mAdapter
.notifyDataSetChanged();
594 * Interface to implement by any Activity that includes some instance of FileListFragment
596 * @author David A. Velasco
598 public interface ContainerActivity
extends TransferServiceGetter
, OnRemoteOperationListener
{
601 * Callback method invoked when a the user browsed into a different folder through the list of files
605 public void onBrowsedDownTo(OCFile folder
);
607 public void startDownloadForPreview(OCFile file
);
609 public void startMediaPreview(OCFile file
, int i
, boolean b
);
611 public void startImagePreview(OCFile file
);
613 public void startSyncFolderOperation(OCFile folder
);
616 * Callback method invoked when a the 'transfer state' of a file changes.
618 * This happens when a download or upload is started or ended for a file.
620 * This method is necessary by now to update the user interface of the double-pane layout in tablets
621 * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
622 * won't provide the needed response before the method where this is called finishes.
624 * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
626 * @param file OCFile which state changed.
627 * @param downloading Flag signaling if the file is now downloading.
628 * @param uploading Flag signaling if the file is now uploading.
630 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
);
632 public void startDownloadForSending(OCFile file
);
638 public void onDismiss(EditNameDialog dialog
) {
639 if (dialog
.getResult()) {
640 String newFilename
= dialog
.getNewFilename();
641 Log_OC
.d(TAG
, "name edit dialog dismissed with new name " + newFilename
);
642 RemoteOperation operation
=
643 new RenameFileOperation(
645 AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()),
647 ((FileActivity
)getSherlockActivity()).getStorageManager());
648 operation
.execute(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity
, mHandler
, getSherlockActivity());
649 ((FileActivity
) getSherlockActivity()).showLoadingDialog();
655 public void onConfirmation(String callerTag
) {
656 if (callerTag
.equals(FileDetailFragment
.FTAG_CONFIRMATION
)) {
657 FileDataStorageManager storageManager
=
658 ((FileActivity
)getSherlockActivity()).getStorageManager();
659 if (storageManager
.getFileById(mTargetFile
.getFileId()) != null
) {
660 RemoteOperation operation
= new RemoveFileOperation( mTargetFile
,
663 operation
.execute(AccountUtils
.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity
, mHandler
, getSherlockActivity());
665 ((FileActivity
) getSherlockActivity()).showLoadingDialog();
671 public void onNeutral(String callerTag
) {
672 ((FileActivity
)getSherlockActivity()).getStorageManager().removeFile(mTargetFile
, false
, true
); // TODO perform in background task / new thread
674 mContainerActivity
.onTransferStateChanged(mTargetFile
, false
, false
);
678 public void onCancel(String callerTag
) {
679 Log_OC
.d(TAG
, "REMOVAL CANCELED");
683 * LoaderManager.LoaderCallbacks<Cursor>
687 * Instantiate and return a new Loader for the given ID. This is where the cursor is created.
690 public Loader
<Cursor
> onCreateLoader(int id
, Bundle bundle
) {
691 Log_OC
.d(TAG
, "onCreateLoader start");
692 mCursorLoader
= new FileListCursorLoader((FileActivity
)getSherlockActivity(),
693 ((FileActivity
)getSherlockActivity()).getStorageManager());
695 mCursorLoader
.setParentId(mFile
.getFileId());
697 mCursorLoader
.setParentId(1);
699 Log_OC
.d(TAG
, "onCreateLoader end");
700 return mCursorLoader
;
705 * Called when a previously created loader has finished its load. Here, you can start using the cursor.
708 public void onLoadFinished(Loader
<Cursor
> loader
, Cursor cursor
) {
709 Log_OC
.d(TAG
, "onLoadFinished start");
711 FileDataStorageManager storageManager
= ((FileActivity
)getSherlockActivity()).getStorageManager();
712 if (storageManager
!= null
) {
713 mCursorLoader
.setStorageManager(storageManager
);
715 mCursorLoader
.setParentId(mFile
.getFileId());
717 mCursorLoader
.setParentId(1);
719 mAdapter
.swapCursor(mCursorLoader
.loadInBackground());
722 // if(mAdapter != null && cursor != null)
723 // mAdapter.swapCursor(cursor); //swap the new cursor in.
725 // Log_OC.d(TAG,"OnLoadFinished: mAdapter is null");
727 Log_OC
.d(TAG
, "onLoadFinished end");
732 * Called when a previously created loader is being reset, thus making its data unavailable.
733 * It is being reset in order to create a new cursor to query different data.
734 * This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
735 * We need to make sure we are no longer using it.
738 public void onLoaderReset(Loader
<Cursor
> loader
) {
739 Log_OC
.d(TAG
, "onLoadReset start");
741 mAdapter
.swapCursor(null
);
743 Log_OC
.d(TAG
,"OnLoadFinished: mAdapter is null");
744 Log_OC
.d(TAG
, "onLoadReset end");