+
+ /**
+ * Get public link from the DB to fill in the "Share link" section
+ *
+ * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager}
+ * instance ready to use. If not ready, does nothing.
+ */
+ public void refreshPublicShareFromDB() {
+ if (((FileActivity) mListener).getStorageManager() != null) {
+ // Get public share
+ mPublicShare = ((FileActivity) mListener).getStorageManager().getFirstShareByPathAndType(
+ mFile.getRemotePath(),
+ ShareType.PUBLIC_LINK,
+ ""
+ );
+
+ // Update list of users/groups
+ updatePublicShareSection();
+ }
+ }
+
+ /**
+ * Updates in the UI the section about public share with the information in the current
+ * public share bound to mFile, if any
+ */
+ private void updatePublicShareSection() {
+ if (mPublicShare != null && ShareType.PUBLIC_LINK.equals(mPublicShare.getShareType())) {
+ // 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);
+ getShareViaLinkSwitch().setChecked(true);
+ shareViaLinkSwitch.setOnCheckedChangeListener(
+ mOnShareViaLinkSwitchCheckedChangeListener
+ );
+ }
+ getExpirationDateSection().setVisibility(View.VISIBLE);
+ getPasswordSection().setVisibility(View.VISIBLE);
+ getGetLinkButton().setVisibility(View.VISIBLE);
+
+ } else {
+ // 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);
+ }
+ }
+
+ private Switch getShareViaLinkSwitch() {
+ return (Switch) getView().findViewById(R.id.shareViaLinkSectionSwitch);
+ }
+
+ private View getExpirationDateSection() {
+ return getView().findViewById(R.id.shareViaLinkExpirationSection);
+ }
+
+ private TextView getExpirationDateValue() {
+ return (TextView) getView().findViewById(R.id.shareViaLinkExpirationValue);
+ }
+
+ private View getPasswordSection() {
+ return getView().findViewById(R.id.shareViaLinkPasswordSection);
+ }
+
+ private TextView getExpirationPasswordValue() {
+ return (TextView) getView().findViewById(R.id.shareViaLinkPasswordValue);
+ }
+
+ private AppCompatButton getGetLinkButton() {
+ return (AppCompatButton) getView().findViewById(R.id.shareViewLinkGetLinkButton);
+ }
+
+