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
.ImageView
;
39 import android
.widget
.ListAdapter
;
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
) {
72 // TODO Auto-generated method stub
77 public int getCount() {
78 return mFiles
!= null ? mFiles
.size() : 0;
82 public Object
getItem(int position
) {
83 if (mFiles
.size() <= position
)
85 return mFiles
.get(position
);
89 public long getItemId(int position
) {
90 return mFiles
!= null ? mFiles
.get(position
).getFileId() : 0;
94 public int getItemViewType(int position
) {
95 // TODO Auto-generated method stub
100 public View
getView(int position
, View convertView
, ViewGroup parent
) {
101 View view
= convertView
;
103 LayoutInflater inflator
= (LayoutInflater
) mContext
104 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
105 view
= inflator
.inflate(R
.layout
.list_layout
, null
);
107 if (mFiles
.size() > position
) {
108 OCFile file
= mFiles
.get(position
);
109 TextView fileName
= (TextView
) view
.findViewById(R
.id
.Filename
);
110 String name
= file
.getFileName();
112 fileName
.setText(name
);
113 ImageView fileIcon
= (ImageView
) view
.findViewById(R
.id
.imageView1
);
114 if (file
.getMimetype() == null
|| !file
.getMimetype().equals("DIR")) {
115 fileIcon
.setImageResource(R
.drawable
.file
);
117 fileIcon
.setImageResource(R
.drawable
.ic_menu_archive
);
119 ImageView localStateView
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
120 if (FileDownloader
.isDownloading(mAccount
, file
.getRemotePath())) {
121 localStateView
.setImageResource(R
.drawable
.downloading_file_indicator
);
122 localStateView
.setVisibility(View
.VISIBLE
);
123 } else if (FileUploader
.isUploading(mAccount
, file
.getRemotePath())) {
124 localStateView
.setImageResource(R
.drawable
.uploading_file_indicator
);
125 localStateView
.setVisibility(View
.VISIBLE
);
126 } else if (file
.isDown()) {
127 localStateView
.setImageResource(R
.drawable
.local_file_indicator
);
128 localStateView
.setVisibility(View
.VISIBLE
);
130 localStateView
.setVisibility(View
.INVISIBLE
);
133 ImageView down = (ImageView) view.findViewById(R.id.imageView2);
134 ImageView downloading = (ImageView) view.findViewById(R.id.imageView4);
135 ImageView uploading = (ImageView) view.findViewById(R.id.imageView5);
136 if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) {
137 down.setVisibility(View.INVISIBLE);
138 downloading.setVisibility(View.VISIBLE);
139 uploading.setVisibility(View.INVISIBLE);
140 } else if (FileUploader.isUploading(mAccount, file.getRemotePath())) {
141 down.setVisibility(View.INVISIBLE);
142 downloading.setVisibility(View.INVISIBLE);
143 uploading.setVisibility(View.VISIBLE);
144 } else if (file.isDown()) {
145 down.setVisibility(View.VISIBLE);
146 downloading.setVisibility(View.INVISIBLE);
147 uploading.setVisibility(View.INVISIBLE);
149 down.setVisibility(View.INVISIBLE);
150 downloading.setVisibility(View.INVISIBLE);
151 uploading.setVisibility(View.INVISIBLE);
154 if (!file
.isDirectory()) {
155 view
.findViewById(R
.id
.file_size
).setVisibility(View
.VISIBLE
);
156 view
.findViewById(R
.id
.last_mod
).setVisibility(View
.VISIBLE
);
157 ((TextView
)view
.findViewById(R
.id
.file_size
)).setText(DisplayUtils
.bytesToHumanReadable(file
.getFileLength()));
158 ((TextView
)view
.findViewById(R
.id
.last_mod
)).setText(DisplayUtils
.unixTimeToHumanReadable(file
.getModificationTimestamp()));
159 // this if-else is needed even thoe fav icon is visible by default
160 // because android reuses views in listview
161 if (!file
.keepInSync()) {
162 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.GONE
);
164 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.VISIBLE
);
167 view
.findViewById(R
.id
.file_size
).setVisibility(View
.GONE
);
168 view
.findViewById(R
.id
.last_mod
).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