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 eu
.alefzero
.owncloud
.R
;
21 import eu
.alefzero
.owncloud
.R
.id
;
22 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
23 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
24 import eu
.alefzero
.owncloud
.ui
.activity
.FileDetailActivity
;
25 import eu
.alefzero
.owncloud
.ui
.adapter
.FileListListAdapter
;
26 import eu
.alefzero
.owncloud
.ui
.fragment
.ActionBar
;
27 import android
.accounts
.Account
;
28 import android
.accounts
.AccountManager
;
29 import android
.app
.Activity
;
30 import android
.app
.Service
;
31 import android
.content
.Intent
;
32 import android
.database
.Cursor
;
33 import android
.net
.Uri
;
34 import android
.os
.Bundle
;
35 import android
.support
.v4
.app
.FragmentTransaction
;
36 import android
.support
.v4
.app
.ListFragment
;
37 import android
.view
.LayoutInflater
;
38 import android
.view
.View
;
39 import android
.view
.ViewGroup
;
40 import android
.widget
.ArrayAdapter
;
41 import android
.widget
.ListView
;
42 import android
.widget
.TextView
;
43 import android
.widget
.Toast
;
46 * A Fragment that lists all files and folders in a given path.
47 * @author Bartek Przybylski
50 public class FileList
extends ListFragment
{
51 private Cursor mCursor
;
52 private Account mAccount
;
53 private AccountManager mAccountManager
;
54 private View mheaderView
;
58 public void onCreate(Bundle savedInstanceState
) {
59 // TODO Auto-generated method stub
60 super.onCreate(savedInstanceState
);
62 mAccountManager
= (AccountManager
)getActivity().getSystemService(Service
.ACCOUNT_SERVICE
);
63 mAccount
= mAccountManager
.getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
)[0];
68 public void onActivityCreated(Bundle savedInstanceState
) {
69 // TODO Auto-generated method stub
70 super.onActivityCreated(savedInstanceState
);
74 public void onListItemClick(ListView l
, View v
, int position
, long id
) {
75 FileDetail fd
= (FileDetail
) getFragmentManager().findFragmentById(R
.id
.fileDetail
);
76 ActionBar ab
= (ActionBar
) getFragmentManager().findFragmentById(R
.id
.actionBar
);
78 if (!mCursor
.moveToPosition(position
)) {
79 throw new IndexOutOfBoundsException("Incorrect item selected");
81 if (mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
)).equals("DIR")) {
82 String id_
= mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
._ID
));
83 String dirname
= mCursor
.getString(mCursor
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
84 //ab..push(DisplayUtils.HtmlDecode(dirname));
85 //mPath.addLast(DisplayUtils.HtmlDecode(dirname));
87 mCursor
= getActivity().managedQuery(Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_DIR
, id_
),
89 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?",
90 new String
[]{mAccount
.name
}, null
);
91 setListAdapter(new FileListListAdapter(mCursor
, getActivity()));
94 super.onListItemClick(l
, v
, position
, id
);
97 Intent i
= new Intent(getActivity(), FileDetailActivity
.class);
98 i
.putExtra("FILE_PATH", ab
.getCurrentPath());
99 i
.putExtra("FILE_NAME", ((TextView
)v
.findViewById(R
.id
.Filename
)).getText());
102 //fd.use(((TextView)v.findViewById(R.id.Filename)).getText());
104 i
.putExtra("FILE_PATH", ab
.getCurrentPath());
105 i
.putExtra("FILE_NAME", ((TextView
)v
.findViewById(R
.id
.Filename
)).getText());
108 super.onListItemClick(l
, v
, position
, id
);
113 public void onDestroyView() {
114 setListAdapter(null
);
115 super.onDestroyView();
118 private void populateFileList() {
119 mCursor
= getActivity().getContentResolver().query(ProviderTableMeta
.CONTENT_URI
,
121 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+"=?",
122 new String
[]{mAccount
.name
},
125 setListAdapter(new FileListListAdapter(mCursor
, getActivity()));