+
+ /**
+ * Get public link from the DB to fill in the "Share link" section in the UI.
+ *
+ * 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 public share section
+ 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);
+ shareViaLinkSwitch.setChecked(true);
+ shareViaLinkSwitch.setOnCheckedChangeListener(
+ mOnShareViaLinkSwitchCheckedChangeListener
+ );
+ }
+ getExpirationDateSection().setVisibility(View.VISIBLE);
+ getPasswordSection().setVisibility(View.VISIBLE);
+ getGetLinkButton().setVisibility(View.VISIBLE);
+
+ /// update state of expiration date switch and message depending on expiration date
+ /// update state of expiration date switch and message depending on expiration date
+ Switch expirationDateSwitch = getExpirationDateSwitch();
+ // set null listener before setChecked() to prevent infinite loop of calls
+ expirationDateSwitch.setOnCheckedChangeListener(null);
+ long expirationDate = mPublicShare.getExpirationDate();
+ if (expirationDate > 0) {
+ if (!expirationDateSwitch.isChecked()) {
+ expirationDateSwitch.toggle();
+ }
+ String formattedDate =
+ SimpleDateFormat.getDateInstance().format(
+ new Date(expirationDate)
+ );
+ getExpirationDateValue().setText(formattedDate);
+ } else {
+ if (expirationDateSwitch.isChecked()) {
+ expirationDateSwitch.toggle();
+ }
+ getExpirationDateValue().setText(R.string.empty);
+ }
+ // recover listener
+ expirationDateSwitch.setOnCheckedChangeListener(
+ mOnExpirationDateSwitchCheckedChangeListener
+ );
+
+ /// 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
+ 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);
+ }
+
+ private View getExpirationDateSection() {
+ return getView().findViewById(R.id.shareViaLinkExpirationSection);
+ }
+
+ private Switch getExpirationDateSwitch() {
+ return (Switch) getView().findViewById(R.id.shareViaLinkExpirationSwitch);
+ }
+
+ private TextView getExpirationDateValue() {
+ return (TextView) getView().findViewById(R.id.shareViaLinkExpirationValue);
+ }
+
+ private View getPasswordSection() {
+ return getView().findViewById(R.id.shareViaLinkPasswordSection);
+ }
+
+ private Switch getPasswordSwitch() {
+ return (Switch) getView().findViewById(R.id.shareViaLinkPasswordSwitch);
+ }
+
+ private TextView getPasswordValue() {
+ return (TextView) getView().findViewById(R.id.shareViaLinkPasswordValue);
+ }
+
+ private AppCompatButton getGetLinkButton() {
+ return (AppCompatButton) getView().findViewById(R.id.shareViewLinkGetLinkButton);
+ }
+
+