Merge remote-tracking branch 'newpipe/dev' into rebase

This commit is contained in:
Alexander-- 2020-03-15 09:08:01 +06:59
commit 6aca344bf7
251 changed files with 7588 additions and 2315 deletions

View file

@ -0,0 +1,6 @@
package org.schabi.newpipe.util
/**
* Default duration when using throttle functions across the app, in milliseconds.
*/
const val DEFAULT_THROTTLE_TIMEOUT = 120L

View file

@ -31,18 +31,23 @@ import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.feed.FeedExtractor;
import org.schabi.newpipe.extractor.feed.FeedInfo;
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.search.SearchInfo;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
@ -131,6 +136,22 @@ public final class ExtractorHelper {
ChannelInfo.getMoreItems(NewPipe.getService(serviceId), url, nextStreamsUrl));
}
public static Single<ListInfo<StreamInfoItem>> getFeedInfoFallbackToChannelInfo(final int serviceId,
final String url) {
final Maybe<ListInfo<StreamInfoItem>> maybeFeedInfo = Maybe.fromCallable(() -> {
final StreamingService service = NewPipe.getService(serviceId);
final FeedExtractor feedExtractor = service.getFeedExtractor(url);
if (feedExtractor == null) {
return null;
}
return FeedInfo.getInfo(feedExtractor);
});
return maybeFeedInfo.switchIfEmpty(getChannelInfo(serviceId, url, true));
}
public static Single<CommentsInfo> getCommentsInfo(final int serviceId,
final String url,
boolean forceLoad) {

View file

@ -213,6 +213,42 @@ public class Localization {
return output;
}
/**
* Localize an amount of seconds into a human readable string.
*
* <p>The seconds will be converted to the closest whole time unit.
* <p>For example, 60 seconds would give "1 minute", 119 would also give "1 minute".
*
* @param context used to get plurals resources.
* @param durationInSecs an amount of seconds.
* @return duration in a human readable string.
*/
@NonNull
public static String localizeDuration(Context context, int durationInSecs) {
if (durationInSecs < 0) {
throw new IllegalArgumentException("duration can not be negative");
}
final int days = (int) (durationInSecs / (24 * 60 * 60L)); /* greater than a day */
durationInSecs %= (24 * 60 * 60L);
final int hours = (int) (durationInSecs / (60 * 60L)); /* greater than an hour */
durationInSecs %= (60 * 60L);
final int minutes = (int) (durationInSecs / 60L);
final int seconds = (int) (durationInSecs % 60L);
final Resources resources = context.getResources();
if (days > 0) {
return resources.getQuantityString(R.plurals.days, days, days);
} else if (hours > 0) {
return resources.getQuantityString(R.plurals.hours, hours, hours);
} else if (minutes > 0) {
return resources.getQuantityString(R.plurals.minutes, minutes, minutes);
} else {
return resources.getQuantityString(R.plurals.seconds, seconds, seconds);
}
}
/*//////////////////////////////////////////////////////////////////////////
// Pretty Time
//////////////////////////////////////////////////////////////////////////*/

View file

@ -23,6 +23,7 @@ import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.RouterActivity;
import org.schabi.newpipe.about.AboutActivity;
import org.schabi.newpipe.database.feed.model.FeedGroupEntity;
import org.schabi.newpipe.download.DownloadActivity;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
@ -343,9 +344,13 @@ public class NavigationHelper {
.commit();
}
public static void openWhatsNewFragment(FragmentManager fragmentManager) {
public static void openFeedFragment(FragmentManager fragmentManager) {
openFeedFragment(fragmentManager, FeedGroupEntity.GROUP_ALL_ID, null);
}
public static void openFeedFragment(FragmentManager fragmentManager, long groupId, @Nullable String groupName) {
defaultTransaction(fragmentManager)
.replace(R.id.fragment_holder, new FeedFragment())
.replace(R.id.fragment_holder, FeedFragment.newInstance(groupId, groupName))
.addToBackStack(null)
.commit();
}

View file

@ -99,6 +99,17 @@ public class ThemeHelper {
return isLightThemeSelected(context) ? R.style.LightDialogTheme : R.style.DarkDialogTheme;
}
/**
* Return a min-width dialog theme styled according to the (default) selected theme.
*
* @param context context to get the selected theme
* @return the dialog style (the default one)
*/
@StyleRes
public static int getMinWidthDialogTheme(Context context) {
return isLightThemeSelected(context) ? R.style.LightDialogMinWidthTheme : R.style.DarkDialogMinWidthTheme;
}
/**
* Return the selected theme styled according to the serviceId.
*