c3db9a47fb69ba9340e1035e280e3839741d8ed4
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / ConflictsResolveActivity.java
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) 2015 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 *
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 */
22
23 package com.owncloud.android.ui.activity;
24
25 import com.actionbarsherlock.app.ActionBar;
26 import com.owncloud.android.datamodel.OCFile;
27 import com.owncloud.android.files.services.FileUploader;
28 import com.owncloud.android.lib.common.utils.Log_OC;
29 import com.owncloud.android.ui.dialog.ConflictsResolveDialog;
30 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision;
31 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener;
32 import com.owncloud.android.utils.DisplayUtils;
33
34 import android.content.Intent;
35 import android.os.Bundle;
36
37 /**
38 * Wrapper activity which will be launched if keep-in-sync file will be modified by external
39 * application.
40 */
41 public class ConflictsResolveActivity extends FileActivity implements OnConflictDecisionMadeListener {
42
43 private String TAG = ConflictsResolveActivity.class.getSimpleName();
44
45 @Override
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
48 ActionBar actionBar = getSupportActionBar();
49 actionBar.setIcon(DisplayUtils.getSeasonalIconId());
50 }
51
52 @Override
53 public void conflictDecisionMade(Decision decision) {
54 Intent i = new Intent(getApplicationContext(), FileUploader.class);
55
56 switch (decision) {
57 case CANCEL:
58 finish();
59 return;
60 case OVERWRITE:
61 i.putExtra(FileUploader.KEY_FORCE_OVERWRITE, true);
62 break;
63 case KEEP_BOTH:
64 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
65 break;
66 default:
67 Log_OC.wtf(TAG, "Unhandled conflict decision " + decision);
68 return;
69 }
70 i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
71 i.putExtra(FileUploader.KEY_FILE, getFile());
72 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
73
74 startService(i);
75 finish();
76 }
77
78 @Override
79 protected void onAccountSet(boolean stateWasRecovered) {
80 super.onAccountSet(stateWasRecovered);
81 if (getAccount() != null) {
82 OCFile file = getFile();
83 if (getFile() == null) {
84 Log_OC.e(TAG, "No conflictive file received");
85 finish();
86 } else {
87 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
88 file = getStorageManager().getFileByPath(file.getRemotePath()); // file = null if not in the current Account
89 if (file != null) {
90 setFile(file);
91 ConflictsResolveDialog d = ConflictsResolveDialog.newInstance(file.getRemotePath(), this);
92 d.showDialog(this);
93
94 } else {
95 // account was changed to a different one - just finish
96 finish();
97 }
98 }
99
100 } else {
101 finish();
102 }
103
104 }
105 }