2 * ownCloud Android client application
5 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
21 package com
.owncloud
.android
.ui
.dialog
;
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
;
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
;
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.
51 * Dialog Fragment to show the share options of a file/folder
53 * Search the users and share with them
55 public class ShareFileDialogFragment
extends DialogFragment
56 implements DialogInterface
.OnClickListener
{
57 private static final String TAG
= ShareFileDialogFragment
.class.getSimpleName();
59 // the fragment initialization parameters
60 private static final String ARG_FILE
= "FILE";
61 private static final String ARG_ACCOUNT
= "ACCOUNT";
65 private Account mAccount
;
67 private OnFragmentInteractionListener mListener
;
70 * Public factory method to create new ShareFileDialogFragment instances.
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.
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
);
85 public ShareFileDialogFragment() {
86 // Required empty public constructor
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
);
99 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
101 // Inflate the layout for the dialog
102 LayoutInflater inflater
= getActivity().getLayoutInflater();
103 View view
= inflater
.inflate(R
.layout
.share_file_dialog
, null
);
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
);
118 TextView filename
= (TextView
) view
.findViewById(R
.id
.shareFileName
);
119 filename
.setText(mFile
.getFileName());
121 TextView size
= (TextView
) view
.findViewById(R
.id
.shareFileSize
);
122 if (mFile
.isFolder()){
123 size
.setVisibility(View
.GONE
);
125 size
.setText(DisplayUtils
.bytesToHumanReadable(mFile
.getFileLength()));
129 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity());
130 builder
.setView(view
)
131 .setPositiveButton(R
.string
.common_ok
, this)
132 .setTitle(R
.string
.share_dialog_title
);
134 Dialog d
= builder
.create();
139 public void onClick(DialogInterface dialog
, int which
) {
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
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.
153 public interface OnFragmentInteractionListener
{
154 // TODO: Update argument type and name
155 public void onFragmentInteraction(Uri uri
);