2 * ownCloud Android client application
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.ui
.activity
;
24 import android
.app
.SearchManager
;
25 import android
.content
.Intent
;
26 import android
.net
.Uri
;
27 import android
.os
.Bundle
;
28 import android
.support
.v4
.app
.FragmentTransaction
;
29 import android
.widget
.Toast
;
31 import com
.owncloud
.android
.R
;
32 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
33 import com
.owncloud
.android
.providers
.UsersAndGroupsSearchProvider
;
35 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
36 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
37 import com
.owncloud
.android
.datamodel
.OCFile
;
38 import com
.owncloud
.android
.lib
.resources
.shares
.OCShare
;
39 import com
.owncloud
.android
.lib
.resources
.shares
.ShareType
;
40 import com
.owncloud
.android
.operations
.CreateShareWithShareeOperation
;
41 import com
.owncloud
.android
.operations
.UnshareOperation
;
42 import com
.owncloud
.android
.ui
.fragment
.SearchFragment
;
43 import com
.owncloud
.android
.ui
.fragment
.ShareFileFragment
;
44 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
45 import com
.owncloud
.android
.utils
.GetShareWithUsersAsyncTask
;
47 import java
.util
.ArrayList
;
50 * Activity for sharing files
53 public class ShareActivity
extends FileActivity
54 implements ShareFileFragment
.OnShareFragmentInteractionListener
,
55 SearchFragment
.OnSearchFragmentInteractionListener
{
57 private static final String TAG
= ShareActivity
.class.getSimpleName();
59 private static final String TAG_SHARE_FRAGMENT
= "SHARE_FRAGMENT";
60 private static final String TAG_SEARCH_FRAGMENT
= "SEARCH_USER_AND_GROUPS_FRAGMENT";
62 private static final String DIALOG_WAIT_LOAD_DATA
= "DIALOG_WAIT_LOAD_DATA";
64 private ShareFileFragment mShareFileFragment
;
65 private SearchFragment mSearchFragment
;
68 protected void onCreate(Bundle savedInstanceState
) {
69 super.onCreate(savedInstanceState
);
72 setContentView(R
.layout
.share_activity
);
74 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
76 if (savedInstanceState
!= null
) {
78 mShareFileFragment
= (ShareFileFragment
) getSupportFragmentManager().
79 getFragment(savedInstanceState
, TAG_SHARE_FRAGMENT
);
80 mSearchFragment
= (SearchFragment
) getSupportFragmentManager().
81 getFragment(savedInstanceState
, TAG_SEARCH_FRAGMENT
);
83 if (mShareFileFragment
!= null
){
84 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
86 if (mSearchFragment
!= null
){
87 ft
.hide(mShareFileFragment
);
88 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
95 mShareFileFragment
= ShareFileFragment
.newInstance(getFile(), getAccount());
96 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
99 mSearchFragment
= null
;
102 handleIntent(getIntent());
109 protected void onNewIntent(Intent intent
) {
111 handleIntent(intent
);
115 private void handleIntent(Intent intent
) {
116 // Verify the action and get the query
117 if (Intent
.ACTION_SEARCH
.equals(intent
.getAction())) {
118 String query
= intent
.getStringExtra(SearchManager
.QUERY
);
119 Log_OC
.w(TAG
, "Ignored Intent requesting to query for " + query
);
121 } else if (UsersAndGroupsSearchProvider
.ACTION_SHARE_WITH
.equals(intent
.getAction())) {
122 Uri data
= intent
.getData();
124 data
.getLastPathSegment(),
125 UsersAndGroupsSearchProvider
.DATA_GROUP
.equals(data
.getAuthority())
129 Log_OC
.wtf(TAG
, "Unexpected intent " + intent
.toString());
133 private void doShareWith(String shareeName
, boolean isGroup
) {
134 getFileOperationsHelper().shareFileWithSharee(
137 (isGroup ? ShareType
.GROUP
: ShareType
.USER
)
142 protected void onSaveInstanceState(Bundle outState
) {
143 super.onSaveInstanceState(outState
);
144 //Save the fragment's instance
145 getSupportFragmentManager().putFragment(outState
, TAG_SHARE_FRAGMENT
, mShareFileFragment
);
146 if (mSearchFragment
!= null
) {
147 getSupportFragmentManager().putFragment(outState
, TAG_SEARCH_FRAGMENT
, mSearchFragment
);
153 public void showSearchUsersAndGroups(ArrayList
<OCShare
> shares
) {
154 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
155 mSearchFragment
= SearchFragment
.newInstance(getFile(), getAccount(), shares
);
156 ft
.hide(mShareFileFragment
);
157 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
158 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
163 // Call to Unshare operation
164 public void unshareWith(OCShare share
){
165 OCFile file
= getFile();
166 getFileOperationsHelper().unshareFileWithUserOrGroup(file
, share
.getShareType(), share
.getShareWith());
170 * Get users and groups from the server to fill in the "share with" list
173 public void refreshUsersOrGroupsListFromServer(){
175 showLoadingDialog(getString(R
.string
.common_loading
));
176 // Get Users and Groups
177 GetShareWithUsersAsyncTask getTask
= new GetShareWithUsersAsyncTask(this);
178 Object
[] params
= { getFile(), getAccount(), getStorageManager()};
179 getTask
.execute(params
);
183 public void onBackPressed() {
184 super.onBackPressed();
185 if (mSearchFragment
!= null
){
186 mSearchFragment
= null
;
187 getSupportFragmentManager().popBackStackImmediate();
188 mShareFileFragment
.refreshUsersOrGroupsListFromDB();
193 * Updates the view associated to the activity after the finish of some operation over files
194 * in the current account.
196 * @param operation Removal operation performed.
197 * @param result Result of the removal.
200 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
201 super.onRemoteOperationFinish(operation
, result
);
203 if (result
.isSuccess()) {
204 refreshUsersInLists();
205 if (operation
instanceof CreateShareWithShareeOperation
) {
207 getIntent().setAction(null
);
213 private void refreshUsersInLists(){
214 if (mShareFileFragment
!= null
){
215 mShareFileFragment
.refreshUsersOrGroupsListFromDB();
217 if (mSearchFragment
!= null
) {
218 mSearchFragment
.refreshUsersOrGroupsListFromDB();