Copyright note fixes
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / ConflictsResolveDialog.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 version 2,
7 * as published by the Free Software Foundation.
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.dialog;
20
21 import android.app.AlertDialog;
22 import android.app.Dialog;
23 import android.content.DialogInterface;
24 import android.os.Bundle;
25 import android.support.v4.app.Fragment;
26 import android.support.v4.app.FragmentTransaction;
27
28 import com.actionbarsherlock.app.SherlockDialogFragment;
29 import com.actionbarsherlock.app.SherlockFragmentActivity;
30 import com.owncloud.android.R;
31
32 /**
33 * Dialog which will be displayed to user upon keep-in-sync file conflict.
34 *
35 * @author Bartek Przybylski
36 *
37 */
38 public class ConflictsResolveDialog extends SherlockDialogFragment {
39
40 public static enum Decision {
41 CANCEL,
42 KEEP_BOTH,
43 OVERWRITE
44 }
45
46 OnConflictDecisionMadeListener mListener;
47
48 public static ConflictsResolveDialog newInstance(String path, OnConflictDecisionMadeListener listener) {
49 ConflictsResolveDialog f = new ConflictsResolveDialog();
50 Bundle args = new Bundle();
51 args.putString("remotepath", path);
52 f.setArguments(args);
53 f.mListener = listener;
54 return f;
55 }
56
57 @Override
58 public Dialog onCreateDialog(Bundle savedInstanceState) {
59 String remotepath = getArguments().getString("remotepath");
60 return new AlertDialog.Builder(getSherlockActivity())
61 .setIcon(R.drawable.icon)
62 .setTitle(R.string.conflict_title)
63 .setMessage(String.format(getString(R.string.conflict_message), remotepath))
64 .setPositiveButton(R.string.conflict_overwrite,
65 new DialogInterface.OnClickListener() {
66
67 @Override
68 public void onClick(DialogInterface dialog, int which) {
69 if (mListener != null)
70 mListener.ConflictDecisionMade(Decision.OVERWRITE);
71 }
72 })
73 .setNeutralButton(R.string.conflict_keep_both,
74 new DialogInterface.OnClickListener() {
75 @Override
76 public void onClick(DialogInterface dialog, int which) {
77 if (mListener != null)
78 mListener.ConflictDecisionMade(Decision.KEEP_BOTH);
79 }
80 })
81 .setNegativeButton(R.string.conflict_dont_upload,
82 new DialogInterface.OnClickListener() {
83 @Override
84 public void onClick(DialogInterface dialog, int which) {
85 if (mListener != null)
86 mListener.ConflictDecisionMade(Decision.CANCEL);
87 }
88 })
89 .create();
90 }
91
92 public void showDialog(SherlockFragmentActivity activity) {
93 Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
94 FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
95 if (prev != null) {
96 ft.remove(prev);
97 }
98 ft.addToBackStack(null);
99
100 this.show(ft, "dialog");
101 }
102
103 public void dismissDialog(SherlockFragmentActivity activity) {
104 Fragment prev = activity.getSupportFragmentManager().findFragmentByTag(getTag());
105 if (prev != null) {
106 FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
107 ft.remove(prev);
108 ft.commit();
109 }
110 }
111
112 @Override
113 public void onCancel(DialogInterface dialog) {
114 mListener.ConflictDecisionMade(Decision.CANCEL);
115 }
116
117 public interface OnConflictDecisionMadeListener {
118 public void ConflictDecisionMade(Decision decision);
119 }
120 }