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
.accounts
.Account
;
25 import android
.app
.SearchManager
;
26 import android
.content
.Intent
;
27 import android
.net
.Uri
;
28 import android
.os
.Bundle
;
29 import android
.support
.v4
.app
.Fragment
;
30 import android
.support
.v4
.app
.FragmentManager
;
31 import android
.support
.v4
.app
.FragmentTransaction
;
32 import android
.support
.v7
.app
.AppCompatActivity
;
33 import android
.widget
.Toast
;
35 import com
.owncloud
.android
.R
;
36 import com
.owncloud
.android
.datamodel
.OCFile
;
37 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
38 import com
.owncloud
.android
.providers
.UsersAndGroupsSearchProvider
;
39 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
40 import com
.owncloud
.android
.ui
.fragment
.SearchFragment
;
41 import com
.owncloud
.android
.ui
.fragment
.ShareFileFragment
;
44 * Activity for sharing files
47 public class ShareActivity
extends AppCompatActivity
48 implements ShareFileFragment
.OnShareFragmentInteractionListener
,
49 SearchFragment
.OnSearchFragmentInteractionListener
{
51 private static final String TAG
= ShareActivity
.class.getSimpleName();
53 private static final String TAG_SHARE_FRAGMENT
= "SHARE_FRAGMENT";
54 private static final String TAG_SEARCH_FRAGMENT
= "SEARCH_USER_AND_GROUPS_FRAGMENT";
56 private static final String DIALOG_WAIT_LOAD_DATA
= "DIALOG_WAIT_LOAD_DATA";
58 private Account mAccount
;
61 private ShareFileFragment mShareFileFragment
;
62 private SearchFragment mSearchFragment
;
65 protected void onCreate(Bundle savedInstanceState
) {
66 super.onCreate(savedInstanceState
);
67 setContentView(R
.layout
.share_activity
);
69 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
71 if (savedInstanceState
!= null
) {
72 mFile
= savedInstanceState
.getParcelable(FileActivity
.EXTRA_FILE
);
73 mAccount
= savedInstanceState
.getParcelable(FileActivity
.EXTRA_ACCOUNT
);
75 mShareFileFragment
= (ShareFileFragment
) getSupportFragmentManager().
76 getFragment(savedInstanceState
, TAG_SHARE_FRAGMENT
);
77 mSearchFragment
= (SearchFragment
) 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
);
86 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
93 mFile
= getIntent().getParcelableExtra(FileActivity
.EXTRA_FILE
);
94 mAccount
= getIntent().getParcelableExtra(FileActivity
.EXTRA_ACCOUNT
);
97 mShareFileFragment
= ShareFileFragment
.newInstance(mFile
, mAccount
);
98 ft
.replace(R
.id
.share_fragment_container
, mShareFileFragment
, TAG_SHARE_FRAGMENT
);
101 mSearchFragment
= null
;
104 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
);
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 doMySearch(String query
) {
134 // TODO implement , or prevent that search may be sent without choosing from the suggestions list
135 Toast
.makeText(this, "You want to search for [" + query
+ "]", Toast
.LENGTH_SHORT
).show();
138 private void doShareWith(String username
, boolean isGroup
) {
141 Toast
.makeText(this, "You want to SHARE with GROUP [" + username
+ "]", Toast
.LENGTH_SHORT
).show();
144 Toast
.makeText(this, "You want to SHARE with USER [" + username
+ "]", Toast
.LENGTH_SHORT
).show();
149 protected void onSaveInstanceState(Bundle outState
) {
150 super.onSaveInstanceState(outState
);
151 outState
.putParcelable(FileActivity
.EXTRA_FILE
, mFile
);
152 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, mAccount
);
154 //Save the fragment's instance
155 getSupportFragmentManager().putFragment(outState
, TAG_SHARE_FRAGMENT
, mShareFileFragment
);
156 if (mSearchFragment
!= null
) {
157 getSupportFragmentManager().putFragment(outState
, TAG_SEARCH_FRAGMENT
, mSearchFragment
);
163 public void showSearchUsersAndGroups() {
164 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
165 mSearchFragment
= SearchFragment
.newInstance(mFile
, mAccount
);
166 ft
.hide(mShareFileFragment
);
167 ft
.add(R
.id
.share_fragment_container
, mSearchFragment
, TAG_SEARCH_FRAGMENT
);
168 ft
.addToBackStack(TAG_SEARCH_FRAGMENT
);
173 public void onBackPressed() {
174 super.onBackPressed();
175 if (mSearchFragment
!= null
){
176 getSupportFragmentManager().popBackStackImmediate();
177 mSearchFragment
= null
;
182 public void onShareFragmentInteraction(Uri uri
) {
187 public void onSearchFragmentInteraction(Uri uri
) {
192 * Show waiting for loading data
194 public void showWaitingLoadDialog() {
196 LoadingDialog loading
= new LoadingDialog(
197 getResources().getString(R
.string
.common_loading
));
198 FragmentManager fm
= getSupportFragmentManager();
199 FragmentTransaction ft
= fm
.beginTransaction();
200 loading
.show(ft
, DIALOG_WAIT_LOAD_DATA
);
206 * Dismiss waiting for loading data
208 public void dismissWaitingLoadDialog(){
209 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_LOAD_DATA
);
211 LoadingDialog loading
= (LoadingDialog
) frag
;