Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when no default browser is set and improve share dialogs (on some devices) #5187

Merged
merged 3 commits into from Jan 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import org.schabi.newpipe.R;

import java.lang.reflect.Field;
Expand Down
31 changes: 18 additions & 13 deletions app/src/main/java/org/schabi/newpipe/App.java
Expand Up @@ -6,26 +6,16 @@
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.multidex.MultiDexApplication;
import androidx.preference.PreferenceManager;

import com.nostra13.universalimageloader.cache.memory.impl.LRULimitedMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.CompositeException;
import io.reactivex.rxjava3.exceptions.MissingBackpressureException;
import io.reactivex.rxjava3.exceptions.OnErrorNotImplementedException;
import io.reactivex.rxjava3.exceptions.UndeliverableException;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.acra.ACRA;
import org.acra.config.ACRAConfigurationException;
import org.acra.config.CoreConfiguration;
Expand All @@ -41,6 +31,21 @@
import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.util.StateSaver;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.CompositeException;
import io.reactivex.rxjava3.exceptions.MissingBackpressureException;
import io.reactivex.rxjava3.exceptions.OnErrorNotImplementedException;
import io.reactivex.rxjava3.exceptions.UndeliverableException;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;

/*
* Copyright (C) Hans-Christoph Steiner 2016 <hans@eds.org>
* App.java is part of NewPipe.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/schabi/newpipe/DownloaderImpl.java
Expand Up @@ -2,10 +2,10 @@

import android.content.Context;
import android.os.Build;
import androidx.preference.PreferenceManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;

import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.downloader.Request;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/schabi/newpipe/ImageDownloader.java
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;

import androidx.preference.PreferenceManager;

import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Expand Up @@ -20,8 +20,6 @@

package org.schabi.newpipe;

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -43,6 +41,7 @@
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.Spinner;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
Expand All @@ -53,10 +52,9 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceManager;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.schabi.newpipe.databinding.ActivityMainBinding;
import org.schabi.newpipe.databinding.DrawerHeaderBinding;
import org.schabi.newpipe.databinding.DrawerLayoutBinding;
Expand Down Expand Up @@ -89,6 +87,12 @@
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.views.FocusOverlayView;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/schabi/newpipe/RouterActivity.java
Expand Up @@ -188,7 +188,7 @@ private void showUnsupportedUrlDialog(final String url) {
.setPositiveButton(R.string.open_in_browser,
(dialog, which) -> ShareUtils.openUrlInBrowser(this, url))
.setNegativeButton(R.string.share,
(dialog, which) -> ShareUtils.shareUrl(this, "", url)) // no subject
(dialog, which) -> ShareUtils.shareText(this, "", url)) // no subject
.setNeutralButton(R.string.cancel, null)
.setOnDismissListener(dialog -> finish())
.show();
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/org/schabi/newpipe/about/AboutActivity.java
Expand Up @@ -146,16 +146,17 @@ public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup
aboutBinding.appVersion.setText(BuildConfig.VERSION_NAME);

aboutBinding.githubLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.github_url)));
openUrlInBrowser(context, context.getString(R.string.github_url), false));

aboutBinding.donationLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.donation_url)));
openUrlInBrowser(context, context.getString(R.string.donation_url), false));

aboutBinding.websiteLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.website_url)));
openUrlInBrowser(context, context.getString(R.string.website_url), false));

aboutBinding.privacyPolicyLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.privacy_policy_url)));
openUrlInBrowser(context, context.getString(R.string.privacy_policy_url),
false));

return aboutBinding.getRoot();
}
Expand Down
Expand Up @@ -16,7 +16,6 @@
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -101,6 +100,7 @@
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.TextLinkifier;
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.views.AnimatedProgressBar;
import org.schabi.newpipe.views.LargeTextMovementMethod;
Expand All @@ -112,10 +112,7 @@
import java.util.concurrent.TimeUnit;

import icepick.State;
import io.noties.markwon.Markwon;
import io.noties.markwon.linkify.LinkifyPlugin;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
Expand Down Expand Up @@ -1232,28 +1229,20 @@ private void prepareDescription(final Description description) {
return;
}

if (description.getType() == Description.HTML) {
disposables.add(Single.just(description.getContent())
.map(descriptionText ->
HtmlCompat.fromHtml(descriptionText,
HtmlCompat.FROM_HTML_MODE_LEGACY))
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(spanned -> {
videoDescriptionView.setText(spanned);
videoDescriptionView.setVisibility(View.VISIBLE);
}));
} else if (description.getType() == Description.MARKDOWN) {
final Markwon markwon = Markwon.builder(requireContext())
.usePlugin(LinkifyPlugin.create())
.build();
markwon.setMarkdown(videoDescriptionView, description.getContent());
videoDescriptionView.setVisibility(View.VISIBLE);
} else {
//== Description.PLAIN_TEXT
videoDescriptionView.setAutoLinkMask(Linkify.WEB_URLS);
videoDescriptionView.setText(description.getContent(), TextView.BufferType.SPANNABLE);
videoDescriptionView.setVisibility(View.VISIBLE);
switch (description.getType()) {
case Description.HTML:
disposables.add(TextLinkifier.createLinksFromHtmlBlock(requireContext(),
description.getContent(), videoDescriptionView,
HtmlCompat.FROM_HTML_MODE_LEGACY));
break;
case Description.MARKDOWN:
disposables.add(TextLinkifier.createLinksFromMarkdownText(requireContext(),
description.getContent(), videoDescriptionView));
break;
case Description.PLAIN_TEXT: default:
disposables.add(TextLinkifier.createLinksFromPlainText(requireContext(),
description.getContent(), videoDescriptionView));
break;
}
}

Expand Down Expand Up @@ -1569,8 +1558,8 @@ public void handleResult(@NonNull final StreamInfo info) {
prepareDescription(info.getDescription());
updateProgressInfo(info);
initThumbnailViews(info);
showMetaInfoInTextView(info.getMetaInfo(), detailMetaInfoTextView, detailMetaInfoSeparator);

disposables.add(showMetaInfoInTextView(info.getMetaInfo(), detailMetaInfoTextView,
detailMetaInfoSeparator));

if (player == null || player.isStopped()) {
updateOverlayData(info.getName(), info.getUploaderName(), info.getThumbnailUrl());
Expand Down
@@ -1,8 +1,6 @@
package org.schabi.newpipe.fragments.list.channel;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -188,8 +186,7 @@ public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
private void openRssFeed() {
final ChannelInfo info = currentInfo;
if (info != null) {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(info.getFeedUrl()));
startActivity(intent);
ShareUtils.openUrlInBrowser(requireContext(), info.getFeedUrl(), false);
}
}

Expand All @@ -209,7 +206,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
break;
case R.id.menu_item_share:
if (currentInfo != null) {
ShareUtils.shareUrl(requireContext(), name, currentInfo.getOriginalUrl());
ShareUtils.shareText(requireContext(), name, currentInfo.getOriginalUrl());
}
break;
default:
Expand Down
Expand Up @@ -242,7 +242,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
ShareUtils.openUrlInBrowser(requireContext(), url);
break;
case R.id.menu_item_share:
ShareUtils.shareUrl(requireContext(), name, url);
ShareUtils.shareText(requireContext(), name, url);
break;
case R.id.menu_item_bookmark:
onBookmarkClicked();
Expand Down
Expand Up @@ -280,8 +280,8 @@ public void onResume() {

handleSearchSuggestion();

showMetaInfoInTextView(metaInfo == null ? null : Arrays.asList(metaInfo),
metaInfoTextView, metaInfoSeparator);
disposables.add(showMetaInfoInTextView(metaInfo == null ? null : Arrays.asList(metaInfo),
metaInfoTextView, metaInfoSeparator));

if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
initSuggestionObserver();
Expand Down Expand Up @@ -1002,11 +1002,11 @@ public void handleResult(@NonNull final SearchInfo result) {
// List<MetaInfo> cannot be bundled without creating some containers
metaInfo = new MetaInfo[result.getMetaInfo().size()];
metaInfo = result.getMetaInfo().toArray(metaInfo);
disposables.add(showMetaInfoInTextView(result.getMetaInfo(), metaInfoTextView,
metaInfoSeparator));

handleSearchSuggestion();

showMetaInfoInTextView(result.getMetaInfo(), metaInfoTextView, metaInfoSeparator);

lastSearchedString = searchString;
nextPage = result.getNextPage();

Expand Down
Expand Up @@ -13,15 +13,14 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;


import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.info_list.InfoItemBuilder;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.CommentTextOnTouchListener;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
Expand Down
@@ -1,10 +1,11 @@
package org.schabi.newpipe.info_list.holder;

import androidx.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.preference.PreferenceManager;

import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
Expand Down
Expand Up @@ -4,16 +4,15 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down
Expand Up @@ -33,9 +33,9 @@
import java.util.List;

import icepick.State;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;

Expand Down
Expand Up @@ -300,7 +300,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {

val actions = DialogInterface.OnClickListener { _, i ->
when (i) {
0 -> ShareUtils.shareUrl(requireContext(), selectedItem.name, selectedItem.url)
0 -> ShareUtils.shareText(requireContext(), selectedItem.name, selectedItem.url)
1 -> deleteChannel(selectedItem)
}
}
Expand Down
Expand Up @@ -34,8 +34,8 @@
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import org.schabi.newpipe.databinding.PlayerBinding;
import org.schabi.newpipe.App;
import org.schabi.newpipe.databinding.PlayerBinding;
import org.schabi.newpipe.util.ThemeHelper;

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
Expand Down