ConflictsResolveDialog.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. 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.DialogFragment;
  27. import android.support.v4.app.Fragment;
  28. import android.support.v4.app.FragmentTransaction;
  29. import android.support.v7.app.ActionBarActivity;
  30. import com.owncloud.android.R;
  31. import com.owncloud.android.utils.DisplayUtils;
  32. /**
  33. * Dialog which will be displayed to user upon keep-in-sync file conflict.
  34. */
  35. public class ConflictsResolveDialog extends DialogFragment {
  36. public static enum Decision {
  37. CANCEL,
  38. KEEP_BOTH,
  39. OVERWRITE
  40. }
  41. OnConflictDecisionMadeListener mListener;
  42. public static ConflictsResolveDialog newInstance(String path, OnConflictDecisionMadeListener listener) {
  43. ConflictsResolveDialog f = new ConflictsResolveDialog();
  44. Bundle args = new Bundle();
  45. args.putString("remotepath", path);
  46. f.setArguments(args);
  47. f.mListener = listener;
  48. return f;
  49. }
  50. @Override
  51. public Dialog onCreateDialog(Bundle savedInstanceState) {
  52. String remotepath = getArguments().getString("remotepath");
  53. return new AlertDialog.Builder(getActivity())
  54. .setIcon(DisplayUtils.getSeasonalIconId())
  55. .setTitle(R.string.conflict_title)
  56. .setMessage(String.format(getString(R.string.conflict_message), remotepath))
  57. .setPositiveButton(R.string.conflict_overwrite,
  58. new DialogInterface.OnClickListener() {
  59. @Override
  60. public void onClick(DialogInterface dialog, int which) {
  61. if (mListener != null)
  62. mListener.conflictDecisionMade(Decision.OVERWRITE);
  63. }
  64. })
  65. .setNeutralButton(R.string.conflict_keep_both,
  66. new DialogInterface.OnClickListener() {
  67. @Override
  68. public void onClick(DialogInterface dialog, int which) {
  69. if (mListener != null)
  70. mListener.conflictDecisionMade(Decision.KEEP_BOTH);
  71. }
  72. })
  73. .setNegativeButton(R.string.conflict_dont_upload,
  74. new DialogInterface.OnClickListener() {
  75. @Override
  76. public void onClick(DialogInterface dialog, int which) {
  77. if (mListener != null)
  78. mListener.conflictDecisionMade(Decision.CANCEL);
  79. }
  80. })
  81. .create();
  82. }
  83. public void showDialog(ActionBarActivity activity) {
  84. Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
  85. FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
  86. if (prev != null) {
  87. ft.remove(prev);
  88. }
  89. ft.addToBackStack(null);
  90. this.show(ft, "dialog");
  91. }
  92. public void dismissDialog(ActionBarActivity activity) {
  93. Fragment prev = activity.getSupportFragmentManager().findFragmentByTag(getTag());
  94. if (prev != null) {
  95. FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
  96. ft.remove(prev);
  97. ft.commit();
  98. }
  99. }
  100. @Override
  101. public void onCancel(DialogInterface dialog) {
  102. mListener.conflictDecisionMade(Decision.CANCEL);
  103. }
  104. public interface OnConflictDecisionMadeListener {
  105. public void conflictDecisionMade(Decision decision);
  106. }
  107. }