Remove android.support.widget components from the sharewith view. Waiting for introdu...
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / ShareActivity.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 package com.owncloud.android.ui.activity;
22
23 import android.accounts.Account;
24 import android.net.Uri;
25 import android.os.Bundle;
26 import android.support.v4.app.FragmentTransaction;
27 import android.support.v7.app.AppCompatActivity;
28 import android.support.v7.widget.Toolbar;
29
30 import com.owncloud.android.R;
31 import com.owncloud.android.datamodel.OCFile;
32 import com.owncloud.android.ui.fragment.SearchFragment;
33 import com.owncloud.android.ui.fragment.ShareFileFragment;
34
35 /**
36 * Activity for sharing files
37 */
38
39 public class ShareActivity extends AppCompatActivity
40 implements ShareFileFragment.OnShareFragmentInteractionListener,
41 SearchFragment.OnSearchFragmentInteractionListener {
42
43 private static final String TAG_SHARE_FRAGMENT = "SHARE_FRAGMENT";
44 private static final String TAG_SEARCH_FRAGMENT = "SEARCH_USER_AND_GROUPS_FRAGMENT";
45
46 private Account mAccount;
47 private OCFile mFile;
48
49 private ShareFileFragment mShareFileFragment;
50 private SearchFragment mSearchFragment;
51
52 @Override
53 protected void onCreate(Bundle savedInstanceState) {
54 super.onCreate(savedInstanceState);
55 setContentView(R.layout.share_activity);
56
57 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
58
59 if (savedInstanceState != null) {
60 mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
61 mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
62
63 mShareFileFragment = (ShareFileFragment) getSupportFragmentManager().
64 getFragment(savedInstanceState, TAG_SHARE_FRAGMENT);
65 mSearchFragment = (SearchFragment) getSupportFragmentManager().
66 getFragment(savedInstanceState, TAG_SEARCH_FRAGMENT);
67
68 if (mShareFileFragment != null){
69 ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
70
71 if (mSearchFragment != null){
72 ft.hide(mShareFileFragment);
73 ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
74 ft.addToBackStack(TAG_SEARCH_FRAGMENT);
75 }
76 ft.commit();
77 }
78
79 } else {
80 // Read Extras
81 mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
82 mAccount = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
83
84 // Add Share fragment
85 mShareFileFragment = ShareFileFragment.newInstance(mFile, mAccount);
86 ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
87 ft.commit();
88
89 mSearchFragment = null;
90 }
91
92 }
93
94 @Override
95 protected void onSaveInstanceState(Bundle outState) {
96 super.onSaveInstanceState(outState);
97 outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
98 outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount);
99
100 //Save the fragment's instance
101 getSupportFragmentManager().putFragment(outState, TAG_SHARE_FRAGMENT, mShareFileFragment);
102 if (mSearchFragment != null) {
103 getSupportFragmentManager().putFragment(outState, TAG_SEARCH_FRAGMENT, mSearchFragment);
104 }
105
106 }
107
108 @Override
109 public void showSearchUsersAndGroups() {
110 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
111 mSearchFragment = SearchFragment.newInstance(mFile, mAccount);
112 ft.hide(mShareFileFragment);
113 ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
114 ft.addToBackStack(TAG_SEARCH_FRAGMENT);
115 ft.commit();
116 }
117
118 @Override
119 public void onBackPressed() {
120 super.onBackPressed();
121 if (mSearchFragment != null){
122 getSupportFragmentManager().popBackStackImmediate();
123 mSearchFragment = null;
124 }
125 }
126
127 @Override
128 public void onShareFragmentInteraction(Uri uri) {
129
130 }
131
132 @Override
133 public void onSearchFragmentInteraction(Uri uri) {
134
135 }
136 }