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
.FileDownloaderBinder
;
27 import com
.owncloud
.android
.files
.services
.FileUploader
;
28 import com
.owncloud
.android
.ui
.activity
.TransferServiceGetter
;
30 import com
.owncloud
.android
.R
;
32 import android
.accounts
.Account
;
33 import android
.content
.Context
;
34 import android
.view
.LayoutInflater
;
35 import android
.view
.View
;
36 import android
.view
.ViewGroup
;
37 import android
.widget
.BaseAdapter
;
38 import android
.widget
.ImageView
;
39 import android
.widget
.ListAdapter
;
40 import android
.widget
.ListView
;
41 import android
.widget
.TextView
;
44 * This Adapter populates a ListView with all files and folders in an ownCloud
47 * @author Bartek Przybylski
50 public class FileListListAdapter
extends BaseAdapter
implements ListAdapter
{
51 private Context mContext
;
52 private OCFile mFile
= null
;
53 private Vector
<OCFile
> mFiles
= null
;
54 private DataStorageManager mStorageManager
;
55 private Account mAccount
;
56 private TransferServiceGetter mTransferServiceGetter
;
58 public FileListListAdapter(OCFile file
, DataStorageManager storage_man
,
59 Context context
, TransferServiceGetter transferServiceGetter
) {
60 mStorageManager
= storage_man
;
62 mAccount
= AccountUtils
.getCurrentOwnCloudAccount(mContext
);
63 mTransferServiceGetter
= transferServiceGetter
;
66 mFiles = mStorageManager.getDirectoryContent(mFile);*/
70 public boolean areAllItemsEnabled() {
75 public boolean isEnabled(int position
) {
80 public int getCount() {
81 return mFiles
!= null ? mFiles
.size() : 0;
85 public Object
getItem(int position
) {
86 if (mFiles
== null
|| mFiles
.size() <= position
)
88 return mFiles
.get(position
);
92 public long getItemId(int position
) {
93 if (mFiles
== null
|| mFiles
.size() <= position
)
95 return mFiles
.get(position
).getFileId();
99 public int getItemViewType(int position
) {
104 public View
getView(int position
, View convertView
, ViewGroup parent
) {
105 View view
= convertView
;
107 LayoutInflater inflator
= (LayoutInflater
) mContext
108 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
109 view
= inflator
.inflate(R
.layout
.list_layout
, null
);
111 if (mFiles
!= null
&& mFiles
.size() > position
) {
112 OCFile file
= mFiles
.get(position
);
113 TextView fileName
= (TextView
) view
.findViewById(R
.id
.Filename
);
114 String name
= file
.getFileName();
116 fileName
.setText(name
);
117 ImageView fileIcon
= (ImageView
) view
.findViewById(R
.id
.imageView1
);
118 if (file
.getMimetype() == null
|| !file
.getMimetype().equals("DIR")) {
119 fileIcon
.setImageResource(R
.drawable
.file
);
121 fileIcon
.setImageResource(R
.drawable
.ic_menu_archive
);
123 ImageView localStateView
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
124 //if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) {
125 FileDownloaderBinder downloaderBinder
= mTransferServiceGetter
.getFileDownloaderBinder();
126 if (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, file
.getRemotePath())) {
127 localStateView
.setImageResource(R
.drawable
.downloading_file_indicator
);
128 localStateView
.setVisibility(View
.VISIBLE
);
129 } else if (FileUploader
.isUploading(mAccount
, file
.getRemotePath())) {
130 localStateView
.setImageResource(R
.drawable
.uploading_file_indicator
);
131 localStateView
.setVisibility(View
.VISIBLE
);
132 } else if (file
.isDown()) {
133 localStateView
.setImageResource(R
.drawable
.local_file_indicator
);
134 localStateView
.setVisibility(View
.VISIBLE
);
136 localStateView
.setVisibility(View
.INVISIBLE
);
140 TextView fileSizeV
= (TextView
) view
.findViewById(R
.id
.file_size
);
141 TextView lastModV
= (TextView
) view
.findViewById(R
.id
.last_mod
);
142 ImageView checkBoxV
= (ImageView
) view
.findViewById(R
.id
.custom_checkbox
);
144 if (!file
.isDirectory()) {
145 fileSizeV
.setVisibility(View
.VISIBLE
);
146 fileSizeV
.setText(DisplayUtils
.bytesToHumanReadable(file
.getFileLength()));
147 lastModV
.setVisibility(View
.VISIBLE
);
148 lastModV
.setText(DisplayUtils
.unixTimeToHumanReadable(file
.getModificationTimestamp()));
149 // this if-else is needed even thoe fav icon is visible by default
150 // because android reuses views in listview
151 if (!file
.keepInSync()) {
152 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.GONE
);
154 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.VISIBLE
);
157 ListView parentList
= (ListView
)parent
;
158 if (parentList
.getChoiceMode() == ListView
.CHOICE_MODE_NONE
) {
159 checkBoxV
.setVisibility(View
.GONE
);
161 if (parentList
.isItemChecked(position
)) {
162 checkBoxV
.setImageResource(android
.R
.drawable
.checkbox_on_background
);
164 checkBoxV
.setImageResource(android
.R
.drawable
.checkbox_off_background
);
166 checkBoxV
.setVisibility(View
.VISIBLE
);
170 fileSizeV
.setVisibility(View
.GONE
);
171 lastModV
.setVisibility(View
.GONE
);
172 checkBoxV
.setVisibility(View
.GONE
);
173 view
.findViewById(R
.id
.imageView3
).setVisibility(View
.GONE
);
181 public int getViewTypeCount() {
186 public boolean hasStableIds() {
191 public boolean isEmpty() {
192 return (mFiles
== null
|| mFiles
.isEmpty());
196 * Change the adapted directory for a new one
197 * @param directory New file to adapt. Can be NULL, meaning "no content to adapt".
199 public void swapDirectory(OCFile directory
) {
201 if (mStorageManager
!= null
) {
202 mFiles
= mStorageManager
.getDirectoryContent(mFile
);
206 notifyDataSetChanged();