2 * ownCloud Android client application
4 * @author Bartek Przybylski
5 * Copyright (C) 2012 Bartek Przybylski
6 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
22 package com
.owncloud
.android
.ui
.dialog
;
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
;
33 import com
.owncloud
.android
.R
;
34 import com
.owncloud
.android
.utils
.DisplayUtils
;
38 * Dialog which will be displayed to user upon keep-in-sync file conflict.
40 public class ConflictsResolveDialog
extends DialogFragment
{
42 public static enum Decision
{
49 OnConflictDecisionMadeListener mListener
;
51 public static ConflictsResolveDialog
newInstance(String path
, OnConflictDecisionMadeListener listener
) {
52 ConflictsResolveDialog f
= new ConflictsResolveDialog();
53 Bundle args
= new Bundle();
54 args
.putString("remotepath", path
);
56 f
.mListener
= listener
;
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() {
71 public void onClick(DialogInterface dialog
, int which
) {
72 if (mListener
!= null
)
73 mListener
.conflictDecisionMade(Decision
.OVERWRITE
);
76 .setNeutralButton(R
.string
.conflict_keep_both
,
77 new DialogInterface
.OnClickListener() {
79 public void onClick(DialogInterface dialog
, int which
) {
80 if (mListener
!= null
)
81 mListener
.conflictDecisionMade(Decision
.KEEP_BOTH
);
84 .setNegativeButton(R
.string
.conflict_use_server_version
,
85 new DialogInterface
.OnClickListener() {
87 public void onClick(DialogInterface dialog
, int which
) {
88 if (mListener
!= null
)
89 mListener
.conflictDecisionMade(Decision
.SERVER
);
95 public void showDialog(AppCompatActivity activity
) {
96 Fragment prev
= activity
.getSupportFragmentManager().findFragmentByTag("dialog");
97 FragmentTransaction ft
= activity
.getSupportFragmentManager().beginTransaction();
101 ft
.addToBackStack(null
);
103 this.show(ft
, "dialog");
106 public void dismissDialog(AppCompatActivity activity
) {
107 Fragment prev
= activity
.getSupportFragmentManager().findFragmentByTag(getTag());
109 FragmentTransaction ft
= activity
.getSupportFragmentManager().beginTransaction();
116 public void onCancel(DialogInterface dialog
) {
117 mListener
.conflictDecisionMade(Decision
.CANCEL
);
120 public interface OnConflictDecisionMadeListener
{
121 public void conflictDecisionMade(Decision decision
);