From: David A. Velasco Date: Wed, 28 Oct 2015 09:58:33 +0000 (+0100) Subject: Renamed SearchFragment to SearchShareesFragment X-Git-Tag: oc-android-1.9^2~30^2~7 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/f91241566a3eeac3bc160ea10f5e0d52b735efef?ds=inline Renamed SearchFragment to SearchShareesFragment --- diff --git a/src/com/owncloud/android/ui/activity/ShareActivity.java b/src/com/owncloud/android/ui/activity/ShareActivity.java index 7d98d7a4..13c4b754 100644 --- a/src/com/owncloud/android/ui/activity/ShareActivity.java +++ b/src/com/owncloud/android/ui/activity/ShareActivity.java @@ -26,7 +26,6 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; -import android.widget.Toast; import com.owncloud.android.R; import com.owncloud.android.lib.common.utils.Log_OC; @@ -38,10 +37,8 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.operations.CreateShareWithShareeOperation; -import com.owncloud.android.operations.UnshareOperation; -import com.owncloud.android.ui.fragment.SearchFragment; +import com.owncloud.android.ui.fragment.SearchShareesFragment; import com.owncloud.android.ui.fragment.ShareFileFragment; -import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.GetShareWithUsersAsyncTask; import java.util.ArrayList; @@ -52,7 +49,7 @@ import java.util.ArrayList; public class ShareActivity extends FileActivity implements ShareFileFragment.OnShareFragmentInteractionListener, - SearchFragment.OnSearchFragmentInteractionListener { + SearchShareesFragment.OnSearchFragmentInteractionListener { private static final String TAG = ShareActivity.class.getSimpleName(); @@ -62,7 +59,7 @@ public class ShareActivity extends FileActivity private static final String DIALOG_WAIT_LOAD_DATA = "DIALOG_WAIT_LOAD_DATA"; private ShareFileFragment mShareFileFragment; - private SearchFragment mSearchFragment; + private SearchShareesFragment mSearchFragment; @Override protected void onCreate(Bundle savedInstanceState) { @@ -77,7 +74,7 @@ public class ShareActivity extends FileActivity mShareFileFragment = (ShareFileFragment) getSupportFragmentManager(). getFragment(savedInstanceState, TAG_SHARE_FRAGMENT); - mSearchFragment = (SearchFragment) getSupportFragmentManager(). + mSearchFragment = (SearchShareesFragment) getSupportFragmentManager(). getFragment(savedInstanceState, TAG_SEARCH_FRAGMENT); if (mShareFileFragment != null){ @@ -152,7 +149,7 @@ public class ShareActivity extends FileActivity @Override public void showSearchUsersAndGroups(ArrayList shares) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - mSearchFragment = SearchFragment.newInstance(getFile(), getAccount(), shares); + mSearchFragment = SearchShareesFragment.newInstance(getFile(), getAccount(), shares); ft.hide(mShareFileFragment); ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT); ft.addToBackStack(TAG_SEARCH_FRAGMENT); diff --git a/src/com/owncloud/android/ui/fragment/SearchFragment.java b/src/com/owncloud/android/ui/fragment/SearchFragment.java deleted file mode 100644 index da0807ad..00000000 --- a/src/com/owncloud/android/ui/fragment/SearchFragment.java +++ /dev/null @@ -1,230 +0,0 @@ -/** - * ownCloud Android client application - * - * @author masensio - * @author David A. Velasco - * Copyright (C) 2015 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.owncloud.android.ui.fragment; - -import android.accounts.Account; -import android.app.Activity; -import android.app.SearchManager; -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; -import android.widget.ListView; -import android.widget.SearchView; - -import com.owncloud.android.R; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.ui.activity.ShareActivity; -import com.owncloud.android.ui.adapter.ShareUserListAdapter; - -import java.util.ArrayList; - -/** - * Fragment for Searching users and groups - * - * A simple {@link Fragment} subclass. - * Activities that contain this fragment must implement the - * {@link SearchFragment.OnSearchFragmentInteractionListener} interface - * to handle interaction events. - * Use the {@link SearchFragment#newInstance} factory method to - * create an instance of this fragment. - */ -public class SearchFragment extends Fragment implements ShareUserListAdapter.ShareUserAdapterListener { - private static final String TAG = SearchFragment.class.getSimpleName(); - - // the fragment initialization parameters - private static final String ARG_FILE = "FILE"; - private static final String ARG_ACCOUNT = "ACCOUNT"; - private static final String ARG_SHARES = "SHARES"; - - // Parameters - private OCFile mFile; - private Account mAccount; - private ArrayList mShares; - private ShareUserListAdapter mUserGroupsAdapter = null; - - private OnSearchFragmentInteractionListener mListener; - - /** - * Public factory method to create new SearchFragment instances. - * - * @param fileToShare An {@link OCFile} to show in the fragment - * @param account An ownCloud account - * @param - * @return A new instance of fragment SearchFragment. - */ - // TODO: Rename and change types and number of parameters - public static SearchFragment newInstance(OCFile fileToShare, Account account, ArrayList shares) { - SearchFragment fragment = new SearchFragment(); - Bundle args = new Bundle(); - args.putParcelable(ARG_FILE, fileToShare); - args.putParcelable(ARG_ACCOUNT, account); - args.putParcelableArrayList(ARG_SHARES, shares); - fragment.setArguments(args); - return fragment; - } - - public SearchFragment() { - // Required empty public constructor - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments() != null) { - mFile = getArguments().getParcelable(ARG_FILE); - mAccount = getArguments().getParcelable(ARG_ACCOUNT); - mShares = getArguments().getParcelableArrayList(ARG_SHARES); - } - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.search_users_groups_layout, container, false); - - // Get the SearchView and set the searchable configuration - SearchView searchView = (SearchView) view.findViewById(R.id.searchView); - SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); - searchView.setSearchableInfo(searchManager.getSearchableInfo( - getActivity().getComponentName()) // assumes parent activity is the searchable activity - ); - searchView.setIconifiedByDefault(false); // do not iconify the widget; expand it by default - - searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); // avoid fullscreen with softkeyboard - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - Log_OC.v(TAG, "onQueryTextSubmit intercepted, query: " + query); - return true; // return true to prevent the query is processed to be queried; - // a user / group will be picked only if selected in the list of suggestions - } - - @Override - public boolean onQueryTextChange(String newText) { - return false; // let it for the parent listener in the hierarchy / default behaviour - } - }); - - // Show data: Fill in list of users and groups - ListView usersList = (ListView) view.findViewById(R.id.searchUsersListView); - mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(), - R.layout.share_user_item, mShares, this); - if (mShares.size() > 0) { - usersList.setVisibility(View.VISIBLE); - usersList.setAdapter(mUserGroupsAdapter); - } - - return view; - } - - /** - * Get users and groups fromn the DB to fill in the "share with" list - */ - public void refreshUsersOrGroupsListFromDB (){ - // Get Users and Groups - mShares = ((ShareActivity) mListener).getStorageManager().getSharesWithForAFile(mFile.getRemotePath(), - mAccount.name); - - // Update list of users/groups - updateListOfUserGroups(); - } - - private void updateListOfUserGroups() { - // Update list of users/groups - mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(), - R.layout.share_user_item, mShares, this); - - // Show data - ListView usersList = (ListView) getView().findViewById(R.id.searchUsersListView); - - if (mShares.size() > 0) { - usersList.setVisibility(View.VISIBLE); - usersList.setAdapter(mUserGroupsAdapter); - - } else { - usersList.setVisibility(View.GONE); - } - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - mListener = (OnSearchFragmentInteractionListener) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement OnFragmentInteractionListener"); - } - } - - @Override - public void onStart() { - super.onStart(); - // focus the search view and request the software keyboard be shown - View searchView = getView().findViewById(R.id.searchView); - if (searchView.requestFocus()) { - InputMethodManager imm = (InputMethodManager) - getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.showSoftInput(searchView.findFocus(), InputMethodManager.SHOW_IMPLICIT); - } - } - } - - @Override - public void onDetach() { - super.onDetach(); - mListener = null; - } - - @Override - public void unshareButtonPressed(OCShare share) { - // Unshare - mListener.unshareWith(share); - Log_OC.d(TAG, "Unshare - " + share.getSharedWithDisplayName()); - } - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - *

- * See the Android Training lesson Communicating with Other Fragments for more information. - */ - public interface OnSearchFragmentInteractionListener { - void unshareWith(OCShare share); - } - -} diff --git a/src/com/owncloud/android/ui/fragment/SearchShareesFragment.java b/src/com/owncloud/android/ui/fragment/SearchShareesFragment.java new file mode 100644 index 00000000..7bbdf01d --- /dev/null +++ b/src/com/owncloud/android/ui/fragment/SearchShareesFragment.java @@ -0,0 +1,230 @@ +/** + * ownCloud Android client application + * + * @author masensio + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.ui.fragment; + +import android.accounts.Account; +import android.app.Activity; +import android.app.SearchManager; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import android.widget.ListView; +import android.widget.SearchView; + +import com.owncloud.android.R; +import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.ui.activity.ShareActivity; +import com.owncloud.android.ui.adapter.ShareUserListAdapter; + +import java.util.ArrayList; + +/** + * Fragment for Searching users and groups + * + * A simple {@link Fragment} subclass. + * Activities that contain this fragment must implement the + * {@link SearchShareesFragment.OnSearchFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link SearchShareesFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class SearchShareesFragment extends Fragment implements ShareUserListAdapter.ShareUserAdapterListener { + private static final String TAG = SearchShareesFragment.class.getSimpleName(); + + // the fragment initialization parameters + private static final String ARG_FILE = "FILE"; + private static final String ARG_ACCOUNT = "ACCOUNT"; + private static final String ARG_SHARES = "SHARES"; + + // Parameters + private OCFile mFile; + private Account mAccount; + private ArrayList mShares; + private ShareUserListAdapter mUserGroupsAdapter = null; + + private OnSearchFragmentInteractionListener mListener; + + /** + * Public factory method to create new SearchShareesFragment instances. + * + * @param fileToShare An {@link OCFile} to show in the fragment + * @param account An ownCloud account + * @param + * @return A new instance of fragment SearchShareesFragment. + */ + // TODO: Rename and change types and number of parameters + public static SearchShareesFragment newInstance(OCFile fileToShare, Account account, ArrayList shares) { + SearchShareesFragment fragment = new SearchShareesFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARG_FILE, fileToShare); + args.putParcelable(ARG_ACCOUNT, account); + args.putParcelableArrayList(ARG_SHARES, shares); + fragment.setArguments(args); + return fragment; + } + + public SearchShareesFragment() { + // Required empty public constructor + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mFile = getArguments().getParcelable(ARG_FILE); + mAccount = getArguments().getParcelable(ARG_ACCOUNT); + mShares = getArguments().getParcelableArrayList(ARG_SHARES); + } + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.search_users_groups_layout, container, false); + + // Get the SearchView and set the searchable configuration + SearchView searchView = (SearchView) view.findViewById(R.id.searchView); + SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); + searchView.setSearchableInfo(searchManager.getSearchableInfo( + getActivity().getComponentName()) // assumes parent activity is the searchable activity + ); + searchView.setIconifiedByDefault(false); // do not iconify the widget; expand it by default + + searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); // avoid fullscreen with softkeyboard + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + Log_OC.v(TAG, "onQueryTextSubmit intercepted, query: " + query); + return true; // return true to prevent the query is processed to be queried; + // a user / group will be picked only if selected in the list of suggestions + } + + @Override + public boolean onQueryTextChange(String newText) { + return false; // let it for the parent listener in the hierarchy / default behaviour + } + }); + + // Show data: Fill in list of users and groups + ListView usersList = (ListView) view.findViewById(R.id.searchUsersListView); + mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(), + R.layout.share_user_item, mShares, this); + if (mShares.size() > 0) { + usersList.setVisibility(View.VISIBLE); + usersList.setAdapter(mUserGroupsAdapter); + } + + return view; + } + + /** + * Get users and groups fromn the DB to fill in the "share with" list + */ + public void refreshUsersOrGroupsListFromDB (){ + // Get Users and Groups + mShares = ((ShareActivity) mListener).getStorageManager().getSharesWithForAFile(mFile.getRemotePath(), + mAccount.name); + + // Update list of users/groups + updateListOfUserGroups(); + } + + private void updateListOfUserGroups() { + // Update list of users/groups + mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(), + R.layout.share_user_item, mShares, this); + + // Show data + ListView usersList = (ListView) getView().findViewById(R.id.searchUsersListView); + + if (mShares.size() > 0) { + usersList.setVisibility(View.VISIBLE); + usersList.setAdapter(mUserGroupsAdapter); + + } else { + usersList.setVisibility(View.GONE); + } + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + mListener = (OnSearchFragmentInteractionListener) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + @Override + public void onStart() { + super.onStart(); + // focus the search view and request the software keyboard be shown + View searchView = getView().findViewById(R.id.searchView); + if (searchView.requestFocus()) { + InputMethodManager imm = (InputMethodManager) + getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.showSoftInput(searchView.findFocus(), InputMethodManager.SHOW_IMPLICIT); + } + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + @Override + public void unshareButtonPressed(OCShare share) { + // Unshare + mListener.unshareWith(share); + Log_OC.d(TAG, "Unshare - " + share.getSharedWithDisplayName()); + } + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated + * to the activity and potentially other fragments contained in that + * activity. + *

+ * See the Android Training lesson Communicating with Other Fragments for more information. + */ + public interface OnSearchFragmentInteractionListener { + void unshareWith(OCShare share); + } + +}