Show the layout to hsare with user in phone and tablet
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / ShareFileDialogFragment.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 package com.owncloud.android.ui.dialog;
22
23 import android.accounts.Account;
24 import android.app.Dialog;
25 import android.content.DialogInterface;
26 import android.graphics.Bitmap;
27 import android.net.Uri;
28 import android.os.Bundle;
29 import android.app.Fragment;
30 import android.support.v4.app.DialogFragment;
31 import android.support.v7.app.AlertDialog;
32 import android.view.LayoutInflater;
33 import android.view.View;
34 import android.widget.ImageView;
35 import android.widget.TextView;
36
37 import com.owncloud.android.R;
38 import com.owncloud.android.datamodel.OCFile;
39 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
40 import com.owncloud.android.utils.DisplayUtils;
41 import com.owncloud.android.utils.MimetypeIconUtil;
42
43 /**
44 * A simple {@link Fragment} subclass.
45 * Activities that contain this fragment must implement the
46 * {@link ShareFileDialogFragment.OnFragmentInteractionListener} interface
47 * to handle interaction events.
48 * Use the {@link ShareFileDialogFragment#newInstance} factory method to
49 * create an instance of this fragment.
50 *
51 * Dialog Fragment to show the share options of a file/folder
52 *
53 * Search the users and share with them
54 */
55 public class ShareFileDialogFragment extends DialogFragment
56 implements DialogInterface.OnClickListener{
57 private static final String TAG = ShareFileDialogFragment.class.getSimpleName();
58
59 // the fragment initialization parameters
60 private static final String ARG_FILE = "FILE";
61 private static final String ARG_ACCOUNT = "ACCOUNT";
62
63 // Parameters
64 private OCFile mFile;
65 private Account mAccount;
66
67 private OnFragmentInteractionListener mListener;
68
69 /**
70 * Public factory method to create new ShareFileDialogFragment instances.
71 *
72 * @param fileToShare An {@link OCFile} to show in the fragment
73 * @param account An ownCloud account
74 * @return A new instance of fragment ShareFragment.
75 */
76 public static ShareFileDialogFragment newInstance(OCFile fileToShare, Account account) {
77 ShareFileDialogFragment fragment = new ShareFileDialogFragment();
78 Bundle args = new Bundle();
79 args.putParcelable(ARG_FILE, fileToShare);
80 args.putParcelable(ARG_ACCOUNT, account);
81 fragment.setArguments(args);
82 return fragment;
83 }
84
85 public ShareFileDialogFragment() {
86 // Required empty public constructor
87 }
88
89 @Override
90 public void onCreate(Bundle savedInstanceState) {
91 super.onCreate(savedInstanceState);
92 if (getArguments() != null) {
93 mFile = getArguments().getParcelable(ARG_FILE);
94 mAccount = getArguments().getParcelable(ARG_ACCOUNT);
95 }
96 }
97
98 @Override
99 public Dialog onCreateDialog(Bundle savedInstanceState) {
100
101 // Inflate the layout for the dialog
102 LayoutInflater inflater = getActivity().getLayoutInflater();
103 View view = inflater.inflate(R.layout.share_file_dialog, null);
104
105 // Setup layout
106 // Image
107 ImageView icon = (ImageView) view.findViewById(R.id.shareFileIcon);
108 icon.setImageResource(MimetypeIconUtil.getFileTypeIconId(mFile.getMimetype(),
109 mFile.getFileName()));
110 if (mFile.isImage()) {
111 String remoteId = String.valueOf(mFile.getRemoteId());
112 Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId);
113 if (thumbnail != null){
114 icon.setImageBitmap(thumbnail);
115 }
116 }
117 // Name
118 TextView filename = (TextView) view.findViewById(R.id.shareFileName);
119 filename.setText(mFile.getFileName());
120 // Size
121 TextView size = (TextView) view.findViewById(R.id.shareFileSize);
122 if (mFile.isFolder()){
123 size.setVisibility(View.GONE);
124 } else {
125 size.setText(DisplayUtils.bytesToHumanReadable(mFile.getFileLength()));
126 }
127
128 // Build the dialog
129 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
130 builder.setView(view)
131 .setPositiveButton(R.string.common_ok, this)
132 .setTitle(R.string.share_link_title);
133
134 Dialog d = builder.create();
135 return d;
136 }
137
138 @Override
139 public void onClick(DialogInterface dialog, int which) {
140
141 }
142
143 /**
144 * This interface must be implemented by activities that contain this
145 * fragment to allow an interaction in this fragment to be communicated
146 * to the activity and potentially other fragments contained in that
147 * activity.
148 * <p/>
149 * See the Android Training lesson <a href=
150 * "http://developer.android.com/training/basics/fragments/communicating.html"
151 * >Communicating with Other Fragments</a> for more information.
152 */
153 public interface OnFragmentInteractionListener {
154 // TODO: Update argument type and name
155 public void onFragmentInteraction(Uri uri);
156 }
157
158 }