Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drawable_resources/ic_content-copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/owncloud/android/utils/ClipboardUtil.java
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions src/main/res/drawable/ic_content_copy.xml
Original file line number Diff line number Diff line change
@@ -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>
25 changes: 15 additions & 10 deletions src/main/res/layout/file_details_sharing_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/menu/file_detail_sharing_link_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
3 changes: 2 additions & 1 deletion src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,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>
Expand Down Expand Up @@ -486,6 +486,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>
Expand Down