Skip to content

Commit 973b20e

Browse files
committed
feat(history): implement functional infinite search history preference (#11726)
1 parent 09e4bea commit 973b20e

6 files changed

Lines changed: 59 additions & 12 deletions

File tree

NewPipeExtractor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 3af73262cc60cf555fd5f1d691f6c58e2db38ef5

app/src/main/java/org/schabi/newpipe/database/history/dao/SearchHistoryDAO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@ public interface SearchHistoryDAO extends HistoryDAO<SearchHistoryEntry> {
4949
@Query("SELECT " + SEARCH + " FROM " + TABLE_NAME + " WHERE " + SEARCH + " LIKE :query || '%'"
5050
+ " GROUP BY " + SEARCH + ORDER_BY_MAX_CREATION_DATE + " LIMIT :limit")
5151
Flowable<List<String>> getSimilarEntries(String query, int limit);
52+
53+
54+
@Query("SELECT * FROM " + TABLE_NAME + ORDER_BY_CREATION_DATE)
55+
List<SearchHistoryEntry> getAllEntries();
56+
57+
@androidx.room.Delete
58+
void delete(SearchHistoryEntry entry);
5259
}

app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,27 @@ public Maybe<Long> onSearched(final int serviceId, final String search) {
203203
latestEntry.setCreationDate(currentTime);
204204
return (long) searchHistoryTable.update(latestEntry);
205205
} else {
206-
return searchHistoryTable.insert(newEntry);
206+
final long insertedId = searchHistoryTable.insert(newEntry);
207+
208+
//New
209+
final boolean infiniteEnabled = sharedPreferences.getBoolean(
210+
"infinite_search_history", false
211+
);
212+
if (!infiniteEnabled) {
213+
final List<SearchHistoryEntry> allEntries = searchHistoryTable.getAllEntries();
214+
final int maxSize = 25;
215+
if (allEntries.size() > maxSize) {
216+
for (int i = maxSize; i < allEntries.size(); i++) {
217+
searchHistoryTable.delete(allEntries.get(i));
218+
}
219+
}
220+
}
221+
return insertedId;
207222
}
208223
})).subscribeOn(Schedulers.io());
209224
}
210225

226+
211227
public Single<Integer> deleteSearchHistory(final String search) {
212228
return Single.fromCallable(() -> searchHistoryTable.deleteAllWhereQuery(search))
213229
.subscribeOn(Schedulers.io());
@@ -218,12 +234,22 @@ public Single<Integer> deleteCompleteSearchHistory() {
218234
.subscribeOn(Schedulers.io());
219235
}
220236

221-
public Flowable<List<String>> getRelatedSearches(final String query,
222-
final int similarQueryLimit,
223-
final int uniqueQueryLimit) {
237+
public Flowable<List<String>> getRelatedSearches(
238+
final String query,
239+
final int similarQueryLimit,
240+
final int uniqueQueryLimit
241+
) {
242+
final boolean infiniteEnabled = sharedPreferences.getBoolean(
243+
"infinite_search_history", false
244+
);
245+
final int largeLimit = 100000;
246+
247+
final int sLimit = infiniteEnabled ? largeLimit : similarQueryLimit;
248+
final int uLimit = infiniteEnabled ? largeLimit : uniqueQueryLimit;
249+
224250
return query.length() > 0
225-
? searchHistoryTable.getSimilarEntries(query, similarQueryLimit)
226-
: searchHistoryTable.getUniqueEntries(uniqueQueryLimit);
251+
? searchHistoryTable.getSimilarEntries(query, sLimit)
252+
: searchHistoryTable.getUniqueEntries(uLimit);
227253
}
228254

229255
private boolean isSearchHistoryEnabled() {

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,4 +882,7 @@
882882
<string name="youtube_player_http_403">HTTP error 403 received from server while playing, likely caused by an IP ban or streaming URL deobfuscation issues</string>
883883
<string name="sign_in_confirm_not_bot_error">%1$s refused to provide data, asking for a login to confirm the requester is not a bot.\n\nYour IP might have been temporarily banned by %1$s, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data).</string>
884884
<string name="unsupported_content_in_country">This content is not available for the currently selected content country.\n\nChange your selection from \"Settings > Content > Default content country\".</string>
885+
<string name="pref_infinite_search_history_title">Enable Infinite Search History</string>
886+
<string name="pref_infinite_search_history_summary">Allow search history to load infinitely instead of being limited to 25 entries.</string>
887+
<string name="infinite_search_history_key">infinite_search_history</string>
885888
</resources>

app/src/main/res/xml/history_settings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
app:singleLineTitle="false"
3939
app:iconSpaceReserved="false" />
4040

41+
42+
<SwitchPreferenceCompat
43+
android:defaultValue="false"
44+
android:key="@string/infinite_search_history_key"
45+
android:title="@string/pref_infinite_search_history_title"
46+
android:summary="@string/pref_infinite_search_history_summary"
47+
app:singleLineTitle="false"
48+
app:iconSpaceReserved="false" />
49+
50+
4151
<PreferenceCategory
4252
android:layout="@layout/settings_category_header_layout"
4353
android:title="@string/settings_category_clear_data_title"

settings.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ include ':app'
33
// Use a local copy of NewPipe Extractor by uncommenting the lines below.
44
// We assume, that NewPipe and NewPipe Extractor have the same parent directory.
55
// If this is not the case, please change the path in includeBuild().
6-
7-
//includeBuild('../NewPipeExtractor') {
8-
// dependencySubstitution {
9-
// substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor')
10-
// }
11-
//}
6+
//
7+
includeBuild('../NewPipeExtractor') {
8+
dependencySubstitution {
9+
substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor')
10+
}
11+
}

0 commit comments

Comments
 (0)