1 /* ownCloud Android client application
3 * @author David A. Velasco
4 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
20 package com
.owncloud
.android
.ui
.fragment
;
22 import android
.accounts
.Account
;
23 import android
.app
.Activity
;
24 import android
.support
.v4
.app
.Fragment
;
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
;
34 * Common methods for {@link Fragment}s containing {@link OCFile}s
36 public class FileFragment
extends SherlockFragment
{
40 protected ContainerActivity mContainerActivity
;
44 * Creates an empty fragment.
46 * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
48 public FileFragment() {
53 * Creates an instance for a given {@OCFile}.
57 public FileFragment(OCFile file
) {
62 * Getter for the hold {@link OCFile}
64 * @return The {@link OCFile} hold
66 public OCFile
getFile() {
71 protected void setFile(OCFile file
) {
80 public void onAttach(Activity activity
) {
81 super.onAttach(activity
);
83 mContainerActivity
= (ContainerActivity
) activity
;
85 } catch (ClassCastException e
) {
86 throw new ClassCastException(activity
.toString() + " must implement " + ContainerActivity
.class.getSimpleName());
95 public void onDetach() {
96 mContainerActivity
= null
;
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
105 public interface ContainerActivity
extends ComponentsGetter
{
108 * Request the parent activity to show the details of an {@link OCFile}.
110 * @param file File to show details
112 public void showDetails(OCFile file
);
115 ///// TO UNIFY IN A SINGLE CALLBACK METHOD - EVENT NOTIFICATIONs -> something happened inside the fragment, MAYBE activity is interested --> unify in notification method
117 * Callback method invoked when a the user browsed into a different folder through the list of files
121 public void onBrowsedDownTo(OCFile folder
);
124 * Callback method invoked when a the 'transfer state' of a file changes.
126 * This happens when a download or upload is started or ended for a file.
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.
132 * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
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.
138 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
);