1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package eu
.alefzero
.owncloud
.ui
.fragment
;
20 import java
.util
.Vector
;
22 import android
.app
.Activity
;
23 import android
.os
.Bundle
;
24 import android
.util
.Log
;
25 import android
.view
.LayoutInflater
;
26 import android
.view
.View
;
27 import android
.view
.ViewGroup
;
28 import android
.widget
.AdapterView
;
29 import eu
.alefzero
.owncloud
.R
;
30 import eu
.alefzero
.owncloud
.datamodel
.DataStorageManager
;
31 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
32 import eu
.alefzero
.owncloud
.ui
.FragmentListView
;
33 import eu
.alefzero
.owncloud
.ui
.adapter
.FileListListAdapter
;
36 * A Fragment that lists all files and folders in a given path.
38 * @author Bartek Przybylski
41 public class FileListFragment
extends FragmentListView
{
42 private static final String TAG
= "FileListFragment";
44 private FileListFragment
.ContainerActivity mContainerActivity
;
46 private OCFile mFile
= null
;
47 private FileListListAdapter mAdapter
;
54 public void onAttach(Activity activity
) {
55 super.onAttach(activity
);
57 mContainerActivity
= (ContainerActivity
) activity
;
58 } catch (ClassCastException e
) {
59 throw new ClassCastException(activity
.toString() + " must implement FileListFragment.ContainerActivity");
65 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
66 Bundle savedInstanceState
) {
67 Log
.i(getClass().toString(), "onCreateView() start");
68 super.onCreateView(inflater
, container
, savedInstanceState
);
69 getListView().setDivider(getResources().getDrawable(R
.drawable
.uploader_list_separator
));
70 getListView().setDividerHeight(1);
72 Log
.i(getClass().toString(), "onCreateView() end");
78 public void onActivityCreated(Bundle savedInstanceState
) {
79 Log
.i(getClass().toString(), "onActivityCreated() start");
81 super.onCreate(savedInstanceState
);
82 //mAdapter = new FileListListAdapter();
84 Log
.i(getClass().toString(), "onActivityCreated() stop");
89 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
90 OCFile file
= (OCFile
) mAdapter
.getItem(position
);
92 /// Click on a directory
93 if (file
.getMimetype().equals("DIR")) {
97 // any other updates are let to the container Activity
98 mContainerActivity
.onDirectoryClick(file
);
100 } else { /// Click on a file
101 mContainerActivity
.onFileClick(file
);
105 Log
.d(TAG
, "Null object in ListAdapter!!");
111 * Call this, when the user presses the up button
113 public void onNavigateUp() {
114 OCFile parentDir
= null
;
117 DataStorageManager storageManager
= mContainerActivity
.getStorageManager();
118 parentDir
= storageManager
.getFileById(mFile
.getParentId());
121 listDirectory(parentDir
);
125 * Use this to query the {@link OCFile} that is currently
126 * being displayed by this fragment
127 * @return The currently viewed OCFile
129 public OCFile
getCurrentFile(){
134 * Calls {@link FileListFragment#listDirectory(OCFile)} with a null parameter
136 public void listDirectory(){
141 * Lists the given directory on the view. When the input parameter is null,
142 * it will either refresh the last known directory, or list the root
143 * if there never was a directory.
145 * @param directory File to be listed
147 public void listDirectory(OCFile directory
) {
149 DataStorageManager storageManager
= mContainerActivity
.getStorageManager();
151 // Check input parameters for null
152 if(directory
== null
){
156 directory
= storageManager
.getFileByPath("/");
157 if (directory
== null
) return; // no files, wait for sync
162 // If that's not a directory -> List its parent
163 if(!directory
.isDirectory()){
164 Log
.w(TAG
, "You see, that is not a directory -> " + directory
.toString());
165 directory
= storageManager
.getFileById(directory
.getParentId());
170 mAdapter
= new FileListListAdapter(directory
, storageManager
, getActivity());
171 setListAdapter(mAdapter
);
177 * Interface to implement by any Activity that includes some instance of FileListFragment
179 * @author David A. Velasco
181 public interface ContainerActivity
{
184 * Callback method invoked when a directory is clicked by the user on the files list
188 public void onDirectoryClick(OCFile file
);
191 * Callback method invoked when a file (non directory) is clicked by the user on the files list
195 public void onFileClick(OCFile file
);
198 * Getter for the current DataStorageManager in the container activity
200 public DataStorageManager
getStorageManager();