1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
19 package com
.owncloud
.android
.ui
.dialog
;
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
;
28 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
29 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
30 import com
.owncloud
.android
.R
;
33 * Dialog which will be displayed to user upon keep-in-sync file conflict.
35 * @author Bartek Przybylski
38 public class ConflictsResolveDialog
extends SherlockDialogFragment
{
40 public static enum Decision
{
46 OnConflictDecisionMadeListener mListener
;
48 public static ConflictsResolveDialog
newInstance(String path
, OnConflictDecisionMadeListener listener
) {
49 ConflictsResolveDialog f
= new ConflictsResolveDialog();
50 Bundle args
= new Bundle();
51 args
.putString("remotepath", path
);
53 f
.mListener
= listener
;
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() {
68 public void onClick(DialogInterface dialog
, int which
) {
69 if (mListener
!= null
)
70 mListener
.ConflictDecisionMade(Decision
.OVERWRITE
);
73 .setNeutralButton(R
.string
.conflict_keep_both
,
74 new DialogInterface
.OnClickListener() {
76 public void onClick(DialogInterface dialog
, int which
) {
77 if (mListener
!= null
)
78 mListener
.ConflictDecisionMade(Decision
.KEEP_BOTH
);
81 .setNegativeButton(R
.string
.conflict_dont_upload
,
82 new DialogInterface
.OnClickListener() {
84 public void onClick(DialogInterface dialog
, int which
) {
85 if (mListener
!= null
)
86 mListener
.ConflictDecisionMade(Decision
.CANCEL
);
92 public void showDialog(SherlockFragmentActivity activity
) {
93 Fragment prev
= activity
.getSupportFragmentManager().findFragmentByTag("dialog");
94 FragmentTransaction ft
= activity
.getSupportFragmentManager().beginTransaction();
98 ft
.addToBackStack(null
);
100 this.show(ft
, "dialog");
103 public void dismissDialog(SherlockFragmentActivity activity
) {
104 Fragment prev
= activity
.getSupportFragmentManager().findFragmentByTag(getTag());
106 FragmentTransaction ft
= activity
.getSupportFragmentManager().beginTransaction();
113 public void onCancel(DialogInterface dialog
) {
114 mListener
.ConflictDecisionMade(Decision
.CANCEL
);
117 public interface OnConflictDecisionMadeListener
{
118 public void ConflictDecisionMade(Decision decision
);