Skip to content

Commit

Permalink
Merge branch 'dev' into Use_BitmapCompat_createScaledBitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Aug 7, 2022
2 parents 6e6f992 + 74921d3 commit 0069883
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 149 deletions.
26 changes: 12 additions & 14 deletions app/src/main/java/org/schabi/newpipe/DownloaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
import org.schabi.newpipe.extractor.downloader.Request;
import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.util.CookieUtils;
import org.schabi.newpipe.util.InfoCache;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
Expand Down Expand Up @@ -63,19 +65,15 @@ public static DownloaderImpl getInstance() {
}

public String getCookies(final String url) {
final List<String> resultCookies = new ArrayList<>();
if (url.contains(YOUTUBE_DOMAIN)) {
final String youtubeCookie = getCookie(YOUTUBE_RESTRICTED_MODE_COOKIE_KEY);
if (youtubeCookie != null) {
resultCookies.add(youtubeCookie);
}
}
final String youtubeCookie = url.contains(YOUTUBE_DOMAIN)
? getCookie(YOUTUBE_RESTRICTED_MODE_COOKIE_KEY) : null;

// Recaptcha cookie is always added TODO: not sure if this is necessary
final String recaptchaCookie = getCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY);
if (recaptchaCookie != null) {
resultCookies.add(recaptchaCookie);
}
return CookieUtils.concatCookies(resultCookies);
return Stream.of(youtubeCookie, getCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY))
.filter(Objects::nonNull)
.flatMap(cookies -> Arrays.stream(cookies.split("; *")))
.distinct()
.collect(Collectors.joining("; "));
}

