ConflictsResolveActivity.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author Bartek Przybylski
  5. * @author David A. Velasco
  6. * Copyright (C) 2012 Bartek Przybylski
  7. * Copyright (C) 2016 ownCloud Inc.
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. * <p/>
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.ui.activity;
  22. import android.content.Intent;
  23. import android.os.Bundle;
  24. import com.owncloud.android.datamodel.OCFile;
  25. import com.owncloud.android.files.services.FileDownloader;
  26. import com.owncloud.android.files.services.FileUploader;
  27. import com.owncloud.android.lib.common.utils.Log_OC;
  28. import com.owncloud.android.ui.dialog.ConflictsResolveDialog;
  29. import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision;
  30. import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener;
  31. /**
  32. * Wrapper activity which will be launched if keep-in-sync file will be modified by external
  33. * application.
  34. */
  35. public class ConflictsResolveActivity extends FileActivity implements OnConflictDecisionMadeListener {
  36. private static final String TAG = ConflictsResolveActivity.class.getSimpleName();
  37. @Override
  38. protected void onCreate(Bundle savedInstanceState) {
  39. super.onCreate(savedInstanceState);
  40. }
  41. @Override
  42. public void conflictDecisionMade(Decision decision) {
  43. Integer behaviour = null;
  44. Boolean forceOverwrite = null;
  45. switch (decision) {
  46. case CANCEL:
  47. finish();
  48. return;
  49. case OVERWRITE:
  50. // use local version -> overwrite on server
  51. forceOverwrite = true;
  52. break;
  53. case KEEP_BOTH:
  54. behaviour = FileUploader.LOCAL_BEHAVIOUR_MOVE;
  55. break;
  56. case SERVER:
  57. // use server version -> delete local, request download
  58. Intent intent = new Intent(this, FileDownloader.class);
  59. intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
  60. intent.putExtra(FileDownloader.EXTRA_FILE, getFile());
  61. startService(intent);
  62. finish();
  63. return;
  64. default:
  65. Log_OC.e(TAG, "Unhandled conflict decision " + decision);
  66. return;
  67. }
  68. FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
  69. requester.uploadUpdate(this, getAccount(), getFile(), behaviour, forceOverwrite);
  70. finish();
  71. }
  72. @Override
  73. protected void onAccountSet(boolean stateWasRecovered) {
  74. super.onAccountSet(stateWasRecovered);
  75. if (getAccount() != null) {
  76. OCFile file = getFile();
  77. if (getFile() == null) {
  78. Log_OC.e(TAG, "No conflictive file received");
  79. finish();
  80. } else {
  81. /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
  82. file = getStorageManager().getFileByPath(file.getRemotePath()); // file = null if not in the
  83. // current Account
  84. if (file != null) {
  85. setFile(file);
  86. ConflictsResolveDialog d = ConflictsResolveDialog.newInstance(file.getRemotePath(), this);
  87. d.showDialog(this);
  88. } else {
  89. // account was changed to a different one - just finish
  90. finish();
  91. }
  92. }
  93. } else {
  94. finish();
  95. }
  96. }
  97. }