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
.operations
.UnshareOperation
;
38 import com
.owncloud
.android
.ui
.fragment
.SearchFragment
;
39 import com
.owncloud
.android
.ui
.fragment
.ShareFileFragment
;
42 * Activity for sharing files
45 public class ShareActivity
extends FileActivity
46 implements ShareFileFragment
.OnShareFragmentInteractionListener
,
47 SearchFragment
.OnSearchFragmentInteractionListener
{
49 private static final String TAG
= ShareActivity
.class.getSimpleName();
51 private static final String TAG_SHARE_FRAGMENT
= "SHARE_FRAGMENT";
52 private static final String TAG_SEARCH_FRAGMENT
= "SEARCH_USER_AND_GROUPS_FRAGMENT";
54 private static final String DIALOG_WAIT_LOAD_DATA
= "DIALOG_WAIT_LOAD_DATA";
56 private ShareFileFragment mShareFileFragment
;
57 private SearchFragment mSearchFragment
;
60 protected void onCreate(Bundle savedInstanceState
) {
61 super.onCreate(savedInstanceState
);
62 setContentView(R
.layout
.share_activity
);
64 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
66 if (savedInstanceState
!= null
) {
68 mShareFileFragment
= (ShareFileFragment
) getSupportFragmentManager().
69 getFragment(savedInstanceState
, TAG_SHARE_FRAGMENT
);
70 mSearchFragment
= (SearchFragment
) getSupportFragmentManager().
71 getFragment(savedInstanceState
, TAG_SEARCH_FRAGMENT
);
73 if (mShareFileFragment
!= null
){
74 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
76 if (mSearchFragment
!= null
){
77 ft
.hide(mShareFileFragment
);
78 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
79 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
86 mShareFileFragment
= ShareFileFragment
.newInstance(getFile(), getAccount());
87 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
90 mSearchFragment
= null
;
93 handleIntent(getIntent());
98 protected void onNewIntent(Intent intent
) {
100 handleIntent(intent
);
104 private void handleIntent(Intent intent
) {
105 // Verify the action and get the query
106 if (Intent
.ACTION_SEARCH
.equals(intent
.getAction())) {
107 String query
= intent
.getStringExtra(SearchManager
.QUERY
);
110 } else if (UsersAndGroupsSearchProvider
.ACTION_SHARE_WITH
.equals(intent
.getAction())) {
111 Uri data
= intent
.getData();
113 data
.getLastPathSegment(),
114 UsersAndGroupsSearchProvider
.DATA_GROUP
.equals(data
.getAuthority())
118 Log_OC
.wtf(TAG
, "Unexpected intent " + intent
.toString());
122 private void doMySearch(String query
) {
123 // TODO implement , or prevent that search may be sent without choosing from the suggestions list
124 Toast
.makeText(this, "You want to search for [" + query
+ "]", Toast
.LENGTH_SHORT
).show();
127 private void doShareWith(String username
, boolean isGroup
) {
130 Toast
.makeText(this, "You want to SHARE with GROUP [" + username
+ "]", Toast
.LENGTH_SHORT
).show();
133 Toast
.makeText(this, "You want to SHARE with USER [" + username
+ "]", Toast
.LENGTH_SHORT
).show();
138 protected void onSaveInstanceState(Bundle outState
) {
139 super.onSaveInstanceState(outState
);
140 //Save the fragment's instance
141 getSupportFragmentManager().putFragment(outState
, TAG_SHARE_FRAGMENT
, mShareFileFragment
);
142 if (mSearchFragment
!= null
) {
143 getSupportFragmentManager().putFragment(outState
, TAG_SEARCH_FRAGMENT
, mSearchFragment
);
149 public void showSearchUsersAndGroups() {
150 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
151 mSearchFragment
= SearchFragment
.newInstance(getFile(), getAccount());
152 ft
.hide(mShareFileFragment
);
153 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
154 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
159 public void onBackPressed() {
160 super.onBackPressed();
161 if (mSearchFragment
!= null
){
162 getSupportFragmentManager().popBackStackImmediate();
163 mSearchFragment
= null
;
168 * Updates the view associated to the activity after the finish of some operation over files
169 * in the current account.
171 * @param operation Removal operation performed.
172 * @param result Result of the removal.
175 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
176 super.onRemoteOperationFinish(operation
, result
);
177 if (operation
instanceof UnshareOperation
) {
178 if (mShareFileFragment
!= null
){
179 mShareFileFragment
.refreshUsersOrGroupsList();
186 public void onShareFragmentInteraction(Uri uri
) {
191 public void onSearchFragmentInteraction(Uri uri
) {