From f6e8636cfa87a7a2728a0b435d98e2acefb0d237 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 30 Jun 2020 09:45:40 +0200 Subject: [PATCH] remove EditShareFragment.java Signed-off-by: tobiasKaminsky --- scripts/analysis/findbugs-results.txt | 2 +- .../ui/fragment/EditShareFragment.java | 525 ------------------ src/main/res/layout/edit_share_layout.xml | 103 ---- src/main/res/values/dims.xml | 1 - src/main/res/values/strings.xml | 2 - 5 files changed, 1 insertion(+), 632 deletions(-) delete mode 100644 src/main/java/com/owncloud/android/ui/fragment/EditShareFragment.java delete mode 100644 src/main/res/layout/edit_share_layout.xml diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index d61d31715d..3d9988adcd 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -336 \ No newline at end of file +335 diff --git a/src/main/java/com/owncloud/android/ui/fragment/EditShareFragment.java b/src/main/java/com/owncloud/android/ui/fragment/EditShareFragment.java deleted file mode 100644 index 2d364f8e35..0000000000 --- a/src/main/java/com/owncloud/android/ui/fragment/EditShareFragment.java +++ /dev/null @@ -1,525 +0,0 @@ -/* - * ownCloud Android client application - * - * @author masensio - * @author David A. Velasco - * Copyright (C) 2015 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.owncloud.android.ui.fragment; - -import android.graphics.PorterDuff; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.TextView; - -import com.nextcloud.client.account.User; -import com.owncloud.android.R; -import com.owncloud.android.datamodel.FileDataStorageManager; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.lib.resources.shares.SharePermissionsBuilder; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.resources.status.OCCapability; -import com.owncloud.android.ui.activity.FileActivity; -import com.owncloud.android.utils.ThemeUtils; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatCheckBox; -import androidx.appcompat.widget.SwitchCompat; -import androidx.fragment.app.Fragment; - -public class EditShareFragment extends Fragment { - - private static final String TAG = EditShareFragment.class.getSimpleName(); - - /** The fragment initialization parameters */ - private static final String ARG_SHARE = "SHARE"; - private static final String ARG_FILE = "FILE"; - private static final String ARG_USER = "USER"; - - /** Ids of CheckBoxes depending on R.id.canEdit CheckBox */ - private static final int sSubordinateCheckBoxIds[] = { - R.id.canEditCreateCheckBox, - R.id.canEditChangeCheckBox, - R.id.canEditDeleteCheckBox - }; - - /** Share to show & edit, received as a parameter in construction time */ - private OCShare mShare; - - /** File bound to mShare, received as a parameter in construction time */ - private OCFile mFile; - - /** Account of the shared file, received as a parameter in construction time */ - private User user; - - /** - * Capabilities of the server. - */ - private OCCapability mCapabilities; - - /** Listener for changes on privilege checkboxes */ - private CompoundButton.OnCheckedChangeListener mOnPrivilegeChangeListener; - - /** - * Public factory method to create new EditShareFragment instances. - * - * @param shareToEdit An {@link OCShare} to show and edit in the fragment - * @param sharedFile The {@link OCFile} bound to 'shareToEdit' - * @param user User holding 'sharedFile' - * @return A new instance of fragment EditShareFragment. - */ - public static EditShareFragment newInstance(OCShare shareToEdit, OCFile sharedFile, User user) { - EditShareFragment fragment = new EditShareFragment(); - Bundle args = new Bundle(); - args.putParcelable(ARG_SHARE, shareToEdit); - args.putParcelable(ARG_FILE, sharedFile); - args.putParcelable(ARG_USER, user); - fragment.setArguments(args); - return fragment; - } - - /** - * {@inheritDoc} - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Log_OC.d(TAG, "onCreate"); - if (getArguments() != null) { - mShare = getArguments().getParcelable(ARG_SHARE); - mFile = getArguments().getParcelable(ARG_FILE); - /* OC account holding the shared file, received as a parameter in construction time */ - user = getArguments().getParcelable(ARG_USER); - } - - FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(), - getContext().getContentResolver()); - mCapabilities = storageManager.getCapability(user.getAccountName()); - } - - - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - Log_OC.d(TAG, "onActivityCreated"); - getActivity().setTitle(mShare.getSharedWithDisplayName()); - } - - - /** - * {@inheritDoc} - */ - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - Log_OC.d(TAG, "onCreateView"); - - // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.edit_share_layout, container, false); - - ((TextView) view.findViewById(R.id.editShareTitle)).setText( - getResources().getString(R.string.share_with_edit_title, mShare.getSharedWithDisplayName())); - - View headerDivider = view.findViewById(R.id.share_header_divider); - headerDivider.getBackground().setColorFilter(ThemeUtils.primaryAccentColor(getContext()), - PorterDuff.Mode.SRC_ATOP); - - // Setup layout - refreshUiFromState(view); - - return view; - } - - /** - * Get known server capabilities from DB - *

- * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager} - * instance ready to use. If not ready, does nothing. - */ - public void refreshCapabilitiesFromDB() { - if (getActivity() instanceof FileActivity) { - FileActivity fileActivity = (FileActivity) getActivity(); - if (fileActivity.getStorageManager() != null) { - mCapabilities = fileActivity.getStorageManager().getCapability(user.getAccountName()); - } - } - } - - /** - * Updates the UI with the current permissions in the edited {@OCShare} - * - * @param editShareView Root view in the fragment. - */ - private void refreshUiFromState(View editShareView) { - if (editShareView != null) { - setPermissionsListening(editShareView, false); - - int sharePermissions = mShare.getPermissions(); - boolean isFederated = ShareType.FEDERATED.equals(mShare.getShareType()); - - int accentColor = ThemeUtils.primaryAccentColor(getContext()); - - SwitchCompat shareSwitch = editShareView.findViewById(R.id.canShareSwitch); - ThemeUtils.tintSwitch(shareSwitch, accentColor, true); - - if (isFederated) { - shareSwitch.setVisibility(View.INVISIBLE); - } else if (mCapabilities != null && mCapabilities.getFilesSharingResharing().isFalse()) { - shareSwitch.setVisibility(View.GONE); - } - - shareSwitch.setChecked((sharePermissions & OCShare.SHARE_PERMISSION_FLAG) > 0); - - SwitchCompat switchCompat = editShareView.findViewById(R.id.canEditSwitch); - ThemeUtils.tintSwitch(switchCompat, accentColor, true); - int anyUpdatePermission = OCShare.CREATE_PERMISSION_FLAG | OCShare.UPDATE_PERMISSION_FLAG | - OCShare.DELETE_PERMISSION_FLAG; - boolean canEdit = (sharePermissions & anyUpdatePermission) > 0; - switchCompat.setChecked(canEdit); - - boolean areEditOptionsAvailable = !isFederated; - - if (mFile.isFolder() && areEditOptionsAvailable) { - /// TODO change areEditOptionsAvailable in order to delete !isFederated - // from checking when iOS is ready - AppCompatCheckBox checkBox = editShareView.findViewById(R.id.canEditCreateCheckBox); - checkBox.setChecked((sharePermissions & OCShare.CREATE_PERMISSION_FLAG) > 0); - checkBox.setVisibility(canEdit ? View.VISIBLE : View.GONE); - ThemeUtils.tintCheckbox(checkBox, accentColor); - - checkBox = editShareView.findViewById(R.id.canEditChangeCheckBox); - checkBox.setChecked((sharePermissions & OCShare.UPDATE_PERMISSION_FLAG) > 0); - checkBox.setVisibility(canEdit ? View.VISIBLE : View.GONE); - ThemeUtils.tintCheckbox(checkBox, accentColor); - - checkBox = editShareView.findViewById(R.id.canEditDeleteCheckBox); - checkBox.setChecked((sharePermissions & OCShare.DELETE_PERMISSION_FLAG) > 0); - checkBox.setVisibility(canEdit ? View.VISIBLE : View.GONE); - ThemeUtils.tintCheckbox(checkBox, accentColor); - } - - setPermissionsListening(editShareView, true); - } - } - - /** - * Binds or unbinds listener for user actions to enable or disable a permission on the edited share - * to the views receiving the user events. - * - * @param editShareView Root view in the fragment. - * @param enable When 'true', listener is bound to view; when 'false', it is unbound. - */ - private void setPermissionsListening(View editShareView, boolean enable) { - if (enable && mOnPrivilegeChangeListener == null) { - mOnPrivilegeChangeListener = new OnPrivilegeChangeListener(); - } - CompoundButton.OnCheckedChangeListener changeListener = enable ? mOnPrivilegeChangeListener : null; - CompoundButton compound; - - compound = editShareView.findViewById(R.id.canShareSwitch); - compound.setOnCheckedChangeListener(changeListener); - - compound = editShareView.findViewById(R.id.canEditSwitch); - compound.setOnCheckedChangeListener(changeListener); - - if (mFile.isFolder()) { - compound = editShareView.findViewById(R.id.canEditCreateCheckBox); - compound.setOnCheckedChangeListener(changeListener); - - compound = editShareView.findViewById(R.id.canEditChangeCheckBox); - compound.setOnCheckedChangeListener(changeListener); - - compound = editShareView.findViewById(R.id.canEditDeleteCheckBox); - compound.setOnCheckedChangeListener(changeListener); - } - - } - - /** - * Listener for user actions that enable or disable a privilege - */ - private class OnPrivilegeChangeListener - implements CompoundButton.OnCheckedChangeListener { - - /** - * Called by every {@link SwitchCompat} and {@link CheckBox} in the fragment to update - * the state of its associated permission. - * - * @param compound {@link CompoundButton} toggled by the user - * @param isChecked New switch state. - */ - @Override - public void onCheckedChanged(CompoundButton compound, boolean isChecked) { - if (!isResumed()) { - // very important, setCheched(...) is called automatically during - // Fragment recreation on device rotations - return; - } - /// else, getView() cannot be NULL - - CompoundButton subordinate; - switch (compound.getId()) { - case R.id.canShareSwitch: - Log_OC.v(TAG, "canShareCheckBox toggled to " + isChecked); - updatePermissionsToShare(); - break; - - case R.id.canEditSwitch: - Log_OC.v(TAG, "canEditCheckBox toggled to " + isChecked); - /// sync subordinate CheckBoxes - boolean isFederated = ShareType.FEDERATED.equals(mShare.getShareType()); - if (mFile.isFolder()) { - if (isChecked) { - if (!isFederated) { - /// not federated shares -> enable all the subpermisions - for (int subordinateCheckBoxId : sSubordinateCheckBoxIds) { - //noinspection ConstantConditions, prevented in the method beginning - subordinate = getView().findViewById(subordinateCheckBoxId); - subordinate.setVisibility(View.VISIBLE); - if (!subordinate.isChecked() && !mFile.isSharedWithMe()) { // see (1) - toggleDisablingListener(subordinate); - } - } - } else { - /// federated share -> enable delete subpermission, as server side; TODO why? - //noinspection ConstantConditions, prevented in the method beginning - subordinate = getView().findViewById(R.id.canEditDeleteCheckBox); - if (!subordinate.isChecked()) { - toggleDisablingListener(subordinate); - } - - } - } else { - for (int sSubordinateCheckBoxId : sSubordinateCheckBoxIds) { - //noinspection ConstantConditions, prevented in the method beginning - subordinate = getView().findViewById(sSubordinateCheckBoxId); - subordinate.setVisibility(View.GONE); - if (subordinate.isChecked()) { - toggleDisablingListener(subordinate); - } - } - } - } - - if (!(mFile.isFolder() && isChecked && mFile.isSharedWithMe()) // see (1) - || isFederated) { - updatePermissionsToShare(); - } - - // updatePermissionsToShare() // see (1) - // (1) These modifications result in an exceptional UI behaviour for the case - // where the switch 'can edit' is enabled for a *reshared folder*; if the same - // behaviour was applied than for owned folder, and the user did not have full - // permissions to update the folder, an error would be reported by the server - // and the children checkboxes would be automatically hidden again - break; - - case R.id.canEditCreateCheckBox: - Log_OC.v(TAG, "canEditCreateCheckBox toggled to " + isChecked); - syncCanEditSwitch(compound, isChecked); - updatePermissionsToShare(); - break; - - case R.id.canEditChangeCheckBox: - Log_OC.v(TAG, "canEditChangeCheckBox toggled to " + isChecked); - syncCanEditSwitch(compound, isChecked); - updatePermissionsToShare(); - break; - - case R.id.canEditDeleteCheckBox: - Log_OC.v(TAG, "canEditDeleteCheckBox toggled to " + isChecked); - syncCanEditSwitch(compound, isChecked); - updatePermissionsToShare(); - break; - } - - } - - /** - * Sync value of "can edit" {@link SwitchCompat} according to a change in one of its subordinate checkboxes. - * - * If all the subordinates are disabled, "can edit" has to be disabled. - * - * If any subordinate is enabled, "can edit" has to be enabled. - * - * @param subordinateCheckBoxView Subordinate {@link CheckBox} that was changed. - * @param isChecked 'true' iif subordinateCheckBoxView was checked. - */ - private void syncCanEditSwitch(View subordinateCheckBoxView, boolean isChecked) { - CompoundButton canEditCompound = getView().findViewById(R.id.canEditSwitch); - if (isChecked) { - if (!canEditCompound.isChecked()) { - toggleDisablingListener(canEditCompound); - } - } else { - boolean allDisabled = true; - for (int i = 0; allDisabled && i < sSubordinateCheckBoxIds.length; i++) { - allDisabled &= - sSubordinateCheckBoxIds[i] == subordinateCheckBoxView.getId() || - !((CheckBox) getView().findViewById(sSubordinateCheckBoxIds[i])).isChecked() - ; - } - if (canEditCompound.isChecked() && allDisabled) { - toggleDisablingListener(canEditCompound); - for (int sSubordinateCheckBoxId : sSubordinateCheckBoxIds) { - getView().findViewById(sSubordinateCheckBoxId).setVisibility(View.GONE); - } - } - } - } - - - /** - * Toggle value of received {@link CompoundButton} granting that its change listener is not called. - * - * @param compound {@link CompoundButton} (switch or checkBox) to toggle without reporting to - * the change listener - */ - private void toggleDisablingListener(CompoundButton compound) { - compound.setOnCheckedChangeListener(null); - compound.toggle(); - compound.setOnCheckedChangeListener(this); - } - } - - - /** - * Updates the UI after the result of an update operation on the edited {@link OCShare} permissions. - * - * @param result Result of an update on the edited {@link OCShare} permissions. - */ - public void onUpdateSharePermissionsFinished(RemoteOperationResult result) { - if (result.isSuccess()) { - refreshUiFromDB(getView()); - } else { - refreshUiFromState(getView()); - } - } - - /** - * Get {@link OCShare} instance from DB and updates 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 refreshUiFromDB() { - if (getView() != null) { - refreshUiFromDB(getView()); - } - } - - - /** - * Get {@link OCShare} instance from DB and updates the UI. - * - * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager} - * instance ready to use. If not ready, does nothing. - * - * @param editShareView Root view in the fragment. - */ - private void refreshUiFromDB(View editShareView) { - FileDataStorageManager storageManager = ((FileActivity) getActivity()).getStorageManager(); - if (storageManager != null) { - // Get edited share - mShare = storageManager.getShareById(mShare.getId()); - - // Updates UI with new state - refreshUiFromState(editShareView); - } - } - - - /** - * Updates the permissions of the {@link OCShare} according to the values set in the UI - */ - private void updatePermissionsToShare() { - SharePermissionsBuilder spb = new SharePermissionsBuilder(); - spb.setSharePermission(getCanShareSwitch().isChecked()); - if (mFile.isFolder()) { - spb.setUpdatePermission(getCanEditChangeCheckBox().isChecked()) - .setCreatePermission(getCanEditCreateCheckBox().isChecked()) - .setDeletePermission(getCanEditDeleteCheckBox().isChecked()); - } else { - spb.setUpdatePermission(getCanEditSwitch().isChecked()); - } - int permissions = spb.build(); - - ((FileActivity) getActivity()).getFileOperationsHelper(). - setPermissionsToShare( - mShare, - permissions - ) - ; - } - - /** - * Shortcut to access {@link SwitchCompat} R.id.canShareSwitch - * - * @return {@link SwitchCompat} R.id.canShareCheckBox or null if called before - * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} finished. - */ - private SwitchCompat getCanShareSwitch() { - return (SwitchCompat) getView().findViewById(R.id.canShareSwitch); - } - - /** - * Shortcut to access {@link SwitchCompat} R.id.canEditSwitch - * - * @return {@link SwitchCompat} R.id.canEditSwitch or null if called before - * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} finished. - */ - private SwitchCompat getCanEditSwitch() { - return (SwitchCompat) getView().findViewById(R.id.canEditSwitch); - } - - /** - * Shortcut to access {@link CheckBox} R.id.canEditCreateCheckBox - * - * @return {@link CheckBox} R.id.canEditCreateCheckBox or null if called before - * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} finished. - */ - private CheckBox getCanEditCreateCheckBox() { - return (CheckBox) getView().findViewById(R.id.canEditCreateCheckBox); - } - - /** - * Shortcut to access {@link CheckBox} R.id.canEditChangeCheckBox - * - * @return {@link CheckBox} R.id.canEditChangeCheckBox or null if called before - * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} finished. - */ - private CheckBox getCanEditChangeCheckBox() { - return (CheckBox) getView().findViewById(R.id.canEditChangeCheckBox); - } - - /** - * Shortcut to access {@link CheckBox} R.id.canEditDeleteCheckBox - * - * @return {@link CheckBox} R.id.canEditDeleteCheckBox or null if called before - * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} finished. - */ - private CheckBox getCanEditDeleteCheckBox() { - return (CheckBox) getView().findViewById(R.id.canEditDeleteCheckBox); - } - -} diff --git a/src/main/res/layout/edit_share_layout.xml b/src/main/res/layout/edit_share_layout.xml deleted file mode 100644 index 9f4fcd79fc..0000000000 --- a/src/main/res/layout/edit_share_layout.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/res/values/dims.xml b/src/main/res/values/dims.xml index 5db4f757c2..ed1a377f7d 100644 --- a/src/main/res/values/dims.xml +++ b/src/main/res/values/dims.xml @@ -61,7 +61,6 @@ 196dip 40dip 12sp - 2dp 12dp 20dp 15dp diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 53c1c05365..298e6f254e 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -473,7 +473,6 @@ edit Hide file listing Share with… - Share with %1$s Unset Name, federated cloud ID or email address… @@ -486,7 +485,6 @@ Unshare can share - can edit can create can change can delete