Change ShareActivity type, now it is a FileActivity
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / ShareActivity.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
7 *
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.
11 *
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.
16 *
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/>.
19 *
20 */
21
22 package com.owncloud.android.ui.activity;
23
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;
34
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;
42
43 /**
44 * Activity for sharing files
45 */
46
47 public class ShareActivity extends FileActivity
48 implements ShareFileFragment.OnShareFragmentInteractionListener,
49 SearchFragment.OnSearchFragmentInteractionListener {
50
51 private static final String TAG = ShareActivity.class.getSimpleName();
52
53 private static final String TAG_SHARE_FRAGMENT = "SHARE_FRAGMENT";
54 private static final String TAG_SEARCH_FRAGMENT = "SEARCH_USER_AND_GROUPS_FRAGMENT";
55
56 private static final String DIALOG_WAIT_LOAD_DATA = "DIALOG_WAIT_LOAD_DATA";
57
58 private ShareFileFragment mShareFileFragment;
59 private SearchFragment mSearchFragment;
60
61 @Override
62 protected void onCreate(Bundle savedInstanceState) {
63 super.onCreate(savedInstanceState);
64 setContentView(R.layout.share_activity);
65
66 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
67
68 if (savedInstanceState != null) {
69
70 mShareFileFragment = (ShareFileFragment) getSupportFragmentManager().
71 getFragment(savedInstanceState, TAG_SHARE_FRAGMENT);
72 mSearchFragment = (SearchFragment) getSupportFragmentManager().
73 getFragment(savedInstanceState, TAG_SEARCH_FRAGMENT);
74
75 if (mShareFileFragment != null){
76 ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
77
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);
82 }
83 ft.commit();
84 }
85
86 } else {
87 // Add Share fragment
88 mShareFileFragment = ShareFileFragment.newInstance(getFile(), getAccount());
89 ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
90 ft.commit();
91
92 mSearchFragment = null;
93 }
94
95 handleIntent(getIntent());
96 }
97
98
99 @Override
100 protected void onNewIntent(Intent intent) {
101 setIntent(intent);
102 handleIntent(intent);
103 }
104
105
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);
110 doMySearch(query);
111
112 } else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
113 Uri data = intent.getData();
114 doShareWith(
115 data.getLastPathSegment(),
116 UsersAndGroupsSearchProvider.DATA_GROUP.equals(data.getAuthority())
117 );
118
119 } else {
120 Log_OC.wtf(TAG, "Unexpected intent " + intent.toString());
121 }
122 }
123
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();
127 }
128
129 private void doShareWith(String username, boolean isGroup) {
130 // TODO implement
131 if (isGroup) {
132 Toast.makeText(this, "You want to SHARE with GROUP [" + username + "]", Toast.LENGTH_SHORT).show();
133
134 } else {
135 Toast.makeText(this, "You want to SHARE with USER [" + username + "]", Toast.LENGTH_SHORT).show();
136 }
137 }
138
139 @Override
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);
146 }
147
148 }
149
150 @Override
151 public void showSearchUsersAndGroups() {
152 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
153 mSearchFragment = SearchFragment.newInstance(getFile(), getAccount());
154 ft.hide(mShareFileFragment);
155 ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
156 ft.addToBackStack(TAG_SEARCH_FRAGMENT);
157 ft.commit();
158 }
159
160 @Override
161 public void onBackPressed() {
162 super.onBackPressed();
163 if (mSearchFragment != null){
164 getSupportFragmentManager().popBackStackImmediate();
165 mSearchFragment = null;
166 }
167 }
168
169 @Override
170 public void onShareFragmentInteraction(Uri uri) {
171
172 }
173
174 @Override
175 public void onSearchFragmentInteraction(Uri uri) {
176
177 }
178 }