ContactsPreferenceActivity.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Tobias Kaminsky
  5. * @author Chris Narkiewicz <hello@ezaquarii.com>
  6. * Copyright (C) 2017 Tobias Kaminsky
  7. * Copyright (C) 2017 Nextcloud GmbH.
  8. * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. package com.owncloud.android.ui.activity;
  24. import android.content.Context;
  25. import android.content.Intent;
  26. import android.os.Bundle;
  27. import com.nextcloud.client.account.User;
  28. import com.nextcloud.client.jobs.BackgroundJobManager;
  29. import com.owncloud.android.R;
  30. import com.owncloud.android.datamodel.OCFile;
  31. import com.owncloud.android.ui.fragment.FileFragment;
  32. import com.owncloud.android.ui.fragment.contactsbackup.BackupFragment;
  33. import com.owncloud.android.ui.fragment.contactsbackup.BackupListFragment;
  34. import javax.inject.Inject;
  35. import androidx.drawerlayout.widget.DrawerLayout;
  36. import androidx.fragment.app.FragmentManager;
  37. import androidx.fragment.app.FragmentTransaction;
  38. /**
  39. * This activity shows all settings for contact backup/restore
  40. */
  41. public class ContactsPreferenceActivity extends FileActivity implements FileFragment.ContainerActivity {
  42. public static final String TAG = ContactsPreferenceActivity.class.getSimpleName();
  43. public static final String EXTRA_FILE = "FILE";
  44. public static final String EXTRA_USER = "USER";
  45. /**
  46. * Warning: default for this extra is different between this activity and {@link BackupFragment}
  47. */
  48. public static final String EXTRA_SHOW_SIDEBAR = "SHOW_SIDEBAR";
  49. public static final String PREFERENCE_CONTACTS_AUTOMATIC_BACKUP = "PREFERENCE_CONTACTS_AUTOMATIC_BACKUP";
  50. public static final String PREFERENCE_CONTACTS_LAST_BACKUP = "PREFERENCE_CONTACTS_LAST_BACKUP";
  51. public static final String BACKUP_TO_LIST = "BACKUP_TO_LIST";
  52. @Inject BackgroundJobManager backgroundJobManager;
  53. public static void startActivity(Context context) {
  54. Intent intent = new Intent(context, ContactsPreferenceActivity.class);
  55. context.startActivity(intent);
  56. }
  57. public static void startActivityWithContactsFile(Context context, User user, OCFile file) {
  58. Intent intent = new Intent(context, ContactsPreferenceActivity.class);
  59. intent.putExtra(EXTRA_FILE, file);
  60. intent.putExtra(EXTRA_USER, user);
  61. context.startActivity(intent);
  62. }
  63. public static void startActivityWithoutSidebar(Context context) {
  64. Intent intent = new Intent(context, ContactsPreferenceActivity.class);
  65. intent.putExtra(EXTRA_SHOW_SIDEBAR, false);
  66. context.startActivity(intent);
  67. }
  68. @Override
  69. protected void onCreate(Bundle savedInstanceState) {
  70. super.onCreate(savedInstanceState);
  71. setContentView(R.layout.contacts_preference);
  72. // setup toolbar
  73. setupToolbar();
  74. // setup drawer
  75. //setupDrawer(R.id.nav_contacts); // TODO needed?
  76. // show sidebar?
  77. boolean showSidebar = getIntent().getBooleanExtra(EXTRA_SHOW_SIDEBAR, true);
  78. if (!showSidebar) {
  79. setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
  80. if (getSupportActionBar() != null) {
  81. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  82. }
  83. if (mDrawerToggle != null) {
  84. mDrawerToggle.setDrawerIndicatorEnabled(false);
  85. }
  86. }
  87. Intent intent = getIntent();
  88. if (savedInstanceState == null) {
  89. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  90. if (intent == null || intent.getParcelableExtra(EXTRA_FILE) == null ||
  91. intent.getParcelableExtra(EXTRA_USER) == null) {
  92. BackupFragment fragment = BackupFragment.create(showSidebar);
  93. transaction.add(R.id.frame_container, fragment);
  94. } else {
  95. OCFile file = intent.getParcelableExtra(EXTRA_FILE);
  96. User user = intent.getParcelableExtra(EXTRA_USER);
  97. BackupListFragment contactListFragment = BackupListFragment.newInstance(file, user);
  98. transaction.add(R.id.frame_container, contactListFragment);
  99. }
  100. transaction.commit();
  101. }
  102. }
  103. @Override
  104. public void showDetails(OCFile file) {
  105. // not needed
  106. }
  107. @Override
  108. public void showDetails(OCFile file, int activeTab) {
  109. // not needed
  110. }
  111. @Override
  112. public void onBrowsedDownTo(OCFile folder) {
  113. // not needed
  114. }
  115. @Override
  116. public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
  117. // not needed
  118. }
  119. @Override
  120. public void onBackPressed() {
  121. if (getSupportFragmentManager().findFragmentByTag(BackupListFragment.TAG) != null) {
  122. getSupportFragmentManager().popBackStack(BACKUP_TO_LIST, FragmentManager.POP_BACK_STACK_INCLUSIVE);
  123. } else {
  124. finish();
  125. }
  126. }
  127. }