Skip to content

Commit

Permalink
Merge pull request TeamNewPipe/NewPipe#5187 from TiA4f8R/share-improv…
Browse files Browse the repository at this point in the history
…ements

Share improvements + fix crash when no default browser is set on some devices
  • Loading branch information
Stypox authored and tossj committed Apr 20, 2021
1 parent 65825f1 commit fe16337
Show file tree
Hide file tree
Showing 47 changed files with 434 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import org.schabi.newpipelegacy.R;

import java.lang.reflect.Field;
Expand Down
31 changes: 18 additions & 13 deletions app/src/main/java/org/schabi/newpipelegacy/App.java
Original file line number Diff line number Diff line change
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.newpipelegacy.util.ServiceHelper;
import org.schabi.newpipelegacy.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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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/newpipelegacy/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

package org.schabi.newpipelegacy;

import static org.schabi.newpipelegacy.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.newpipelegacy.databinding.ActivityMainBinding;
import org.schabi.newpipelegacy.databinding.DrawerHeaderBinding;
import org.schabi.newpipelegacy.databinding.DrawerLayoutBinding;
Expand Down Expand Up @@ -89,6 +87,12 @@
import org.schabi.newpipelegacy.util.ThemeHelper;
import org.schabi.newpipelegacy.views.FocusOverlayView;

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

import static org.schabi.newpipelegacy.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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 @@ -102,6 +101,7 @@
import org.schabi.newpipelegacy.util.NavigationHelper;
import org.schabi.newpipelegacy.util.PermissionHelper;
import org.schabi.newpipelegacy.util.ShareUtils;
import org.schabi.newpipelegacy.util.TextLinkifier;
import org.schabi.newpipelegacy.util.ThemeHelper;
import org.schabi.newpipelegacy.views.AnimatedProgressBar;
import org.schabi.newpipelegacy.views.LargeTextMovementMethod;
Expand All @@ -113,10 +113,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 @@ -1233,28 +1230,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 @@ -1570,8 +1559,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
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.schabi.newpipelegacy.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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;


import org.schabi.newpipelegacy.R;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipelegacy.info_list.InfoItemBuilder;
import org.schabi.newpipelegacy.local.history.HistoryRecordManager;
import org.schabi.newpipelegacy.report.ErrorActivity;
import org.schabi.newpipelegacy.util.DeviceUtils;
import org.schabi.newpipelegacy.util.CommentTextOnTouchListener;
import org.schabi.newpipelegacy.util.DeviceUtils;
import org.schabi.newpipelegacy.util.ImageDisplayConstants;
import org.schabi.newpipelegacy.util.Localization;
import org.schabi.newpipelegacy.util.NavigationHelper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.schabi.newpipelegacy.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.newpipelegacy.R;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import com.xwray.groupie.Section
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import icepick.State
import io.reactivex.rxjava3.disposables.CompositeDisposable
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
import org.schabi.newpipelegacy.R
import org.schabi.newpipelegacy.database.feed.model.FeedGroupEntity
import org.schabi.newpipelegacy.databinding.DialogTitleBinding
import org.schabi.newpipelegacy.databinding.FragmentSubscriptionBinding
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
import org.schabi.newpipelegacy.fragments.BaseStateFragment
import org.schabi.newpipelegacy.ktx.animate
import org.schabi.newpipelegacy.local.subscription.SubscriptionViewModel.SubscriptionState
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

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

import static org.schabi.newpipelegacy.util.Localization.assureCorrectAppLanguage;
Expand Down
Loading

0 comments on commit fe16337

Please sign in to comment.