+
+ /**
+ * Binds listener for user actions that start any update on a expiration date
+ * for the public link to the views receiving the user events.
+ *
+ * @param shareView Root view in the fragment.
+ */
+ private void initExpirationListener(View shareView) {
+ mOnExpirationDateInteractionListener = new OnExpirationDateInteractionListener();
+
+ ((Switch) shareView.findViewById(R.id.shareViaLinkExpirationSwitch)).
+ setOnCheckedChangeListener(mOnExpirationDateInteractionListener);
+
+ shareView.findViewById(R.id.shareViaLinkExpirationLabel).
+ setOnClickListener(mOnExpirationDateInteractionListener);
+
+ shareView.findViewById(R.id.shareViaLinkExpirationValue).
+ setOnClickListener(mOnExpirationDateInteractionListener);
+ }
+
+ /**
+ * Listener for user actions that start any update on the expiration date for the public link.
+ */
+ private class OnExpirationDateInteractionListener
+ implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {
+
+ /**
+ * Called by R.id.shareViaLinkExpirationSwitch to set or clear the expiration date.
+ *
+ * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkExpirationSwitch
+ * @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) {
+ ExpirationDatePickerDialogFragment dialog =
+ ExpirationDatePickerDialogFragment.newInstance(mFile);
+ dialog.show(
+ getActivity().getSupportFragmentManager(),
+ ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG
+ );
+
+ } else {
+ ((FileActivity) getActivity()).getFileOperationsHelper().
+ setExpirationDateToShareViaLink(mFile, -1, -1, -1);
+ }
+
+ // undo the toggle to grant the view will be correct if the dialog is cancelled
+ switchView.setOnCheckedChangeListener(null);
+ switchView.toggle();
+ switchView.setOnCheckedChangeListener(mOnExpirationDateInteractionListener);
+ }
+
+ /**
+ * Called by R.id.shareViaLinkExpirationLabel or R.id.shareViaLinkExpirationValue
+ * to change the current expiration date.
+ *
+ * @param expirationView Label or value view touched by the user.
+ */
+ @Override
+ public void onClick(View expirationView) {
+ if (mPublicShare != null && mPublicShare.getExpirationDate() > 0) {
+ ExpirationDatePickerDialogFragment dialog =
+ ExpirationDatePickerDialogFragment.newInstance(mFile);
+ // TODO set the current chosen value in the dialog
+ dialog.show(
+ getActivity().getSupportFragmentManager(),
+ ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG
+ );
+ }
+ }
+ }
+
+