From 8f78e61c6f218fa148306a24b2551e13306d3fa7 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 9 May 2019 11:50:13 +0200 Subject: [PATCH 1/6] if ask for password is set, show an optional password dialog Signed-off-by: tobiasKaminsky --- build.gradle | 6 ++-- .../datamodel/FileDataStorageManager.java | 4 +++ .../com/owncloud/android/db/ProviderMeta.java | 1 + .../providers/FileContentProvider.java | 22 ++++++++++++- .../ui/activity/FileDisplayActivity.java | 9 ++++-- .../android/ui/activity/ShareActivity.java | 7 ++-- .../android/ui/dialog/SendShareDialog.java | 21 +++++++++--- .../dialog/SharePasswordDialogFragment.java | 31 ++++++++++++++---- .../fragment/FileDetailSharingFragment.java | 20 ++++++------ .../ui/fragment/ShareFileFragment.java | 32 +++++++++---------- .../ui/helpers/FileOperationsHelper.java | 5 +-- src/main/res/values/strings.xml | 1 + 12 files changed, 108 insertions(+), 51 deletions(-) diff --git a/build.gradle b/build.gradle index 62145ed5d615..b716709c87b0 100644 --- a/build.gradle +++ b/build.gradle @@ -251,9 +251,9 @@ dependencies { // dependencies for app building implementation 'androidx.multidex:multidex:2.0.1' // implementation project('nextcloud-android-library') - genericImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' - gplayImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' - versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' + genericImplementation 'com.github.nextcloud:android-library:askForPassword-SNAPSHOT' + gplayImplementation 'com.github.nextcloud:android-library:askForPassword-SNAPSHOT' + versionDevImplementation 'com.github.nextcloud:android-library:askForPassword-SNAPSHOT' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.google.android.material:material:1.0.0' diff --git a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index 30b94412fd8c..e5150e2db12a 100644 --- a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1924,6 +1924,8 @@ public OCCapability saveCapabilities(OCCapability capability) { capability.getFilesSharingPublicEnabled().getValue()); cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED, capability.getFilesSharingPublicPasswordEnforced().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD, + capability.getFilesSharingPublicAskForPassword().getValue()); cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED, capability.getFilesSharingPublicExpireDateEnabled().getValue()); cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS, @@ -2078,6 +2080,8 @@ private OCCapability createCapabilityInstance(Cursor c) { .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED)))); capability.setFilesSharingPublicPasswordEnforced(CapabilityBooleanType.fromValue(c.getInt(c .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED)))); + capability.setFilesSharingPublicAskForPassword(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD)))); capability.setFilesSharingPublicExpireDateEnabled(CapabilityBooleanType.fromValue(c.getInt(c .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED)))); capability.setFilesSharingPublicExpireDateDays(c.getInt(c diff --git a/src/main/java/com/owncloud/android/db/ProviderMeta.java b/src/main/java/com/owncloud/android/db/ProviderMeta.java index 7621a6ea1169..4848c32e2591 100644 --- a/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -155,6 +155,7 @@ static public class ProviderTableMeta implements BaseColumns { public static final String CAPABILITIES_SHARING_API_ENABLED = "sharing_api_enabled"; public static final String CAPABILITIES_SHARING_PUBLIC_ENABLED = "sharing_public_enabled"; public static final String CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED = "sharing_public_password_enforced"; + public static final String CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD = "sharing_public_ask_for_password"; public static final String CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED = "sharing_public_expire_date_enabled"; public static final String CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS = diff --git a/src/main/java/com/owncloud/android/providers/FileContentProvider.java b/src/main/java/com/owncloud/android/providers/FileContentProvider.java index 86ae7efaa40d..5b76158b2b82 100644 --- a/src/main/java/com/owncloud/android/providers/FileContentProvider.java +++ b/src/main/java/com/owncloud/android/providers/FileContentProvider.java @@ -770,7 +770,8 @@ private void createCapabilitiesTable(SQLiteDatabase db) { + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + TEXT + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + INTEGER + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + INTEGER - + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + " TEXT );"); + + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + TEXT + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD + " INTEGER );"); } private void createUploadsTable(SQLiteDatabase db) { @@ -1946,6 +1947,25 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (!upgraded) { Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion)); } + + if (oldVersion < 47 && newVersion >= 47) { + Log_OC.i(SQL, "Entering in the #47 add askForPassword to capability table"); + db.beginTransaction(); + try { + db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME + + ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD + + " INTEGER "); + + upgraded = true; + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + + if (!upgraded) { + Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion)); + } } @Override diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 53ce4114389b..fd37af8be408 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -2016,10 +2016,13 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope // Was tried without password, but not sure that it's optional. // Try with password before giving up; see also ShareFileFragment#OnShareViaLinkListener - if (fileDetailFragment != null - && fileDetailFragment.isAdded()) { // only if added to the view hierarchy!! + if (fileDetailFragment != null && fileDetailFragment.isAdded()) { // only if added to the view hierarchy - fileDetailFragment.getFileDetailSharingFragment().requestPasswordForShareViaLink(true); + fileDetailFragment + .getFileDetailSharingFragment() + .requestPasswordForShareViaLink(true, + getCapabilities().getFilesSharingPublicAskForPassword() + .isTrue()); } } else { diff --git a/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java b/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java index ee8f04b41fb5..bc9460e88180 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java @@ -355,10 +355,11 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope // Try with password before giving up; see also ShareFileFragment#OnShareViaLinkListener ShareFileFragment shareFileFragment = getShareFileFragment(); - if (shareFileFragment != null - && shareFileFragment.isAdded()) { // only if added to the view hierarchy!! + if (shareFileFragment != null && shareFileFragment.isAdded()) { // only if added to the view hierarchy!! - shareFileFragment.requestPasswordForShareViaLink(true); + boolean askForPassword = getCapabilities().getFilesSharingPublicAskForPassword().isTrue(); + + shareFileFragment.requestPasswordForShareViaLink(true, askForPassword); } } else { diff --git a/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java b/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java index d7b7c99bc607..8836f5bee021 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java @@ -18,6 +18,7 @@ import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.adapter.SendButtonAdapter; @@ -26,6 +27,8 @@ import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.ThemeUtils; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.List; @@ -60,6 +63,7 @@ public class SendShareDialog extends BottomSheetDialogFragment { private static final String KEY_OCFILE = "KEY_OCFILE"; private static final String KEY_SHARING_PUBLIC_PASSWORD_ENFORCED = "KEY_SHARING_PUBLIC_PASSWORD_ENFORCED"; + private static final String KEY_SHARING_PUBLIC_ASK_FOR_PASSWORD = "KEY_SHARING_PUBLIC_ASK_FOR_PASSWORD"; private static final String KEY_HIDE_NCSHARING_OPTIONS = "KEY_HIDE_NCSHARING_OPTIONS"; private static final String TAG = SendShareDialog.class.getSimpleName(); public static final String PACKAGE_NAME = "PACKAGE_NAME"; @@ -69,16 +73,20 @@ public class SendShareDialog extends BottomSheetDialogFragment { private OCFile file; private boolean hideNcSharingOptions; private boolean sharingPublicPasswordEnforced; + private boolean sharingPublicAskForPassword; private FileOperationsHelper fileOperationsHelper; - public static SendShareDialog newInstance(OCFile file, boolean hideNcSharingOptions, boolean sharingPublicPasswordEnforced) { + public static SendShareDialog newInstance(OCFile file, boolean hideNcSharingOptions, OCCapability capability) { SendShareDialog dialogFragment = new SendShareDialog(); Bundle args = new Bundle(); args.putParcelable(KEY_OCFILE, file); args.putBoolean(KEY_HIDE_NCSHARING_OPTIONS, hideNcSharingOptions); - args.putBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, sharingPublicPasswordEnforced); + args.putBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, + capability.getFilesSharingPublicPasswordEnforced().isTrue()); + args.putBoolean(KEY_SHARING_PUBLIC_ASK_FOR_PASSWORD, + capability.getFilesSharingPublicAskForPassword().isTrue()); dialogFragment.setArguments(args); return dialogFragment; @@ -93,11 +101,14 @@ public void onCreate(@Nullable Bundle savedInstanceState) { file = getArguments().getParcelable(KEY_OCFILE); hideNcSharingOptions = getArguments().getBoolean(KEY_HIDE_NCSHARING_OPTIONS, false); sharingPublicPasswordEnforced = getArguments().getBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, false); + sharingPublicAskForPassword = getArguments().getBoolean(KEY_SHARING_PUBLIC_ASK_FOR_PASSWORD); } @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NotNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.send_share_fragment, container, false); @@ -178,7 +189,9 @@ private void shareByLink() { } private void requestPasswordForShareViaLink() { - SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(file, true); + SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(file, + true, + sharingPublicAskForPassword); dialog.show(getFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); } diff --git a/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java index cb8b76e174e7..aa02cf940cb5 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java @@ -55,11 +55,13 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo private static final String ARG_FILE = "FILE"; private static final String ARG_SHARE = "SHARE"; private static final String ARG_CREATE_SHARE = "CREATE_SHARE"; + private static final String ARG_ASK_FOR_PASSWORD = "ASK_FOR_PASSWORD"; public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT"; private OCFile file; private OCShare share; private boolean createShare; + private boolean askForPassword; @Override public void onStart() { @@ -81,11 +83,12 @@ public void onStart() { * is bound to it. * @return Dialog ready to show. */ - public static SharePasswordDialogFragment newInstance(OCFile file, boolean createShare) { + public static SharePasswordDialogFragment newInstance(OCFile file, boolean createShare, boolean askForPassword) { SharePasswordDialogFragment frag = new SharePasswordDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_FILE, file); args.putBoolean(ARG_CREATE_SHARE, createShare); + args.putBoolean(ARG_ASK_FOR_PASSWORD, askForPassword); frag.setArguments(args); return frag; } @@ -116,6 +119,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { file = getArguments().getParcelable(ARG_FILE); share = getArguments().getParcelable(ARG_SHARE); createShare = getArguments().getBoolean(ARG_CREATE_SHARE, false); + askForPassword = getArguments().getBoolean(ARG_ASK_FOR_PASSWORD, false); // Inflate the layout for the dialog LayoutInflater inflater = getActivity().getLayoutInflater(); @@ -130,6 +134,13 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { inputText.setText(""); inputText.requestFocus(); + int title; + if (askForPassword) { + title = R.string.share_link_optional_password_title; + } else { + title = R.string.share_link_password_title; + } + // Build the dialog AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Theme_ownCloud_Dialog_NoButtonBarStyle); @@ -137,7 +148,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { .setPositiveButton(R.string.common_ok, this) .setNegativeButton(R.string.common_cancel, this) .setNeutralButton(R.string.common_delete, this) - .setTitle(R.string.share_link_password_title); + .setTitle(title); Dialog d = builder.create(); Window window = d.getWindow(); @@ -153,11 +164,9 @@ public void onClick(DialogInterface dialog, int which) { if (which == AlertDialog.BUTTON_POSITIVE) { String password = ((TextView) (getDialog().findViewById(R.id.share_password))).getText().toString(); - if (TextUtils.isEmpty(password)) { - DisplayUtils.showSnackMessage( - getActivity().findViewById(android.R.id.content), - R.string.share_link_empty_password - ); + if (!askForPassword && TextUtils.isEmpty(password)) { + DisplayUtils.showSnackMessage(getActivity().findViewById(android.R.id.content), + R.string.share_link_empty_password); return; } @@ -172,6 +181,14 @@ public void onClick(DialogInterface dialog, int which) { } else { setPassword(share, null); } + } else if (which == AlertDialog.BUTTON_NEGATIVE) { + if (askForPassword) { + if (share == null) { + setPassword(createShare, file, null); + } else { + setPassword(share, null); + } + } } } diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index e5e25fe30cb4..26c58997d83c 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -320,10 +320,10 @@ public void toggleShareByLink() { } private void createShareLink() { - if (capabilities != null && - capabilities.getFilesSharingPublicPasswordEnforced().isTrue()) { + if (capabilities != null && (capabilities.getFilesSharingPublicPasswordEnforced().isTrue() || + capabilities.getFilesSharingPublicAskForPassword().isTrue())) { // password enforced by server, request to the user before trying to create - requestPasswordForShareViaLink(true); + requestPasswordForShareViaLink(true, capabilities.getFilesSharingPublicAskForPassword().isTrue()); } else { // create without password if not enforced by server or we don't know if enforced; @@ -417,7 +417,7 @@ private boolean optionsItemSelected(MenuItem item) { return true; case R.id.action_password: { - requestPasswordForShareViaLink(false); + requestPasswordForShareViaLink(false, capabilities.getFilesSharingPublicAskForPassword().isTrue()); return true; } case R.id.action_share_expiration_date: { @@ -527,12 +527,14 @@ public void updateNoteToShare(OCShare share, String note) { /** * Starts a dialog that requests a password to the user to protect a share link. * - * @param createShare When 'true', the request for password will be followed by the creation of a new - * public link; when 'false', a public share is assumed to exist, and the password - * is bound to it. + * @param createShare When 'true', the request for password will be followed by the creation of a new public + * link; when 'false', a public share is assumed to exist, and the password is bound to it. + * @param askForPassword if true, password is optional */ - public void requestPasswordForShareViaLink(boolean createShare) { - SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(file, createShare); + public void requestPasswordForShareViaLink(boolean createShare, boolean askForPassword) { + SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(file, + createShare, + askForPassword); dialog.show(getChildFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); } diff --git a/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java index 9ff6c2867f3c..b197957d0047 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -285,15 +285,13 @@ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { return; } if (isChecked) { - if (mCapabilities != null && - mCapabilities.getFilesSharingPublicPasswordEnforced().isTrue()) { + if (mCapabilities != null && (mCapabilities.getFilesSharingPublicPasswordEnforced().isTrue() || + mCapabilities.getFilesSharingPublicAskForPassword().isTrue())) { // password enforced by server, request to the user before trying to create - requestPasswordForShareViaLink(true); - + requestPasswordForShareViaLink(true, mCapabilities.getFilesSharingPublicAskForPassword().isTrue()); } else { // create without password if not enforced by server or we don't know if enforced; - ((FileActivity) getActivity()).getFileOperationsHelper(). - shareFileViaLink(mFile, null); + ((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(mFile, null); // ShareActivity#onCreateShareViaLinkOperationFinish will take care if password // is enforced by the server but app doesn't know, or if server version is @@ -301,8 +299,7 @@ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { } } else { - ((FileActivity) getActivity()).getFileOperationsHelper(). - unshareFileViaLink(mFile); + ((FileActivity) getActivity()).getFileOperationsHelper().unshareFileViaLink(mFile); } // undo the toggle to grant the view will be correct if any intermediate dialog is cancelled or @@ -429,10 +426,9 @@ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { return; } if (isChecked) { - requestPasswordForShareViaLink(false); + requestPasswordForShareViaLink(false, mCapabilities.getFilesSharingPublicAskForPassword().isTrue()); } else { - ((FileActivity) getActivity()).getFileOperationsHelper(). - setPasswordToShareViaLink(mFile, ""); // "" clears + ((FileActivity) getActivity()).getFileOperationsHelper().setPasswordToShareViaLink(mFile, ""); // clears } // undo the toggle to grant the view will be correct if the dialog is cancelled @@ -450,7 +446,7 @@ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { @Override public void onClick(View passwordView) { if (mPublicShare != null && mPublicShare.isPasswordProtected()) { - requestPasswordForShareViaLink(false); + requestPasswordForShareViaLink(false, mCapabilities.getFilesSharingPublicAskForPassword().isTrue()); } } } @@ -890,12 +886,14 @@ private void hidePublicShare() { /** * Starts a dialog that requests a password to the user to protect a share link. * - * @param createShare When 'true', the request for password will be followed by the creation of a new - * public link; when 'false', a public share is assumed to exist, and the password - * is bound to it. + * @param createShare When 'true', the request for password will be followed by the creation of a new public + * link; when 'false', a public share is assumed to exist, and the password is bound to it. + * @param askForPassword if true, password is optional */ - public void requestPasswordForShareViaLink(boolean createShare) { - SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(mFile, createShare); + public void requestPasswordForShareViaLink(boolean createShare, boolean askForPassword) { + SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(mFile, + createShare, + askForPassword); dialog.show(getFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); } diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 38b0a7810920..c5e9eb3db6c8 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -717,10 +717,7 @@ public void sendShareFile(OCFile file, boolean hideNcSharingOptions) { ft.addToBackStack(null); OCCapability capability = mFileActivity.getStorageManager().getCapability(mFileActivity.getAccount().name); - SendShareDialog mSendShareDialog; - - mSendShareDialog = SendShareDialog.newInstance(file, hideNcSharingOptions, - capability.getFilesSharingPublicPasswordEnforced().isTrue()); + SendShareDialog mSendShareDialog = SendShareDialog.newInstance(file, hideNcSharingOptions, capability); mSendShareDialog.setFileOperationsHelper(this); mSendShareDialog.show(ft, "TAG_SEND_SHARE_DIALOG"); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 45a350a5e21a..45859a5c5df3 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -350,6 +350,7 @@ Unable to update. Please check whether the file exists An error occurred while trying to update the share Enter a password + Enter an optional password You must enter a password Send From 788cea14b847d46972251e3ca1c4b29bf8e9f589 Mon Sep 17 00:00:00 2001 From: nextcloud-android-bot Date: Thu, 9 May 2019 11:07:22 +0000 Subject: [PATCH 2/6] Drone: update FindBugs results to reflect reduced error/warning count [skip ci] Signed-off-by: nextcloud-android-bot --- scripts/analysis/findbugs-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index 9ec873d37d50..c8eb5888ce88 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -438 \ No newline at end of file +438 From 9650a14e572edd52ea7791220fc9277c9a999bd0 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 10 May 2019 08:46:06 +0200 Subject: [PATCH 3/6] change capability name Signed-off-by: tobiasKaminsky --- .../android/datamodel/FileDataStorageManager.java | 9 +++++---- .../java/com/owncloud/android/db/ProviderMeta.java | 3 ++- .../android/providers/FileContentProvider.java | 3 ++- .../android/ui/activity/FileDisplayActivity.java | 2 +- .../owncloud/android/ui/activity/ShareActivity.java | 2 +- .../owncloud/android/ui/dialog/SendShareDialog.java | 2 +- .../ui/fragment/FileDetailSharingFragment.java | 8 +++++--- .../android/ui/fragment/ShareFileFragment.java | 11 +++++++---- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index e5150e2db12a..0fb9b3f8d5a4 100644 --- a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1924,8 +1924,8 @@ public OCCapability saveCapabilities(OCCapability capability) { capability.getFilesSharingPublicEnabled().getValue()); cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED, capability.getFilesSharingPublicPasswordEnforced().getValue()); - cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD, - capability.getFilesSharingPublicAskForPassword().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD, + capability.getFilesSharingPublicAskForOptionalPassword().getValue()); cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED, capability.getFilesSharingPublicExpireDateEnabled().getValue()); cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS, @@ -2080,8 +2080,9 @@ private OCCapability createCapabilityInstance(Cursor c) { .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED)))); capability.setFilesSharingPublicPasswordEnforced(CapabilityBooleanType.fromValue(c.getInt(c .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED)))); - capability.setFilesSharingPublicAskForPassword(CapabilityBooleanType.fromValue(c.getInt(c - .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD)))); + capability.setFilesSharingPublicAskForOptionalPassword( + CapabilityBooleanType.fromValue( + c.getInt(c.getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD)))); capability.setFilesSharingPublicExpireDateEnabled(CapabilityBooleanType.fromValue(c.getInt(c .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED)))); capability.setFilesSharingPublicExpireDateDays(c.getInt(c diff --git a/src/main/java/com/owncloud/android/db/ProviderMeta.java b/src/main/java/com/owncloud/android/db/ProviderMeta.java index 4848c32e2591..bd212e5c4041 100644 --- a/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -155,7 +155,8 @@ static public class ProviderTableMeta implements BaseColumns { public static final String CAPABILITIES_SHARING_API_ENABLED = "sharing_api_enabled"; public static final String CAPABILITIES_SHARING_PUBLIC_ENABLED = "sharing_public_enabled"; public static final String CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED = "sharing_public_password_enforced"; - public static final String CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD = "sharing_public_ask_for_password"; + public static final String CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD = + "sharing_public_ask_for_optional_password"; public static final String CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED = "sharing_public_expire_date_enabled"; public static final String CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS = diff --git a/src/main/java/com/owncloud/android/providers/FileContentProvider.java b/src/main/java/com/owncloud/android/providers/FileContentProvider.java index 5b76158b2b82..f16ab4b29e8a 100644 --- a/src/main/java/com/owncloud/android/providers/FileContentProvider.java +++ b/src/main/java/com/owncloud/android/providers/FileContentProvider.java @@ -771,7 +771,8 @@ private void createCapabilitiesTable(SQLiteDatabase db) { + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + INTEGER + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + INTEGER + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + TEXT - + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD + " INTEGER );"); + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD + INTEGER + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD + " INTEGER );"); } private void createUploadsTable(SQLiteDatabase db) { diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index fd37af8be408..2e0df3ffe7e7 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -2021,7 +2021,7 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope fileDetailFragment .getFileDetailSharingFragment() .requestPasswordForShareViaLink(true, - getCapabilities().getFilesSharingPublicAskForPassword() + getCapabilities().getFilesSharingPublicAskForOptionalPassword() .isTrue()); } diff --git a/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java b/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java index bc9460e88180..8c651db2e93f 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java @@ -357,7 +357,7 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope ShareFileFragment shareFileFragment = getShareFileFragment(); if (shareFileFragment != null && shareFileFragment.isAdded()) { // only if added to the view hierarchy!! - boolean askForPassword = getCapabilities().getFilesSharingPublicAskForPassword().isTrue(); + boolean askForPassword = getCapabilities().getFilesSharingPublicAskForOptionalPassword().isTrue(); shareFileFragment.requestPasswordForShareViaLink(true, askForPassword); } diff --git a/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java b/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java index 8836f5bee021..a27d4e9b1143 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java @@ -86,7 +86,7 @@ public static SendShareDialog newInstance(OCFile file, boolean hideNcSharingOpti args.putBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, capability.getFilesSharingPublicPasswordEnforced().isTrue()); args.putBoolean(KEY_SHARING_PUBLIC_ASK_FOR_PASSWORD, - capability.getFilesSharingPublicAskForPassword().isTrue()); + capability.getFilesSharingPublicAskForOptionalPassword().isTrue()); dialogFragment.setArguments(args); return dialogFragment; diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 26c58997d83c..6b136b8a3727 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -321,9 +321,10 @@ public void toggleShareByLink() { private void createShareLink() { if (capabilities != null && (capabilities.getFilesSharingPublicPasswordEnforced().isTrue() || - capabilities.getFilesSharingPublicAskForPassword().isTrue())) { + capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue())) { // password enforced by server, request to the user before trying to create - requestPasswordForShareViaLink(true, capabilities.getFilesSharingPublicAskForPassword().isTrue()); + requestPasswordForShareViaLink(true, + capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue()); } else { // create without password if not enforced by server or we don't know if enforced; @@ -417,7 +418,8 @@ private boolean optionsItemSelected(MenuItem item) { return true; case R.id.action_password: { - requestPasswordForShareViaLink(false, capabilities.getFilesSharingPublicAskForPassword().isTrue()); + requestPasswordForShareViaLink(false, + capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue()); return true; } case R.id.action_share_expiration_date: { diff --git a/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java index b197957d0047..860ab879f356 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -286,9 +286,10 @@ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { } if (isChecked) { if (mCapabilities != null && (mCapabilities.getFilesSharingPublicPasswordEnforced().isTrue() || - mCapabilities.getFilesSharingPublicAskForPassword().isTrue())) { + mCapabilities.getFilesSharingPublicAskForOptionalPassword().isTrue())) { // password enforced by server, request to the user before trying to create - requestPasswordForShareViaLink(true, mCapabilities.getFilesSharingPublicAskForPassword().isTrue()); + requestPasswordForShareViaLink(true, + mCapabilities.getFilesSharingPublicAskForOptionalPassword().isTrue()); } else { // create without password if not enforced by server or we don't know if enforced; ((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(mFile, null); @@ -426,7 +427,8 @@ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { return; } if (isChecked) { - requestPasswordForShareViaLink(false, mCapabilities.getFilesSharingPublicAskForPassword().isTrue()); + requestPasswordForShareViaLink(false, + mCapabilities.getFilesSharingPublicAskForOptionalPassword().isTrue()); } else { ((FileActivity) getActivity()).getFileOperationsHelper().setPasswordToShareViaLink(mFile, ""); // clears } @@ -446,7 +448,8 @@ public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { @Override public void onClick(View passwordView) { if (mPublicShare != null && mPublicShare.isPasswordProtected()) { - requestPasswordForShareViaLink(false, mCapabilities.getFilesSharingPublicAskForPassword().isTrue()); + requestPasswordForShareViaLink(false, + mCapabilities.getFilesSharingPublicAskForOptionalPassword().isTrue()); } } } From d372a21bd4d0c5a8aa89e836d4d65f26383a5e29 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 10 May 2019 09:52:37 +0200 Subject: [PATCH 4/6] combine if statement Signed-off-by: tobiasKaminsky --- .../ui/dialog/SharePasswordDialogFragment.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java index aa02cf940cb5..389fac994b55 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java @@ -181,13 +181,11 @@ public void onClick(DialogInterface dialog, int which) { } else { setPassword(share, null); } - } else if (which == AlertDialog.BUTTON_NEGATIVE) { - if (askForPassword) { - if (share == null) { - setPassword(createShare, file, null); - } else { - setPassword(share, null); - } + } else if (which == AlertDialog.BUTTON_NEGATIVE && askForPassword) { + if (share == null) { + setPassword(createShare, file, null); + } else { + setPassword(share, null); } } } From a0a841f7dd6e7f1b94d10044b52a5e5577880cbe Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 13 May 2019 08:51:52 +0200 Subject: [PATCH 5/6] revert to master branch Signed-off-by: tobiasKaminsky --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index b716709c87b0..62145ed5d615 100644 --- a/build.gradle +++ b/build.gradle @@ -251,9 +251,9 @@ dependencies { // dependencies for app building implementation 'androidx.multidex:multidex:2.0.1' // implementation project('nextcloud-android-library') - genericImplementation 'com.github.nextcloud:android-library:askForPassword-SNAPSHOT' - gplayImplementation 'com.github.nextcloud:android-library:askForPassword-SNAPSHOT' - versionDevImplementation 'com.github.nextcloud:android-library:askForPassword-SNAPSHOT' + genericImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' + gplayImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' + versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.google.android.material:material:1.0.0' From 1edf2cd82c47c124e93302fa96473f9d98d4d81c Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 14 May 2019 13:28:10 +0200 Subject: [PATCH 6/6] changes due to rebase Signed-off-by: tobiasKaminsky --- src/main/java/com/owncloud/android/db/ProviderMeta.java | 2 +- .../com/owncloud/android/providers/FileContentProvider.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/db/ProviderMeta.java b/src/main/java/com/owncloud/android/db/ProviderMeta.java index bd212e5c4041..b291a1c3f4b3 100644 --- a/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -31,7 +31,7 @@ */ public class ProviderMeta { public static final String DB_NAME = "filelist"; - public static final int DB_VERSION = 46; + public static final int DB_VERSION = 47; private ProviderMeta() { // No instance diff --git a/src/main/java/com/owncloud/android/providers/FileContentProvider.java b/src/main/java/com/owncloud/android/providers/FileContentProvider.java index f16ab4b29e8a..008b0437290b 100644 --- a/src/main/java/com/owncloud/android/providers/FileContentProvider.java +++ b/src/main/java/com/owncloud/android/providers/FileContentProvider.java @@ -771,7 +771,6 @@ private void createCapabilitiesTable(SQLiteDatabase db) { + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + INTEGER + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + INTEGER + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + TEXT - + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD + INTEGER + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD + " INTEGER );"); } @@ -1954,7 +1953,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.beginTransaction(); try { db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME + - ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_PASSWORD + + ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD + " INTEGER "); upgraded = true;