1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.ui
.adapter
;
24 import com
.owncloud
.android
.db
.ProviderMeta
.ProviderTableMeta
;
26 import com
.owncloud
.android
.AccountUtils
;
27 import com
.owncloud
.android
.R
;
28 import eu
.alefzero
.webdav
.WebdavUtils
;
29 import android
.accounts
.Account
;
30 import android
.accounts
.AccountManager
;
31 import android
.content
.Context
;
32 import android
.content
.Intent
;
33 import android
.database
.Cursor
;
34 import android
.database
.DataSetObserver
;
35 import android
.net
.Uri
;
36 import android
.text
.TextUtils
;
37 import android
.view
.LayoutInflater
;
38 import android
.view
.View
;
39 import android
.view
.ViewGroup
;
40 import android
.widget
.ImageView
;
41 import android
.widget
.ListAdapter
;
42 import android
.widget
.TextView
;
44 public class FileListActionListAdapter
implements ListAdapter
{
46 private Context mContext
;
47 private Account mAccount
;
48 private String mFilename
, mFileType
, mFilePath
, mFileStoragePath
;
50 private final int ITEM_DOWNLOAD
= 0;
52 // private final int ITEM_SHARE = 1;
54 public FileListActionListAdapter(Cursor c
, Context co
, Account account
) {
56 mFilename
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
57 mFileType
= c
.getString(c
58 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
));
59 mFilePath
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_PATH
));
60 mFileStoragePath
= c
.getString(c
61 .getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
));
62 // mItemId = c.getString(c.getColumnIndex(ProviderTableMeta._ID));
66 public boolean areAllItemsEnabled() {
70 public boolean isEnabled(int position
) {
74 public int getCount() {
78 public Object
getItem(int position
) {
80 Intent intent
= new Intent(Intent
.ACTION_VIEW
);
81 if (TextUtils
.isEmpty(mFileStoragePath
)) {
82 intent
.putExtra("toDownload", true
);
83 AccountManager accm
= (AccountManager
) mContext
84 .getSystemService(Context
.ACCOUNT_SERVICE
);
85 String ocurl
= accm
.getUserData(mAccount
,
86 AccountUtils
.constructFullURLForAccount(mContext
, mAccount
));
87 ocurl
+= WebdavUtils
.encodePath(mFilePath
+ mFilename
);
88 intent
.setData(Uri
.parse(ocurl
));
90 intent
.putExtra("toDownload", false
);
91 intent
.setDataAndType(Uri
.fromFile(new File(mFileStoragePath
)),
99 public long getItemId(int position
) {
103 public int getItemViewType(int position
) {
107 public View
getView(int position
, View convertView
, ViewGroup parent
) {
108 View v
= convertView
;
110 LayoutInflater vi
= (LayoutInflater
) mContext
111 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
112 v
= vi
.inflate(R
.layout
.file_display_action_list_element
, null
);
119 tv
= (TextView
) v
.findViewById(R
.id
.textView1
);
120 if (mFileStoragePath
== null
) {
121 tv
.setText("Download");
125 iv
= (ImageView
) v
.findViewById(R
.id
.imageView1
);
126 iv
.setImageResource(R
.drawable
.download
);
133 public int getViewTypeCount() {
137 public boolean hasStableIds() {
141 public boolean isEmpty() {
145 public void registerDataSetObserver(DataSetObserver observer
) { }
147 public void unregisterDataSetObserver(DataSetObserver observer
) { }
149 private void setActionName(TextView tv
) {
150 if (mFileType
.matches("image/.*")) {
152 } else if (mFileType
.matches("audio/.*")
153 || mFileType
.matches("video/.*")) {