ConflictsResolveDialog.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* ownCloud Android client application
  2. * Copyright (C) 2012 Bartek Przybylski
  3. * Copyright (C) 2012-2013 ownCloud Inc.
  4. *
  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.
  8. *
  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.
  13. *
  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/>.
  16. *
  17. */
  18. package com.owncloud.android.ui.dialog;
  19. import android.app.AlertDialog;
  20. import android.app.Dialog;
  21. import android.content.DialogInterface;
  22. import android.os.Bundle;
  23. import android.support.v4.app.Fragment;
  24. import android.support.v4.app.FragmentTransaction;
  25. import com.actionbarsherlock.app.SherlockDialogFragment;
  26. import com.actionbarsherlock.app.SherlockFragmentActivity;
  27. import com.owncloud.android.R;
  28. import com.owncloud.android.utils.DisplayUtils;
  29. /**
  30. * Dialog which will be displayed to user upon keep-in-sync file conflict.
  31. *
  32. * @author Bartek Przybylski
  33. *
  34. */
  35. public class ConflictsResolveDialog extends SherlockDialogFragment {
  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(getSherlockActivity())
  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(SherlockFragmentActivity 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(SherlockFragmentActivity 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. }