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