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
.R
.drawable
;
25 import eu
.alefzero
.owncloud
.R
.id
;
26 import eu
.alefzero
.owncloud
.R
.layout
;
27 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
28 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
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
, mItemId
;
50 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
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
));
57 mFilePath
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_PATH
));
58 mFileStoragePath
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
));
59 mItemId
= c
.getString(c
.getColumnIndex(ProviderTableMeta
._ID
));
63 public boolean areAllItemsEnabled() {
64 // TODO Auto-generated method stub
68 public boolean isEnabled(int position
) {
69 // TODO Auto-generated method stub
73 public int getCount() {
74 // TODO Auto-generated method stub
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
.getSystemService(Context
.ACCOUNT_SERVICE
);
84 String ocurl
= accm
.getUserData(mAccount
, AccountAuthenticator
.KEY_OC_URL
);
85 ocurl
+= mFilePath
+ mFilename
;
86 intent
.setData(Uri
.parse(ocurl
));
88 intent
.putExtra("toDownload", false
);
89 intent
.setDataAndType(Uri
.fromFile(new File(mFileStoragePath
)), mFileType
);
96 public long getItemId(int position
) {
97 // TODO Auto-generated method stub
101 public int getItemViewType(int position
) {
102 // TODO Auto-generated method stub
106 public View
getView(int position
, View convertView
, ViewGroup parent
) {
107 View v
= convertView
;
109 LayoutInflater vi
= (LayoutInflater
) mContext
.getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
110 v
= vi
.inflate(R
.layout
.file_display_action_list_element
, null
);
117 tv
= (TextView
) v
.findViewById(R
.id
.textView1
);
118 if (mFileStoragePath
== null
) {
119 tv
.setText("Download");
123 iv
= (ImageView
) v
.findViewById(R
.id
.imageView1
);
124 iv
.setImageResource(R
.drawable
.download
);
131 public int getViewTypeCount() {
132 // TODO Auto-generated method stub
136 public boolean hasStableIds() {
137 // TODO Auto-generated method stub
141 public boolean isEmpty() {
142 // TODO Auto-generated method stub
146 public void registerDataSetObserver(DataSetObserver observer
) {
147 // TODO Auto-generated method stub
151 public void unregisterDataSetObserver(DataSetObserver observer
) {
152 // TODO Auto-generated method stub
156 private void setActionName(TextView tv
) {
157 if (mFileType
.matches("image/.*")) {
159 } else if (mFileType
.matches("audio/.*") || mFileType
.matches("video/.*")) {