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