Show the 'search' layout in phone and tablet
[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 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
57 setSupportActionBar(toolbar);
58
59 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
60
61 if (savedInstanceState != null) {
62 mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
63 mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
64
65 mShareFileFragment = (ShareFileFragment) getSupportFragmentManager().
66 getFragment(savedInstanceState, TAG_SHARE_FRAGMENT);
67 mSearchFragment = (SearchFragment) getSupportFragmentManager().
68 getFragment(savedInstanceState, TAG_SEARCH_FRAGMENT);
69
70 if (mShareFileFragment != null){
71 ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
72
73 if (mSearchFragment != null){
74 ft.hide(mShareFileFragment);
75 ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
76 ft.addToBackStack(TAG_SEARCH_FRAGMENT);
77 }
78 ft.commit();
79 }
80
81 } else {
82 // Read Extras
83 mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
84 mAccount = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
85
86 // Add Share fragment
87 mShareFileFragment = ShareFileFragment.newInstance(mFile, mAccount);
88 ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
89 ft.commit();
90
91 mSearchFragment = null;
92 }
93
94 }
95
96 @Override
97 protected void onSaveInstanceState(Bundle outState) {
98 super.onSaveInstanceState(outState);
99 outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
100 outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount);
101
102 //Save the fragment's instance
103 getSupportFragmentManager().putFragment(outState, TAG_SHARE_FRAGMENT, mShareFileFragment);
104 if (mSearchFragment != null) {
105 getSupportFragmentManager().putFragment(outState, TAG_SEARCH_FRAGMENT, mSearchFragment);
106 }
107
108 }
109
110 @Override
111 public void showSearchUsersAndGroups() {
112 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
113 mSearchFragment = SearchFragment.newInstance(mFile, mAccount);
114 ft.hide(mShareFileFragment);
115 ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
116 ft.addToBackStack(TAG_SEARCH_FRAGMENT);
117 ft.commit();
118 }
119
120 @Override
121 public void onBackPressed() {
122 super.onBackPressed();
123 if (mSearchFragment != null){
124 getSupportFragmentManager().popBackStackImmediate();
125 mSearchFragment = null;
126 }
127 }
128
129 @Override
130 public void onShareFragmentInteraction(Uri uri) {
131
132 }
133
134 @Override
135 public void onSearchFragmentInteraction(Uri uri) {
136
137 }
138 }