npe fix for file upload on instance saving since actionbar in list mode doesn't habe...
[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.FileUploader;
30 import com.owncloud.android.lib.common.utils.Log_OC;
31 import com.owncloud.android.ui.dialog.ConflictsResolveDialog;
32 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision;
33 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener;
34
35 /**
36 * Wrapper activity which will be launched if keep-in-sync file will be modified by external
37 * application.
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 super.onAccountSet(stateWasRecovered);
77 if (getAccount() != null) {
78 OCFile file = getFile();
79 if (getFile() == null) {
80 Log_OC.e(TAG, "No conflictive file received");
81 finish();
82 } else {
83 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
84 file = getStorageManager().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 finish();
98 }
99
100 }
101 }