2b912ee8e06b8165874052972ad35e1721f02ef2
[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 f, Context context) {
47 mFile = f;
48 mFiles = mFile.getDirectoryContent();
49 mContext = context;
50 }
51
52 public boolean areAllItemsEnabled() {
53 return true;
54 }
55
56 public boolean isEnabled(int position) {
57 // TODO Auto-generated method stub
58 return true;
59 }
60
61 public int getCount() {
62 // TODO Auto-generated method stub
63 return mFiles != null ? mFiles.size() : 0;
64 }
65
66 public Object getItem(int position) {
67 if (mFiles.size() <= position)
68 return null;
69 return mFiles.get(position);
70 }
71
72 public long getItemId(int position) {
73 // TODO Auto-generated method stub
74 return 0;
75 }
76
77 public int getItemViewType(int position) {
78 // TODO Auto-generated method stub
79 return 0;
80 }
81
82 public View getView(int position, View convertView, ViewGroup parent) {
83 View v = convertView;
84 if (v == null) {
85 LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
86 v = vi.inflate(R.layout.list_layout, null);
87 }
88 if (mFiles.size() > position) {
89 OCFile f = mFiles.get(position);
90 TextView tv = (TextView) v.findViewById(R.id.Filename);
91 tv.setText(DisplayUtils.HtmlDecode(f.getFileName()));
92 if (!f.getMimetype().equals("DIR")) {
93 ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
94 iv.setImageResource(R.drawable.file);
95 }
96 }
97
98 return v;
99 }
100
101 public int getViewTypeCount() {
102 // TODO Auto-generated method stub
103 return 4;
104 }
105
106 public boolean hasStableIds() {
107 // TODO Auto-generated method stub
108 return true;
109 }
110
111 public boolean isEmpty() {
112 // TODO Auto-generated method stub
113 return false;
114 }
115
116 public void registerDataSetObserver(DataSetObserver observer) {
117 // TODO Auto-generated method stub
118
119 }
120
121 public void unregisterDataSetObserver(DataSetObserver observer) {
122 // TODO Auto-generated method stub
123
124 }
125 }