fa72803d5574ff635a78c25bed56161cfc36b1a4
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / adapter / FileListListAdapter.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
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.
8 *
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.
13 *
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/>.
16 *
17 */
18 package eu.alefzero.owncloud.ui.adapter;
19
20 import java.util.Vector;
21
22 import eu.alefzero.owncloud.DisplayUtils;
23 import eu.alefzero.owncloud.R;
24 import eu.alefzero.owncloud.datamodel.OCFile;
25
26 import android.content.Context;
27 import android.database.DataSetObserver;
28 import android.view.LayoutInflater;
29 import android.view.View;
30 import android.view.ViewGroup;
31 import android.widget.ImageView;
32 import android.widget.ListAdapter;
33 import android.widget.TextView;
34
35 /**
36 * This Adapter populates a ListView with all files and
37 * folders in an ownCloud instance.
38 * @author Bartek Przybylski
39 *
40 */
41 public class FileListListAdapter implements ListAdapter {
42 private Context mContext;
43 private OCFile mFile;
44 private Vector<OCFile> mFiles;
45
46 public FileListListAdapter(OCFile file, Context context) {
47 mFile = file;
48 mFiles = mFile.getDirectoryContent();
49 mContext = context;
50 }
51
52 @Override
53 public boolean areAllItemsEnabled() {
54 return true;
55 }
56
57 @Override
58 public boolean isEnabled(int position) {
59 // TODO Auto-generated method stub
60 return true;
61 }
62
63 @Override
64 public int getCount() {
65 return mFiles != null ? mFiles.size() : 0;
66 }
67
68 @Override
69 public Object getItem(int position) {
70 if (mFiles.size() <= position)
71 return null;
72 return mFiles.get(position);
73 }
74
75 @Override
76 public long getItemId(int position) {
77 return mFiles != null ? mFiles.get(position).getFileId() : 0;
78 }
79
80 @Override
81 public int getItemViewType(int position) {
82 // TODO Auto-generated method stub
83 return 0;
84 }
85
86 @Override
87 public View getView(int position, View convertView, ViewGroup parent) {
88 View view = convertView;
89 if (view == null) {
90 LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
91 view = inflator.inflate(R.layout.list_layout, null);
92 }
93 if (mFiles.size() > position) {
94 OCFile file = mFiles.get(position);
95 TextView fileName = (TextView) view.findViewById(R.id.Filename);
96 fileName.setText(DisplayUtils.HtmlDecode(file.getFileName()));
97 if (!file.getMimetype().equals("DIR")) {
98 ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
99 fileIcon.setImageResource(R.drawable.file);
100 }
101 }
102
103 return view;
104 }
105
106 @Override
107 public int getViewTypeCount() {
108 return 4;
109 }
110
111 @Override
112 public boolean hasStableIds() {
113 return true;
114 }
115
116 @Override
117 public boolean isEmpty() {
118 return mFiles != null ? mFiles.isEmpty() : false;
119 }
120
121 @Override
122 public void registerDataSetObserver(DataSetObserver observer) {
123 // TODO Auto-generated method stub
124
125 }
126
127 @Override
128 public void unregisterDataSetObserver(DataSetObserver observer) {
129 // TODO Auto-generated method stub
130
131 }
132 }