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
.view
.LayoutInflater
;
35 import android
.view
.View
;
36 import android
.view
.ViewGroup
;
37 import android
.widget
.ImageView
;
38 import android
.widget
.ListAdapter
;
39 import android
.widget
.ListView
;
40 import android
.widget
.TextView
;
43 * This Adapter populates a ListView with all files and folders in an ownCloud
46 * @author Bartek Przybylski
49 public class FileListListAdapter
implements ListAdapter
{
50 private Context mContext
;
52 private Vector
<OCFile
> mFiles
;
53 private DataStorageManager mStorageManager
;
54 private Account mAccount
;
56 public FileListListAdapter(OCFile file
, DataStorageManager storage_man
,
59 mStorageManager
= storage_man
;
60 mFiles
= mStorageManager
.getDirectoryContent(mFile
);
62 mAccount
= AccountUtils
.getCurrentOwnCloudAccount(mContext
);
66 public boolean areAllItemsEnabled() {
71 public boolean isEnabled(int position
) {
76 public int getCount() {
77 return mFiles
!= null ? mFiles
.size() : 0;
81 public Object
getItem(int position
) {
82 if (mFiles
.size() <= position
)
84 return mFiles
.get(position
);
88 public long getItemId(int position
) {
89 return mFiles
!= null ? mFiles
.get(position
).getFileId() : 0;
93 public int getItemViewType(int position
) {
98 public View
getView(int position
, View convertView
, ViewGroup parent
) {
99 View view
= convertView
;
101 LayoutInflater inflator
= (LayoutInflater
) mContext
102 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
103 view
= inflator
.inflate(R
.layout
.list_layout
, null
);
105 if (mFiles
.size() > position
) {
106 OCFile file
= mFiles
.get(position
);
107 TextView fileName
= (TextView
) view
.findViewById(R
.id
.Filename
);
108 String name
= file
.getFileName();
110 fileName
.setText(name
);
111 ImageView fileIcon
= (ImageView
) view
.findViewById(R
.id
.imageView1
);
112 if (file
.getMimetype() == null
|| !file
.getMimetype().equals("DIR")) {
113 fileIcon
.setImageResource(R
.drawable
.file
);
115 fileIcon
.setImageResource(R
.drawable
.ic_menu_archive
);
117 ImageView localStateView
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
118 if (FileDownloader
.isDownloading(mAccount
, file
.getRemotePath())) {
119 localStateView
.setImageResource(R
.drawable
.downloading_file_indicator
);
120 localStateView
.setVisibility(View
.VISIBLE
);
121 } else if (FileUploader
.isUploading(mAccount
, file
.getRemotePath())) {
122 localStateView
.setImageResource(R
.drawable
.uploading_file_indicator
);
123 localStateView
.setVisibility(View
.VISIBLE
);
124 } else if (file
.isDown()) {
125 localStateView
.setImageResource(R
.drawable
.local_file_indicator
);
126 localStateView
.setVisibility(View
.VISIBLE
);
128 localStateView
.setVisibility(View
.INVISIBLE
);
132 TextView fileSizeV
= (TextView
) view
.findViewById(R
.id
.file_size
);
133 TextView lastModV
= (TextView
) view
.findViewById(R
.id
.last_mod
);
134 ImageView checkBoxV
= (ImageView
) view
.findViewById(R
.id
.custom_checkbox
);
136 if (!file
.isDirectory()) {
137 fileSizeV
.setVisibility(View
.VISIBLE
);
138 fileSizeV
.setText(DisplayUtils
.bytesToHumanReadable(file
.getFileLength()));
139 lastModV
.setVisibility(View
.VISIBLE
);
140 lastModV
.setText(DisplayUtils
.unixTimeToHumanReadable(file
.getModificationTimestamp()));
141 // this if-else is needed even thoe fav icon is visible by default
142 // because android reuses views in listview
143 if (!file
.keepInSync()) {
144 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.GONE
);
146 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.VISIBLE
);
149 ListView parentList
= (ListView
)parent
;
150 if (parentList
.getChoiceMode() == ListView
.CHOICE_MODE_NONE
) {
151 checkBoxV
.setVisibility(View
.GONE
);
153 if (parentList
.isItemChecked(position
)) {
154 checkBoxV
.setImageResource(android
.R
.drawable
.checkbox_on_background
);
156 checkBoxV
.setImageResource(android
.R
.drawable
.checkbox_off_background
);
158 checkBoxV
.setVisibility(View
.VISIBLE
);
162 fileSizeV
.setVisibility(View
.GONE
);
163 lastModV
.setVisibility(View
.GONE
);
164 checkBoxV
.setVisibility(View
.GONE
);
165 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.GONE
);
173 public int getViewTypeCount() {
178 public boolean hasStableIds() {
183 public boolean isEmpty() {
184 return mFiles
!= null ? mFiles
.isEmpty() : false
;
188 public void registerDataSetObserver(DataSetObserver observer
) {
192 public void unregisterDataSetObserver(DataSetObserver observer
) {