Some cleanup
[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.datamodel.OCFile;
23 import com.owncloud.android.files.services.FileUploader;
24 import com.owncloud.android.ui.dialog.ConflictsResolveDialog;
25 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision;
26 import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener;
27
28 import android.accounts.Account;
29 import android.content.Intent;
30 import android.os.Bundle;
31 import android.util.Log;
32
33 /**
34 * Wrapper activity which will be launched if keep-in-sync file will be modified by external
35 * application.
36 *
37 * @author Bartek Przybylski
38 *
39 */
40 public class ConflictsResolveActivity extends SherlockFragmentActivity implements OnConflictDecisionMadeListener {
41
42 public static final String EXTRA_FILE = "FILE";
43 public static final String EXTRA_ACCOUNT = "ACCOUNT";
44
45 private String TAG = ConflictsResolveActivity.class.getSimpleName();
46
47 //private String mRemotePath;
48
49 //private String mLocalPath;
50
51 private OCFile mFile;
52 private Account mOCAccount;
53
54 @Override
55 protected void onCreate(Bundle savedInstanceState) {
56 super.onCreate(savedInstanceState);
57
58 //mRemotePath = getIntent().getStringExtra("remotepath");
59 //mLocalPath = getIntent().getStringExtra("localpath");
60 mFile = getIntent().getParcelableExtra(EXTRA_FILE);
61 mOCAccount = getIntent().getParcelableExtra(EXTRA_ACCOUNT);
62 ConflictsResolveDialog d = ConflictsResolveDialog.newInstance(mFile.getRemotePath(), this);
63 d.showDialog(this);
64 }
65
66 @Override
67 public void ConflictDecisionMade(Decision decision) {
68 Intent i = new Intent(getApplicationContext(), FileUploader.class);
69
70 switch (decision) {
71 case CANCEL:
72 finish();
73 return;
74 case OVERWRITE:
75 i.putExtra(FileUploader.KEY_FORCE_OVERWRITE, true);
76 break;
77 case KEEP_BOTH:
78 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
79 break;
80 default:
81 Log.wtf(TAG, "Unhandled conflict decision " + decision);
82 return;
83 }
84 i.putExtra(FileUploader.KEY_ACCOUNT, mOCAccount);
85 i.putExtra(FileUploader.KEY_FILE, mFile);
86 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
87
88 startService(i);
89 finish();
90 }
91 }