FileFragment.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2015 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.ui.fragment;
  21. import android.accounts.Account;
  22. import android.app.Activity;
  23. import android.support.v4.app.Fragment;
  24. import com.owncloud.android.datamodel.OCFile;
  25. import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
  26. import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
  27. import com.owncloud.android.ui.activity.ComponentsGetter;
  28. /**
  29. * Common methods for {@link Fragment}s containing {@link OCFile}s
  30. */
  31. public class FileFragment extends Fragment {
  32. private OCFile mFile;
  33. protected ContainerActivity mContainerActivity;
  34. /**
  35. * Creates an empty fragment.
  36. *
  37. * It's necessary to keep a public constructor without parameters; the system uses it when
  38. * 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 " +
  72. ContainerActivity.class.getSimpleName());
  73. }
  74. }
  75. /**
  76. * {@inheritDoc}
  77. */
  78. @Override
  79. public void onDetach() {
  80. mContainerActivity = null;
  81. super.onDetach();
  82. }
  83. /**
  84. * Interface to implement by any Activity that includes some instance of FileListFragment
  85. * Interface to implement by any Activity that includes some instance of FileFragment
  86. */
  87. public interface ContainerActivity extends ComponentsGetter {
  88. /**
  89. * Request the parent activity to show the details of an {@link OCFile}.
  90. *
  91. * @param file File to show details
  92. */
  93. public void showDetails(OCFile file);
  94. ///// TO UNIFY IN A SINGLE CALLBACK METHOD - EVENT NOTIFICATIONs -> something happened
  95. // 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
  98. * list of files
  99. *
  100. * @param folder
  101. */
  102. public void onBrowsedDownTo(OCFile folder);
  103. /**
  104. * Callback method invoked when a the 'transfer state' of a file changes.
  105. *
  106. * This happens when a download or upload is started or ended for a file.
  107. *
  108. * This method is necessary by now to update the user interface of the double-pane layout
  109. * in tablets because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)}
  110. * and {@link FileUploaderBinder#isUploading(Account, OCFile)}
  111. * won't provide the needed response before the method where this is called finishes.
  112. *
  113. * TODO Remove this when the transfer state of a file is kept in the database
  114. * (other thing TODO)
  115. *
  116. * @param file OCFile which state changed.
  117. * @param downloading Flag signaling if the file is now downloading.
  118. * @param uploading Flag signaling if the file is now uploading.
  119. */
  120. public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading);
  121. /**
  122. * Request the parent activity to show the view for sharing an {@link OCFile}.
  123. *
  124. * @param file File to share
  125. */
  126. public void showShareFile(OCFile file);
  127. }
  128. }