[tx-robot] updated from transifex
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / ConflictsResolveDialog.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author Bartek Przybylski
5 * Copyright (C) 2012 Bartek Przybylski
6 * Copyright (C) 2015 ownCloud Inc.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 package com.owncloud.android.ui.dialog;
23
24 import android.support.v7.app.AlertDialog;
25 import android.app.Dialog;
26 import android.content.DialogInterface;
27 import android.os.Bundle;
28 import android.support.v4.app.DialogFragment;
29 import android.support.v4.app.Fragment;
30 import android.support.v4.app.FragmentTransaction;
31 import android.support.v7.app.AppCompatActivity;
32
33 import com.owncloud.android.R;
34 import com.owncloud.android.utils.DisplayUtils;
35
36
37 /**
38 * Dialog which will be displayed to user upon keep-in-sync file conflict.
39 */
40 public class ConflictsResolveDialog extends DialogFragment {
41
42 public static enum Decision {
43 CANCEL,
44 KEEP_BOTH,
45 OVERWRITE,
46 SERVER
47 }
48
49 OnConflictDecisionMadeListener mListener;
50
51 public static ConflictsResolveDialog newInstance(String path, OnConflictDecisionMadeListener listener) {
52 ConflictsResolveDialog f = new ConflictsResolveDialog();
53 Bundle args = new Bundle();
54 args.putString("remotepath", path);
55 f.setArguments(args);
56 f.mListener = listener;
57 return f;
58 }
59
60 @Override
61 public Dialog onCreateDialog(Bundle savedInstanceState) {
62 String remotepath = getArguments().getString("remotepath");
63 return new AlertDialog.Builder(getActivity(), R.style.Theme_ownCloud_Dialog)
64 .setIcon(R.drawable.ic_warning)
65 .setTitle(R.string.conflict_title)
66 .setMessage(String.format(getString(R.string.conflict_message), remotepath))
67 .setPositiveButton(R.string.conflict_use_local_version,
68 new DialogInterface.OnClickListener() {
69
70 @Override
71 public void onClick(DialogInterface dialog, int which) {
72 if (mListener != null)
73 mListener.conflictDecisionMade(Decision.OVERWRITE);
74 }
75 })
76 .setNeutralButton(R.string.conflict_keep_both,
77 new DialogInterface.OnClickListener() {
78 @Override
79 public void onClick(DialogInterface dialog, int which) {
80 if (mListener != null)
81 mListener.conflictDecisionMade(Decision.KEEP_BOTH);
82 }
83 })
84 .setNegativeButton(R.string.conflict_use_server_version,
85 new DialogInterface.OnClickListener() {
86 @Override
87 public void onClick(DialogInterface dialog, int which) {
88 if (mListener != null)
89 mListener.conflictDecisionMade(Decision.SERVER);
90 }
91 })
92 .create();
93 }
94
95 public void showDialog(AppCompatActivity activity) {
96 Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
97 FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
98 if (prev != null) {
99 ft.remove(prev);
100 }
101 ft.addToBackStack(null);
102
103 this.show(ft, "dialog");
104 }
105
106 public void dismissDialog(AppCompatActivity activity) {
107 Fragment prev = activity.getSupportFragmentManager().findFragmentByTag(getTag());
108 if (prev != null) {
109 FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
110 ft.remove(prev);
111 ft.commit();
112 }
113 }
114
115 @Override
116 public void onCancel(DialogInterface dialog) {
117 mListener.conflictDecisionMade(Decision.CANCEL);
118 }
119
120 public interface OnConflictDecisionMadeListener {
121 public void conflictDecisionMade(Decision decision);
122 }
123 }