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 com
.owncloud
.android
.ui
.adapter
;
20 import java
.util
.Vector
;
22 import com
.owncloud
.android
.AccountUtils
;
23 import com
.owncloud
.android
.DisplayUtils
;
24 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
25 import com
.owncloud
.android
.datamodel
.OCFile
;
26 import com
.owncloud
.android
.files
.services
.FileDownloader
;
27 import com
.owncloud
.android
.files
.services
.FileUploader
;
29 import com
.owncloud
.android
.R
;
31 import android
.accounts
.Account
;
32 import android
.content
.Context
;
33 import android
.database
.DataSetObserver
;
34 import android
.util
.Log
;
35 import android
.view
.LayoutInflater
;
36 import android
.view
.View
;
37 import android
.view
.ViewGroup
;
38 import android
.widget
.CheckedTextView
;
39 import android
.widget
.ImageView
;
40 import android
.widget
.ListAdapter
;
41 import android
.widget
.ListView
;
42 import android
.widget
.TextView
;
45 * This Adapter populates a ListView with all files and folders in an ownCloud
48 * @author Bartek Przybylski
51 public class FileListListAdapter
implements ListAdapter
{
52 private Context mContext
;
54 private Vector
<OCFile
> mFiles
;
55 private DataStorageManager mStorageManager
;
56 private Account mAccount
;
58 public FileListListAdapter(OCFile file
, DataStorageManager storage_man
,
61 mStorageManager
= storage_man
;
62 mFiles
= mStorageManager
.getDirectoryContent(mFile
);
64 mAccount
= AccountUtils
.getCurrentOwnCloudAccount(mContext
);
68 public boolean areAllItemsEnabled() {
73 public boolean isEnabled(int position
) {
74 // TODO Auto-generated method stub
79 public int getCount() {
80 return mFiles
!= null ? mFiles
.size() : 0;
84 public Object
getItem(int position
) {
85 if (mFiles
.size() <= position
)
87 return mFiles
.get(position
);
91 public long getItemId(int position
) {
92 return mFiles
!= null ? mFiles
.get(position
).getFileId() : 0;
96 public int getItemViewType(int position
) {
97 // TODO Auto-generated method stub
102 public View
getView(int position
, View convertView
, ViewGroup parent
) {
103 View view
= convertView
;
105 LayoutInflater inflator
= (LayoutInflater
) mContext
106 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
107 view
= inflator
.inflate(R
.layout
.list_layout
, null
);
109 if (mFiles
.size() > position
) {
110 OCFile file
= mFiles
.get(position
);
111 TextView fileName
= (TextView
) view
.findViewById(R
.id
.Filename
);
112 String name
= file
.getFileName();
114 fileName
.setText(name
);
115 ImageView fileIcon
= (ImageView
) view
.findViewById(R
.id
.imageView1
);
116 if (file
.getMimetype() == null
|| !file
.getMimetype().equals("DIR")) {
117 fileIcon
.setImageResource(R
.drawable
.file
);
119 fileIcon
.setImageResource(R
.drawable
.ic_menu_archive
);
121 ImageView localStateView
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
122 if (FileDownloader
.isDownloading(mAccount
, file
.getRemotePath())) {
123 localStateView
.setImageResource(R
.drawable
.downloading_file_indicator
);
124 localStateView
.setVisibility(View
.VISIBLE
);
125 } else if (FileUploader
.isUploading(mAccount
, file
.getRemotePath())) {
126 localStateView
.setImageResource(R
.drawable
.uploading_file_indicator
);
127 localStateView
.setVisibility(View
.VISIBLE
);
128 } else if (file
.isDown()) {
129 localStateView
.setImageResource(R
.drawable
.local_file_indicator
);
130 localStateView
.setVisibility(View
.VISIBLE
);
132 localStateView
.setVisibility(View
.INVISIBLE
);
136 TextView fileSizeV
= (TextView
) view
.findViewById(R
.id
.file_size
);
137 TextView lastModV
= (TextView
) view
.findViewById(R
.id
.last_mod
);
138 ImageView checkBoxV
= (ImageView
) view
.findViewById(R
.id
.custom_checkbox
);
140 if (!file
.isDirectory()) {
141 fileSizeV
.setVisibility(View
.VISIBLE
);
142 fileSizeV
.setText(DisplayUtils
.bytesToHumanReadable(file
.getFileLength()));
143 lastModV
.setVisibility(View
.VISIBLE
);
144 lastModV
.setText(DisplayUtils
.unixTimeToHumanReadable(file
.getModificationTimestamp()));
145 // this if-else is needed even thoe fav icon is visible by default
146 // because android reuses views in listview
147 if (!file
.keepInSync()) {
148 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.GONE
);
150 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.VISIBLE
);
153 ListView parentList
= (ListView
)parent
;
154 if (parentList
.getChoiceMode() == ListView
.CHOICE_MODE_NONE
) {
155 checkBoxV
.setVisibility(View
.GONE
);
157 checkBoxV
.setVisibility(View
.VISIBLE
);
158 if (parentList
.isItemChecked(position
)) {
159 checkBoxV
.setImageResource(android
.R
.drawable
.checkbox_on_background
);
161 checkBoxV
.setImageResource(android
.R
.drawable
.checkbox_off_background
);
166 fileSizeV
.setVisibility(View
.GONE
);
167 lastModV
.setVisibility(View
.GONE
);
168 checkBoxV
.setVisibility(View
.GONE
);
169 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.GONE
);
177 public int getViewTypeCount() {
182 public boolean hasStableIds() {
187 public boolean isEmpty() {
188 return mFiles
!= null ? mFiles
.isEmpty() : false
;
192 public void registerDataSetObserver(DataSetObserver observer
) {
193 // TODO Auto-generated method stub
198 public void unregisterDataSetObserver(DataSetObserver observer
) {
199 // TODO Auto-generated method stub