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
.GetSharesForFileOperation
;
38 import com
.owncloud
.android
.operations
.UnshareOperation
;
39 import com
.owncloud
.android
.ui
.fragment
.SearchFragment
;
40 import com
.owncloud
.android
.ui
.fragment
.ShareFileFragment
;
43 * Activity for sharing files
46 public class ShareActivity
extends FileActivity
47 implements ShareFileFragment
.OnShareFragmentInteractionListener
,
48 SearchFragment
.OnSearchFragmentInteractionListener
{
50 private static final String TAG
= ShareActivity
.class.getSimpleName();
52 private static final String TAG_SHARE_FRAGMENT
= "SHARE_FRAGMENT";
53 private static final String TAG_SEARCH_FRAGMENT
= "SEARCH_USER_AND_GROUPS_FRAGMENT";
55 private static final String DIALOG_WAIT_LOAD_DATA
= "DIALOG_WAIT_LOAD_DATA";
57 private ShareFileFragment mShareFileFragment
;
58 private SearchFragment mSearchFragment
;
61 protected void onCreate(Bundle savedInstanceState
) {
62 super.onCreate(savedInstanceState
);
64 setContentView(R
.layout
.share_activity
);
66 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
68 if (savedInstanceState
!= null
) {
70 mShareFileFragment
= (ShareFileFragment
) getSupportFragmentManager().
71 getFragment(savedInstanceState
, TAG_SHARE_FRAGMENT
);
72 mSearchFragment
= (SearchFragment
) getSupportFragmentManager().
73 getFragment(savedInstanceState
, TAG_SEARCH_FRAGMENT
);
75 if (mShareFileFragment
!= null
){
76 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
78 if (mSearchFragment
!= null
){
79 ft
.hide(mShareFileFragment
);
80 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
81 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
88 mShareFileFragment
= ShareFileFragment
.newInstance(getFile(), getAccount());
89 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
92 mSearchFragment
= null
;
95 handleIntent(getIntent());
100 protected void onNewIntent(Intent intent
) {
102 handleIntent(intent
);
106 private void handleIntent(Intent intent
) {
107 // Verify the action and get the query
108 if (Intent
.ACTION_SEARCH
.equals(intent
.getAction())) {
109 String query
= intent
.getStringExtra(SearchManager
.QUERY
);
112 } else if (UsersAndGroupsSearchProvider
.ACTION_SHARE_WITH
.equals(intent
.getAction())) {
113 Uri data
= intent
.getData();
115 data
.getLastPathSegment(),
116 UsersAndGroupsSearchProvider
.DATA_GROUP
.equals(data
.getAuthority())
120 Log_OC
.wtf(TAG
, "Unexpected intent " + intent
.toString());
124 private void doMySearch(String query
) {
125 // TODO implement , or prevent that search may be sent without choosing from the suggestions list
126 Toast
.makeText(this, "You want to search for [" + query
+ "]", Toast
.LENGTH_SHORT
).show();
129 private void doShareWith(String username
, boolean isGroup
) {
132 Toast
.makeText(this, "You want to SHARE with GROUP [" + username
+ "]", Toast
.LENGTH_SHORT
).show();
135 Toast
.makeText(this, "You want to SHARE with USER [" + username
+ "]", Toast
.LENGTH_SHORT
).show();
140 protected void onSaveInstanceState(Bundle outState
) {
141 super.onSaveInstanceState(outState
);
142 //Save the fragment's instance
143 getSupportFragmentManager().putFragment(outState
, TAG_SHARE_FRAGMENT
, mShareFileFragment
);
144 if (mSearchFragment
!= null
) {
145 getSupportFragmentManager().putFragment(outState
, TAG_SEARCH_FRAGMENT
, mSearchFragment
);
152 public void showSearchUsersAndGroups() {
153 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
154 mSearchFragment
= SearchFragment
.newInstance(getFile(), getAccount());
155 ft
.hide(mShareFileFragment
);
156 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
157 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
162 public void onBackPressed() {
163 super.onBackPressed();
164 if (mSearchFragment
!= null
){
165 getSupportFragmentManager().popBackStackImmediate();
166 mSearchFragment
= null
;
171 * Updates the view associated to the activity after the finish of some operation over files
172 * in the current account.
174 * @param operation Removal operation performed.
175 * @param result Result of the removal.
178 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
179 super.onRemoteOperationFinish(operation
, result
);
180 if (operation
instanceof UnshareOperation
) {
181 if (mShareFileFragment
!= null
){
182 mShareFileFragment
.refreshUsersOrGroupsListFromDB();
184 } else if (operation
instanceof GetSharesForFileOperation
) {
185 onGetSharesForFileOperationFinish((GetSharesForFileOperation
) operation
, result
);
190 private void onGetSharesForFileOperationFinish(GetSharesForFileOperation operation
, RemoteOperationResult result
){
191 dismissLoadingDialog();
193 if (!result
.isSuccess()) {
194 Toast
.makeText(getApplicationContext(), result
.getLogMessage(), Toast
.LENGTH_LONG
).show();
198 if (mShareFileFragment
!= null
){
199 mShareFileFragment
.refreshUsersOrGroupsListFromDB();
204 public void onSearchFragmentInteraction(Uri uri
) {