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
.Stack
;
21 import java
.util
.Vector
;
23 import android
.accounts
.Account
;
24 import android
.content
.Intent
;
25 import android
.os
.Bundle
;
26 import android
.util
.Log
;
27 import android
.view
.View
;
28 import android
.widget
.AdapterView
;
29 import android
.widget
.Toast
;
30 import eu
.alefzero
.owncloud
.R
;
31 import eu
.alefzero
.owncloud
.authenticator
.AuthUtils
;
32 import eu
.alefzero
.owncloud
.datamodel
.DataStorageManager
;
33 import eu
.alefzero
.owncloud
.datamodel
.FileDataStorageManager
;
34 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
35 import eu
.alefzero
.owncloud
.ui
.FragmentListView
;
36 import eu
.alefzero
.owncloud
.ui
.activity
.FileDetailActivity
;
37 import eu
.alefzero
.owncloud
.ui
.activity
.FileDisplayActivity
;
38 import eu
.alefzero
.owncloud
.ui
.adapter
.FileListListAdapter
;
41 * A Fragment that lists all files and folders in a given path.
42 * @author Bartek Przybylski
45 public class FileListFragment
extends FragmentListView
{
46 private Account mAccount
;
47 private Stack
<String
> mDirNames
;
48 private Vector
<OCFile
> mFiles
;
49 private DataStorageManager mStorageManager
;
51 public FileListFragment() {
52 mDirNames
= new Stack
<String
>();
56 public void onCreate(Bundle savedInstanceState
) {
57 super.onCreate(savedInstanceState
);
59 mAccount
= AuthUtils
.getCurrentOwnCloudAccount(getActivity());
64 public void onItemClick(AdapterView
<?
> l
, View v
, int position
, long id
) {
65 if (mFiles
.size() <= position
) {
66 throw new IndexOutOfBoundsException("Incorrect item selected");
68 OCFile file
= mFiles
.get(position
);
69 String id_
= String
.valueOf(file
.getFileId());
70 if (file
.getMimetype().equals("DIR")) {
71 String dirname
= file
.getFileName();
73 mDirNames
.push(dirname
);
74 ((FileDisplayActivity
)getActivity()).pushPath(dirname
);
79 Intent i
= new Intent(getActivity(), FileDetailActivity
.class);
80 i
.putExtra("FILE_NAME", file
.getFileName());
81 i
.putExtra("FULL_PATH", file
.getPath());
82 i
.putExtra("FILE_ID", id_
);
83 Log
.e("ASD", mAccount
+"");
84 i
.putExtra("ACCOUNT", mAccount
);
85 FileDetailFragment fd
= (FileDetailFragment
) getFragmentManager().findFragmentById(R
.id
.fileDetail
);
94 * Call this, when the user presses the up button
96 public void onNavigateUp() {
102 * Lists the directory
104 private void populateFileList() {
106 for (String a
: mDirNames
)
110 mStorageManager
= new FileDataStorageManager(mAccount
, getActivity().getContentResolver());
111 OCFile file
= mStorageManager
.getFileByPath(s
);
112 mFiles
= mStorageManager
.getDirectoryContent(file
);
113 if (mFiles
== null
|| mFiles
.size() == 0) {
114 Toast
.makeText(getActivity(), "There are no files here", Toast
.LENGTH_LONG
).show();
116 setListAdapter(new FileListListAdapter(file
, mStorageManager
, getActivity()));
119 //TODO: Delete this testing stuff.
120 /*private void addContact(Account account, String name, String username) {
121 Log.i("ASD", "Adding contact: " + name);
122 ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
124 //Create our RawContact
125 ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
126 builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
127 builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
128 builder.withValue(RawContacts.SYNC1, username);
129 operationList.add(builder.build());
131 //Create a Data record of common type 'StructuredName' for our RawContact
132 builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
133 builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0);
134 builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
135 builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name);
136 operationList.add(builder.build());
138 //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
139 builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
140 builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
141 builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.owncloud.contact.profile");
142 builder.withValue(ContactsContract.Data.DATA1, username);
143 builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile");
144 builder.withValue(ContactsContract.Data.DATA3, "View profile");
145 operationList.add(builder.build());
148 getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
149 } catch (Exception e) {
150 Log.e("ASD", "Something went wrong during creation! " + e);