9ac4910541a2eb676c3bbbc2d0f03106607e7d01
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / FileDetail.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
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.
8 *
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.
13 *
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/>.
16 *
17 */
18 package eu.alefzero.owncloud.ui.fragment;
19
20 import eu.alefzero.owncloud.DisplayUtils;
21 import eu.alefzero.owncloud.R;
22 import eu.alefzero.owncloud.cp;
23 import eu.alefzero.owncloud.R.id;
24 import eu.alefzero.owncloud.R.layout;
25 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
26 import android.content.Intent;
27 import android.database.Cursor;
28 import android.net.Uri;
29 import android.os.Bundle;
30 import android.support.v4.app.Fragment;
31 import android.util.Log;
32 import android.view.LayoutInflater;
33 import android.view.View;
34 import android.view.ViewGroup;
35 import android.widget.TextView;
36 import android.widget.Toast;
37
38 /**
39 * This Fragment is used to display the details about a file.
40 * @author Bartek Przybylski
41 *
42 */
43 public class FileDetail extends Fragment {
44
45 public Intent mIntent;
46
47 public void setStuff(Intent intent) {
48 mIntent = intent;
49 setStuff(getView());
50 }
51
52 private void setStuff(View view) {
53 String id = mIntent.getStringExtra("FILE_ID");
54 String account_name = mIntent.getStringExtra("ACCOUNT_NAME");
55 Cursor c = getActivity().managedQuery(
56 Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id),
57 null,
58 ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
59 new String[]{account_name},
60 null);
61 c.moveToFirst();
62
63 String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));
64 setFilename(filename, view);
65 String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));
66 setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mimetype), view);
67 }
68
69 @Override
70 public View onCreateView(LayoutInflater inflater, ViewGroup container,
71 Bundle savedInstanceState) {
72 View v = inflater.inflate(R.layout.file_details, container, false);
73
74 if (getActivity().getIntent() != null) {
75 mIntent = getActivity().getIntent();
76 setStuff(v);
77 }
78 return v;
79 }
80
81 private void setFilename(String filename, View target_view) {
82 TextView tv = (TextView) target_view.findViewById(R.id.textView1);
83 if (tv != null) tv.setText(filename);
84 }
85
86 private void setFiletype(String mimetype, View target_view) {
87 TextView tv = (TextView) target_view.findViewById(R.id.textView2);
88 if (tv != null) tv.setText(mimetype);
89 }
90
91 public void setFilename(String filename) {
92 setFilename(filename, getView());
93 }
94
95 public void setFiletype(String filename) {
96 setFiletype(filename, getView());
97 }
98 }