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/>.
18 package eu
.alefzero
.owncloud
.ui
.fragment
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Stack
;
22 import java
.util
.Vector
;
24 import android
.accounts
.Account
;
25 import android
.content
.ContentProviderOperation
;
26 import android
.content
.Intent
;
27 import android
.os
.Bundle
;
28 import android
.provider
.ContactsContract
;
29 import android
.provider
.ContactsContract
.RawContacts
;
30 import android
.util
.Log
;
31 import android
.view
.View
;
32 import android
.widget
.AdapterView
;
33 import eu
.alefzero
.owncloud
.R
;
34 import eu
.alefzero
.owncloud
.authenticator
.AuthUtils
;
35 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
36 import eu
.alefzero
.owncloud
.ui
.FragmentListView
;
37 import eu
.alefzero
.owncloud
.ui
.activity
.FileDetailActivity
;
38 import eu
.alefzero
.owncloud
.ui
.activity
.FileDisplayActivity
;
39 import eu
.alefzero
.owncloud
.ui
.adapter
.FileListListAdapter
;
42 * A Fragment that lists all files and folders in a given path.
43 * @author Bartek Przybylski
46 public class FileList
extends FragmentListView
{
47 private Account mAccount
;
48 private Stack
<String
> mDirNames
;
49 private Vector
<OCFile
> mFiles
;
52 mDirNames
= new Stack
<String
>();
56 public void onCreate(Bundle savedInstanceState
) {
57 super.onCreate(savedInstanceState
);
59 mAccount
= AuthUtils
.getCurrentOwnCloudAccount(getActivity());
61 //addContact(mAccount, "Bartek Przybylski", "czlowiek");
65 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
66 if (mFiles
.size() <= position
) {
67 throw new IndexOutOfBoundsException("Incorrect item selected");
69 OCFile file
= mFiles
.get(position
);
70 String id_
= String
.valueOf(file
.getFileId());
71 if (file
.getMimetype().equals("DIR")) {
72 String dirname
= file
.getFileName();
74 mDirNames
.push(dirname
);
75 ((FileDisplayActivity
)getActivity()).pushPath(dirname
);
80 Intent i
= new Intent(getActivity(), FileDetailActivity
.class);
81 i
.putExtra("FILE_NAME", file
.getFileName());
82 i
.putExtra("FULL_PATH", file
.getPath());
83 i
.putExtra("FILE_ID", id_
);
84 i
.putExtra("ACCOUNT", mAccount
);
85 FileDetail fd
= (FileDetail
) getFragmentManager().findFragmentById(R
.id
.fileDetail
);
93 public void onBackPressed() {
98 private void populateFileList() {
100 for (String a
: mDirNames
)
103 OCFile file
= new OCFile(getActivity().getContentResolver(), mAccount
, s
);
104 mFiles
= file
.getDirectoryContent();
105 setListAdapter(new FileListListAdapter(file
, getActivity()));
108 private void addContact(Account account
, String name
, String username
) {
109 Log
.i("ASD", "Adding contact: " + name
);
110 ArrayList
<ContentProviderOperation
> operationList
= new ArrayList
<ContentProviderOperation
>();
112 //Create our RawContact
113 ContentProviderOperation
.Builder builder
= ContentProviderOperation
.newInsert(RawContacts
.CONTENT_URI
);
114 builder
.withValue(RawContacts
.ACCOUNT_NAME
, account
.name
);
115 builder
.withValue(RawContacts
.ACCOUNT_TYPE
, account
.type
);
116 builder
.withValue(RawContacts
.SYNC1
, username
);
117 operationList
.add(builder
.build());
119 //Create a Data record of common type 'StructuredName' for our RawContact
120 builder
= ContentProviderOperation
.newInsert(ContactsContract
.Data
.CONTENT_URI
);
121 builder
.withValueBackReference(ContactsContract
.CommonDataKinds
.StructuredName
.RAW_CONTACT_ID
, 0);
122 builder
.withValue(ContactsContract
.Data
.MIMETYPE
, ContactsContract
.CommonDataKinds
.StructuredName
.CONTENT_ITEM_TYPE
);
123 builder
.withValue(ContactsContract
.CommonDataKinds
.StructuredName
.DISPLAY_NAME
, name
);
124 operationList
.add(builder
.build());
126 //Create a Data record of custom type "vnd.android.cursor.item/vnd.fm.last.android.profile" to display a link to the Last.fm profile
127 builder
= ContentProviderOperation
.newInsert(ContactsContract
.Data
.CONTENT_URI
);
128 builder
.withValueBackReference(ContactsContract
.Data
.RAW_CONTACT_ID
, 0);
129 builder
.withValue(ContactsContract
.Data
.MIMETYPE
, "vnd.android.cursor.item/vnd.owncloud.contact.profile");
130 builder
.withValue(ContactsContract
.Data
.DATA1
, username
);
131 builder
.withValue(ContactsContract
.Data
.DATA2
, "Last.fm Profile");
132 builder
.withValue(ContactsContract
.Data
.DATA3
, "View profile");
133 operationList
.add(builder
.build());
136 getActivity().getContentResolver().applyBatch(ContactsContract
.AUTHORITY
, operationList
);
137 } catch (Exception e
) {
138 Log
.e("ASD", "Something went wrong during creation! " + e
);