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