From: masensio Date: Fri, 23 Oct 2015 12:28:48 +0000 (+0200) Subject: Show users/groups in Search Fragment list X-Git-Tag: oc-android-1.9^2~30^2~24 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/671fef617b9bc67300e3d2cddbbfbe9fb8b4937b?ds=inline Show users/groups in Search Fragment list --- diff --git a/res/layout/share_user_item.xml b/res/layout/share_user_item.xml index e360d1d4..5e4020ba 100644 --- a/res/layout/share_user_item.xml +++ b/res/layout/share_user_item.xml @@ -29,7 +29,7 @@ + android:layout_gravity="center_horizontal"/> shares) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - mSearchFragment = SearchFragment.newInstance(getFile(), getAccount()); + mSearchFragment = SearchFragment.newInstance(getFile(), getAccount(), shares); ft.hide(mShareFileFragment); ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT); ft.addToBackStack(TAG_SEARCH_FRAGMENT); @@ -158,6 +165,26 @@ public class ShareActivity extends FileActivity } @Override + // Call to Unshare operation + public void unshareWith(OCShare share){ + OCFile file = getFile(); + getFileOperationsHelper().unshareFileWithUserOrGroup(file, share.getShareType(), share.getShareWith()); + } + + /** + * Get users and groups from the server to fill in the "share with" list + */ + @Override + public void refreshUsersOrGroupsListFromServer(){ + // Show loading + showLoadingDialog(getString(R.string.common_loading)); + // Get Users and Groups + GetShareWithUsersAsyncTask getTask = new GetShareWithUsersAsyncTask(this); + Object[] params = { getFile(), getAccount(), getStorageManager()}; + getTask.execute(params); + } + + @Override public void onBackPressed() { super.onBackPressed(); if (mSearchFragment != null){ @@ -178,30 +205,34 @@ public class ShareActivity extends FileActivity public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { super.onRemoteOperationFinish(operation, result); if (operation instanceof UnshareOperation) { - if (mShareFileFragment != null){ - mShareFileFragment.refreshUsersOrGroupsListFromDB(); - } - } else if (operation instanceof GetSharesForFileOperation) { - onGetSharesForFileOperationFinish((GetSharesForFileOperation) operation, result); + refreshUsersInLists(); + } else if(operation instanceof CreateShareWithShareeOperation){ + refreshUsersInLists(); } - } - private void onGetSharesForFileOperationFinish(GetSharesForFileOperation operation, RemoteOperationResult result){ + @Override + public void onGetDataShareWithFinish(RemoteOperationResult result) { + // Remove loading dismissLoadingDialog(); + if (result != null && result.isSuccess()) { + Log_OC.d(TAG, "Get Data Share With finishes sucessfully"); - if (!result.isSuccess()) { - Toast.makeText(getApplicationContext(), result.getLogMessage(), Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(this, result.getLogMessage(), Toast.LENGTH_SHORT).show(); } - // Show Shares + // Data is on Database + refreshUsersInLists(); + } + + private void refreshUsersInLists(){ if (mShareFileFragment != null){ mShareFileFragment.refreshUsersOrGroupsListFromDB(); } + if (mSearchFragment != null) { + mSearchFragment.refreshUsersOrGroupsListFromDB(); + } } - @Override - public void onSearchFragmentInteraction(Uri uri) { - - } } diff --git a/src/com/owncloud/android/ui/adapter/ShareUserListAdapter.java b/src/com/owncloud/android/ui/adapter/ShareUserListAdapter.java index 76a804fd..413223d6 100644 --- a/src/com/owncloud/android/ui/adapter/ShareUserListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/ShareUserListAdapter.java @@ -41,11 +41,14 @@ public class ShareUserListAdapter extends ArrayAdapter { private Context mContext; private ArrayList mShares; + private ShareUserAdapterListener mListener; - public ShareUserListAdapter(Context context, int resource, ArrayListshares) { + public ShareUserListAdapter(Context context, int resource, ArrayListshares, + ShareUserAdapterListener listener) { super(context, resource); mContext= context; mShares = shares; + mListener = listener; } @Override @@ -79,13 +82,22 @@ public class ShareUserListAdapter extends ArrayAdapter { } userName.setText(name); - ImageView unshareButton = (ImageView) view.findViewById(R.id.unshareButton); - unshareButton.setVisibility(View.GONE); + final ImageView unshareButton = (ImageView) view.findViewById(R.id.unshareButton); + unshareButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mListener.unshareButtonPressed(mShares.get(position)); + } + }); } return view; } + public interface ShareUserAdapterListener { + void unshareButtonPressed(OCShare share); + } + } diff --git a/src/com/owncloud/android/ui/fragment/SearchFragment.java b/src/com/owncloud/android/ui/fragment/SearchFragment.java index c946ee01..3dbf8ff9 100644 --- a/src/com/owncloud/android/ui/fragment/SearchFragment.java +++ b/src/com/owncloud/android/ui/fragment/SearchFragment.java @@ -25,17 +25,22 @@ import android.accounts.Account; import android.app.Activity; import android.app.SearchManager; import android.content.Context; -import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +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 @@ -47,16 +52,19 @@ import com.owncloud.android.lib.common.utils.Log_OC; * Use the {@link SearchFragment#newInstance} factory method to * create an instance of this fragment. */ -public class SearchFragment extends 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; @@ -65,14 +73,16 @@ public class SearchFragment extends Fragment { * * @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) { + 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; } @@ -87,6 +97,7 @@ public class SearchFragment extends Fragment { if (getArguments() != null) { mFile = getArguments().getParcelable(ARG_FILE); mAccount = getArguments().getParcelable(ARG_ACCOUNT); + mShares = getArguments().getParcelableArrayList(ARG_SHARES); } } @@ -121,13 +132,44 @@ public class SearchFragment extends Fragment { } }); + // 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; } - // TODO: Rename method, update argument and hook method into UI event - public void onButtonPressed(Uri uri) { - if (mListener != null) { - mListener.onSearchFragmentInteraction(uri); + /** + * 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); } } @@ -148,7 +190,13 @@ public class SearchFragment extends Fragment { mListener = null; } - // TODO: review if it is necessary + @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 @@ -160,8 +208,7 @@ public class SearchFragment extends Fragment { * >Communicating with Other Fragments for more information. */ public interface OnSearchFragmentInteractionListener { - // TODO: Update argument type and name - public void onSearchFragmentInteraction(Uri uri); + void unshareWith(OCShare share); } } diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index 81e7772d..1b95186b 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -28,25 +28,19 @@ import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; import com.owncloud.android.R; -import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.ThumbnailsCacheManager; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.ShareActivity; import com.owncloud.android.ui.adapter.ShareUserListAdapter; import com.owncloud.android.utils.DisplayUtils; -import com.owncloud.android.utils.GetShareWithUsersAsyncTask; import com.owncloud.android.utils.MimetypeIconUtil; import java.util.ArrayList; @@ -62,7 +56,7 @@ import java.util.ArrayList; * create an instance of this fragment. */ public class ShareFileFragment extends Fragment - implements GetShareWithUsersAsyncTask.OnGetSharesWithUsersTaskListener { + implements ShareUserListAdapter.ShareUserAdapterListener{ private static final String TAG = ShareFileFragment.class.getSimpleName(); @@ -79,8 +73,6 @@ public class ShareFileFragment extends Fragment private OnShareFragmentInteractionListener mListener; - private FileDataStorageManager mFileDataStorageManager; - /** * Public factory method to create new ShareFileFragment instances. * @@ -107,7 +99,6 @@ public class ShareFileFragment extends Fragment if (getArguments() != null) { mFile = getArguments().getParcelable(ARG_FILE); mAccount = getArguments().getParcelable(ARG_ACCOUNT); - mFileDataStorageManager = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); } } @@ -147,7 +138,7 @@ public class ShareFileFragment extends Fragment @Override public void onClick(View view) { // Show Search Fragment - mListener.showSearchUsersAndGroups(); + mListener.showSearchUsersAndGroups(mShares); } }); @@ -159,7 +150,7 @@ public class ShareFileFragment extends Fragment super.onActivityCreated(savedInstanceState); // Load data to the list (start process with an Async Task) - refreshUsersOrGroupsListFromServer(); + mListener.refreshUsersOrGroupsListFromServer(); } @Override @@ -184,7 +175,7 @@ public class ShareFileFragment extends Fragment */ public void refreshUsersOrGroupsListFromDB (){ // Get Users and Groups - mShares = mFileDataStorageManager.getSharesWithForAFile(mFile.getRemotePath(), + mShares = ((ShareActivity) mListener).getStorageManager().getSharesWithForAFile(mFile.getRemotePath(), mAccount.name); // Update list of users/groups @@ -194,7 +185,7 @@ public class ShareFileFragment extends Fragment private void updateListOfUserGroups() { // Update list of users/groups mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(), - R.layout.share_user_item, mShares); + R.layout.share_user_item, mShares, this); // Show data TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers); @@ -205,83 +196,20 @@ public class ShareFileFragment extends Fragment usersList.setVisibility(View.VISIBLE); usersList.setAdapter(mUserGroupsAdapter); - // Add unshare options - registerLongClickListener(usersList); - } else { noShares.setVisibility(View.VISIBLE); usersList.setVisibility(View.GONE); } } - /** - * Get users and groups from the server to fill in the "share with" list - */ - public void refreshUsersOrGroupsListFromServer(){ - // Show loading - ((ShareActivity) getActivity()).showLoadingDialog(getString(R.string.common_loading)); - // Get Users and Groups - GetShareWithUsersAsyncTask getTask = new GetShareWithUsersAsyncTask(this); - Object[] params = { mFile, mAccount, mFileDataStorageManager}; - getTask.execute(params); - } - - private void registerLongClickListener(final ListView listView) { - listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView parent, View view, final int position, - long id) { - // Show unshare button - ImageView unshareButton = (ImageView) view.findViewById(R.id.unshareButton); - if (unshareButton.getVisibility() == View.GONE) { - unshareButton.setVisibility(View.VISIBLE); - unshareButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - // Unshare - unshareWith(mShares.get(position)); - Log_OC.d(TAG, "Unshare - " + - mShares.get(position).getSharedWithDisplayName()); - } - }); - - } else { - unshareButton.setVisibility(View.GONE); - } - view.setAlpha(0); - view.animate().alpha(1).setDuration(500).start(); - return false; - } - }); - } - - // Call to Unshare operation - private void unshareWith(OCShare share){ - OCFile file = ((FileActivity) getActivity()).getFile(); - - ((FileActivity) getActivity()).getFileOperationsHelper(). - unshareFileWithUserOrGroup( - file, share.getShareType(), share.getShareWith() - ); - } - @Override - public void onGetDataShareWithFinish(RemoteOperationResult result) { - // Remove loading - ((ShareActivity) getActivity()).dismissLoadingDialog(); - if (result != null && result.isSuccess()) { - Log_OC.d(TAG, "Get Data Share With finishes sucessfully"); - - } else { - Toast.makeText(getActivity(), result.getLogMessage(), Toast.LENGTH_SHORT).show(); - } - - // Data is on Database - refreshUsersOrGroupsListFromDB(); + public void unshareButtonPressed(OCShare share) { + // Unshare + mListener.unshareWith(share); + Log_OC.d(TAG, "Unshare - " + share.getSharedWithDisplayName()); } - // TODO: review if it is necessary /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated @@ -293,7 +221,9 @@ public class ShareFileFragment extends Fragment * >Communicating with Other Fragments for more information. */ public interface OnShareFragmentInteractionListener { - void showSearchUsersAndGroups(); + void showSearchUsersAndGroups(ArrayList shares); + void refreshUsersOrGroupsListFromServer(); + void unshareWith(OCShare share); } }