FileFragment.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* ownCloud Android client application
  2. * Copyright (C) 2012-2013 ownCloud Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. package com.owncloud.android.ui.fragment;
  18. import android.accounts.Account;
  19. import android.app.Activity;
  20. import android.support.v4.app.Fragment;
  21. import com.actionbarsherlock.app.SherlockFragment;
  22. import com.owncloud.android.datamodel.OCFile;
  23. import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
  24. import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
  25. import com.owncloud.android.ui.activity.ComponentsGetter;
  26. /**
  27. * Common methods for {@link Fragment}s containing {@link OCFile}s
  28. *
  29. * @author David A. Velasco
  30. *
  31. */
  32. public class FileFragment extends SherlockFragment {
  33. private OCFile mFile;
  34. protected ContainerActivity mContainerActivity;
  35. /**
  36. * Creates an empty fragment.
  37. *
  38. * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
  39. */
  40. public FileFragment() {
  41. mFile = null;
  42. }
  43. /**
  44. * Creates an instance for a given {@OCFile}.
  45. *
  46. * @param file
  47. */
  48. public FileFragment(OCFile file) {
  49. mFile = file;
  50. }
  51. /**
  52. * Getter for the hold {@link OCFile}
  53. *
  54. * @return The {@link OCFile} hold
  55. */
  56. public OCFile getFile() {
  57. return mFile;
  58. }
  59. protected void setFile(OCFile file) {
  60. mFile = file;
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. @Override
  66. public void onAttach(Activity activity) {
  67. super.onAttach(activity);
  68. try {
  69. mContainerActivity = (ContainerActivity) activity;
  70. } catch (ClassCastException e) {
  71. throw new ClassCastException(activity.toString() + " must implement " + ContainerActivity.class.getSimpleName());
  72. }
  73. }
  74. /**
  75. * {@inheritDoc}
  76. */
  77. @Override
  78. public void onDetach() {
  79. mContainerActivity = null;
  80. super.onDetach();
  81. }
  82. /**
  83. * Interface to implement by any Activity that includes some instance of FileListFragment
  84. * Interface to implement by any Activity that includes some instance of FileFragment
  85. *
  86. * @author David A. Velasco
  87. */
  88. public interface ContainerActivity extends ComponentsGetter {
  89. /**
  90. * Request the parent activity to show the details of an {@link OCFile}.
  91. *
  92. * @param file File to show details
  93. */
  94. public void showDetails(OCFile file);
  95. ///// TO UNIFY IN A SINGLE CALLBACK METHOD - EVENT NOTIFICATIONs -> something happened inside the fragment, MAYBE activity is interested --> unify in notification method
  96. /**
  97. * Callback method invoked when a the user browsed into a different folder through the list of files
  98. *
  99. * @param file
  100. */
  101. public void onBrowsedDownTo(OCFile folder);
  102. /**
  103. * Callback method invoked when a the 'transfer state' of a file changes.
  104. *
  105. * This happens when a download or upload is started or ended for a file.
  106. *
  107. * This method is necessary by now to update the user interface of the double-pane layout in tablets
  108. * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
  109. * won't provide the needed response before the method where this is called finishes.
  110. *
  111. * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
  112. *
  113. * @param file OCFile which state changed.
  114. * @param downloading Flag signaling if the file is now downloading.
  115. * @param uploading Flag signaling if the file is now uploading.
  116. */
  117. public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading);
  118. }
  119. }