Annotate params and methods with NonNull
This commit is contained in:
parent
f02df6d80c
commit
218f25c171
4 changed files with 41 additions and 27 deletions
|
@ -2,6 +2,8 @@ package org.schabi.newpipe.util.external_communication;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
|
@ -44,9 +46,10 @@ public final class InternalUrlsHandler {
|
||||||
* @param url the URL to check if it can be handled
|
* @param url the URL to check if it can be handled
|
||||||
* @return true if the URL can be handled by NewPipe, false if it cannot
|
* @return true if the URL can be handled by NewPipe, false if it cannot
|
||||||
*/
|
*/
|
||||||
public static boolean handleUrlCommentsTimestamp(final CompositeDisposable disposables,
|
public static boolean handleUrlCommentsTimestamp(@NonNull final CompositeDisposable
|
||||||
|
disposables,
|
||||||
final Context context,
|
final Context context,
|
||||||
final String url) {
|
@NonNull final String url) {
|
||||||
return handleUrl(disposables, context, url, HASHTAG_TIMESTAMP_PATTERN);
|
return handleUrl(disposables, context, url, HASHTAG_TIMESTAMP_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +66,10 @@ public final class InternalUrlsHandler {
|
||||||
* @param url the URL to check if it can be handled
|
* @param url the URL to check if it can be handled
|
||||||
* @return true if the URL can be handled by NewPipe, false if it cannot
|
* @return true if the URL can be handled by NewPipe, false if it cannot
|
||||||
*/
|
*/
|
||||||
public static boolean handleUrlDescriptionTimestamp(final CompositeDisposable disposables,
|
public static boolean handleUrlDescriptionTimestamp(@NonNull final CompositeDisposable
|
||||||
|
disposables,
|
||||||
final Context context,
|
final Context context,
|
||||||
final String url) {
|
@NonNull final String url) {
|
||||||
return handleUrl(disposables, context, url, AMPERSAND_TIMESTAMP_PATTERN);
|
return handleUrl(disposables, context, url, AMPERSAND_TIMESTAMP_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +86,10 @@ public final class InternalUrlsHandler {
|
||||||
* @param pattern the pattern to use
|
* @param pattern the pattern to use
|
||||||
* @return true if the URL can be handled by NewPipe, false if it cannot
|
* @return true if the URL can be handled by NewPipe, false if it cannot
|
||||||
*/
|
*/
|
||||||
private static boolean handleUrl(final CompositeDisposable disposables,
|
private static boolean handleUrl(@NonNull final CompositeDisposable disposables,
|
||||||
final Context context,
|
final Context context,
|
||||||
final String url,
|
@NonNull final String url,
|
||||||
final Pattern pattern) {
|
@NonNull final Pattern pattern) {
|
||||||
final String matchedUrl;
|
final String matchedUrl;
|
||||||
final StreamingService service;
|
final StreamingService service;
|
||||||
final StreamingService.LinkType linkType;
|
final StreamingService.LinkType linkType;
|
||||||
|
@ -128,10 +132,10 @@ public final class InternalUrlsHandler {
|
||||||
* @param seconds the position in seconds at which the floating player will start
|
* @param seconds the position in seconds at which the floating player will start
|
||||||
* @return true if the playback of the content has successfully started or false if not
|
* @return true if the playback of the content has successfully started or false if not
|
||||||
*/
|
*/
|
||||||
public static boolean playOnPopup(final CompositeDisposable disposables,
|
public static boolean playOnPopup(@NonNull final CompositeDisposable disposables,
|
||||||
final Context context,
|
final Context context,
|
||||||
final String url,
|
final String url,
|
||||||
final StreamingService service,
|
@NonNull final StreamingService service,
|
||||||
final int seconds) {
|
final int seconds) {
|
||||||
final LinkHandlerFactory factory = service.getStreamLHFactory();
|
final LinkHandlerFactory factory = service.getStreamLHFactory();
|
||||||
final String cleanUrl;
|
final String cleanUrl;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.schabi.newpipe.util.external_communication;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
@ -17,13 +18,14 @@ public final class KoreUtils {
|
||||||
|| serviceId == ServiceList.SoundCloud.getServiceId());
|
|| serviceId == ServiceList.SoundCloud.getServiceId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldShowPlayWithKodi(final Context context, final int serviceId) {
|
public static boolean shouldShowPlayWithKodi(@NonNull final Context context,
|
||||||
|
final int serviceId) {
|
||||||
return isServiceSupportedByKore(serviceId)
|
return isServiceSupportedByKore(serviceId)
|
||||||
&& PreferenceManager.getDefaultSharedPreferences(context)
|
&& PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
.getBoolean(context.getString(R.string.show_play_with_kodi_key), false);
|
.getBoolean(context.getString(R.string.show_play_with_kodi_key), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstallKoreDialog(final Context context) {
|
public static void showInstallKoreDialog(@NonNull final Context context) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setMessage(R.string.kore_not_found)
|
builder.setMessage(R.string.kore_not_found)
|
||||||
.setPositiveButton(R.string.install, (dialog, which) ->
|
.setPositiveButton(R.string.install, (dialog, which) ->
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
@ -33,7 +34,7 @@ public final class ShareUtils {
|
||||||
* @param context the context to use
|
* @param context the context to use
|
||||||
* @param packageId the package id of the app to be installed
|
* @param packageId the package id of the app to be installed
|
||||||
*/
|
*/
|
||||||
public static void installApp(final Context context, final String packageId) {
|
public static void installApp(@NonNull final Context context, final String packageId) {
|
||||||
// Try market scheme
|
// Try market scheme
|
||||||
final boolean marketSchemeResult = openIntentInApp(context, new Intent(Intent.ACTION_VIEW,
|
final boolean marketSchemeResult = openIntentInApp(context, new Intent(Intent.ACTION_VIEW,
|
||||||
Uri.parse("market://details?id=" + packageId))
|
Uri.parse("market://details?id=" + packageId))
|
||||||
|
@ -57,7 +58,7 @@ public final class ShareUtils {
|
||||||
* for HTTP protocol or for the created intent
|
* for HTTP protocol or for the created intent
|
||||||
* @return true if the URL can be opened or false if it cannot
|
* @return true if the URL can be opened or false if it cannot
|
||||||
*/
|
*/
|
||||||
public static boolean openUrlInBrowser(final Context context,
|
public static boolean openUrlInBrowser(@NonNull final Context context,
|
||||||
final String url,
|
final String url,
|
||||||
final boolean httpDefaultBrowserTest) {
|
final boolean httpDefaultBrowserTest) {
|
||||||
final String defaultPackageName;
|
final String defaultPackageName;
|
||||||
|
@ -107,7 +108,7 @@ public final class ShareUtils {
|
||||||
* @param url the url to browse
|
* @param url the url to browse
|
||||||
* @return true if the URL can be opened or false if it cannot be
|
* @return true if the URL can be opened or false if it cannot be
|
||||||
**/
|
**/
|
||||||
public static boolean openUrlInBrowser(final Context context, final String url) {
|
public static boolean openUrlInBrowser(@NonNull final Context context, final String url) {
|
||||||
return openUrlInBrowser(context, url, true);
|
return openUrlInBrowser(context, url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +127,8 @@ public final class ShareUtils {
|
||||||
* to open the intent (true) or not (false)
|
* to open the intent (true) or not (false)
|
||||||
* @return true if the intent can be opened or false if it cannot be
|
* @return true if the intent can be opened or false if it cannot be
|
||||||
*/
|
*/
|
||||||
public static boolean openIntentInApp(final Context context,
|
public static boolean openIntentInApp(@NonNull final Context context,
|
||||||
final Intent intent,
|
@NonNull final Intent intent,
|
||||||
final boolean showToast) {
|
final boolean showToast) {
|
||||||
final String defaultPackageName = getDefaultAppPackageName(context, intent);
|
final String defaultPackageName = getDefaultAppPackageName(context, intent);
|
||||||
|
|
||||||
|
@ -159,8 +160,8 @@ public final class ShareUtils {
|
||||||
* @param intent the intent to open
|
* @param intent the intent to open
|
||||||
* @param setTitleChooser set the title "Open with" to the chooser if true, else not
|
* @param setTitleChooser set the title "Open with" to the chooser if true, else not
|
||||||
*/
|
*/
|
||||||
private static void openAppChooser(final Context context,
|
private static void openAppChooser(@NonNull final Context context,
|
||||||
final Intent intent,
|
@NonNull final Intent intent,
|
||||||
final boolean setTitleChooser) {
|
final boolean setTitleChooser) {
|
||||||
final Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
|
final Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
|
chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
|
||||||
|
@ -214,7 +215,8 @@ public final class ShareUtils {
|
||||||
* @return the package name of the default app, an empty string if there's no app installed to
|
* @return the package name of the default app, an empty string if there's no app installed to
|
||||||
* handle the intent or the app chooser if there's no default
|
* handle the intent or the app chooser if there's no default
|
||||||
*/
|
*/
|
||||||
private static String getDefaultAppPackageName(final Context context, final Intent intent) {
|
private static String getDefaultAppPackageName(@NonNull final Context context,
|
||||||
|
@NonNull final Intent intent) {
|
||||||
final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent,
|
final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent,
|
||||||
PackageManager.MATCH_DEFAULT_ONLY);
|
PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
|
|
||||||
|
@ -237,8 +239,8 @@ public final class ShareUtils {
|
||||||
* @param content the content to share
|
* @param content the content to share
|
||||||
* @param imagePreviewUrl the image of the subject
|
* @param imagePreviewUrl the image of the subject
|
||||||
*/
|
*/
|
||||||
public static void shareText(final Context context,
|
public static void shareText(@NonNull final Context context,
|
||||||
final String title,
|
@NonNull final String title,
|
||||||
final String content,
|
final String content,
|
||||||
final String imagePreviewUrl) {
|
final String imagePreviewUrl) {
|
||||||
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
|
@ -272,7 +274,9 @@ public final class ShareUtils {
|
||||||
* @param title the title of the content
|
* @param title the title of the content
|
||||||
* @param content the content to share
|
* @param content the content to share
|
||||||
*/
|
*/
|
||||||
public static void shareText(final Context context, final String title, final String content) {
|
public static void shareText(@NonNull final Context context,
|
||||||
|
@NonNull final String title,
|
||||||
|
final String content) {
|
||||||
shareText(context, title, content, "");
|
shareText(context, title, content, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +287,7 @@ public final class ShareUtils {
|
||||||
* @param context the context to use
|
* @param context the context to use
|
||||||
* @param text the text to copy
|
* @param text the text to copy
|
||||||
*/
|
*/
|
||||||
public static void copyToClipboard(final Context context, final String text) {
|
public static void copyToClipboard(@NonNull final Context context, final String text) {
|
||||||
final ClipboardManager clipboardManager =
|
final ClipboardManager clipboardManager =
|
||||||
ContextCompat.getSystemService(context, ClipboardManager.class);
|
ContextCompat.getSystemService(context, ClipboardManager.class);
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ public final class TextLinkifier {
|
||||||
* will be called
|
* will be called
|
||||||
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public static Disposable createLinksFromHtmlBlock(final Context context,
|
public static Disposable createLinksFromHtmlBlock(final Context context,
|
||||||
final String htmlBlock,
|
final String htmlBlock,
|
||||||
final TextView textView,
|
final TextView textView,
|
||||||
|
@ -82,9 +83,10 @@ public final class TextLinkifier {
|
||||||
* @param contentUrl the URL of the content
|
* @param contentUrl the URL of the content
|
||||||
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public static Disposable createLinksFromPlainText(final Context context,
|
public static Disposable createLinksFromPlainText(final Context context,
|
||||||
final String plainTextBlock,
|
final String plainTextBlock,
|
||||||
final TextView textView,
|
@NonNull final TextView textView,
|
||||||
final StreamingService streamingService,
|
final StreamingService streamingService,
|
||||||
final String contentUrl) {
|
final String contentUrl) {
|
||||||
textView.setAutoLinkMask(Linkify.WEB_URLS);
|
textView.setAutoLinkMask(Linkify.WEB_URLS);
|
||||||
|
@ -109,6 +111,7 @@ public final class TextLinkifier {
|
||||||
* @param contentUrl the URL of the content
|
* @param contentUrl the URL of the content
|
||||||
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public static Disposable createLinksFromMarkdownText(final Context context,
|
public static Disposable createLinksFromMarkdownText(final Context context,
|
||||||
final String markdownBlock,
|
final String markdownBlock,
|
||||||
final TextView textView,
|
final TextView textView,
|
||||||
|
@ -134,7 +137,7 @@ public final class TextLinkifier {
|
||||||
* @param streamingService the {@link StreamingService} of the content
|
* @param streamingService the {@link StreamingService} of the content
|
||||||
*/
|
*/
|
||||||
private static void addClickListenersOnHashtags(final Context context,
|
private static void addClickListenersOnHashtags(final Context context,
|
||||||
final SpannableStringBuilder
|
@NonNull final SpannableStringBuilder
|
||||||
spannableDescription,
|
spannableDescription,
|
||||||
final StreamingService streamingService) {
|
final StreamingService streamingService) {
|
||||||
final String descriptionText = spannableDescription.toString();
|
final String descriptionText = spannableDescription.toString();
|
||||||
|
@ -174,7 +177,7 @@ public final class TextLinkifier {
|
||||||
* @param streamingService the {@link StreamingService} of the content
|
* @param streamingService the {@link StreamingService} of the content
|
||||||
*/
|
*/
|
||||||
private static void addClickListenersOnTimestamps(final Context context,
|
private static void addClickListenersOnTimestamps(final Context context,
|
||||||
final SpannableStringBuilder
|
@NonNull final SpannableStringBuilder
|
||||||
spannableDescription,
|
spannableDescription,
|
||||||
final String contentUrl,
|
final String contentUrl,
|
||||||
final StreamingService streamingService) {
|
final StreamingService streamingService) {
|
||||||
|
@ -232,6 +235,7 @@ public final class TextLinkifier {
|
||||||
* @param contentUrl the URL of the content
|
* @param contentUrl the URL of the content
|
||||||
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
* @return a disposable to be stored somewhere and disposed when activity/fragment is destroyed
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
private static Disposable changeIntentsOfDescriptionLinks(final Context context,
|
private static Disposable changeIntentsOfDescriptionLinks(final Context context,
|
||||||
final CharSequence chars,
|
final CharSequence chars,
|
||||||
final TextView textView,
|
final TextView textView,
|
||||||
|
@ -279,7 +283,7 @@ public final class TextLinkifier {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setTextViewCharSequence(final TextView textView,
|
private static void setTextViewCharSequence(@NonNull final TextView textView,
|
||||||
final CharSequence charSequence) {
|
final CharSequence charSequence) {
|
||||||
textView.setText(charSequence);
|
textView.setText(charSequence);
|
||||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
Loading…
Reference in a new issue