+
+ /**
+ * Listener for user actions that start any update on a password for the public link.
+ */
+ private class OnPasswordInteractionListener
+ implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {
+
+ /**
+ * Called by R.id.shareViaLinkPasswordSwitch to set or clear the password.
+ *
+ * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkPasswordSwitch
+ * @param isChecked New switch state.
+ */
+ @Override
+ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) {
+ if (!isResumed()) {
+ // very important, setCheched(...) is called automatically during
+ // Fragment recreation on device rotations
+ return;
+ }
+ if (isChecked) {
+ ((FileActivity) getActivity()).getFileOperationsHelper().
+ requestPasswordForShareViaLink(mFile);
+ } else {
+ ((FileActivity) getActivity()).getFileOperationsHelper().
+ setPasswordToShareViaLink(mFile, ""); // "" clears
+ }
+
+ // undo the toggle to grant the view will be correct if the dialog is cancelled
+ switchView.setOnCheckedChangeListener(null);
+ switchView.toggle();
+ switchView.setOnCheckedChangeListener(mOnPasswordInteractionListener);
+ }
+
+ /**
+ * Called by R.id.shareViaLinkPasswordLabel or R.id.shareViaLinkPasswordValue
+ * to change the current password.
+ *
+ * @param passwordView Label or value view touched by the user.
+ */
+ @Override
+ public void onClick(View passwordView) {
+ if (mPublicShare != null && mPublicShare.isPasswordProtected()) {
+ ((FileActivity) getActivity()).getFileOperationsHelper().
+ requestPasswordForShareViaLink(mFile);
+ }
+ }
+ }
+
+