7fa955a5bc3974d7f858a3c80c9150a5fc819d19
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / SearchFragment.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.fragment;
22
23 import android.accounts.Account;
24 import android.app.Activity;
25 import android.net.Uri;
26 import android.os.Bundle;
27 import android.support.v4.app.Fragment;
28 import android.view.LayoutInflater;
29 import android.view.View;
30 import android.view.ViewGroup;
31
32 import com.owncloud.android.R;
33 import com.owncloud.android.datamodel.OCFile;
34
35 /**
36 * Fragment for Searching users and groups
37 *
38 * A simple {@link Fragment} subclass.
39 * Activities that contain this fragment must implement the
40 * {@link SearchFragment.OnSearchFragmentInteractionListener} interface
41 * to handle interaction events.
42 * Use the {@link SearchFragment#newInstance} factory method to
43 * create an instance of this fragment.
44 */
45 public class SearchFragment extends Fragment {
46 private static final String TAG = ShareFileFragment.class.getSimpleName();
47
48 // the fragment initialization parameters
49 private static final String ARG_FILE = "FILE";
50 private static final String ARG_ACCOUNT = "ACCOUNT";
51
52 // Parameters
53 private OCFile mFile;
54 private Account mAccount;
55
56 private OnSearchFragmentInteractionListener mListener;
57
58 /**
59 * Public factory method to create new SearchFragment instances.
60 *
61 * @param fileToShare An {@link OCFile} to show in the fragment
62 * @param account An ownCloud account
63 * @return A new instance of fragment SearchFragment.
64 */
65 // TODO: Rename and change types and number of parameters
66 public static SearchFragment newInstance(OCFile fileToShare, Account account) {
67 SearchFragment fragment = new SearchFragment();
68 Bundle args = new Bundle();
69 args.putParcelable(ARG_FILE, fileToShare);
70 args.putParcelable(ARG_ACCOUNT, account);
71 fragment.setArguments(args);
72 return fragment;
73 }
74
75 public SearchFragment() {
76 // Required empty public constructor
77 }
78
79 @Override
80 public void onCreate(Bundle savedInstanceState) {
81 super.onCreate(savedInstanceState);
82 if (getArguments() != null) {
83 mFile = getArguments().getParcelable(ARG_FILE);
84 mAccount = getArguments().getParcelable(ARG_ACCOUNT);
85 }
86
87 }
88
89 @Override
90 public View onCreateView(LayoutInflater inflater, ViewGroup container,
91 Bundle savedInstanceState) {
92 // Inflate the layout for this fragment
93 View view = inflater.inflate(R.layout.search_users_groups_layout, container, false);
94
95 return view;
96 }
97
98 // TODO: Rename method, update argument and hook method into UI event
99 public void onButtonPressed(Uri uri) {
100 if (mListener != null) {
101 mListener.onSearchFragmentInteraction(uri);
102 }
103 }
104
105 @Override
106 public void onAttach(Activity activity) {
107 super.onAttach(activity);
108 try {
109 mListener = (OnSearchFragmentInteractionListener) activity;
110 } catch (ClassCastException e) {
111 throw new ClassCastException(activity.toString()
112 + " must implement OnFragmentInteractionListener");
113 }
114 }
115
116 @Override
117 public void onDetach() {
118 super.onDetach();
119 mListener = null;
120 }
121
122 // TODO: review if it is necessary
123 /**
124 * This interface must be implemented by activities that contain this
125 * fragment to allow an interaction in this fragment to be communicated
126 * to the activity and potentially other fragments contained in that
127 * activity.
128 * <p/>
129 * See the Android Training lesson <a href=
130 * "http://developer.android.com/training/basics/fragments/communicating.html"
131 * >Communicating with Other Fragments</a> for more information.
132 */
133 public interface OnSearchFragmentInteractionListener {
134 // TODO: Update argument type and name
135 public void onSearchFragmentInteraction(Uri uri);
136 }
137
138 }