FileDetailSharingFragment.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Andy Scherzinger
  5. * Copyright (C) 2018 Andy Scherzinger
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package com.owncloud.android.ui.fragment;
  21. import android.accounts.Account;
  22. import android.accounts.AccountManager;
  23. import android.app.SearchManager;
  24. import android.content.Context;
  25. import android.content.res.Resources;
  26. import android.graphics.PorterDuff;
  27. import android.graphics.drawable.Drawable;
  28. import android.os.Bundle;
  29. import android.text.TextUtils;
  30. import android.view.LayoutInflater;
  31. import android.view.Menu;
  32. import android.view.MenuItem;
  33. import android.view.View;
  34. import android.view.ViewGroup;
  35. import android.widget.ImageView;
  36. import android.widget.LinearLayout;
  37. import android.widget.PopupMenu;
  38. import android.widget.TextView;
  39. import com.google.android.material.snackbar.Snackbar;
  40. import com.nextcloud.client.account.UserAccountManager;
  41. import com.nextcloud.client.di.Injectable;
  42. import com.owncloud.android.R;
  43. import com.owncloud.android.datamodel.FileDataStorageManager;
  44. import com.owncloud.android.datamodel.OCFile;
  45. import com.owncloud.android.lib.common.OwnCloudAccount;
  46. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  47. import com.owncloud.android.lib.resources.shares.OCShare;
  48. import com.owncloud.android.lib.resources.shares.SharePermissionsBuilder;
  49. import com.owncloud.android.lib.resources.shares.ShareType;
  50. import com.owncloud.android.lib.resources.status.OCCapability;
  51. import com.owncloud.android.ui.activity.FileActivity;
  52. import com.owncloud.android.ui.activity.FileDisplayActivity;
  53. import com.owncloud.android.ui.adapter.UserListAdapter;
  54. import com.owncloud.android.ui.decoration.SimpleListItemDividerDecoration;
  55. import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment;
  56. import com.owncloud.android.ui.dialog.NoteDialogFragment;
  57. import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
  58. import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper;
  59. import com.owncloud.android.ui.fragment.util.SharingMenuHelper;
  60. import com.owncloud.android.ui.helpers.FileOperationsHelper;
  61. import com.owncloud.android.utils.ClipboardUtil;
  62. import com.owncloud.android.utils.DisplayUtils;
  63. import com.owncloud.android.utils.ThemeUtils;
  64. import java.util.List;
  65. import javax.inject.Inject;
  66. import androidx.annotation.NonNull;
  67. import androidx.annotation.Nullable;
  68. import androidx.appcompat.widget.AppCompatCheckBox;
  69. import androidx.appcompat.widget.SearchView;
  70. import androidx.fragment.app.Fragment;
  71. import androidx.recyclerview.widget.LinearLayoutManager;
  72. import androidx.recyclerview.widget.RecyclerView;
  73. import butterknife.BindView;
  74. import butterknife.ButterKnife;
  75. import butterknife.OnClick;
  76. import butterknife.Unbinder;
  77. public class FileDetailSharingFragment extends Fragment implements UserListAdapter.ShareeListAdapterListener,
  78. DisplayUtils.AvatarGenerationListener, Injectable {
  79. private static final String ARG_FILE = "FILE";
  80. private static final String ARG_ACCOUNT = "ACCOUNT";
  81. // to show share with users/groups info
  82. private List<OCShare> shares;
  83. private OCFile file;
  84. private Account account;
  85. private OCCapability capabilities;
  86. private OCShare publicShare;
  87. private FileOperationsHelper fileOperationsHelper;
  88. private FileDisplayActivity fileDisplayActivity;
  89. private FileDataStorageManager fileDataStorageManager;
  90. private Unbinder unbinder;
  91. @BindView(R.id.searchView)
  92. SearchView searchView;
  93. @BindView(R.id.shareUsersList)
  94. RecyclerView usersList;
  95. @BindView(R.id.shareNoUsers)
  96. TextView noList;
  97. @BindView(R.id.share_by_link)
  98. AppCompatCheckBox shareByLink;
  99. @BindView(R.id.share_link_copy_icon)
  100. ImageView shareLinkCopyIcon;
  101. @BindView(R.id.overflow_menu_share_link)
  102. ImageView overflowMenuShareLink;
  103. @BindView(R.id.share_by_link_allow_editing)
  104. AppCompatCheckBox shareByLinkAllowEditing;
  105. @BindView(R.id.share_by_link_container)
  106. LinearLayout shareByLinkContainer;
  107. @BindView(R.id.shared_with_you_container)
  108. LinearLayout sharedWithYouContainer;
  109. @BindView(R.id.shared_with_you_avatar)
  110. ImageView sharedWithYouAvatar;
  111. @BindView(R.id.shared_with_you_username)
  112. TextView sharedWithYouUsername;
  113. @BindView(R.id.shared_with_you_note)
  114. TextView sharedWithYouNote;
  115. @BindView(R.id.copy_internal_link_icon)
  116. ImageView internalLinkIcon;
  117. @Inject UserAccountManager accountManager;
  118. public static FileDetailSharingFragment newInstance(OCFile file, Account account) {
  119. FileDetailSharingFragment fragment = new FileDetailSharingFragment();
  120. Bundle args = new Bundle();
  121. args.putParcelable(ARG_FILE, file);
  122. args.putParcelable(ARG_ACCOUNT, account);
  123. fragment.setArguments(args);
  124. return fragment;
  125. }
  126. @Override
  127. public void onCreate(@Nullable Bundle savedInstanceState) {
  128. super.onCreate(savedInstanceState);
  129. if (savedInstanceState != null) {
  130. file = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
  131. account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
  132. } else {
  133. Bundle arguments = getArguments();
  134. if (arguments != null) {
  135. file = getArguments().getParcelable(ARG_FILE);
  136. account = getArguments().getParcelable(ARG_ACCOUNT);
  137. }
  138. }
  139. if (file == null) {
  140. throw new IllegalArgumentException("File may not be null");
  141. }
  142. if (account == null) {
  143. throw new IllegalArgumentException("Account may not be null");
  144. }
  145. fileDisplayActivity = (FileDisplayActivity) getActivity();
  146. if (fileDisplayActivity == null) {
  147. throw new IllegalArgumentException("FileActivity may not be null");
  148. }
  149. fileOperationsHelper = fileDisplayActivity.getFileOperationsHelper();
  150. fileDataStorageManager = fileDisplayActivity.getStorageManager();
  151. }
  152. @Override
  153. public void onActivityCreated(Bundle savedInstanceState) {
  154. super.onActivityCreated(savedInstanceState);
  155. refreshCapabilitiesFromDB();
  156. refreshPublicShareFromDB();
  157. }
  158. @Override
  159. public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  160. View view = inflater.inflate(R.layout.file_details_sharing_fragment, container, false);
  161. unbinder = ButterKnife.bind(this, view);
  162. if (fileDataStorageManager == null) {
  163. fileDataStorageManager = new FileDataStorageManager(account, fileDisplayActivity.getContentResolver());
  164. }
  165. setupView();
  166. // todo extract
  167. internalLinkIcon.getBackground().setColorFilter(getResources().getColor(R.color.grey_db),
  168. PorterDuff.Mode.SRC_IN);
  169. internalLinkIcon.getDrawable().mutate().setColorFilter(getResources().getColor(R.color.black),
  170. PorterDuff.Mode.SRC_IN);
  171. return view;
  172. }
  173. @Override
  174. public void onDestroy() {
  175. super.onDestroy();
  176. unbinder.unbind();
  177. }
  178. @Override
  179. public void onAttach(Context context) {
  180. super.onAttach(context);
  181. if (!(getActivity() instanceof FileActivity)) {
  182. throw new IllegalArgumentException("Calling activity must be of type FileActivity");
  183. }
  184. }
  185. private void setupView() {
  186. setShareWithYou();
  187. if (file.canReshare()) {
  188. setShareByLinkInfo(file.isSharedViaLink());
  189. setShareWithUserInfo();
  190. FileDetailSharingFragmentHelper.setupSearchView(
  191. (SearchManager) fileDisplayActivity.getSystemService(Context.SEARCH_SERVICE), searchView,
  192. fileDisplayActivity.getComponentName());
  193. ThemeUtils.themeSearchView(searchView, false, requireContext());
  194. } else {
  195. searchView.setVisibility(View.GONE);
  196. shareByLinkContainer.setVisibility(View.GONE);
  197. noList.setText(R.string.reshare_not_allowed);
  198. }
  199. }
  200. /**
  201. * Updates Share by link UI
  202. *
  203. * @param isShareByLink flag is share by link is enable
  204. */
  205. public void setShareByLinkInfo(boolean isShareByLink) {
  206. shareByLink.setChecked(isShareByLink);
  207. if (isShareByLink) {
  208. shareLinkCopyIcon.setVisibility(View.VISIBLE);
  209. } else {
  210. shareLinkCopyIcon.setVisibility(View.INVISIBLE);
  211. }
  212. int accentColor = ThemeUtils.primaryAccentColor(getContext());
  213. ThemeUtils.tintCheckbox(shareByLink, accentColor);
  214. ThemeUtils.tintCheckbox(shareByLinkAllowEditing, accentColor);
  215. setLinkDetailVisible(isShareByLink);
  216. }
  217. private void setLinkDetailVisible(boolean visible) {
  218. if (visible) {
  219. shareByLinkAllowEditing.setVisibility(View.VISIBLE);
  220. overflowMenuShareLink.setVisibility(View.VISIBLE);
  221. } else {
  222. shareByLinkAllowEditing.setVisibility(View.INVISIBLE);
  223. overflowMenuShareLink.setVisibility(View.INVISIBLE);
  224. }
  225. }
  226. /**
  227. * Update Share With data
  228. */
  229. public void setShareWithUserInfo() {
  230. // Get Users and Groups
  231. shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(), account.name);
  232. // Update list of users/groups
  233. updateListOfUserGroups();
  234. }
  235. private void setShareWithYou() {
  236. if (accountManager.accountOwnsFile(file, account)) {
  237. sharedWithYouContainer.setVisibility(View.GONE);
  238. } else {
  239. sharedWithYouUsername.setText(
  240. String.format(getString(R.string.shared_with_you_by), file.getOwnerDisplayName()));
  241. DisplayUtils.setAvatar(account, file.getOwnerId(), this, getResources().getDimension(
  242. R.dimen.file_list_item_avatar_icon_radius), getResources(), sharedWithYouAvatar,
  243. getContext());
  244. sharedWithYouAvatar.setVisibility(View.VISIBLE);
  245. String note = file.getNote();
  246. if (!TextUtils.isEmpty(note)) {
  247. sharedWithYouNote.setText(file.getNote());
  248. sharedWithYouNote.setVisibility(View.VISIBLE);
  249. } else {
  250. sharedWithYouNote.setVisibility(View.GONE);
  251. }
  252. }
  253. }
  254. private void updateListOfUserGroups() {
  255. // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed
  256. if (shares.size() > 0) {
  257. AccountManager accountManager = AccountManager.get(getContext());
  258. String userId = accountManager.getUserData(account,
  259. com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
  260. usersList.setVisibility(View.VISIBLE);
  261. usersList.setAdapter(new UserListAdapter(fileDisplayActivity.getSupportFragmentManager(),
  262. fileDisplayActivity, shares, account, file, this, userId));
  263. usersList.setLayoutManager(new LinearLayoutManager(getContext()));
  264. usersList.addItemDecoration(new SimpleListItemDividerDecoration(getContext()));
  265. noList.setVisibility(View.GONE);
  266. } else {
  267. usersList.setVisibility(View.GONE);
  268. noList.setVisibility(View.VISIBLE);
  269. }
  270. }
  271. @OnClick(R.id.share_by_link)
  272. public void toggleShareByLink() {
  273. if (shareByLink.isChecked()) {
  274. createShareLink();
  275. } else {
  276. fileOperationsHelper.unshareFileViaLink(file);
  277. }
  278. }
  279. @OnClick(R.id.copy_internal_container)
  280. public void copyInternalLink() {
  281. OwnCloudAccount account = accountManager.getCurrentOwnCloudAccount();
  282. if (account == null) {
  283. DisplayUtils.showSnackMessage(getView(), getString(R.string.could_not_retrieve_url));
  284. return;
  285. }
  286. FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file, createInternalLink(account, file));
  287. }
  288. private String createInternalLink(OwnCloudAccount account, OCFile file) {
  289. return account.getBaseUri() + "/index.php/f/" + file.getLocalId();
  290. }
  291. private void createShareLink() {
  292. if (capabilities != null && (capabilities.getFilesSharingPublicPasswordEnforced().isTrue() ||
  293. capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue())) {
  294. // password enforced by server, request to the user before trying to create
  295. requestPasswordForShareViaLink(true,
  296. capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue());
  297. } else {
  298. // create without password if not enforced by server or we don't know if enforced;
  299. fileOperationsHelper.shareFileViaLink(file, null);
  300. }
  301. }
  302. private void showSendLinkTo() {
  303. if (file.isSharedViaLink()) {
  304. if (TextUtils.isEmpty(file.getPublicLink())) {
  305. fileOperationsHelper.getFileWithLink(file);
  306. } else {
  307. FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file, file.getPublicLink());
  308. }
  309. }
  310. }
  311. @OnClick({R.id.share_link_copy_icon})
  312. public void copyLinkToClipboard() {
  313. if (file.isSharedViaLink()) {
  314. if (TextUtils.isEmpty(file.getPublicLink())) {
  315. fileOperationsHelper.getFileWithLink(file);
  316. } else {
  317. ClipboardUtil.copyToClipboard(getActivity(), file.getPublicLink());
  318. }
  319. }
  320. }
  321. @OnClick(R.id.share_by_link_allow_editing)
  322. public void toggleShareLinkAllowEditing() {
  323. if (file.isSharedViaLink()) {
  324. fileOperationsHelper.setUploadPermissionsToShare(file, shareByLinkAllowEditing.isChecked());
  325. }
  326. }
  327. @OnClick(R.id.overflow_menu_share_link)
  328. public void showLinkOverflowMenu() {
  329. Context context = getContext();
  330. if (context != null && ThemeUtils.themingEnabled(context)) {
  331. // use grey as fallback for elements where custom theming is not available
  332. context.getTheme().applyStyle(R.style.FallbackThemingTheme, true);
  333. } else {
  334. context = getActivity();
  335. }
  336. PopupMenu popup = new PopupMenu(context, overflowMenuShareLink);
  337. popup.inflate(R.menu.file_detail_sharing_link_menu);
  338. prepareOptionsMenu(popup.getMenu());
  339. popup.setOnMenuItemClickListener(this::optionsItemSelected);
  340. popup.show();
  341. }
  342. private void prepareOptionsMenu(Menu menu) {
  343. Resources res = getResources();
  344. SharingMenuHelper.setupHideFileListingMenuItem(
  345. menu.findItem(R.id.action_hide_file_listing),
  346. file.isFolder(),
  347. shareByLinkAllowEditing.isChecked(),
  348. publicShare.getPermissions()
  349. );
  350. SharingMenuHelper.setupHideFileDownload(menu.findItem(R.id.action_hide_file_download),
  351. publicShare.isHideFileDownload(), capabilities);
  352. SharingMenuHelper.setupPasswordMenuItem(
  353. menu.findItem(R.id.action_password),
  354. publicShare.isPasswordProtected()
  355. );
  356. SharingMenuHelper.setupExpirationDateMenuItem(
  357. menu.findItem(R.id.action_share_expiration_date),
  358. publicShare.getExpirationDate(),
  359. res
  360. );
  361. menu.findItem(R.id.action_share_send_note).setVisible(capabilities.getVersion().isNoteOnShareSupported());
  362. }
  363. private boolean optionsItemSelected(MenuItem item) {
  364. switch (item.getItemId()) {
  365. case R.id.action_hide_file_listing: {
  366. item.setChecked(!item.isChecked());
  367. if (capabilities.getFilesFileDrop().isTrue()) {
  368. setHideFileListingPermissionsToShare(publicShare, item.isChecked());
  369. } else {
  370. // not supported in ownCloud
  371. showNotSupportedByOcMessage();
  372. }
  373. return true;
  374. }
  375. case R.id.action_hide_file_download:
  376. item.setChecked(!item.isChecked());
  377. setHideFileDownloadPermissionToShare(file, item.isChecked());
  378. return true;
  379. case R.id.action_password: {
  380. requestPasswordForShareViaLink(false,
  381. capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue());
  382. return true;
  383. }
  384. case R.id.action_share_expiration_date: {
  385. ExpirationDatePickerDialogFragment dialog = ExpirationDatePickerDialogFragment.newInstance(file, -1);
  386. dialog.show(
  387. fileDisplayActivity.getSupportFragmentManager(),
  388. ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG
  389. );
  390. return true;
  391. }
  392. case R.id.action_share_send_link: {
  393. if(shareByLink.isChecked() && file.isSharedViaLink() && !TextUtils.isEmpty(file.getPublicLink())) {
  394. FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file, file.getPublicLink());
  395. } else {
  396. showSendLinkTo();
  397. }
  398. return true;
  399. }
  400. case R.id.action_share_send_note:
  401. NoteDialogFragment dialog = NoteDialogFragment.newInstance(publicShare);
  402. dialog.show(fileDisplayActivity.getSupportFragmentManager(), NoteDialogFragment.NOTE_FRAGMENT);
  403. return true;
  404. default:
  405. return super.onOptionsItemSelected(item);
  406. }
  407. }
  408. @Override
  409. public void setHideFileListingPermissionsToShare(OCShare share, boolean hideFileListing) {
  410. fileOperationsHelper.setHideFileListingPermissionsToShare(share, hideFileListing);
  411. }
  412. @Override
  413. public void setHideFileDownloadPermissionToShare(OCFile file, boolean hideFileDownload) {
  414. fileOperationsHelper.setHideFileDownloadPermissionsToShare(file, hideFileDownload);
  415. }
  416. @Override
  417. public void showNotSupportedByOcMessage() {
  418. if (getView() != null) {
  419. Snackbar.make(getView(), R.string.files_drop_not_supported, Snackbar.LENGTH_LONG)
  420. .setAction(R.string.learn_more, v ->
  421. DisplayUtils.startLinkIntent(requireActivity(), R.string.url_server_install))
  422. .show();
  423. }
  424. }
  425. /**
  426. * Updates the UI after the result of an update operation on the edited {@link OCFile}.
  427. *
  428. * @param result {@link RemoteOperationResult} of an update on the edited {@link OCFile} sharing information.
  429. * @param file the edited {@link OCFile}
  430. */
  431. public void onUpdateShareInformation(RemoteOperationResult result, OCFile file) {
  432. this.file = file;
  433. if (result.isSuccess()) {
  434. refreshUiFromDB();
  435. } else {
  436. setupView();
  437. }
  438. }
  439. /**
  440. * Get {@link OCShare} instance from DB and updates the UI.
  441. */
  442. private void refreshUiFromDB() {
  443. if (publicShare != null) {
  444. // Get edited shared by link
  445. publicShare = fileDataStorageManager.getShareById(publicShare.getId());
  446. }
  447. // Updates UI with new state
  448. setupView();
  449. }
  450. @Override
  451. public void unshareWith(OCShare share) {
  452. fileOperationsHelper.unshareFileWithUserOrGroup(file, share.getShareType(), share.getShareWith());
  453. }
  454. @Override
  455. public int updatePermissionsToShare(OCShare share, boolean canReshare, boolean canEdit, boolean canEditCreate,
  456. boolean canEditChange, boolean canEditDelete) {
  457. SharePermissionsBuilder spb = new SharePermissionsBuilder();
  458. spb.setSharePermission(canReshare);
  459. if (file.isFolder()) {
  460. spb.setUpdatePermission(canEditChange)
  461. .setCreatePermission(canEditCreate)
  462. .setDeletePermission(canEditDelete);
  463. } else {
  464. spb.setUpdatePermission(canEdit);
  465. }
  466. int permissions = spb.build();
  467. fileOperationsHelper.setPermissionsToShare(share, permissions);
  468. return permissions;
  469. }
  470. @Override
  471. public void updateNoteToShare(OCShare share, String note) {
  472. fileOperationsHelper.updateNoteToShare(share, note);
  473. }
  474. /**
  475. * Starts a dialog that requests a password to the user to protect a share link.
  476. *
  477. * @param createShare When 'true', the request for password will be followed by the creation of a new public
  478. * link; when 'false', a public share is assumed to exist, and the password is bound to it.
  479. * @param askForPassword if true, password is optional
  480. */
  481. public void requestPasswordForShareViaLink(boolean createShare, boolean askForPassword) {
  482. SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(file,
  483. createShare,
  484. askForPassword);
  485. dialog.show(getChildFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT);
  486. }
  487. @Override
  488. public void requestPasswordForShare(OCShare share) {
  489. SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(share);
  490. dialog.show(getChildFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT);
  491. }
  492. /**
  493. * Get known server capabilities from DB
  494. */
  495. public void refreshCapabilitiesFromDB() {
  496. capabilities = fileDataStorageManager.getCapability(account.name);
  497. }
  498. /**
  499. * Get public link from the DB to fill in the "Share link" section in the UI.
  500. *
  501. * Takes into account server capabilities before reading database.
  502. */
  503. public void refreshPublicShareFromDB() {
  504. if (FileDetailSharingFragmentHelper.isPublicShareDisabled(capabilities) || !file.canReshare()) {
  505. shareByLinkContainer.setVisibility(View.GONE);
  506. } else {
  507. // Get public share
  508. publicShare = fileDataStorageManager.getFirstShareByPathAndType(file.getRemotePath(),
  509. ShareType.PUBLIC_LINK, "");
  510. // Update public share section
  511. updatePublicShareSection();
  512. }
  513. }
  514. /**
  515. * Updates in the UI the section about public share with the information
  516. * in the current public share bound to, if any.
  517. */
  518. private void updatePublicShareSection() {
  519. if (publicShare != null && ShareType.PUBLIC_LINK.equals(publicShare.getShareType())) {
  520. shareByLink.setChecked(true);
  521. if (publicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) {
  522. shareByLinkAllowEditing.setChecked(true);
  523. } else {
  524. shareByLinkAllowEditing.setChecked(false);
  525. }
  526. setShareByLinkInfo(true);
  527. } else {
  528. setShareByLinkInfo(false);
  529. }
  530. }
  531. @Override
  532. public void onSaveInstanceState(@NonNull Bundle outState) {
  533. super.onSaveInstanceState(outState);
  534. outState.putParcelable(FileActivity.EXTRA_FILE, file);
  535. outState.putParcelable(FileActivity.EXTRA_ACCOUNT, account);
  536. }
  537. @Override
  538. public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
  539. sharedWithYouAvatar.setImageDrawable(avatarDrawable);
  540. }
  541. @Override
  542. public boolean shouldCallGeneratedCallback(String tag, Object callContext) {
  543. return false;
  544. }
  545. }