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
.db
.ProviderMeta
.ProviderTableMeta
;
25 import com
.owncloud
.android
.AccountUtils
;
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() {
69 public boolean isEnabled(int position
) {
73 public int getCount() {
77 public Object
getItem(int position
) {
79 Intent intent
= new Intent(Intent
.ACTION_VIEW
);
80 if (TextUtils
.isEmpty(mFileStoragePath
)) {
81 intent
.putExtra("toDownload", true
);
82 AccountManager accm
= (AccountManager
) mContext
83 .getSystemService(Context
.ACCOUNT_SERVICE
);
84 String ocurl
= accm
.getUserData(mAccount
,
85 AccountUtils
.constructFullURLForAccount(mContext
, mAccount
));
86 ocurl
+= WebdavUtils
.encodePath(mFilePath
+ mFilename
);
87 intent
.setData(Uri
.parse(ocurl
));
89 intent
.putExtra("toDownload", false
);
90 intent
.setDataAndType(Uri
.fromFile(new File(mFileStoragePath
)),
98 public long getItemId(int position
) {
102 public int getItemViewType(int position
) {
106 public View
getView(int position
, View convertView
, ViewGroup parent
) {
107 View v
= convertView
;
109 LayoutInflater vi
= (LayoutInflater
) mContext
110 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
111 v
= vi
.inflate(R
.layout
.file_display_action_list_element
, null
);
118 tv
= (TextView
) v
.findViewById(R
.id
.textView1
);
119 if (mFileStoragePath
== null
) {
120 tv
.setText("Download");
124 iv
= (ImageView
) v
.findViewById(R
.id
.imageView1
);
125 iv
.setImageResource(R
.drawable
.download
);
132 public int getViewTypeCount() {
136 public boolean hasStableIds() {
140 public boolean isEmpty() {
144 public void registerDataSetObserver(DataSetObserver observer
) { }
146 public void unregisterDataSetObserver(DataSetObserver observer
) { }
148 private void setActionName(TextView tv
) {
149 if (mFileType
.matches("image/.*")) {
151 } else if (mFileType
.matches("audio/.*")
152 || mFileType
.matches("video/.*")) {