diff --git a/drawable_resources/ic_content-copy.svg b/drawable_resources/ic_content-copy.svg new file mode 100644 index 000000000000..bce7028fc2f6 --- /dev/null +++ b/drawable_resources/ic_content-copy.svg @@ -0,0 +1 @@ + diff --git a/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.java b/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.java index a04d9413a592..16bdab55a069 100644 --- a/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.java @@ -1,8 +1,10 @@ -/** +/* * ownCloud Android client application * * @author David A. Velasco + * @author Andy Scherzinger * Copyright (C) 2015 ownCloud Inc. + * Copyright (C) 2018 Andy Scherzinger * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -15,65 +17,27 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * */ package com.owncloud.android.ui.activity; import android.app.Activity; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.Intent; import android.os.Bundle; -import android.widget.Toast; -import com.owncloud.android.R; -import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.utils.ClipboardUtil; /** - * Activity copying the text of the received Intent into the system clibpoard. + * Activity copying the text of the received Intent into the system clipboard. */ -@SuppressWarnings("deprecation") public class CopyToClipboardActivity extends Activity { - private static final String TAG = CopyToClipboardActivity.class.getName(); - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - try { - - // get the clipboard system service - ClipboardManager clipboardManager = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE); - - // get the text to copy into the clipboard - Intent intent = getIntent(); - CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); - - if (text != null && text.length() > 0) { - // minimum API level >= 11 -> only modern Clipboard - ClipData clip = ClipData.newPlainText( - getString(R.string.clipboard_label, getString(R.string.app_name)), - text - ); - clipboardManager.setPrimaryClip(clip); - - // API level < 11 -> legacy Clipboard - NOT SUPPORTED ANYMORE - // clipboardManager.setText(text); - - // alert the user that the text is in the clipboard and we're done - Toast.makeText(this, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(this, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show(); - } - - } catch (Exception e) { - Toast.makeText(this, R.string.clipboard_uxexpected_error, Toast.LENGTH_SHORT).show(); - Log_OC.e(TAG, "Exception caught while copying to clipboard", e); - } + ClipboardUtil.copyToClipboard(this, getIntent().getCharSequenceExtra(Intent.EXTRA_TEXT).toString()); finish(); } - } 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 1bd19493965e..4b5e02881f1c 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1878,6 +1878,7 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB(); + fileDetailFragment.getFileDetailSharingFragment().onUpdateShareInformation(result, getFile()); refreshListOfFilesFragment(false); } else { // Detect Failure (403) --> maybe needs password 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 e3426ce22798..a94157452279 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -34,6 +34,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SearchView; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -59,6 +60,7 @@ import com.owncloud.android.ui.dialog.SharePasswordDialogFragment; import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper; import com.owncloud.android.ui.fragment.util.SharingMenuHelper; +import com.owncloud.android.utils.ClipboardUtil; import com.owncloud.android.utils.ThemeUtils; import java.util.ArrayList; @@ -95,6 +97,9 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt @BindView(R.id.share_by_link) AppCompatCheckBox shareByLink; + @BindView(R.id.share_link_copy_icon) + ImageView shareLinkCopyIcon; + @BindView(R.id.overflow_menu_share_link) ImageView overflowMenuShareLink; @@ -171,6 +176,11 @@ private void setupView() { */ public void setShareByLinkInfo(boolean isShareByLink) { shareByLink.setChecked(isShareByLink); + if (isShareByLink) { + shareLinkCopyIcon.setVisibility(View.VISIBLE); + } else { + shareLinkCopyIcon.setVisibility(View.INVISIBLE); + } int accentColor = ThemeUtils.primaryAccentColor(getContext()); ThemeUtils.tintCheckbox(shareByLink, accentColor); ThemeUtils.tintCheckbox(shareByLinkAllowEditing, accentColor); @@ -240,13 +250,23 @@ public void toggleShareByLink() { } } - @OnClick(R.id.share_link_label) - public void showSendLinkTo() { + private void showSendLinkTo() { if (file.isSharedViaLink()) { ((FileActivity) getActivity()).getFileOperationsHelper().getFileWithLink(file); } } + @OnClick({R.id.share_link_copy_icon}) + public void copyLinkToClipboard() { + if (file.isSharedViaLink()) { + if (TextUtils.isEmpty(file.getPublicLink())) { + showSendLinkTo(); + } else { + ClipboardUtil.copyToClipboard(getActivity(), file.getPublicLink()); + } + } + } + @OnClick(R.id.share_by_link_allow_editing) public void toggleShareLinkAllowEditing() { if (file.isSharedViaLink()) { @@ -315,6 +335,10 @@ private boolean optionsItemSelected(MenuItem item) { ); return true; } + case R.id.action_share_send_link: { + showSendLinkTo(); + return true; + } default: return super.onOptionsItemSelected(item); } diff --git a/src/main/java/com/owncloud/android/utils/ClipboardUtil.java b/src/main/java/com/owncloud/android/utils/ClipboardUtil.java new file mode 100644 index 000000000000..632aea487d98 --- /dev/null +++ b/src/main/java/com/owncloud/android/utils/ClipboardUtil.java @@ -0,0 +1,60 @@ +/* + * Nextcloud Android client application + * + * @author Andy Scherzinger + * Copyright (C) 2018 Andy Scherzinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see . + */ + +package com.owncloud.android.utils; + +import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.widget.Toast; + +import com.owncloud.android.R; +import com.owncloud.android.lib.common.utils.Log_OC; + +/** + * Helper implementation to copy a string into the system clipboard. + */ +public class ClipboardUtil { + private static final String TAG = ClipboardUtil.class.getName(); + + private ClipboardUtil() { + } + + public static void copyToClipboard(Activity activity, String text) { + if (text != null && text.length() > 0) { + try { + ClipData clip = ClipData.newPlainText( + activity.getString( + R.string.clipboard_label, activity.getString(R.string.app_name)), + text + ); + ((ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip); + + Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + Toast.makeText(activity, R.string.clipboard_unexpected_error, Toast.LENGTH_SHORT).show(); + Log_OC.e(TAG, "Exception caught while copying to clipboard", e); + } + } else { + Toast.makeText(activity, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/src/main/res/drawable/ic_content_copy.xml b/src/main/res/drawable/ic_content_copy.xml new file mode 100644 index 000000000000..0c0f622bc4c1 --- /dev/null +++ b/src/main/res/drawable/ic_content_copy.xml @@ -0,0 +1,23 @@ + + + + diff --git a/src/main/res/layout/file_details_sharing_fragment.xml b/src/main/res/layout/file_details_sharing_fragment.xml index 031e8cb6d498..a6cb54643376 100644 --- a/src/main/res/layout/file_details_sharing_fragment.xml +++ b/src/main/res/layout/file_details_sharing_fragment.xml @@ -54,19 +54,24 @@ android:id="@+id/share_by_link" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="center_vertical"/> + android:layout_gravity="center_vertical" + android:text="@string/share_via_link_section_title"/> - + android:contentDescription="@string/copy_link" + android:paddingBottom="@dimen/standard_quarter_margin" + android:scaleType="fitStart" + android:src="@drawable/ic_content_copy" + android:layout_gravity="start|center"/> + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 80e67ae35049..e05758cadd3a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -365,7 +365,7 @@ Copy link Copied to clipboard Received no text to copy to clipboard - Unexpected error while copying to clipboard + Unexpected error while copying to clipboard Text copied from %1$s Critical error: Unable to perform operations @@ -486,6 +486,7 @@ Expires %1$s Set expiration date Share link + Send link Password-protected Set password edit