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
;
22 import android
.accounts
.Account
;
23 import android
.accounts
.AccountManager
;
24 import android
.app
.FragmentManager
;
25 import android
.app
.Service
;
26 import android
.content
.Intent
;
27 import android
.database
.Cursor
;
28 import android
.net
.Uri
;
29 import android
.os
.Bundle
;
30 import android
.support
.v4
.app
.FragmentTransaction
;
31 import android
.util
.Log
;
32 import android
.view
.LayoutInflater
;
33 import android
.view
.View
;
34 import android
.view
.ViewGroup
;
35 import android
.widget
.AdapterView
;
36 import android
.widget
.TextView
;
37 import eu
.alefzero
.owncloud
.R
;
38 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
39 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
40 import eu
.alefzero
.owncloud
.ui
.FragmentListView
;
41 import eu
.alefzero
.owncloud
.ui
.activity
.FileDetailActivity
;
42 import eu
.alefzero
.owncloud
.ui
.activity
.FileDisplayActivity
;
43 import eu
.alefzero
.owncloud
.ui
.adapter
.FileListListAdapter
;
46 * A Fragment that lists all files and folders in a given path.
47 * @author Bartek Przybylski
50 public class FileList
extends FragmentListView
{
51 private Cursor mCursor
;
52 private Account mAccount
;
53 private AccountManager mAccountManager
;
54 private Stack
<String
> mDirNames
;
55 private Stack
<String
> mParentsIds
;
58 mDirNames
= new Stack
<String
>();
59 mParentsIds
= new Stack
<String
>();
63 public void onCreate(Bundle savedInstanceState
) {
64 super.onCreate(savedInstanceState
);
66 mAccountManager
= (AccountManager
)getActivity().getSystemService(Service
.ACCOUNT_SERVICE
);
67 mAccount
= mAccountManager
.getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
)[0];
72 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
73 if (!mCursor
.moveToPosition(position
)) {
74 throw new IndexOutOfBoundsException("Incorrect item selected");
76 String id_
= mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
._ID
));
77 if (mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
)).equals("DIR")) {
78 String dirname
= mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
80 mDirNames
.push(dirname
);
81 mParentsIds
.push(id_
);
82 ((FileDisplayActivity
)getActivity()).pushPath(dirname
);
87 Intent i
= new Intent(getActivity(), FileDetailActivity
.class);
88 i
.putExtra("FILE_NAME", ((TextView
)v
.findViewById(R
.id
.Filename
)).getText());
89 i
.putExtra("FILE_ID", id_
);
90 i
.putExtra("ACCOUNT_NAME", mAccount
.name
);
91 FileDetail fd
= (FileDetail
) getFragmentManager().findFragmentById(R
.id
.fileDetail
);
99 public void onBackPressed() {
105 private void populateFileList() {
106 if (mParentsIds
.empty()) {
107 mCursor
= getActivity().getContentResolver().query(ProviderTableMeta
.CONTENT_URI
,
109 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+"=?",
110 new String
[]{mAccount
.name
},
113 mCursor
= getActivity().managedQuery(Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_DIR
, mParentsIds
.peek()),
115 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?",
116 new String
[]{mAccount
.name
}, null
);
118 setListAdapter(new FileListListAdapter(mCursor
, getActivity()));