import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.operations.GetSharesForFileOperation;
+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.ShareFileFragment;
+import com.owncloud.android.utils.ErrorMessageAdapter;
+import com.owncloud.android.utils.GetShareWithUsersAsyncTask;
+
+import java.util.ArrayList;
/**
* Activity for sharing files
*/
public class ShareActivity extends FileActivity
- implements ShareFileFragment.OnShareFragmentInteractionListener,
+ implements GetShareWithUsersAsyncTask.OnGetSharesWithUsersTaskListener,
+ ShareFileFragment.OnShareFragmentInteractionListener,
SearchFragment.OnSearchFragmentInteractionListener {
private static final String TAG = ShareActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ onAccountSet(false);
setContentView(R.layout.share_activity);
if (mSearchFragment != null){
ft.hide(mShareFileFragment);
ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
- ft.addToBackStack(TAG_SEARCH_FRAGMENT);
}
ft.commit();
}
}
handleIntent(getIntent());
+
+
}
// Verify the action and get the query
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
- doMySearch(query);
+ Log_OC.w(TAG, "Ignored Intent requesting to query for " + query);
} else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
Uri data = intent.getData();
}
}
- private void doMySearch(String query) {
- // TODO implement , or prevent that search may be sent without choosing from the suggestions list
- Toast.makeText(this, "You want to search for [" + query + "]", Toast.LENGTH_SHORT).show();
- }
-
- private void doShareWith(String username, boolean isGroup) {
- // TODO implement
- if (isGroup) {
- Toast.makeText(this, "You want to SHARE with GROUP [" + username + "]", Toast.LENGTH_SHORT).show();
-
- } else {
- Toast.makeText(this, "You want to SHARE with USER [" + username + "]", Toast.LENGTH_SHORT).show();
- }
+ private void doShareWith(String shareeName, boolean isGroup) {
+ getFileOperationsHelper().shareFileWithSharee(
+ getFile(),
+ shareeName,
+ (isGroup ? ShareType.GROUP : ShareType.USER)
+ );
}
@Override
}
-
@Override
- public void showSearchUsersAndGroups() {
+ public void showSearchUsersAndGroups(ArrayList<OCShare> 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);
}
@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){
- getSupportFragmentManager().popBackStackImmediate();
mSearchFragment = null;
+ getSupportFragmentManager().popBackStackImmediate();
+ mShareFileFragment.refreshUsersOrGroupsListFromDB();
}
}
@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
super.onRemoteOperationFinish(operation, result);
- if (operation instanceof UnshareOperation) {
- if (mShareFileFragment != null){
- mShareFileFragment.refreshUsersOrGroupsListFromDB();
+ if (operation instanceof UnshareOperation ||
+ operation instanceof CreateShareWithShareeOperation) {
+
+ if (result.isSuccess()) {
+ refreshUsersInLists();
+ if (operation instanceof CreateShareWithShareeOperation) {
+ // Clean action
+ getIntent().setAction(null);
+ }
+ } else {
+ Toast.makeText(
+ this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG
+ ).show();
}
- } else if (operation instanceof GetSharesForFileOperation) {
- onGetSharesForFileOperationFinish((GetSharesForFileOperation) operation, result);
- }
+ /*} else if (operation instanceof GetSharesForFileOperation) {
+ onGetSharesForFileOperationFinish((GetSharesForFileOperation) operation, result);*/
+ }
}
- 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) {
-
- }
}