Bladeren bron

Merge pull request #2730 from nextcloud/shareLinkHandling

Display copy icon and adding send action to the link menu
Tobias Kaminsky 6 jaren geleden
bovenliggende
commit
db0b0cbf75

+ 1 - 0
drawable_resources/ic_content-copy.svg

@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" /></svg>

+ 6 - 42
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 <http://www.gnu.org/licenses/>.
- *
  */
 
 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 com.owncloud.android.R;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.utils.DisplayUtils;
+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
-                DisplayUtils.showSnackMessage(this, R.string.clipboard_text_copied);
-            } else {
-                DisplayUtils.showSnackMessage(this, R.string.clipboard_no_text_to_copy);
-            }
-
-        } catch (Exception e) {
-            DisplayUtils.showSnackMessage(this, R.string.clipboard_uxexpected_error);
-            Log_OC.e(TAG, "Exception caught while copying to clipboard", e);
-        }
+        ClipboardUtil.copyToClipboard(this, getIntent().getCharSequenceExtra(Intent.EXTRA_TEXT).toString());
 
         finish();
     }
-
 }

+ 1 - 0
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1937,6 +1937,7 @@ public class FileDisplayActivity extends HookActivity
             chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
 
             fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();
+            fileDetailFragment.getFileDetailSharingFragment().onUpdateShareInformation(result, getFile());
             refreshListOfFilesFragment(false);
         } else {
             // Detect Failure (403) --> maybe needs password

+ 27 - 3
src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java

@@ -34,6 +34,7 @@ import android.support.v7.widget.AppCompatCheckBox;
 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.ExpirationDatePickerDialogFragment;
 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 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
      */
     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 class FileDetailSharingFragment extends Fragment implements UserListAdapt
         }
     }
 
-    @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()) {
@@ -307,7 +327,7 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
                 requestPasswordForShareViaLink(false);
                 return true;
             }
-            case R.id.action_expiration_date: {
+            case R.id.action_share_expiration_date: {
                 ExpirationDatePickerDialogFragment dialog = ExpirationDatePickerDialogFragment.newInstance(file, -1);
                 dialog.show(
                         getActivity().getSupportFragmentManager(),
@@ -315,6 +335,10 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
                 );
                 return true;
             }
+            case R.id.action_share_send_link: {
+                showSendLinkTo();
+                return true;
+            }
             default:
                 return super.onOptionsItemSelected(item);
         }

+ 60 - 0
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 <http://www.gnu.org/licenses/>.
+ */
+
+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();
+        }
+    }
+}

+ 23 - 0
src/main/res/drawable/ic_content_copy.xml

@@ -0,0 +1,23 @@
+<!--
+    @author Google LLC
+    Copyright (C) 2018 Google LLC
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
+</vector>

+ 15 - 10
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"/>
 
-            <TextView
-                android:id="@+id/share_link_label"
+            <ImageView
+                android:id="@+id/share_link_copy_icon"
                 android:layout_width="0dp"
-                android:layout_height="wrap_content"
-                android:layout_gravity="start|center"
-                android:textColor="@color/black"
+                android:layout_height="32dp"
+                android:paddingEnd="@dimen/standard_eighth_margin"
+                android:paddingLeft="@dimen/standard_half_margin"
+                android:paddingRight="@dimen/standard_eighth_margin"
+                android:paddingStart="@dimen/standard_half_margin"
+                android:paddingTop="@dimen/standard_quarter_margin"
                 android:layout_weight="1"
-                android:textSize="16sp"
-                android:paddingTop="@dimen/standard_half_padding"
-                android:paddingBottom="@dimen/standard_half_padding"
-                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"/>
 
             <android.support.v7.widget.AppCompatCheckBox
                 android:id="@+id/share_by_link_allow_editing"

+ 5 - 0
src/main/res/menu/file_detail_sharing_link_menu.xml

@@ -38,5 +38,10 @@
         android:showAsAction="never"
         android:title="@string/share_expiration_date_label"
         app:showAsAction="never" />
+    <item
+        android:id="@+id/action_share_send_link"
+        android:showAsAction="never"
+        android:title="@string/share_via_link_send_link_label"
+        app:showAsAction="never" />
 
 </menu>

+ 2 - 1
src/main/res/values/strings.xml

@@ -372,7 +372,7 @@
     <string name="copy_link">Copy link</string>
     <string name="clipboard_text_copied">Copied to clipboard</string>
     <string name="clipboard_no_text_to_copy">Received no text to copy to clipboard</string>
-    <string name="clipboard_uxexpected_error">Unexpected error while copying to clipboard</string>
+    <string name="clipboard_unexpected_error">Unexpected error while copying to clipboard</string>
     <string name="clipboard_label">Text copied from %1$s</string>
 
     <string name="error_cant_bind_to_operations_service">Critical error: Unable to perform operations</string>
@@ -493,6 +493,7 @@
     <string name="share_expiration_date_label">Expires %1$s</string>
     <string name="share_no_expiration_date_label">Set expiration date</string>
     <string name="share_via_link_section_title">Share link</string>
+    <string name="share_via_link_send_link_label">Send link</string>
     <string name="share_password_title">Password-protected</string>
     <string name="share_no_password_title">Set password</string>
     <string name="edit_permission_label">edit</string>