mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-24 05:46:14 +03:00
Fix #841 "Link" functionality in text menu causes error
This commit is contained in:
parent
85021909f3
commit
81f71ca574
2 changed files with 27 additions and 11 deletions
|
@ -3,6 +3,7 @@ package it.niedermann.owncloud.notes.util;
|
|||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -11,7 +12,6 @@ import androidx.annotation.Nullable;
|
|||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
|
||||
|
@ -44,15 +44,30 @@ public class ClipboardUtil {
|
|||
}
|
||||
|
||||
public static String getClipboardURLorNull(Context context) {
|
||||
String clipboardURL = null;
|
||||
ClipData clipboardData = Objects.requireNonNull(((ClipboardManager) Objects.requireNonNull(context.getSystemService(CLIPBOARD_SERVICE))).getPrimaryClip());
|
||||
if (clipboardData.getItemCount() > 0) {
|
||||
try {
|
||||
clipboardURL = new URL(clipboardData.getItemAt(0).getText().toString()).toString();
|
||||
} catch (MalformedURLException e) {
|
||||
Log.d(TAG, "Clipboard does not contain a valid URL: " + clipboardData.getItemAt(0).getText().toString());
|
||||
}
|
||||
final ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
|
||||
if (clipboardManager == null) {
|
||||
return null;
|
||||
}
|
||||
return clipboardURL;
|
||||
final ClipData clipboardData = clipboardManager.getPrimaryClip();
|
||||
if (clipboardData == null) {
|
||||
return null;
|
||||
}
|
||||
if (clipboardData.getItemCount() < 1) {
|
||||
return null;
|
||||
}
|
||||
final ClipData.Item clipItem = clipboardData.getItemAt(0);
|
||||
if (clipItem == null) {
|
||||
return null;
|
||||
}
|
||||
CharSequence clipText = clipItem.getText();
|
||||
if (TextUtils.isEmpty(clipText)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new URL(clipText.toString()).toString();
|
||||
} catch (MalformedURLException e) {
|
||||
Log.d(TAG, "Clipboard does not contain a valid URL: " + clipText);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
- Note list widget should create a note in it's respective category (#817)
|
||||
- Note list widget should create a note in it's respective category (#817)
|
||||
- "Link" functionality in text menu causes error (#841)
|
Loading…
Reference in a new issue