Merge branch 'text_file_preview_pr_707_with_develop' of github.com:owncloud/android...
[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 android.content.Intent;
26 import android.os.Bundle;
27
28 import com.owncloud.android.datamodel.OCFile;
29 import com.owncloud.android.files.services.FileDownloader;
30 import com.owncloud.android.files.services.FileUploader;
31 import com.owncloud.android.lib.common.utils.Log_OC;
32 import com.owncloud.android.ui.dialog.ConflictsResolveDialog;
33 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision;
34 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener;
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 }
48
49 @Override
50 public void conflictDecisionMade(Decision decision) {
51 Intent i = new Intent(getApplicationContext(), FileUploader.class);
52
53 switch (decision) {
54 case CANCEL:
55 finish();
56 return;
57 case OVERWRITE:
58 // use local version -> overwrite on server
59 i.putExtra(FileUploader.KEY_FORCE_OVERWRITE, true);
60 break;
61 case KEEP_BOTH:
62 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
63 break;
64 case SERVER:
65 // use server version -> delete local, request download
66 Intent intent = new Intent(this, FileDownloader.class);
67 intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
68 intent.putExtra(FileDownloader.EXTRA_FILE, getFile());
69 startService(intent);
70 finish();
71 return;
72 default:
73 Log_OC.wtf(TAG, "Unhandled conflict decision " + decision);
74 return;
75 }
76 i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
77 i.putExtra(FileUploader.KEY_FILE, getFile());
78 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
79
80 startService(i);
81 finish();
82 }
83
84 @Override
85 protected void onAccountSet(boolean stateWasRecovered) {
86 super.onAccountSet(stateWasRecovered);
87 if (getAccount() != null) {
88 OCFile file = getFile();
89 if (getFile() == null) {
90 Log_OC.e(TAG, "No conflictive file received");
91 finish();
92 } else {
93 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
94 file = getStorageManager().getFileByPath(file.getRemotePath()); // file = null if not in the current Account
95 if (file != null) {
96 setFile(file);
97 ConflictsResolveDialog d = ConflictsResolveDialog.newInstance(file.getRemotePath(), this);
98 d.showDialog(this);
99
100 } else {
101 // account was changed to a different one - just finish
102 finish();
103 }
104 }
105
106 } else {
107 finish();
108 }
109
110 }
111 }