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/>.
19 package com
.owncloud
.android
.ui
.adapter
;
23 import com
.owncloud
.android
.authenticator
.AccountAuthenticator
;
24 import com
.owncloud
.android
.db
.ProviderMeta
.ProviderTableMeta
;
26 import com
.owncloud
.android
.R
;
27 import eu
.alefzero
.webdav
.WebdavUtils
;
28 import android
.accounts
.Account
;
29 import android
.accounts
.AccountManager
;
30 import android
.content
.Context
;
31 import android
.content
.Intent
;
32 import android
.database
.Cursor
;
33 import android
.database
.DataSetObserver
;
34 import android
.net
.Uri
;
35 import android
.text
.TextUtils
;
36 import android
.view
.LayoutInflater
;
37 import android
.view
.View
;
38 import android
.view
.ViewGroup
;
39 import android
.widget
.ImageView
;
40 import android
.widget
.ListAdapter
;
41 import android
.widget
.TextView
;
43 public class FileListActionListAdapter
implements ListAdapter
{
45 private Context mContext
;
46 private Account mAccount
;
47 private String mFilename
, mFileType
, mFilePath
, mFileStoragePath
;
49 private final int ITEM_DOWNLOAD
= 0;
51 // private final int ITEM_SHARE = 1;
53 public FileListActionListAdapter(Cursor c
, Context co
, Account account
) {
55 mFilename
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
56 mFileType
= c
.getString(c
57 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
));
58 mFilePath
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_PATH
));
59 mFileStoragePath
= c
.getString(c
60 .getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
));
61 // mItemId = c.getString(c.getColumnIndex(ProviderTableMeta._ID));
65 public boolean areAllItemsEnabled() {
66 // TODO Auto-generated method stub
70 public boolean isEnabled(int position
) {
71 // TODO Auto-generated method stub
75 public int getCount() {
76 // TODO Auto-generated method stub
80 public Object
getItem(int position
) {
82 Intent intent
= new Intent(Intent
.ACTION_VIEW
);
83 if (TextUtils
.isEmpty(mFileStoragePath
)) {
84 intent
.putExtra("toDownload", true
);
85 AccountManager accm
= (AccountManager
) mContext
86 .getSystemService(Context
.ACCOUNT_SERVICE
);
87 String ocurl
= accm
.getUserData(mAccount
,
88 AccountAuthenticator
.KEY_OC_URL
);
89 ocurl
+= WebdavUtils
.encodePath(mFilePath
+ mFilename
);
90 intent
.setData(Uri
.parse(ocurl
));
92 intent
.putExtra("toDownload", false
);
93 intent
.setDataAndType(Uri
.fromFile(new File(mFileStoragePath
)),
101 public long getItemId(int position
) {
102 // TODO Auto-generated method stub
106 public int getItemViewType(int position
) {
107 // TODO Auto-generated method stub
111 public View
getView(int position
, View convertView
, ViewGroup parent
) {
112 View v
= convertView
;
114 LayoutInflater vi
= (LayoutInflater
) mContext
115 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
116 v
= vi
.inflate(R
.layout
.file_display_action_list_element
, null
);
123 tv
= (TextView
) v
.findViewById(R
.id
.textView1
);
124 if (mFileStoragePath
== null
) {
125 tv
.setText("Download");
129 iv
= (ImageView
) v
.findViewById(R
.id
.imageView1
);
130 iv
.setImageResource(R
.drawable
.download
);
137 public int getViewTypeCount() {
138 // TODO Auto-generated method stub
142 public boolean hasStableIds() {
143 // TODO Auto-generated method stub
147 public boolean isEmpty() {
148 // TODO Auto-generated method stub
152 public void registerDataSetObserver(DataSetObserver observer
) {
153 // TODO Auto-generated method stub
157 public void unregisterDataSetObserver(DataSetObserver observer
) {
158 // TODO Auto-generated method stub
162 private void setActionName(TextView tv
) {
163 if (mFileType
.matches("image/.*")) {
165 } else if (mFileType
.matches("audio/.*")
166 || mFileType
.matches("video/.*")) {