X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f1b3208f1a8e5383e63db4c05342489ea2cd6225..729a9b7c77eddad66f25b9ca8cb934d84ea8ee20:/src/com/owncloud/android/ui/fragment/ShareFileFragment.java diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index ee979c60..2ed5d0b2 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -92,6 +92,12 @@ public class ShareFileFragment extends Fragment /** Public share bound to the file */ private OCShare mPublicShare; + /** Listener for changes on switch to share / unshare publicly */ + private CompoundButton.OnCheckedChangeListener mOnShareViaLinkSwitchCheckedChangeListener; + + /** Listener for changes on switch to set / clear password on public link */ + private CompoundButton.OnCheckedChangeListener mOnPasswordSwitchCheckedChangeListener; + /** * Public factory method to create new ShareFileFragment instances. @@ -175,32 +181,37 @@ public class ShareFileFragment extends Fragment }); // Switch to create public share - Switch shareViaLinkSwitch = (Switch) view.findViewById(R.id.shareViaLinkSectionSwitch); - shareViaLinkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + mOnShareViaLinkSwitchCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (!isResumed()) { + // very important, setCheched(...) is called automatically during + // Fragment recreation on device rotations + return; + } if (isChecked) { - // TODO real implementation: create public share - // expand section - getExpirationDateSection().setVisibility(View.VISIBLE); - getPasswordSection().setVisibility(View.VISIBLE); - getGetLinkButton().setVisibility(View.VISIBLE); + ((FileActivity) getActivity()).getFileOperationsHelper(). + shareFileViaLink(mFile); } else { - // TODO real implementation: unshare - // collapse section - getExpirationDateSection().setVisibility(View.GONE); - getPasswordSection().setVisibility(View.GONE); - getGetLinkButton().setVisibility(View.GONE); + ((FileActivity) getActivity()).getFileOperationsHelper(). + unshareFileViaLink(mFile); } } - }); + }; + Switch shareViaLinkSwitch = (Switch) view.findViewById(R.id.shareViaLinkSectionSwitch); + shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener); // Switch for expiration date Switch shareViaLinkExpirationSwitch = (Switch) view.findViewById(R.id.shareViaLinkExpirationSwitch); shareViaLinkExpirationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (!isResumed()) { + // very important, setCheched(...) is called automatically during + // Fragment recreation on device rotations + return; + } if (isChecked) { // TODO real implementation: update share with expiration date // show value of expiration date @@ -215,23 +226,25 @@ public class ShareFileFragment extends Fragment }); // Switch for password - Switch shareViaLinkPasswordSwitch = (Switch) view.findViewById(R.id.shareViaLinkPasswordSwitch); - shareViaLinkPasswordSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + mOnPasswordSwitchCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (!isResumed()) { + // very important, setCheched(...) is called automatically during + // Fragment recreation on device rotations + return; + } if (isChecked) { - // TODO real implementation: update share with password - // show - getExpirationPasswordValue().setVisibility(View.VISIBLE); - + ((FileActivity) getActivity()).getFileOperationsHelper(). + requestPasswordForShareViaLink(mFile); } else { - // TODO real implementation: update share without password - // empty value - getExpirationPasswordValue().setVisibility(View.INVISIBLE); + ((FileActivity) getActivity()).getFileOperationsHelper(). + setPasswordToShareViaLink(mFile, ""); // "" clears } } - }); - + }; + Switch shareViaLinkPasswordSwitch = (Switch) view.findViewById(R.id.shareViaLinkPasswordSwitch); + shareViaLinkPasswordSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener); return view; } @@ -343,21 +356,59 @@ public class ShareFileFragment extends Fragment */ private void updatePublicShareSection() { if (mPublicShare != null && ShareType.PUBLIC_LINK.equals(mPublicShare.getShareType())) { - // public share bound -> expand section - getShareViaLinkSwitch().setChecked(true); + /// public share bound -> expand section + Switch shareViaLinkSwitch = getShareViaLinkSwitch(); + if (!shareViaLinkSwitch.isChecked()) { + // set null listener before setChecked() to prevent infinite loop of calls + shareViaLinkSwitch.setOnCheckedChangeListener(null); + shareViaLinkSwitch.setChecked(true); + shareViaLinkSwitch.setOnCheckedChangeListener( + mOnShareViaLinkSwitchCheckedChangeListener + ); + } getExpirationDateSection().setVisibility(View.VISIBLE); getPasswordSection().setVisibility(View.VISIBLE); getGetLinkButton().setVisibility(View.VISIBLE); + /// update state of password switch and message depending on password protection + Switch passwordSwitch = getPasswordSwitch(); + // set null listener before setChecked() to prevent infinite loop of calls + passwordSwitch.setOnCheckedChangeListener(null); + if (mPublicShare.isPasswordProtected()) { + if (!passwordSwitch.isChecked()) { + passwordSwitch.toggle(); + } + getPasswordValue().setVisibility(View.VISIBLE); + } else { + if (passwordSwitch.isChecked()) { + passwordSwitch.toggle(); + } + getPasswordValue().setVisibility(View.INVISIBLE); + } + // recover listener + passwordSwitch.setOnCheckedChangeListener( + mOnPasswordSwitchCheckedChangeListener + ); + + } else { - // no public share -> collapse section - getShareViaLinkSwitch().setChecked(false); + /// no public share -> collapse section + Switch shareViaLinkSwitch = getShareViaLinkSwitch(); + if (shareViaLinkSwitch.isChecked()) { + shareViaLinkSwitch.setOnCheckedChangeListener(null); + getShareViaLinkSwitch().setChecked(false); + shareViaLinkSwitch.setOnCheckedChangeListener( + mOnShareViaLinkSwitchCheckedChangeListener + ); + } getExpirationDateSection().setVisibility(View.GONE); getPasswordSection().setVisibility(View.GONE); getGetLinkButton().setVisibility(View.GONE); } } + /// BEWARE: next methods will failed with NullPointerException if called before onCreateView() finishes + private Switch getShareViaLinkSwitch() { return (Switch) getView().findViewById(R.id.shareViaLinkSectionSwitch); } @@ -374,7 +425,11 @@ public class ShareFileFragment extends Fragment return getView().findViewById(R.id.shareViaLinkPasswordSection); } - private TextView getExpirationPasswordValue() { + private Switch getPasswordSwitch() { + return (Switch) getView().findViewById(R.id.shareViaLinkPasswordSwitch); + } + + private TextView getPasswordValue() { return (TextView) getView().findViewById(R.id.shareViaLinkPasswordValue); }