Update year in license
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / FileFragment.java
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
21 package com.owncloud.android.ui.fragment;
22
23 import android.accounts.Account;
24 import android.app.Activity;
25 import android.support.v4.app.Fragment;
26
27 import com.actionbarsherlock.app.SherlockFragment;
28 import com.owncloud.android.datamodel.OCFile;
29 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
30 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
31 import com.owncloud.android.ui.activity.ComponentsGetter;
32
33
34 /**
35 * Common methods for {@link Fragment}s containing {@link OCFile}s
36 */
37 public class FileFragment extends SherlockFragment {
38
39 private OCFile mFile;
40
41 protected ContainerActivity mContainerActivity;
42
43
44 /**
45 * Creates an empty fragment.
46 *
47 * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
48 */
49 public FileFragment() {
50 mFile = null;
51 }
52
53 /**
54 * Creates an instance for a given {@OCFile}.
55 *
56 * @param file
57 */
58 public FileFragment(OCFile file) {
59 mFile = file;
60 }
61
62 /**
63 * Getter for the hold {@link OCFile}
64 *
65 * @return The {@link OCFile} hold
66 */
67 public OCFile getFile() {
68 return mFile;
69 }
70
71
72 protected void setFile(OCFile file) {
73 mFile = file;
74 }
75
76
77 /**
78 * {@inheritDoc}
79 */
80 @Override
81 public void onAttach(Activity activity) {
82 super.onAttach(activity);
83 try {
84 mContainerActivity = (ContainerActivity) activity;
85
86 } catch (ClassCastException e) {
87 throw new ClassCastException(activity.toString() + " must implement " + ContainerActivity.class.getSimpleName());
88 }
89 }
90
91
92 /**
93 * {@inheritDoc}
94 */
95 @Override
96 public void onDetach() {
97 mContainerActivity = null;
98 super.onDetach();
99 }
100
101
102 /**
103 * Interface to implement by any Activity that includes some instance of FileListFragment
104 * Interface to implement by any Activity that includes some instance of FileFragment
105 */
106 public interface ContainerActivity extends ComponentsGetter {
107
108 /**
109 * Request the parent activity to show the details of an {@link OCFile}.
110 *
111 * @param file File to show details
112 */
113 public void showDetails(OCFile file);
114
115
116 ///// TO UNIFY IN A SINGLE CALLBACK METHOD - EVENT NOTIFICATIONs -> something happened inside the fragment, MAYBE activity is interested --> unify in notification method
117 /**
118 * Callback method invoked when a the user browsed into a different folder through the list of files
119 *
120 * @param file
121 */
122 public void onBrowsedDownTo(OCFile folder);
123
124 /**
125 * Callback method invoked when a the 'transfer state' of a file changes.
126 *
127 * This happens when a download or upload is started or ended for a file.
128 *
129 * This method is necessary by now to update the user interface of the double-pane layout in tablets
130 * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
131 * won't provide the needed response before the method where this is called finishes.
132 *
133 * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
134 *
135 * @param file OCFile which state changed.
136 * @param downloading Flag signaling if the file is now downloading.
137 * @param uploading Flag signaling if the file is now uploading.
138 */
139 public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading);
140
141
142 }
143
144 }