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