ShareActivity.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. package com.owncloud.android.ui.activity;
  21. import android.accounts.Account;
  22. import android.net.Uri;
  23. import android.os.Bundle;
  24. import android.support.v4.app.Fragment;
  25. import android.support.v4.app.FragmentManager;
  26. import android.support.v4.app.FragmentTransaction;
  27. import android.support.v7.app.AppCompatActivity;
  28. import android.support.v7.widget.Toolbar;
  29. import com.owncloud.android.R;
  30. import com.owncloud.android.datamodel.OCFile;
  31. import com.owncloud.android.ui.dialog.LoadingDialog;
  32. import com.owncloud.android.ui.fragment.SearchFragment;
  33. import com.owncloud.android.ui.fragment.ShareFileFragment;
  34. /**
  35. * Activity for sharing files
  36. */
  37. public class ShareActivity extends AppCompatActivity
  38. implements ShareFileFragment.OnShareFragmentInteractionListener,
  39. SearchFragment.OnSearchFragmentInteractionListener {
  40. private static final String TAG_SHARE_FRAGMENT = "SHARE_FRAGMENT";
  41. private static final String TAG_SEARCH_FRAGMENT = "SEARCH_USER_AND_GROUPS_FRAGMENT";
  42. private static final String DIALOG_WAIT_LOAD_DATA = "DIALOG_WAIT_LOAD_DATA";
  43. private Account mAccount;
  44. private OCFile mFile;
  45. private ShareFileFragment mShareFileFragment;
  46. private SearchFragment mSearchFragment;
  47. @Override
  48. protected void onCreate(Bundle savedInstanceState) {
  49. super.onCreate(savedInstanceState);
  50. setContentView(R.layout.share_activity);
  51. FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
  52. if (savedInstanceState != null) {
  53. mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
  54. mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
  55. mShareFileFragment = (ShareFileFragment) getSupportFragmentManager().
  56. getFragment(savedInstanceState, TAG_SHARE_FRAGMENT);
  57. mSearchFragment = (SearchFragment) getSupportFragmentManager().
  58. getFragment(savedInstanceState, TAG_SEARCH_FRAGMENT);
  59. if (mShareFileFragment != null){
  60. ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
  61. if (mSearchFragment != null){
  62. ft.hide(mShareFileFragment);
  63. ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
  64. ft.addToBackStack(TAG_SEARCH_FRAGMENT);
  65. }
  66. ft.commit();
  67. }
  68. } else {
  69. // Read Extras
  70. mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
  71. mAccount = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
  72. // Add Share fragment
  73. mShareFileFragment = ShareFileFragment.newInstance(mFile, mAccount);
  74. ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
  75. ft.commit();
  76. mSearchFragment = null;
  77. }
  78. }
  79. @Override
  80. protected void onSaveInstanceState(Bundle outState) {
  81. super.onSaveInstanceState(outState);
  82. outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
  83. outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount);
  84. //Save the fragment's instance
  85. getSupportFragmentManager().putFragment(outState, TAG_SHARE_FRAGMENT, mShareFileFragment);
  86. if (mSearchFragment != null) {
  87. getSupportFragmentManager().putFragment(outState, TAG_SEARCH_FRAGMENT, mSearchFragment);
  88. }
  89. }
  90. @Override
  91. public void showSearchUsersAndGroups() {
  92. FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
  93. mSearchFragment = SearchFragment.newInstance(mFile, mAccount);
  94. ft.hide(mShareFileFragment);
  95. ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
  96. ft.addToBackStack(TAG_SEARCH_FRAGMENT);
  97. ft.commit();
  98. }
  99. @Override
  100. public void onBackPressed() {
  101. super.onBackPressed();
  102. if (mSearchFragment != null){
  103. getSupportFragmentManager().popBackStackImmediate();
  104. mSearchFragment = null;
  105. }
  106. }
  107. @Override
  108. public void onShareFragmentInteraction(Uri uri) {
  109. }
  110. @Override
  111. public void onSearchFragmentInteraction(Uri uri) {
  112. }
  113. /**
  114. * Show waiting for loading data
  115. */
  116. public void showWaitingLoadDialog() {
  117. // Construct dialog
  118. LoadingDialog loading = new LoadingDialog(
  119. getResources().getString(R.string.common_loading));
  120. FragmentManager fm = getSupportFragmentManager();
  121. FragmentTransaction ft = fm.beginTransaction();
  122. loading.show(ft, DIALOG_WAIT_LOAD_DATA);
  123. }
  124. /**
  125. * Dismiss waiting for loading data
  126. */
  127. public void dismissWaitingLoadDialog(){
  128. Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_LOAD_DATA);
  129. if (frag != null) {
  130. LoadingDialog loading = (LoadingDialog) frag;
  131. loading.dismiss();
  132. }
  133. }
  134. }