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 as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.ui
.dialog
;
22 import android
.app
.AlertDialog
;
23 import android
.app
.Dialog
;
24 import android
.content
.DialogInterface
;
25 import android
.os
.Bundle
;
26 import android
.support
.v4
.app
.Fragment
;
27 import android
.support
.v4
.app
.FragmentTransaction
;
29 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
30 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
31 import com
.owncloud
.android
.R
;
34 * Dialog which will be displayed to user upon keep-in-sync file conflict.
36 * @author Bartek Przybylski
39 public class ConflictsResolveDialog
extends SherlockDialogFragment
{
41 public static enum Decision
{
47 OnConflictDecisionMadeListener mListener
;
49 public static ConflictsResolveDialog
newInstance(String path
, OnConflictDecisionMadeListener listener
) {
50 ConflictsResolveDialog f
= new ConflictsResolveDialog();
51 Bundle args
= new Bundle();
52 args
.putString("remotepath", path
);
54 f
.mListener
= listener
;
59 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
60 String remotepath
= getArguments().getString("remotepath");
61 return new AlertDialog
.Builder(getSherlockActivity())
62 .setIcon(R
.drawable
.icon
)
63 .setTitle(R
.string
.conflict_title
)
64 .setMessage(String
.format(getString(R
.string
.conflict_message
), remotepath
))
65 .setPositiveButton(R
.string
.conflict_overwrite
,
66 new DialogInterface
.OnClickListener() {
69 public void onClick(DialogInterface dialog
, int which
) {
70 if (mListener
!= null
)
71 mListener
.ConflictDecisionMade(Decision
.OVERWRITE
);
74 .setNeutralButton(R
.string
.conflict_keep_both
,
75 new DialogInterface
.OnClickListener() {
77 public void onClick(DialogInterface dialog
, int which
) {
78 if (mListener
!= null
)
79 mListener
.ConflictDecisionMade(Decision
.KEEP_BOTH
);
82 .setNegativeButton(R
.string
.conflict_dont_upload
,
83 new DialogInterface
.OnClickListener() {
85 public void onClick(DialogInterface dialog
, int which
) {
86 if (mListener
!= null
)
87 mListener
.ConflictDecisionMade(Decision
.CANCEL
);
93 public void showDialog(SherlockFragmentActivity activity
) {
94 Fragment prev
= activity
.getSupportFragmentManager().findFragmentByTag("dialog");
95 FragmentTransaction ft
= activity
.getSupportFragmentManager().beginTransaction();
99 ft
.addToBackStack(null
);
101 this.show(ft
, "dialog");
104 public void dismissDialog(SherlockFragmentActivity activity
) {
105 Fragment prev
= activity
.getSupportFragmentManager().findFragmentByTag(getTag());
107 FragmentTransaction ft
= activity
.getSupportFragmentManager().beginTransaction();
114 public void onCancel(DialogInterface dialog
) {
115 mListener
.ConflictDecisionMade(Decision
.CANCEL
);
118 public interface OnConflictDecisionMadeListener
{
119 public void ConflictDecisionMade(Decision decision
);