import android.accounts.Account;
import android.app.Activity;
import android.graphics.Bitmap;
-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.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.ShareActivity;
import com.owncloud.android.ui.adapter.ShareUserListAdapter;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimetypeIconUtil;
-import com.owncloud.android.utils.UnshareWithUserAsyncTask;
import java.util.ArrayList;
* create an instance of this fragment.
*/
public class ShareFileFragment extends Fragment
- implements UnshareWithUserAsyncTask.OnUnshareWithUserTaskListener{
+ implements ShareUserListAdapter.ShareUserAdapterListener{
private static final String TAG = ShareFileFragment.class.getSimpleName();
size.setText(DisplayUtils.bytesToHumanReadable(mFile.getFileLength()));
}
- // List of share with users
- TextView noShares = (TextView) view.findViewById(R.id.shareNoUsers);
-
- // TODO: Get shares from DB and show
-
-
// Add User Button
Button addUserGroupButton = (Button)
view.findViewById(R.id.addUserButton);
@Override
public void onClick(View view) {
// Show Search Fragment
- mListener.showSearchUsersAndGroups();
+ mListener.showSearchUsersAndGroups(mShares);
}
});
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- getShares();
- }
-
- // TODO: Rename method, update argument and hook method into UI event
- public void onButtonPressed(Uri uri) {
- if (mListener != null) {
- mListener.onShareFragmentInteraction(uri);
- }
+ // Load data to the list (start process with an Async Task)
+ mListener.refreshUsersOrGroupsListFromServer();
}
@Override
mListener = null;
}
- // Get users and groups to fill the "share with" list
- private void getShares(){
- mShares = new ArrayList<OCShare>();
-
+ /**
+ * Get users and groups fromn the DB to fill in the "share with" list
+ */
+ public void refreshUsersOrGroupsListFromDB (){
// Get Users and Groups
- FileDataStorageManager fileDataStorageManager =
- new FileDataStorageManager(mAccount, getActivity().getContentResolver());
- mShares = fileDataStorageManager.getSharesWithForAFile(mFile.getRemotePath(), mAccount.name);
+ 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);
+ R.layout.share_user_item, mShares, this);
// Show data
TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers);
usersList.setVisibility(View.VISIBLE);
usersList.setAdapter(mUserGroupsAdapter);
- // Add unshare options
- registerLongClickListener(usersList);
-
} else {
noShares.setVisibility(View.VISIBLE);
usersList.setVisibility(View.GONE);
}
}
- 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((int)(mShares.get(position).getIdRemoteShared()));
- 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;
- }
- });
- }
-
- private void unshareWith(int shareId){
- ( (ShareActivity) getActivity()).showWaitingLoadDialog();
- // Remove Share with id
- UnshareWithUserAsyncTask unshareTask = new UnshareWithUserAsyncTask(this);
- FileDataStorageManager fileDataStorageManager =
- new FileDataStorageManager(mAccount, getActivity().getContentResolver());
- Object[] params = { shareId, mAccount, fileDataStorageManager};
- unshareTask.execute(params);
- }
-
@Override
- public void onUnshareWithFinish(RemoteOperationResult result) {
- // Remove loading
- ((ShareActivity) getActivity()).dismissWaitingLoadDialog();
-
- if (result != null && result.isSuccess()) {
- // Refresh data
- //TODO: Refresh file or delete the user from the list
- updateListOfUserGroups();
-
- } else {
- Toast.makeText(getActivity(), result.getLogMessage(), Toast.LENGTH_SHORT).show();
- }
+ 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
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnShareFragmentInteractionListener {
- void showSearchUsersAndGroups();
-
- void onShareFragmentInteraction(Uri uri);
+ void showSearchUsersAndGroups(ArrayList<OCShare> shares);
+ void refreshUsersOrGroupsListFromServer();
+ void unshareWith(OCShare share);
}
}