Tweaks for source 1.5
[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.owncloud.android.datamodel.OCFile;
26 import com.owncloud.android.files.services.FileDownloader;
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.app.ActionBar;
35 import android.content.Intent;
36 import android.os.Bundle;
37
38 /**
39 * Wrapper activity which will be launched if keep-in-sync file will be modified by external
40 * application.
41 */
42 public class ConflictsResolveActivity extends FileActivity implements OnConflictDecisionMadeListener {
43
44 private String TAG = ConflictsResolveActivity.class.getSimpleName();
45
46 @Override
47 protected void onCreate(Bundle savedInstanceState) {
48 super.onCreate(savedInstanceState);
49 ActionBar actionBar = getActionBar();
50 actionBar.setIcon(DisplayUtils.getSeasonalIconId());
51 }
52
53 @Override
54 public void conflictDecisionMade(Decision decision) {
55 Intent i = new Intent(getApplicationContext(), FileUploader.class);
56
57 switch (decision) {
58 case CANCEL:
59 finish();
60 return;
61 case OVERWRITE:
62 // use local version -> overwrite on server
63 i.putExtra(FileUploader.KEY_FORCE_OVERWRITE, true);
64 break;
65 case KEEP_BOTH:
66 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
67 break;
68 case SERVER:
69 // use server version -> delete local, request download
70 Intent intent = new Intent(this, FileDownloader.class);
71 intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
72 intent.putExtra(FileDownloader.EXTRA_FILE, getFile());
73 startService(intent);
74 finish();
75 return;
76 default:
77 Log_OC.wtf(TAG, "Unhandled conflict decision " + decision);
78 return;
79 }
80 i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
81 i.putExtra(FileUploader.KEY_FILE, getFile());
82 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
83
84 startService(i);
85 finish();
86 }
87
88 @Override
89 protected void onAccountSet(boolean stateWasRecovered) {
90 super.onAccountSet(stateWasRecovered);
91 if (getAccount() != null) {
92 OCFile file = getFile();
93 if (getFile() == null) {
94 Log_OC.e(TAG, "No conflictive file received");
95 finish();
96 } else {
97 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
98 file = getStorageManager().getFileByPath(file.getRemotePath()); // file = null if not in the current Account
99 if (file != null) {
100 setFile(file);
101 ConflictsResolveDialog d = ConflictsResolveDialog.newInstance(file.getRemotePath(), this);
102 d.showDialog(this);
103
104 } else {
105 // account was changed to a different one - just finish
106 finish();
107 }
108 }
109
110 } else {
111 finish();
112 }
113
114 }
115 }