1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
18 package com
.owncloud
.android
.ui
.fragment
;
20 import android
.accounts
.Account
;
21 import android
.app
.Activity
;
22 import android
.support
.v4
.app
.Fragment
;
24 import com
.actionbarsherlock
.app
.SherlockFragment
;
25 import com
.owncloud
.android
.datamodel
.OCFile
;
26 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
27 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
28 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
32 * Common methods for {@link Fragment}s containing {@link OCFile}s
34 * @author David A. Velasco
37 public class FileFragment
extends SherlockFragment
{
41 protected ContainerActivity mContainerActivity
;
45 * Creates an empty fragment.
47 * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
49 public FileFragment() {
54 * Creates an instance for a given {@OCFile}.
58 public FileFragment(OCFile file
) {
63 * Getter for the hold {@link OCFile}
65 * @return The {@link OCFile} hold
67 public OCFile
getFile() {
72 protected void setFile(OCFile file
) {
81 public void onAttach(Activity activity
) {
82 super.onAttach(activity
);
84 mContainerActivity
= (ContainerActivity
) activity
;
86 } catch (ClassCastException e
) {
87 throw new ClassCastException(activity
.toString() + " must implement " + ContainerActivity
.class.getSimpleName());
96 public void onDetach() {
97 mContainerActivity
= null
;
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
106 * @author David A. Velasco
108 public interface ContainerActivity
extends ComponentsGetter
{
111 * Request the parent activity to show the details of an {@link OCFile}.
113 * @param file File to show details
115 public void showDetails(OCFile file
);
118 ///// TO UNIFY IN A SINGLE CALLBACK METHOD - EVENT NOTIFICATIONs -> something happened inside the fragment, MAYBE activity is interested --> unify in notification method
120 * Callback method invoked when a the user browsed into a different folder through the list of files
124 public void onBrowsedDownTo(OCFile folder
);
127 * Callback method invoked when a the 'transfer state' of a file changes.
129 * This happens when a download or upload is started or ended for a file.
131 * This method is necessary by now to update the user interface of the double-pane layout in tablets
132 * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
133 * won't provide the needed response before the method where this is called finishes.
135 * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
137 * @param file OCFile which state changed.
138 * @param downloading Flag signaling if the file is now downloading.
139 * @param uploading Flag signaling if the file is now uploading.
141 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
);
145 * Callback method invoked when the detail fragment wants to notice its container
146 * activity about a relevant state the file shown by the fragment.
148 * Added to notify to FileDisplayActivity about the need of refresh the files list.
150 * Currently called when:
151 * - a download is started;
152 * - a rename is completed;
153 * - a deletion is completed;
154 * - the 'inSync' flag is changed;
156 public void onFileStateChanged();