Revert "Grant that the content of the previous adapter is updated with rotations"
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / OCFileListFragment.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2014 ownCloud Inc.
4 *
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.
8 *
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.
13 *
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/>.
16 *
17 */
18 package com.owncloud.android.ui.fragment;
19
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.List;
23
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.ui.ExtendedListView;
33 import com.owncloud.android.ui.adapter.FileListListAdapter;
34 import com.owncloud.android.ui.activity.FileDisplayActivity;
35 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
36 import com.owncloud.android.ui.dialog.EditNameDialog;
37 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
38 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
39 import com.owncloud.android.ui.preview.PreviewImageFragment;
40 import com.owncloud.android.ui.preview.PreviewMediaFragment;
41 import com.owncloud.android.utils.Log_OC;
42
43 import android.accounts.Account;
44 import android.app.Activity;
45 import android.database.Cursor;
46 import android.net.Uri;
47 import android.os.Bundle;
48 import android.support.v4.app.LoaderManager;
49 import android.support.v4.app.LoaderManager.LoaderCallbacks;
50 import android.support.v4.content.Loader;
51 import android.view.ContextMenu;
52 import android.view.MenuInflater;
53 import android.view.MenuItem;
54 import android.view.View;
55 import android.widget.AdapterView;
56 import android.widget.AdapterView.AdapterContextMenuInfo;
57
58 /**
59 * A Fragment that lists all files and folders in a given path.
60 *
61 * TODO refactorize to get rid of direct dependency on FileDisplayActivity
62 *
63 * @author Bartek Przybylski
64 * @author masensio
65 * @author David A. Velasco
66 */
67 public class OCFileListFragment extends ExtendedListFragment
68 implements EditNameDialogListener, ConfirmationDialogFragmentListener,
69 LoaderCallbacks<Cursor>{
70
71 private static final String TAG = OCFileListFragment.class.getSimpleName();
72
73 private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ? OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
74 private static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
75
76 private static final String KEY_INDEXES = "INDEXES";
77 private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS";
78 private static final String KEY_TOPS = "TOPS";
79 private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL";
80
81 private static final int LOADER_ID = 0;
82
83 private FileFragment.ContainerActivity mContainerActivity;
84
85 private OCFile mFile = null;
86 private FileListListAdapter mAdapter;
87 private LoaderManager mLoaderManager;
88 private FileListCursorLoader mCursorLoader;
89
90 private OCFile mTargetFile;
91
92 // Save the state of the scroll in browsing
93 private ArrayList<Integer> mIndexes;
94 private ArrayList<Integer> mFirstPositions;
95 private ArrayList<Integer> mTops;
96
97 private int mHeightCell = 0;
98
99 /**
100 * {@inheritDoc}
101 */
102 @Override
103 public void onAttach(Activity activity) {
104 super.onAttach(activity);
105 Log_OC.e(TAG, "onAttach");
106 try {
107 mContainerActivity = (FileFragment.ContainerActivity) activity;
108 } catch (ClassCastException e) {
109 throw new ClassCastException(activity.toString() + " must implement " +
110 FileFragment.ContainerActivity.class.getSimpleName());
111 }
112 }
113
114
115 @Override
116 public void onDetach() {
117 mContainerActivity = null;
118 super.onDetach();
119 }
120
121 /**
122 * {@inheritDoc}
123 */
124 @Override
125 public void onActivityCreated(Bundle savedInstanceState) {
126 super.onActivityCreated(savedInstanceState);
127 Log_OC.e(TAG, "onActivityCreated() start");
128
129 mAdapter = new FileListListAdapter(getSherlockActivity(), mContainerActivity);
130 mLoaderManager = getLoaderManager();
131
132 if (savedInstanceState != null) {
133 mFile = savedInstanceState.getParcelable(EXTRA_FILE);
134 mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES);
135 mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS);
136 mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS);
137 mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL);
138
139 } else {
140 mIndexes = new ArrayList<Integer>();
141 mFirstPositions = new ArrayList<Integer>();
142 mTops = new ArrayList<Integer>();
143 mHeightCell = 0;
144
145 }
146
147 // Initialize loaderManager and makes it active
148 mLoaderManager.initLoader(LOADER_ID, null, this);
149
150 setListAdapter(mAdapter);
151
152 registerForContextMenu(getListView());
153 getListView().setOnCreateContextMenuListener(this);
154
155 }
156
157 /**
158 * Saves the current listed folder.
159 */
160 @Override
161 public void onSaveInstanceState (Bundle outState) {
162 super.onSaveInstanceState(outState);
163 outState.putParcelable(EXTRA_FILE, mFile);
164 outState.putIntegerArrayList(KEY_INDEXES, mIndexes);
165 outState.putIntegerArrayList(KEY_FIRST_POSITIONS, mFirstPositions);
166 outState.putIntegerArrayList(KEY_TOPS, mTops);
167 outState.putInt(KEY_HEIGHT_CELL, mHeightCell);
168 }
169
170 /**
171 * Call this, when the user presses the up button.
172 *
173 * Tries to move up the current folder one level. If the parent folder was removed from the database,
174 * it continues browsing up until finding an existing folders.
175 *
176 * return Count of folder levels browsed up.
177 */
178 public int onBrowseUp() {
179 OCFile parentDir = null;
180 int moveCount = 0;
181
182 if(mFile != null){
183 FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
184
185 String parentPath = null;
186 if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
187 parentPath = new File(mFile.getRemotePath()).getParent();
188 parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
189 parentDir = storageManager.getFileByPath(parentPath);
190 moveCount++;
191 } else {
192 parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH); // never returns null; keep the path in root folder
193 }
194 while (parentDir == null) {
195 parentPath = new File(parentPath).getParent();
196 parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
197 parentDir = storageManager.getFileByPath(parentPath);
198 moveCount++;
199 } // exit is granted because storageManager.getFileByPath("/") never returns null
200 mFile = parentDir;
201 }
202
203 if (mFile != null) {
204 listDirectory(mFile);
205
206 ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile);
207
208 // restore index and top position
209 restoreIndexAndTopPosition();
210
211 } // else - should never happen now
212
213 return moveCount;
214 }
215
216 /*
217 * Restore index and position
218 */
219 private void restoreIndexAndTopPosition() {
220 if (mIndexes.size() > 0) {
221 // needs to be checked; not every browse-up had a browse-down before
222
223 int index = mIndexes.remove(mIndexes.size() - 1);
224
225 int firstPosition = mFirstPositions.remove(mFirstPositions.size() -1);
226
227 int top = mTops.remove(mTops.size() - 1);
228
229 ExtendedListView list = (ExtendedListView) getListView();
230 list.setSelectionFromTop(firstPosition, top);
231
232 // Move the scroll if the selection is not visible
233 int indexPosition = mHeightCell*index;
234 int height = list.getHeight();
235
236 if (indexPosition > height) {
237 if (android.os.Build.VERSION.SDK_INT >= 11)
238 {
239 list.smoothScrollToPosition(index);
240 }
241 else if (android.os.Build.VERSION.SDK_INT >= 8)
242 {
243 list.setSelectionFromTop(index, 0);
244 }
245
246 }
247 }
248 }
249
250 /*
251 * Save index and top position
252 */
253 private void saveIndexAndTopPosition(int index) {
254
255 mIndexes.add(index);
256
257 ExtendedListView list = (ExtendedListView) getListView();
258
259 int firstPosition = list.getFirstVisiblePosition();
260 mFirstPositions.add(firstPosition);
261
262 View view = list.getChildAt(0);
263 int top = (view == null) ? 0 : view.getTop() ;
264
265 mTops.add(top);
266
267 // Save the height of a cell
268 mHeightCell = (view == null || mHeightCell != 0) ? mHeightCell : view.getHeight();
269 }
270
271 @Override
272 public void onItemClick(AdapterView<?> l, View v, int position, long id) {
273 OCFile file = mContainerActivity.getStorageManager().createFileInstance(
274 (Cursor) mAdapter.getItem(position));
275 if (file != null) {
276 if (file.isFolder()) {
277 // update state and view of this fragment
278 listDirectory(file);
279 // then, notify parent activity to let it update its state and view, and other fragments
280 mContainerActivity.onBrowsedDownTo(file);
281 // save index and top position
282 saveIndexAndTopPosition(position);
283
284 } else { /// Click on a file
285 if (PreviewImageFragment.canBePreviewed(file)) {
286 // preview image - it handles the download, if needed
287 ((FileDisplayActivity)mContainerActivity).startImagePreview(file);
288
289 } else if (file.isDown()) {
290 if (PreviewMediaFragment.canBePreviewed(file)) {
291 // media preview
292 ((FileDisplayActivity)mContainerActivity).startMediaPreview(file, 0, true);
293 } else {
294 ((FileDisplayActivity)mContainerActivity).getFileOperationsHelper().openFile(file);
295 }
296
297 } else {
298 // automatic download, preview on finish
299 ((FileDisplayActivity)mContainerActivity).startDownloadForPreview(file);
300 }
301
302 }
303
304 } else {
305 Log_OC.d(TAG, "Null object in ListAdapter!!");
306 }
307
308 }
309
310 /**
311 * {@inheritDoc}
312 */
313 @Override
314 public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
315 super.onCreateContextMenu(menu, v, menuInfo);
316 MenuInflater inflater = getSherlockActivity().getMenuInflater();
317 inflater.inflate(R.menu.file_actions_menu, menu);
318 AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
319 OCFile targetFile = mContainerActivity.getStorageManager().createFileInstance(
320 (Cursor) mAdapter.getItem(info.position));
321 List<Integer> toHide = new ArrayList<Integer>();
322 List<Integer> toDisable = new ArrayList<Integer>();
323
324 MenuItem item = null;
325 if (targetFile.isFolder()) {
326 // contextual menu for folders
327 toHide.add(R.id.action_open_file_with);
328 toHide.add(R.id.action_download_file);
329 toHide.add(R.id.action_cancel_download);
330 toHide.add(R.id.action_cancel_upload);
331 toHide.add(R.id.action_sync_file);
332 toHide.add(R.id.action_see_details);
333 toHide.add(R.id.action_send_file);
334 if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile) ||
335 mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile) ) {
336 toDisable.add(R.id.action_rename_file);
337 toDisable.add(R.id.action_remove_file);
338
339 }
340
341 } else {
342 // contextual menu for regular files
343
344 // new design: 'download' and 'open with' won't be available anymore in context menu
345 toHide.add(R.id.action_download_file);
346 toHide.add(R.id.action_open_file_with);
347
348 if (targetFile.isDown()) {
349 toHide.add(R.id.action_cancel_download);
350 toHide.add(R.id.action_cancel_upload);
351
352 } else {
353 toHide.add(R.id.action_sync_file);
354 }
355 if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile)) {
356 toHide.add(R.id.action_cancel_upload);
357 toDisable.add(R.id.action_rename_file);
358 toDisable.add(R.id.action_remove_file);
359
360 } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile)) {
361 toHide.add(R.id.action_cancel_download);
362 toDisable.add(R.id.action_rename_file);
363 toDisable.add(R.id.action_remove_file);
364
365 } else {
366 toHide.add(R.id.action_cancel_download);
367 toHide.add(R.id.action_cancel_upload);
368 }
369 }
370
371 // Options shareLink
372 if (!targetFile.isShareByLink()) {
373 toHide.add(R.id.action_unshare_file);
374 }
375
376 // Send file
377 boolean sendEnabled = getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on");
378 if (!sendEnabled) {
379 toHide.add(R.id.action_send_file);
380 }
381
382 for (int i : toHide) {
383 item = menu.findItem(i);
384 if (item != null) {
385 item.setVisible(false);
386 item.setEnabled(false);
387 }
388 }
389
390 for (int i : toDisable) {
391 item = menu.findItem(i);
392 if (item != null) {
393 item.setEnabled(false);
394 }
395 }
396 }
397
398
399 /**
400 * {@inhericDoc}
401 */
402 @Override
403 public boolean onContextItemSelected (MenuItem item) {
404 AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
405 mTargetFile = mContainerActivity.getStorageManager().createFileInstance(
406 (Cursor) mAdapter.getItem(info.position));
407 switch (item.getItemId()) {
408 case R.id.action_share_file: {
409 mContainerActivity.getFileOperationsHelper().shareFileWithLink(mTargetFile);
410 return true;
411 }
412 case R.id.action_unshare_file: {
413 mContainerActivity.getFileOperationsHelper().unshareFileWithLink(mTargetFile);
414 return true;
415 }
416 case R.id.action_rename_file: {
417 String fileName = mTargetFile.getFileName();
418 int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf(".");
419 int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
420 EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
421 dialog.show(getFragmentManager(), EditNameDialog.TAG);
422 return true;
423 }
424 case R.id.action_remove_file: {
425 int messageStringId = R.string.confirmation_remove_alert;
426 int posBtnStringId = R.string.confirmation_remove_remote;
427 int neuBtnStringId = -1;
428 if (mTargetFile.isFolder()) {
429 messageStringId = R.string.confirmation_remove_folder_alert;
430 posBtnStringId = R.string.confirmation_remove_remote_and_local;
431 neuBtnStringId = R.string.confirmation_remove_folder_local;
432 } else if (mTargetFile.isDown()) {
433 posBtnStringId = R.string.confirmation_remove_remote_and_local;
434 neuBtnStringId = R.string.confirmation_remove_local;
435 }
436 ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
437 messageStringId,
438 new String[]{mTargetFile.getFileName()},
439 posBtnStringId,
440 neuBtnStringId,
441 R.string.common_cancel);
442 confDialog.setOnConfirmationListener(this);
443 confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION);
444 return true;
445 }
446 case R.id.action_sync_file: {
447 mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile);
448 return true;
449 }
450 case R.id.action_cancel_download: {
451 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
452 Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
453 if (downloaderBinder != null && downloaderBinder.isDownloading(account, mTargetFile)) {
454 downloaderBinder.cancel(account, mTargetFile);
455 listDirectory();
456 mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
457 }
458 return true;
459 }
460 case R.id.action_cancel_upload: {
461 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
462 Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
463 if (uploaderBinder != null && uploaderBinder.isUploading(account, mTargetFile)) {
464 uploaderBinder.cancel(account, mTargetFile);
465 listDirectory();
466 mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
467 }
468 return true;
469 }
470 case R.id.action_see_details: {
471 mContainerActivity.showDetails(mTargetFile);
472 return true;
473 }
474 case R.id.action_send_file: {
475 // Obtain the file
476 if (!mTargetFile.isDown()) { // Download the file
477 Log_OC.d(TAG, mTargetFile.getRemotePath() + " : File must be downloaded");
478 ((FileDisplayActivity)mContainerActivity).startDownloadForSending(mTargetFile);
479
480 } else {
481 ((FileDisplayActivity)mContainerActivity).getFileOperationsHelper().sendDownloadedFile(mTargetFile);
482 }
483 return true;
484 }
485 default:
486 return super.onContextItemSelected(item);
487 }
488 }
489
490
491 /**
492 * Use this to query the {@link OCFile} that is currently
493 * being displayed by this fragment
494 * @return The currently viewed OCFile
495 */
496 public OCFile getCurrentFile(){
497 return mFile;
498 }
499
500 /**
501 * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter
502 */
503 public void listDirectory(){
504 listDirectory(null);
505 }
506
507 /**
508 * Lists the given directory on the view. When the input parameter is null,
509 * it will either refresh the last known directory. list the root
510 * if there never was a directory.
511 *
512 * @param directory File to be listed
513 */
514 public void listDirectory(OCFile directory) {
515 FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
516 if (storageManager != null) {
517
518 // Check input parameters for null
519 if(directory == null){
520 if(mFile != null){
521 directory = mFile;
522 } else {
523 directory = storageManager.getFileByPath("/");
524 if (directory == null) return; // no files, wait for sync
525 }
526 }
527
528
529 // If that's not a directory -> List its parent
530 if(!directory.isFolder()){
531 Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString());
532 directory = storageManager.getFileById(directory.getParentId());
533 }
534
535 swapDirectory(directory.getFileId(), storageManager);
536
537 if (mFile == null || !mFile.equals(directory)) {
538 ((ExtendedListView) getListView()).setSelectionFromTop(0, 0);
539 }
540 mFile = directory;
541 }
542 }
543
544
545 /**
546 * Change the adapted directory for a new one
547 * @param folder New file to adapt. Can be NULL, meaning "no content to adapt".
548 * @param updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
549 */
550 public void swapDirectory(long parentId, FileDataStorageManager updatedStorageManager) {
551 FileDataStorageManager storageManager = null;
552 if (updatedStorageManager != null && updatedStorageManager != storageManager) {
553 storageManager = updatedStorageManager;
554 }
555 Cursor newCursor = null;
556 if (storageManager != null) {
557 mAdapter.setStorageManager(storageManager);
558 mCursorLoader.setParentId(parentId);
559 newCursor = mCursorLoader.loadInBackground();//storageManager.getContent(folder.getFileId());
560 Uri uri = Uri.withAppendedPath(
561 ProviderTableMeta.CONTENT_URI_DIR,
562 String.valueOf(parentId));
563 Log_OC.d(TAG, "swapDirectory Uri " + uri);
564 //newCursor.setNotificationUri(getSherlockActivity().getContentResolver(), uri);
565
566 }
567 Cursor oldCursor = mAdapter.swapCursor(newCursor);
568 if (oldCursor != null){
569 oldCursor.close();
570 }
571 mAdapter.notifyDataSetChanged();
572 }
573
574
575 @Override
576 public void onDismiss(EditNameDialog dialog) {
577 if (dialog.getResult()) {
578 String newFilename = dialog.getNewFilename();
579 Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
580 mContainerActivity.getFileOperationsHelper().renameFile(mTargetFile, newFilename);
581 }
582 }
583
584
585 @Override
586 public void onConfirmation(String callerTag) {
587 if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) {
588 FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
589 if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
590 mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, true);
591 }
592 }
593 }
594
595 @Override
596 public void onNeutral(String callerTag) {
597 mContainerActivity.getStorageManager().removeFile(mTargetFile, false, true); // TODO perform in background task / new thread
598 listDirectory();
599 mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
600 }
601
602 @Override
603 public void onCancel(String callerTag) {
604 Log_OC.d(TAG, "REMOVAL CANCELED");
605 }
606
607 /***
608 * LoaderManager.LoaderCallbacks<Cursor>
609 */
610
611 /**
612 * Instantiate and return a new Loader for the given ID. This is where the cursor is created.
613 */
614 @Override
615 public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
616 Log_OC.d(TAG, "onCreateLoader start");
617 mCursorLoader = new FileListCursorLoader(
618 getSherlockActivity(),
619 mContainerActivity.getStorageManager());
620 if (mFile != null) {
621 mCursorLoader.setParentId(mFile.getFileId());
622 } else {
623 mCursorLoader.setParentId(1);
624 }
625 Log_OC.d(TAG, "onCreateLoader end");
626 return mCursorLoader;
627 }
628
629
630 /**
631 * Called when a previously created loader has finished its load. Here, you can start using the cursor.
632 */
633 @Override
634 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
635 Log_OC.d(TAG, "onLoadFinished start");
636
637 FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
638 if (storageManager != null) {
639 mCursorLoader.setStorageManager(storageManager);
640 if (mFile != null) {
641 mCursorLoader.setParentId(mFile.getFileId());
642 } else {
643 mCursorLoader.setParentId(1);
644 }
645 mAdapter.swapCursor(mCursorLoader.loadInBackground());
646 }
647
648 // if(mAdapter != null && cursor != null)
649 // mAdapter.swapCursor(cursor); //swap the new cursor in.
650 // else
651 // Log_OC.d(TAG,"OnLoadFinished: mAdapter is null");
652
653 Log_OC.d(TAG, "onLoadFinished end");
654 }
655
656
657 /**
658 * Called when a previously created loader is being reset, thus making its data unavailable.
659 * It is being reset in order to create a new cursor to query different data.
660 * This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
661 * We need to make sure we are no longer using it.
662 */
663 @Override
664 public void onLoaderReset(Loader<Cursor> loader) {
665 Log_OC.d(TAG, "onLoadReset start");
666 if(mAdapter != null)
667 mAdapter.swapCursor(null);
668 else
669 Log_OC.d(TAG,"OnLoadFinished: mAdapter is null");
670 Log_OC.d(TAG, "onLoadReset end");
671 }
672
673
674 }