From: Bartek Przybylski Date: Sat, 28 Jul 2012 19:15:41 +0000 (+0200) Subject: allow removing local file only X-Git-Tag: oc-android-1.4.3~230 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/0cced280a4c6711229da3a3ab692b0971654a191?ds=inline allow removing local file only --- diff --git a/res/values/strings.xml b/res/values/strings.xml index 7ade27ce..fa3e9249 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -15,7 +15,7 @@ Setup Account There are no ownCloud accounts on your device. In order to use this App, you need to create one. - Sync account + Refresh Upload file Create directory Search @@ -148,7 +148,10 @@ Rename Remove - "Do you really want to remove %1$s ?" + "Do you really want to remove %1$s ?" + Local only + Remove form server + Both remote and local "Successful removal" "Removal could not be completed" diff --git a/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java b/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java index c5394f8c..110f3378 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java @@ -15,13 +15,20 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment { public final static String ARG_CONF_RESOURCE_ID = "resource_id"; public final static String ARG_CONF_ARGUMENTS = "string_array"; - ConfirmationDialogFragmentListener mListener; + public final static String ARG_POSITIVE_BTN_RES = "positive_btn_res"; + public final static String ARG_NEUTRAL_BTN_RES = "neutral_btn_res"; + public final static String ARG_NEGATIVE_BTN_RES = "negative_btn_res"; - public static ConfirmationDialogFragment newInstance(int string_id, String[] arguments) { + private ConfirmationDialogFragmentListener mListener; + + public static ConfirmationDialogFragment newInstance(int string_id, String[] arguments, int posBtn, int neuBtn, int negBtn) { ConfirmationDialogFragment frag = new ConfirmationDialogFragment(); Bundle args = new Bundle(); args.putInt(ARG_CONF_RESOURCE_ID, string_id); args.putStringArray(ARG_CONF_ARGUMENTS, arguments); + args.putInt(ARG_POSITIVE_BTN_RES, posBtn); + args.putInt(ARG_NEUTRAL_BTN_RES, neuBtn); + args.putInt(ARG_NEGATIVE_BTN_RES, negBtn); frag.setArguments(args); return frag; } @@ -34,34 +41,51 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { Object[] confirmationTarget = getArguments().getStringArray(ARG_CONF_ARGUMENTS); int resourceId = getArguments().getInt(ARG_CONF_RESOURCE_ID, -1); + int posBtn = getArguments().getInt(ARG_POSITIVE_BTN_RES, -1); + int neuBtn = getArguments().getInt(ARG_NEUTRAL_BTN_RES, -1); + int negBtn = getArguments().getInt(ARG_NEGATIVE_BTN_RES, -1); + if (confirmationTarget == null || resourceId == -1) { Log.wtf(getTag(), "Calling confirmation dialog without resource or arguments"); return null; } - return new AlertDialog.Builder(getActivity()) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(String.format(getString(resourceId), confirmationTarget)) - .setPositiveButton(R.string.common_ok, + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(String.format(getString(resourceId), confirmationTarget)) + .setIconAttribute(android.R.attr.alertDialogIcon) + .setTitle(android.R.string.dialog_alert_title); + + if (posBtn != -1) + builder.setPositiveButton(posBtn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - mListener.onConfirmation(true, getTag()); + mListener.onConfirmation(getTag()); } - } - ) - .setNegativeButton(R.string.common_cancel, + }); + if (neuBtn != -1) + builder.setNeutralButton(neuBtn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - mListener.onConfirmation(false, getTag()); + mListener.onNeutral(getTag()); + } + }); + if (negBtn != -1) + builder.setNegativeButton(negBtn, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mListener.onCancel(getTag()); } - } - ) - .create(); + }); + return builder.create(); } public interface ConfirmationDialogFragmentListener { - public void onConfirmation(boolean confirmation, String callerTag); + public void onConfirmation(String callerTag); + public void onNeutral(String callerTag); + public void onCancel(String callerTag); } } diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index aa59a5c2..d7fb886f 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -273,7 +273,12 @@ public class FileDetailFragment extends SherlockFragment implements break; } case R.id.fdRemoveBtn: { - ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(R.string.confirmation_remove_alert, new String[]{mFile.getFileName()}); + ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance( + R.string.confirmation_remove_alert, + new String[]{mFile.getFileName()}, + mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote, + mFile.isDown() ? R.string.confirmation_remove_local : -1, + R.string.common_cancel); confDialog.setOnConfirmationListener(this); confDialog.show(getFragmentManager(), FTAG_CONFIRMATION); break; @@ -331,14 +336,31 @@ public class FileDetailFragment extends SherlockFragment implements @Override - public void onConfirmation(boolean confirmation, String callerTag) { - if (confirmation && callerTag.equals(FTAG_CONFIRMATION)) { + public void onConfirmation(String callerTag) { + if (callerTag.equals(FTAG_CONFIRMATION)) { Log.e("ASD","onConfirmation"); FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); if (fdsm.getFileById(mFile.getFileId()) != null) { new Thread(new RemoveRunnable(mFile, mAccount, new Handler())).start(); } - } else if (!confirmation) Log.d(TAG, "REMOVAL CANCELED"); + } + } + + @Override + public void onNeutral(String callerTag) { + FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); + File f = null; + if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) { + f.delete(); + mFile.setStoragePath(null); + fdsm.saveFile(mFile); + updateFileDetails(mFile, mAccount); + } + } + + @Override + public void onCancel(String callerTag) { + Log.d(TAG, "REMOVAL CANCELED"); }