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 android
.accounts
.Account
;
21 import android
.accounts
.AccountManager
;
22 import android
.app
.FragmentManager
;
23 import android
.app
.Service
;
24 import android
.content
.Intent
;
25 import android
.database
.Cursor
;
26 import android
.net
.Uri
;
27 import android
.os
.Bundle
;
28 import android
.support
.v4
.app
.FragmentTransaction
;
29 import android
.view
.LayoutInflater
;
30 import android
.view
.View
;
31 import android
.view
.ViewGroup
;
32 import android
.widget
.AdapterView
;
33 import android
.widget
.TextView
;
34 import eu
.alefzero
.owncloud
.R
;
35 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
36 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
37 import eu
.alefzero
.owncloud
.ui
.FragmentListView
;
38 import eu
.alefzero
.owncloud
.ui
.activity
.FileDetailActivity
;
39 import eu
.alefzero
.owncloud
.ui
.activity
.FileDisplayActivity
;
40 import eu
.alefzero
.owncloud
.ui
.adapter
.FileListListAdapter
;
43 * A Fragment that lists all files and folders in a given path.
44 * @author Bartek Przybylski
47 public class FileList
extends FragmentListView
{
48 private Cursor mCursor
;
49 private Account mAccount
;
50 private AccountManager mAccountManager
;
51 private String mDirName
;
52 private String mParentId
;
59 public FileList(String dirName
, String parentId
) {
65 public void onCreate(Bundle savedInstanceState
) {
66 super.onCreate(savedInstanceState
);
68 mAccountManager
= (AccountManager
)getActivity().getSystemService(Service
.ACCOUNT_SERVICE
);
69 mAccount
= mAccountManager
.getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
)[0];
74 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
75 FileDetail fd
= (FileDetail
) getFragmentManager().findFragmentById(R
.id
.fileDetail
);
76 if (!mCursor
.moveToPosition(position
)) {
77 throw new IndexOutOfBoundsException("Incorrect item selected");
80 if (mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
)).equals("DIR")) {
81 String id_
= mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
._ID
));
82 String dirname
= mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
84 FileList fl
= new FileList(dirname
, id_
);
85 ((FileDisplayActivity
)getActivity()).pushPath(dirname
);
87 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
88 ft
.addToBackStack(null
);
89 ft
.replace(R
.id
.file_list_container
, fl
);
91 getSupportFragmentManager().executePendingTransactions();
94 Intent i
= new Intent(getActivity(), FileDetailActivity
.class);
95 i
.putExtra("FILE_NAME", ((TextView
)v
.findViewById(R
.id
.Filename
)).getText());
103 private void populateFileList() {
104 if (mParentId
== null
|| mDirName
== null
) {
105 mCursor
= getActivity().getContentResolver().query(ProviderTableMeta
.CONTENT_URI
,
107 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+"=?",
108 new String
[]{mAccount
.name
},
111 mCursor
= getActivity().managedQuery(Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_DIR
, mParentId
),
113 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?",
114 new String
[]{mAccount
.name
}, null
);
116 setListAdapter(new FileListListAdapter(mCursor
, getActivity()));