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