3ccc07dc3e00890032da9d2b2b0eefa1f345adc0
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / ConflictsResolveActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 package com.owncloud.android.ui.activity;
21
22 import com.actionbarsherlock.app.SherlockFragmentActivity;
23 import com.owncloud.android.Log_OC;
24 import com.owncloud.android.datamodel.OCFile;
25 import com.owncloud.android.files.services.FileUploader;
26 import com.owncloud.android.ui.dialog.ConflictsResolveDialog;
27 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision;
28 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener;
29
30 import android.accounts.Account;
31 import android.content.Intent;
32 import android.os.Bundle;
33 import android.util.Log;
34
35 /**
36 * Wrapper activity which will be launched if keep-in-sync file will be modified by external
37 * application.
38 *
39 * @author Bartek Przybylski
40 *
41 */
42 public class ConflictsResolveActivity extends SherlockFragmentActivity implements OnConflictDecisionMadeListener {
43
44 public static final String EXTRA_FILE = "FILE";
45 public static final String EXTRA_ACCOUNT = "ACCOUNT";
46
47 private String TAG = ConflictsResolveActivity.class.getSimpleName();
48
49 //private String mRemotePath;
50
51 //private String mLocalPath;
52
53 private OCFile mFile;
54 private Account mOCAccount;
55
56 @Override
57 protected void onCreate(Bundle savedInstanceState) {
58 super.onCreate(savedInstanceState);
59
60 //mRemotePath = getIntent().getStringExtra("remotepath");
61 //mLocalPath = getIntent().getStringExtra("localpath");
62 mFile = getIntent().getParcelableExtra(EXTRA_FILE);
63 mOCAccount = getIntent().getParcelableExtra(EXTRA_ACCOUNT);
64 ConflictsResolveDialog d = ConflictsResolveDialog.newInstance(mFile.getRemotePath(), this);
65 d.showDialog(this);
66 }
67
68 @Override
69 public void ConflictDecisionMade(Decision decision) {
70 Intent i = new Intent(getApplicationContext(), FileUploader.class);
71
72 switch (decision) {
73 case CANCEL:
74 finish();
75 return;
76 case OVERWRITE:
77 i.putExtra(FileUploader.KEY_FORCE_OVERWRITE, true);
78 break;
79 case KEEP_BOTH:
80 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
81 break;
82 default:
83 Log_OC.wtf(TAG, "Unhandled conflict decision " + decision);
84 return;
85 }
86 i.putExtra(FileUploader.KEY_ACCOUNT, mOCAccount);
87 i.putExtra(FileUploader.KEY_FILE, mFile);
88 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
89
90 startService(i);
91 finish();
92 }
93 }