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
;
30 import com
.owncloud
.android
.R
;
31 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
32 import com
.owncloud
.android
.providers
.UsersAndGroupsSearchProvider
;
34 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
35 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
36 import com
.owncloud
.android
.datamodel
.OCFile
;
37 import com
.owncloud
.android
.lib
.resources
.shares
.OCShare
;
38 import com
.owncloud
.android
.lib
.resources
.shares
.ShareType
;
39 import com
.owncloud
.android
.operations
.CreateShareWithShareeOperation
;
40 import com
.owncloud
.android
.ui
.fragment
.SearchShareesFragment
;
41 import com
.owncloud
.android
.ui
.fragment
.ShareFileFragment
;
42 import com
.owncloud
.android
.utils
.GetShareWithUsersAsyncTask
;
44 import java
.util
.ArrayList
;
47 * Activity for sharing files
50 public class ShareActivity
extends FileActivity
51 implements ShareFileFragment
.OnShareFragmentInteractionListener
,
52 SearchShareesFragment
.OnSearchFragmentInteractionListener
{
54 private static final String TAG
= ShareActivity
.class.getSimpleName();
56 private static final String TAG_SHARE_FRAGMENT
= "SHARE_FRAGMENT";
57 private static final String TAG_SEARCH_FRAGMENT
= "SEARCH_USER_AND_GROUPS_FRAGMENT";
59 private static final String DIALOG_WAIT_LOAD_DATA
= "DIALOG_WAIT_LOAD_DATA";
61 private ShareFileFragment mShareFileFragment
;
62 private SearchShareesFragment mSearchFragment
;
65 protected void onCreate(Bundle savedInstanceState
) {
66 super.onCreate(savedInstanceState
);
69 setContentView(R
.layout
.share_activity
);
71 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
73 if (savedInstanceState
!= null
) {
75 mShareFileFragment
= (ShareFileFragment
) getSupportFragmentManager().
76 getFragment(savedInstanceState
, TAG_SHARE_FRAGMENT
);
77 mSearchFragment
= (SearchShareesFragment
) getSupportFragmentManager().
78 getFragment(savedInstanceState
, TAG_SEARCH_FRAGMENT
);
80 if (mShareFileFragment
!= null
){
81 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
83 if (mSearchFragment
!= null
){
84 ft
.hide(mShareFileFragment
);
85 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
92 mShareFileFragment
= ShareFileFragment
.newInstance(getFile(), getAccount());
93 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
96 mSearchFragment
= null
;
99 handleIntent(getIntent());
106 protected void onNewIntent(Intent intent
) {
108 handleIntent(intent
);
112 private void handleIntent(Intent intent
) {
113 // Verify the action and get the query
114 if (Intent
.ACTION_SEARCH
.equals(intent
.getAction())) {
115 String query
= intent
.getStringExtra(SearchManager
.QUERY
);
116 Log_OC
.w(TAG
, "Ignored Intent requesting to query for " + query
);
118 } else if (UsersAndGroupsSearchProvider
.ACTION_SHARE_WITH
.equals(intent
.getAction())) {
119 Uri data
= intent
.getData();
121 data
.getLastPathSegment(),
122 UsersAndGroupsSearchProvider
.DATA_GROUP
.equals(data
.getAuthority())
126 Log_OC
.wtf(TAG
, "Unexpected intent " + intent
.toString());
130 private void doShareWith(String shareeName
, boolean isGroup
) {
131 getFileOperationsHelper().shareFileWithSharee(
134 (isGroup ? ShareType
.GROUP
: ShareType
.USER
)
139 protected void onSaveInstanceState(Bundle outState
) {
140 super.onSaveInstanceState(outState
);
141 //Save the fragment's instance
142 getSupportFragmentManager().putFragment(outState
, TAG_SHARE_FRAGMENT
, mShareFileFragment
);
143 if (mSearchFragment
!= null
) {
144 getSupportFragmentManager().putFragment(outState
, TAG_SEARCH_FRAGMENT
, mSearchFragment
);
150 public void showSearchUsersAndGroups() {
151 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
152 mSearchFragment
= SearchShareesFragment
.newInstance(getFile(), getAccount());
153 ft
.hide(mShareFileFragment
);
154 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
155 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
160 // Call to Unshare operation
161 public void unshareWith(OCShare share
){
162 OCFile file
= getFile();
163 getFileOperationsHelper().unshareFileWithUserOrGroup(file
, share
.getShareType(), share
.getShareWith());
167 * Get users and groups from the server to fill in the "share with" list
170 public void refreshUsersOrGroupsListFromServer(){
172 showLoadingDialog(getString(R
.string
.common_loading
));
173 // Get Users and Groups
174 GetShareWithUsersAsyncTask getTask
= new GetShareWithUsersAsyncTask(this);
175 Object
[] params
= { getFile(), getAccount(), getStorageManager()};
176 getTask
.execute(params
);
180 public void onBackPressed() {
181 super.onBackPressed();
182 if (mSearchFragment
!= null
){
183 mSearchFragment
= null
;
184 getSupportFragmentManager().popBackStackImmediate();
185 mShareFileFragment
.refreshUsersOrGroupsListFromDB();
190 * Updates the view associated to the activity after the finish of some operation over files
191 * in the current account.
193 * @param operation Removal operation performed.
194 * @param result Result of the removal.
197 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
198 super.onRemoteOperationFinish(operation
, result
);
200 if (result
.isSuccess()) {
201 refreshUsersInLists();
202 if (operation
instanceof CreateShareWithShareeOperation
) {
204 getIntent().setAction(null
);
210 private void refreshUsersInLists(){
211 if (mShareFileFragment
!= null
){
212 mShareFileFragment
.refreshUsersOrGroupsListFromDB();
214 if (mSearchFragment
!= null
) {
215 mSearchFragment
.refreshUsersOrGroupsListFromDB();