X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/1bdd67229590048bb37134aeb94426ea77faeaf6..c49cc06d3de203308ef7726338aff4a93be89cdd:/src/com/owncloud/android/ui/fragment/ShareFileFragment.java diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index 9d01bd25..8a589db9 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -23,7 +23,6 @@ package com.owncloud.android.ui.fragment; 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; @@ -43,11 +42,13 @@ 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.lib.resources.shares.ShareType; +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 com.owncloud.android.utils.UnshareWithUserAsyncTask; import java.util.ArrayList; @@ -62,7 +63,7 @@ import java.util.ArrayList; * create an instance of this fragment. */ public class ShareFileFragment extends Fragment - implements UnshareWithUserAsyncTask.OnUnshareWithUserTaskListener{ + implements GetShareWithUsersAsyncTask.OnGetSharesWithUsersTaskListener { private static final String TAG = ShareFileFragment.class.getSimpleName(); @@ -137,12 +138,6 @@ public class ShareFileFragment extends Fragment 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); @@ -161,14 +156,9 @@ public class ShareFileFragment extends Fragment public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - getShares(); - } + // Load data to the list (start process with an Async Task) + refreshUsersOrGroupsListFromServer(); - // TODO: Rename method, update argument and hook method into UI event - public void onButtonPressed(Uri uri) { - if (mListener != null) { - mListener.onShareFragmentInteraction(uri); - } } @Override @@ -188,14 +178,15 @@ public class ShareFileFragment extends Fragment mListener = null; } - // Get users and groups to fill the "share with" list - private void getShares() { - mShares = new ArrayList<>(); - + /** + * 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 = fileDataStorageManager.getSharesWithForAFile(mFile.getRemotePath(), + mAccount.name); // Update list of users/groups updateListOfUserGroups(); @@ -224,6 +215,21 @@ public class ShareFileFragment extends Fragment } } + /** + * Get users and groups from the server to fill in the "share with" list + */ + public void refreshUsersOrGroupsListFromServer(){ + mShares = new ArrayList<>(); + + // Show loading + ((ShareActivity) getActivity()).showLoadingDialog(getString(R.string.common_loading)); + // Get Users and Groups + GetShareWithUsersAsyncTask getTask = new GetShareWithUsersAsyncTask(this); + FileDataStorageManager fileDataStorageManager = ((ShareActivity) getActivity()).getStorageManager(); + Object[] params = { mFile, mAccount, fileDataStorageManager}; + getTask.execute(params); + } + private void registerLongClickListener(final ListView listView) { listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override @@ -237,7 +243,7 @@ public class ShareFileFragment extends Fragment @Override public void onClick(View v) { // Unshare - unshareWith((int)(mShares.get(position).getIdRemoteShared())); + unshareWith(mShares.get(position)); Log_OC.d(TAG, "Unshare - " + mShares.get(position).getSharedWithDisplayName()); } @@ -253,31 +259,52 @@ public class ShareFileFragment extends Fragment }); } - 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); + // 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 onUnshareWithFinish(RemoteOperationResult result) { + public void onGetDataShareWithFinish(RemoteOperationResult result) { // Remove loading - ((ShareActivity) getActivity()).dismissWaitingLoadDialog(); - + ((ShareActivity) getActivity()).dismissLoadingDialog(); if (result != null && result.isSuccess()) { - // Refresh data - //TODO: Refresh file or delete the user from the list - updateListOfUserGroups(); + // update local database + for(Object obj: result.getData()) { + if ( ((OCShare) obj).getShareType() == ShareType.USER || + ((OCShare) obj).getShareType() == ShareType.GROUP ){ + mShares.add((OCShare) obj); + } + } + + // Update list of users/groups + mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(), + R.layout.share_user_item, mShares); + + // Show data + TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers); + ListView usersList = (ListView) getView().findViewById(R.id.shareUsersList); + + if (mShares.size() > 0) { + noShares.setVisibility(View.GONE); + usersList.setVisibility(View.VISIBLE); + usersList.setAdapter(mUserGroupsAdapter); + } else { + noShares.setVisibility(View.VISIBLE); + usersList.setVisibility(View.GONE); + } } else { Toast.makeText(getActivity(), result.getLogMessage(), Toast.LENGTH_SHORT).show(); } } + // TODO: review if it is necessary /** * This interface must be implemented by activities that contain this @@ -291,8 +318,6 @@ public class ShareFileFragment extends Fragment */ public interface OnShareFragmentInteractionListener { void showSearchUsersAndGroups(); - - void onShareFragmentInteraction(Uri uri); } }