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 eu
.alefzero
.owncloud
.ui
.adapter
;
23 import eu
.alefzero
.owncloud
.R
;
24 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
25 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
26 import eu
.alefzero
.webdav
.WebdavUtils
;
27 import android
.accounts
.Account
;
28 import android
.accounts
.AccountManager
;
29 import android
.content
.Context
;
30 import android
.content
.Intent
;
31 import android
.database
.Cursor
;
32 import android
.database
.DataSetObserver
;
33 import android
.net
.Uri
;
34 import android
.text
.TextUtils
;
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
;
42 public class FileListActionListAdapter
implements ListAdapter
{
44 private Context mContext
;
45 private Account mAccount
;
46 private String mFilename
, mFileType
, mFilePath
, mFileStoragePath
;
48 private final int ITEM_DOWNLOAD
= 0;
50 // private final int ITEM_SHARE = 1;
52 public FileListActionListAdapter(Cursor c
, Context co
, Account account
) {
54 mFilename
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
55 mFileType
= c
.getString(c
56 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
));
57 mFilePath
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_PATH
));
58 mFileStoragePath
= c
.getString(c
59 .getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
));
60 // mItemId = c.getString(c.getColumnIndex(ProviderTableMeta._ID));
64 public boolean areAllItemsEnabled() {
65 // TODO Auto-generated method stub
69 public boolean isEnabled(int position
) {
70 // TODO Auto-generated method stub
74 public int getCount() {
75 // TODO Auto-generated method stub
79 public Object
getItem(int position
) {
81 Intent intent
= new Intent(Intent
.ACTION_VIEW
);
82 if (TextUtils
.isEmpty(mFileStoragePath
)) {
83 intent
.putExtra("toDownload", true
);
84 AccountManager accm
= (AccountManager
) mContext
85 .getSystemService(Context
.ACCOUNT_SERVICE
);
86 String ocurl
= accm
.getUserData(mAccount
,
87 AccountAuthenticator
.KEY_OC_URL
);
88 ocurl
+= WebdavUtils
.encodePath(mFilePath
+ mFilename
);
89 intent
.setData(Uri
.parse(ocurl
));
91 intent
.putExtra("toDownload", false
);
92 intent
.setDataAndType(Uri
.fromFile(new File(mFileStoragePath
)),
100 public long getItemId(int position
) {
101 // TODO Auto-generated method stub
105 public int getItemViewType(int position
) {
106 // TODO Auto-generated method stub
110 public View
getView(int position
, View convertView
, ViewGroup parent
) {
111 View v
= convertView
;
113 LayoutInflater vi
= (LayoutInflater
) mContext
114 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
115 v
= vi
.inflate(R
.layout
.file_display_action_list_element
, null
);
122 tv
= (TextView
) v
.findViewById(R
.id
.textView1
);
123 if (mFileStoragePath
== null
) {
124 tv
.setText("Download");
128 iv
= (ImageView
) v
.findViewById(R
.id
.imageView1
);
129 iv
.setImageResource(R
.drawable
.download
);
136 public int getViewTypeCount() {
137 // TODO Auto-generated method stub
141 public boolean hasStableIds() {
142 // TODO Auto-generated method stub
146 public boolean isEmpty() {
147 // TODO Auto-generated method stub
151 public void registerDataSetObserver(DataSetObserver observer
) {
152 // TODO Auto-generated method stub
156 public void unregisterDataSetObserver(DataSetObserver observer
) {
157 // TODO Auto-generated method stub
161 private void setActionName(TextView tv
) {
162 if (mFileType
.matches("image/.*")) {
164 } else if (mFileType
.matches("audio/.*")
165 || mFileType
.matches("video/.*")) {