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 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 com.owncloud.android.utils.UnshareWithUserAsyncTask;
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();
private OnShareFragmentInteractionListener mListener;
+ private FileDataStorageManager mFileDataStorageManager;
+
/**
* Public factory method to create new ShareFileFragment instances.
*
if (getArguments() != null) {
mFile = getArguments().getParcelable(ARG_FILE);
mAccount = getArguments().getParcelable(ARG_ACCOUNT);
+ mFileDataStorageManager = new FileDataStorageManager(mAccount, getActivity().getContentResolver());
}
}
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);
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)
+ refreshUsersOrGroupsListFromServer();
}
@Override
mListener = null;
}
- // Get users and groups to fill the "share with" list
- private void getShares(){
+ /**
+ * 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 = mFileDataStorageManager.getSharesWithForAFile(mFile.getRemotePath(),
+ mAccount.name);
// Update list of users/groups
updateListOfUserGroups();
}
}
+ /**
+ * 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
@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());
}
});
}
- private void unshareWith(int shareId){
- ( (ShareActivity) getActivity()).showLoadingDialog(getActivity().getApplicationContext().
- getString(R.string.common_loading));
- // 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()).dismissLoadingDialog();
-
if (result != null && result.isSuccess()) {
- // Refresh data
- //TODO: Refresh file or delete the user from the list
- updateListOfUserGroups();
+ 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();
}
+
// TODO: review if it is necessary
/**
* This interface must be implemented by activities that contain this
*/
public interface OnShareFragmentInteractionListener {
void showSearchUsersAndGroups();
-
- void onShareFragmentInteraction(Uri uri);
}
}