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 com
.owncloud
.android
.ui
.fragment
;
20 import java
.util
.Vector
;
22 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
23 import com
.owncloud
.android
.datamodel
.OCFile
;
24 import com
.owncloud
.android
.ui
.FragmentListView
;
25 import com
.owncloud
.android
.ui
.adapter
.FileListListAdapter
;
27 import android
.app
.Activity
;
28 import android
.os
.Bundle
;
29 import android
.util
.Log
;
30 import android
.view
.LayoutInflater
;
31 import android
.view
.View
;
32 import android
.view
.ViewGroup
;
33 import android
.widget
.AdapterView
;
34 import com
.owncloud
.android
.R
;
37 * A Fragment that lists all files and folders in a given path.
39 * @author Bartek Przybylski
42 public class FileListFragment
extends FragmentListView
{
43 private static final String TAG
= "FileListFragment";
45 private FileListFragment
.ContainerActivity mContainerActivity
;
47 private OCFile mFile
= null
;
48 private FileListListAdapter mAdapter
;
55 public void onAttach(Activity activity
) {
56 super.onAttach(activity
);
58 mContainerActivity
= (ContainerActivity
) activity
;
59 } catch (ClassCastException e
) {
60 throw new ClassCastException(activity
.toString() + " must implement FileListFragment.ContainerActivity");
66 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
67 Bundle savedInstanceState
) {
68 Log
.i(getClass().toString(), "onCreateView() start");
69 super.onCreateView(inflater
, container
, savedInstanceState
);
70 getListView().setDivider(getResources().getDrawable(R
.drawable
.uploader_list_separator
));
71 getListView().setDividerHeight(1);
73 Log
.i(getClass().toString(), "onCreateView() end");
79 public void onActivityCreated(Bundle savedInstanceState
) {
80 Log
.i(getClass().toString(), "onActivityCreated() start");
82 super.onCreate(savedInstanceState
);
83 //mAdapter = new FileListListAdapter();
85 Log
.i(getClass().toString(), "onActivityCreated() stop");
90 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
91 OCFile file
= (OCFile
) mAdapter
.getItem(position
);
93 /// Click on a directory
94 if (file
.getMimetype().equals("DIR")) {
98 // any other updates are let to the container Activity
99 mContainerActivity
.onDirectoryClick(file
);
101 } else { /// Click on a file
102 mContainerActivity
.onFileClick(file
);
106 Log
.d(TAG
, "Null object in ListAdapter!!");
112 * Call this, when the user presses the up button
114 public void onNavigateUp() {
115 OCFile parentDir
= null
;
118 DataStorageManager storageManager
= mContainerActivity
.getStorageManager();
119 parentDir
= storageManager
.getFileById(mFile
.getParentId());
122 listDirectory(parentDir
);
126 * Use this to query the {@link OCFile} that is currently
127 * being displayed by this fragment
128 * @return The currently viewed OCFile
130 public OCFile
getCurrentFile(){
135 * Calls {@link FileListFragment#listDirectory(OCFile)} with a null parameter
137 public void listDirectory(){
142 * Lists the given directory on the view. When the input parameter is null,
143 * it will either refresh the last known directory, or list the root
144 * if there never was a directory.
146 * @param directory File to be listed
148 public void listDirectory(OCFile directory
) {
150 DataStorageManager storageManager
= mContainerActivity
.getStorageManager();
152 // Check input parameters for null
153 if(directory
== null
){
157 directory
= storageManager
.getFileByPath("/");
158 if (directory
== null
) return; // no files, wait for sync
163 // If that's not a directory -> List its parent
164 if(!directory
.isDirectory()){
165 Log
.w(TAG
, "You see, that is not a directory -> " + directory
.toString());
166 directory
= storageManager
.getFileById(directory
.getParentId());
171 mAdapter
= new FileListListAdapter(directory
, storageManager
, getActivity());
172 setListAdapter(mAdapter
);
178 * Interface to implement by any Activity that includes some instance of FileListFragment
180 * @author David A. Velasco
182 public interface ContainerActivity
{
185 * Callback method invoked when a directory is clicked by the user on the files list
189 public void onDirectoryClick(OCFile file
);
192 * Callback method invoked when a file (non directory) is clicked by the user on the files list
196 public void onFileClick(OCFile file
);
199 * Getter for the current DataStorageManager in the container activity
201 public DataStorageManager
getStorageManager();