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
.fragment
;
23 import android
.accounts
.Account
;
24 import android
.app
.Activity
;
25 import android
.graphics
.Bitmap
;
26 import android
.net
.Uri
;
27 import android
.os
.Bundle
;
28 import android
.support
.design
.widget
.FloatingActionButton
;
29 import android
.support
.v4
.app
.Fragment
;
30 import android
.view
.LayoutInflater
;
31 import android
.view
.View
;
32 import android
.view
.ViewGroup
;
33 import android
.widget
.ImageView
;
34 import android
.widget
.TextView
;
36 import com
.owncloud
.android
.R
;
37 import com
.owncloud
.android
.datamodel
.OCFile
;
38 import com
.owncloud
.android
.datamodel
.ThumbnailsCacheManager
;
39 import com
.owncloud
.android
.utils
.DisplayUtils
;
40 import com
.owncloud
.android
.utils
.MimetypeIconUtil
;
43 * Fragment for Sharing a file with users
45 * A simple {@link Fragment} subclass.
46 * Activities that contain this fragment must implement the
47 * {@link ShareFileFragment.OnShareFragmentInteractionListener} interface
48 * to handle interaction events.
49 * Use the {@link ShareFileFragment#newInstance} factory method to
50 * create an instance of this fragment.
52 public class ShareFileFragment
extends Fragment
{
53 private static final String TAG
= ShareFileFragment
.class.getSimpleName();
55 // the fragment initialization parameters
56 private static final String ARG_FILE
= "FILE";
57 private static final String ARG_ACCOUNT
= "ACCOUNT";
61 private Account mAccount
;
63 private OnShareFragmentInteractionListener mListener
;
66 * Public factory method to create new ShareFileFragment instances.
68 * @param fileToShare An {@link OCFile} to show in the fragment
69 * @param account An ownCloud account
70 * @return A new instance of fragment ShareFileFragment.
72 public static ShareFileFragment
newInstance(OCFile fileToShare
, Account account
) {
73 ShareFileFragment fragment
= new ShareFileFragment();
74 Bundle args
= new Bundle();
75 args
.putParcelable(ARG_FILE
, fileToShare
);
76 args
.putParcelable(ARG_ACCOUNT
, account
);
77 fragment
.setArguments(args
);
81 public ShareFileFragment() {
82 // Required empty public constructor
86 public void onCreate(Bundle savedInstanceState
) {
87 super.onCreate(savedInstanceState
);
88 if (getArguments() != null
) {
89 mFile
= getArguments().getParcelable(ARG_FILE
);
90 mAccount
= getArguments().getParcelable(ARG_ACCOUNT
);
95 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
96 Bundle savedInstanceState
) {
97 // Inflate the layout for this fragment
98 View view
= inflater
.inflate(R
.layout
.share_file_layout
, container
, false
);
102 ImageView icon
= (ImageView
) view
.findViewById(R
.id
.shareFileIcon
);
103 icon
.setImageResource(MimetypeIconUtil
.getFileTypeIconId(mFile
.getMimetype(),
104 mFile
.getFileName()));
105 if (mFile
.isImage()) {
106 String remoteId
= String
.valueOf(mFile
.getRemoteId());
107 Bitmap thumbnail
= ThumbnailsCacheManager
.getBitmapFromDiskCache(remoteId
);
108 if (thumbnail
!= null
){
109 icon
.setImageBitmap(thumbnail
);
113 TextView filename
= (TextView
) view
.findViewById(R
.id
.shareFileName
);
114 filename
.setText(mFile
.getFileName());
116 TextView size
= (TextView
) view
.findViewById(R
.id
.shareFileSize
);
117 if (mFile
.isFolder()){
118 size
.setVisibility(View
.GONE
);
120 size
.setText(DisplayUtils
.bytesToHumanReadable(mFile
.getFileLength()));
124 FloatingActionButton addUserGroupButton
= (FloatingActionButton
)
125 view
.findViewById(R
.id
.addUserButton
);
126 addUserGroupButton
.setOnClickListener(new View
.OnClickListener() {
128 public void onClick(View view
) {
129 // Show Search Fragment
130 mListener
.showSearchUsersAndGroups();
137 // TODO: Rename method, update argument and hook method into UI event
138 public void onButtonPressed(Uri uri
) {
139 if (mListener
!= null
) {
140 mListener
.onShareFragmentInteraction(uri
);
145 public void onAttach(Activity activity
) {
146 super.onAttach(activity
);
148 mListener
= (OnShareFragmentInteractionListener
) activity
;
149 } catch (ClassCastException e
) {
150 throw new ClassCastException(activity
.toString()
151 + " must implement OnShareFragmentInteractionListener");
156 public void onDetach() {
161 // TODO: review if it is necessary
163 * This interface must be implemented by activities that contain this
164 * fragment to allow an interaction in this fragment to be communicated
165 * to the activity and potentially other fragments contained in that
168 * See the Android Training lesson <a href=
169 * "http://developer.android.com/training/basics/fragments/communicating.html"
170 * >Communicating with Other Fragments</a> for more information.
172 public interface OnShareFragmentInteractionListener
{
173 public void showSearchUsersAndGroups();
175 public void onShareFragmentInteraction(Uri uri
);