ConflictsResolveDialog.java 4.5 KB

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