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
.adapter
;
20 import java
.net
.URLDecoder
;
21 import java
.util
.Vector
;
23 import eu
.alefzero
.owncloud
.DisplayUtils
;
24 import eu
.alefzero
.owncloud
.R
;
25 import eu
.alefzero
.owncloud
.datamodel
.DataStorageManager
;
26 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
28 import android
.content
.Context
;
29 import android
.database
.DataSetObserver
;
30 import android
.util
.Log
;
31 import android
.view
.LayoutInflater
;
32 import android
.view
.View
;
33 import android
.view
.ViewGroup
;
34 import android
.widget
.ImageView
;
35 import android
.widget
.ListAdapter
;
36 import android
.widget
.TextView
;
39 * This Adapter populates a ListView with all files and folders in an ownCloud
42 * @author Bartek Przybylski
45 public class FileListListAdapter
implements ListAdapter
{
46 private Context mContext
;
48 private Vector
<OCFile
> mFiles
;
49 private DataStorageManager mStorageManager
;
51 public FileListListAdapter(OCFile file
, DataStorageManager storage_man
,
54 mStorageManager
= storage_man
;
55 mFiles
= mStorageManager
.getDirectoryContent(mFile
);
60 public boolean areAllItemsEnabled() {
65 public boolean isEnabled(int position
) {
66 // TODO Auto-generated method stub
71 public int getCount() {
72 return mFiles
!= null ? mFiles
.size() : 0;
76 public Object
getItem(int position
) {
77 if (mFiles
.size() <= position
)
79 return mFiles
.get(position
);
83 public long getItemId(int position
) {
84 return mFiles
!= null ? mFiles
.get(position
).getFileId() : 0;
88 public int getItemViewType(int position
) {
89 // TODO Auto-generated method stub
94 public View
getView(int position
, View convertView
, ViewGroup parent
) {
95 View view
= convertView
;
97 LayoutInflater inflator
= (LayoutInflater
) mContext
98 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
99 view
= inflator
.inflate(R
.layout
.list_layout
, null
);
101 if (mFiles
.size() > position
) {
102 OCFile file
= mFiles
.get(position
);
103 TextView fileName
= (TextView
) view
.findViewById(R
.id
.Filename
);
104 String name
= file
.getFileName();
106 fileName
.setText(name
);
107 ImageView fileIcon
= (ImageView
) view
.findViewById(R
.id
.imageView1
);
108 if (!file
.getMimetype().equals("DIR")) {
109 fileIcon
.setImageResource(R
.drawable
.file
);
111 fileIcon
.setImageResource(R
.drawable
.ic_menu_archive
);
113 ImageView down
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
114 if (file
.getStoragePath() != null
)
115 down
.setVisibility(View
.VISIBLE
);
117 down
.setVisibility(View
.INVISIBLE
);
119 if (!file
.isDirectory()) {
120 view
.findViewById(R
.id
.file_size
).setVisibility(View
.VISIBLE
);
121 view
.findViewById(R
.id
.last_mod
).setVisibility(View
.VISIBLE
);
122 ((TextView
)view
.findViewById(R
.id
.file_size
)).setText(DisplayUtils
.bytesToHumanReadable(file
.getFileLength()));
123 ((TextView
)view
.findViewById(R
.id
.last_mod
)).setText(DisplayUtils
.unixTimeToHumanReadable(file
.getModificationTimestamp()));
125 view
.findViewById(R
.id
.file_size
).setVisibility(View
.GONE
);
126 view
.findViewById(R
.id
.last_mod
).setVisibility(View
.GONE
);
134 public int getViewTypeCount() {
139 public boolean hasStableIds() {
144 public boolean isEmpty() {
145 return mFiles
!= null ? mFiles
.isEmpty() : false
;
149 public void registerDataSetObserver(DataSetObserver observer
) {
150 // TODO Auto-generated method stub
155 public void unregisterDataSetObserver(DataSetObserver observer
) {
156 // TODO Auto-generated method stub