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 com
.owncloud
.android
.datamodel
.DataStorageManager
;
21 import com
.owncloud
.android
.datamodel
.OCFile
;
22 import com
.owncloud
.android
.ui
.FragmentListView
;
23 import com
.owncloud
.android
.ui
.adapter
.FileListListAdapter
;
25 import android
.app
.Activity
;
26 import android
.os
.Bundle
;
27 import android
.util
.Log
;
28 import android
.view
.LayoutInflater
;
29 import android
.view
.View
;
30 import android
.view
.ViewGroup
;
31 import android
.widget
.AdapterView
;
32 import com
.owncloud
.android
.R
;
35 * A Fragment that lists all files and folders in a given path.
37 * @author Bartek Przybylski
40 public class OCFileListFragment
extends FragmentListView
{
41 private static final String TAG
= "FileListFragment";
43 private OCFileListFragment
.ContainerActivity mContainerActivity
;
45 private OCFile mFile
= null
;
46 private FileListListAdapter mAdapter
;
53 public void onAttach(Activity activity
) {
54 super.onAttach(activity
);
56 mContainerActivity
= (ContainerActivity
) activity
;
57 } catch (ClassCastException e
) {
58 throw new ClassCastException(activity
.toString() + " must implement FileListFragment.ContainerActivity");
64 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
65 Bundle savedInstanceState
) {
66 Log
.i(getClass().toString(), "onCreateView() start");
67 super.onCreateView(inflater
, container
, savedInstanceState
);
68 getListView().setDivider(getResources().getDrawable(R
.drawable
.uploader_list_separator
));
69 getListView().setDividerHeight(1);
71 Log
.i(getClass().toString(), "onCreateView() end");
77 public void onActivityCreated(Bundle savedInstanceState
) {
78 Log
.i(getClass().toString(), "onActivityCreated() start");
80 super.onCreate(savedInstanceState
);
81 //mAdapter = new FileListListAdapter();
83 Log
.i(getClass().toString(), "onActivityCreated() stop");
88 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
89 OCFile file
= (OCFile
) mAdapter
.getItem(position
);
91 /// Click on a directory
92 if (file
.getMimetype().equals("DIR")) {
96 // any other updates are let to the container Activity
97 mContainerActivity
.onDirectoryClick(file
);
99 } else { /// Click on a file
100 mContainerActivity
.onFileClick(file
);
104 Log
.d(TAG
, "Null object in ListAdapter!!");
110 * Call this, when the user presses the up button
112 public void onNavigateUp() {
113 OCFile parentDir
= null
;
116 DataStorageManager storageManager
= mContainerActivity
.getStorageManager();
117 parentDir
= storageManager
.getFileById(mFile
.getParentId());
120 listDirectory(parentDir
);
124 * Use this to query the {@link OCFile} that is currently
125 * being displayed by this fragment
126 * @return The currently viewed OCFile
128 public OCFile
getCurrentFile(){
133 * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter
135 public void listDirectory(){
140 * Lists the given directory on the view. When the input parameter is null,
141 * it will either refresh the last known directory, or list the root
142 * if there never was a directory.
144 * @param directory File to be listed
146 public void listDirectory(OCFile directory
) {
148 DataStorageManager storageManager
= mContainerActivity
.getStorageManager();
150 // Check input parameters for null
151 if(directory
== null
){
155 directory
= storageManager
.getFileByPath("/");
156 if (directory
== null
) return; // no files, wait for sync
161 // If that's not a directory -> List its parent
162 if(!directory
.isDirectory()){
163 Log
.w(TAG
, "You see, that is not a directory -> " + directory
.toString());
164 directory
= storageManager
.getFileById(directory
.getParentId());
169 mAdapter
= new FileListListAdapter(directory
, storageManager
, getActivity());
170 setListAdapter(mAdapter
);
176 * Interface to implement by any Activity that includes some instance of FileListFragment
178 * @author David A. Velasco
180 public interface ContainerActivity
{
183 * Callback method invoked when a directory is clicked by the user on the files list
187 public void onDirectoryClick(OCFile file
);
190 * Callback method invoked when a file (non directory) is clicked by the user on the files list
194 public void onFileClick(OCFile file
);
197 * Getter for the current DataStorageManager in the container activity
199 public DataStorageManager
getStorageManager();