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
.Stack
;
21 import java
.util
.Vector
;
23 import android
.accounts
.Account
;
24 import android
.accounts
.AccountManager
;
25 import android
.app
.Service
;
26 import android
.content
.Intent
;
27 import android
.os
.Bundle
;
28 import android
.view
.View
;
29 import android
.widget
.AdapterView
;
30 import eu
.alefzero
.owncloud
.R
;
31 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
32 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
33 import eu
.alefzero
.owncloud
.ui
.FragmentListView
;
34 import eu
.alefzero
.owncloud
.ui
.activity
.FileDetailActivity
;
35 import eu
.alefzero
.owncloud
.ui
.activity
.FileDisplayActivity
;
36 import eu
.alefzero
.owncloud
.ui
.adapter
.FileListListAdapter
;
39 * A Fragment that lists all files and folders in a given path.
40 * @author Bartek Przybylski
43 public class FileList
extends FragmentListView
{
44 private Account mAccount
;
45 private AccountManager mAccountManager
;
46 private Stack
<String
> mDirNames
;
47 private Vector
<OCFile
> mFiles
;
50 mDirNames
= new Stack
<String
>();
54 public void onCreate(Bundle savedInstanceState
) {
55 super.onCreate(savedInstanceState
);
57 mAccountManager
= (AccountManager
)getActivity().getSystemService(Service
.ACCOUNT_SERVICE
);
58 mAccount
= mAccountManager
.getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
)[0];
63 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
64 if (mFiles
.size() <= position
) {
65 throw new IndexOutOfBoundsException("Incorrect item selected");
67 OCFile file
= mFiles
.get(position
);
68 String id_
= String
.valueOf(file
.getFileId());
69 if (file
.getMimetype().equals("DIR")) {
70 String dirname
= file
.getFileName();
72 mDirNames
.push(dirname
);
73 ((FileDisplayActivity
)getActivity()).pushPath(dirname
);
78 Intent i
= new Intent(getActivity(), FileDetailActivity
.class);
79 i
.putExtra("FILE_NAME", file
.getFileName());
80 i
.putExtra("FULL_PATH", file
.getPath());
81 i
.putExtra("FILE_ID", id_
);
82 i
.putExtra("ACCOUNT", mAccount
);
83 FileDetail fd
= (FileDetail
) getSupportFragmentManager().findFragmentById(R
.id
.fileDetail
);
91 public void onBackPressed() {
96 private void populateFileList() {
98 for (String a
: mDirNames
)
101 OCFile file
= new OCFile(getActivity().getContentResolver(), mAccount
, s
);
102 mFiles
= file
.getDirectoryContent();
103 setListAdapter(new FileListListAdapter(file
, getActivity()));