public String getCookie(final String key) {
Expand Down
11 changes: 2 additions & 9 deletions app/src/main/java/org/schabi/newpipe/database/BasicDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Update;

import java.util.Collection;
Expand All @@ -14,13 +13,10 @@
@Dao
public interface BasicDAO<Entity> {
/* Inserts */
@Insert(onConflict = OnConflictStrategy.ABORT)
@Insert
long insert(Entity entity);

@Insert(onConflict = OnConflictStrategy.ABORT)
List<Long> insertAll(Entity... entities);

@Insert(onConflict = OnConflictStrategy.ABORT)
@Insert
List<Long> insertAll(Collection<Entity> entities);

/* Searches */
Expand All @@ -32,9 +28,6 @@ public interface BasicDAO<Entity> {
@Delete
void delete(Entity entity);

@Delete
int delete(Collection<Entity> entities);

int deleteAll();

/* Updates */
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.stream.Collectors;

/*
* Created by Christian Schabesberger on 24.10.15.
Expand Down Expand Up @@ -182,14 +183,9 @@ private void openPrivacyPolicyDialog(final Context context, final String action)
}

private String formErrorText(final String[] el) {
final StringBuilder text = new StringBuilder();
if (el != null) {
for (final String e : el) {
text.append("-------------------------------------\n").append(e);
}
}
text.append("-------------------------------------");
return text.toString();
final String separator = "-------------------------------------";
return Arrays.stream(el)
.collect(Collectors.joining(separator + "\n", separator + "\n", separator));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.AppDatabase;
import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.feed.dao.FeedDAO;
import org.schabi.newpipe.database.history.dao.SearchHistoryDAO;
import org.schabi.newpipe.database.history.dao.StreamHistoryDAO;
import org.schabi.newpipe.database.history.model.SearchHistoryEntry;
Expand All @@ -51,7 +50,6 @@
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import io.reactivex.rxjava3.core.Completable;
Expand Down Expand Up @@ -89,7 +87,6 @@ public HistoryRecordManager(final Context context) {
* Marks a stream item as watched such that it is hidden from the feed if watched videos are
* hidden. Adds a history entry and updates the stream progress to 100%.
*
* @see FeedDAO#getLiveOrNotPlayedStreams
* @see FeedViewModel#togglePlayedItems
* @param info the item to mark as watched
* @return a Maybe containing the ID of the item if successful
Expand Down Expand Up @@ -176,10 +173,6 @@ public Single<Integer> deleteCompleteStreamStateHistory() {
.subscribeOn(Schedulers.io());
}

public Flowable<List<StreamHistoryEntry>> getStreamHistory() {
return streamHistoryTable.getHistory().subscribeOn(Schedulers.io());
}

public Flowable<List<StreamHistoryEntry>> getStreamHistorySortedById() {
return streamHistoryTable.getHistorySortedById().subscribeOn(Schedulers.io());
}
Expand All @@ -188,24 +181,6 @@ public Flowable<List<StreamStatisticsEntry>> getStreamStatistics() {
return streamHistoryTable.getStatistics().subscribeOn(Schedulers.io());
}

public Single<List<Long>> insertStreamHistory(final Collection<StreamHistoryEntry> entries) {
final List<StreamHistoryEntity> entities = new ArrayList<>(entries.size());
for (final StreamHistoryEntry entry : entries) {
entities.add(entry.toStreamHistoryEntity());
}
return Single.fromCallable(() -> streamHistoryTable.insertAll(entities))
.subscribeOn(Schedulers.io());
}

public Single<Integer> deleteStreamHistory(final Collection<StreamHistoryEntry> entries) {
final List<StreamHistoryEntity> entities = new ArrayList<>(entries.size());
for (final StreamHistoryEntry entry : entries) {
entities.add(entry.toStreamHistoryEntity());
}
return Single.fromCallable(() -> streamHistoryTable.delete(entities))
.subscribeOn(Schedulers.io());
}

private boolean isStreamHistoryEnabled() {
return sharedPreferences.getBoolean(streamHistoryKey, false);
}
Expand Down Expand Up @@ -259,13 +234,6 @@ private boolean isSearchHistoryEnabled() {
// Stream State History
///////////////////////////////////////////////////////

public Maybe<StreamHistoryEntity> getStreamHistory(final StreamInfo info) {
return Maybe.fromCallable(() -> {
final long streamId = streamTable.upsert(new StreamEntity(info));
return streamHistoryTable.getLatestEntry(streamId);
}).subscribeOn(Schedulers.io());
}

public Maybe<StreamStateEntity> loadStreamState(final PlayQueueItem queueItem) {
return queueItem.getStream()
.map(info -> streamTable.upsert(new StreamEntity(info)))
Expand Down Expand Up @@ -311,28 +279,6 @@ public Single<StreamStateEntity[]> loadStreamState(final InfoItem info) {
}).subscribeOn(Schedulers.io());
}

public Single<List<StreamStateEntity>> loadStreamStateBatch(final List<InfoItem> infos) {
return Single.fromCallable(() -> {
final List<StreamStateEntity> result = new ArrayList<>(infos.size());
for (final InfoItem info : infos) {
final List<StreamEntity> entities = streamTable
.getStream(info.getServiceId(), info.getUrl()).blockingFirst();
if (entities.isEmpty()) {
result.add(null);
continue;
}
final List<StreamStateEntity> states = streamStateTable
.getState(entities.get(0).getUid()).blockingFirst();
if (states.isEmpty()) {
result.add(null);
} else {
result.add(states.get(0));
}
}
return result;
}).subscribeOn(Schedulers.io());
}

public Single<List<StreamStateEntity>> loadLocalStreamStateBatch(
final List<? extends LocalItem> items) {
return Single.fromCallable(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import androidx.annotation.XmlRes;
import androidx.preference.PreferenceManager;

import org.schabi.newpipe.util.Localization;
import org.xmlpull.v1.XmlPullParser;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Parses the corresponding preference-file(s).
Expand Down Expand Up @@ -54,7 +54,7 @@ public List<PreferenceSearchItem> parse(
if (xpp.getEventType() == XmlPullParser.START_TAG) {
final PreferenceSearchItem result = parseSearchResult(
xpp,
joinBreadcrumbs(breadcrumbs),
Localization.concatenateStrings(" > ", breadcrumbs),
resId
);

Expand Down Expand Up @@ -82,12 +82,6 @@ public List<PreferenceSearchItem> parse(
return results;
}

private String joinBreadcrumbs(final List<String> breadcrumbs) {
return breadcrumbs.stream()
.filter(crumb -> !TextUtils.isEmpty(crumb))
.collect(Collectors.joining(" > "));
}

private String getAttribute(
final XmlPullParser xpp,
@NonNull final String attribute
Expand Down
24 changes: 0 additions & 24 deletions app/src/main/java/org/schabi/newpipe/util/CookieUtils.java

This file was deleted.

38 changes: 6 additions & 32 deletions app/src/main/java/org/schabi/newpipe/util/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;


/*
Expand Down Expand Up @@ -63,26 +64,14 @@ private Localization() { }

@NonNull
public static String concatenateStrings(final String... strings) {
return concatenateStrings(Arrays.asList(strings));
return concatenateStrings(DOT_SEPARATOR, Arrays.asList(strings));
}

@NonNull
public static String concatenateStrings(final List<String> strings) {
if (strings.isEmpty()) {
return "";
}

final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(strings.get(0));

for (int i = 1; i < strings.size(); i++) {
final String string = strings.get(i);
if (!TextUtils.isEmpty(string)) {
stringBuilder.append(DOT_SEPARATOR).append(strings.get(i));
}
}

return stringBuilder.toString();
public static String concatenateStrings(final String delimiter, final List<String> strings) {
return strings.stream()
.filter(string -> !TextUtils.isEmpty(string))
.collect(Collectors.joining(delimiter));
}

public static org.schabi.newpipe.extractor.localization.Localization getPreferredLocalization(
Expand Down Expand Up @@ -358,19 +347,4 @@ public static void assureCorrectAppLanguage(final Context c) {
private static double round(final double value, final int places) {
return new BigDecimal(value).setScale(places, RoundingMode.HALF_UP).doubleValue();
}

/**
* Workaround to match normalized captions like english to English or deutsch to Deutsch.
* @param list the list to search into
* @param toFind the string to look for
* @return whether the string was found or not
*/
public static boolean containsCaseInsensitive(final List<String> list, final String toFind) {
for (final String i : list) {
if (i.equalsIgnoreCase(toFind)) {
return true;
}
}
return false;
}
}

0 comments on commit 0069883

Please sign in to comment.