Skip to content

Commit 47f9ed0

Browse files
authored
Merge pull request #7934 from TeamNewPipe/release/0.22.1
Release 0.22.1
2 parents 7ae908a + ee3c063 commit 47f9ed0

55 files changed

Lines changed: 599 additions & 271 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/image-minimizer.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
module.exports = async ({github, context}) => {
55
const IGNORE_KEY = '<!-- IGNORE IMAGE MINIFY -->';
66
const IGNORE_ALT_NAME_END = 'ignoreImageMinify';
7+
// Targeted maximum height
78
const IMG_MAX_HEIGHT_PX = 600;
9+
// maximum width of GitHub issues/comments
10+
const IMG_MAX_WIDTH_PX = 800;
11+
// all images that have a lower aspect ratio (-> have a smaller width) than this will be minimized
12+
const MIN_ASPECT_RATIO = IMG_MAX_WIDTH_PX / IMG_MAX_HEIGHT_PX
813

914
// Get the body of the image
1015
let initialBody = null;
@@ -38,6 +43,8 @@ module.exports = async ({github, context}) => {
3843

3944
// Require the probe lib for getting the image dimensions
4045
const probe = require('probe-image-size');
46+
47+
var wasMatchModified = false;
4148

4249
// Try to find and replace the images with minimized ones
4350
let newBody = await replaceAsync(initialBody, REGEX_IMAGE_LOOKUP, async (match, g1, g2) => {
@@ -48,7 +55,7 @@ module.exports = async ({github, context}) => {
4855
return match;
4956
}
5057

51-
let shouldModifiy = false;
58+
let shouldModify = false;
5259
try {
5360
console.log(`Probing ${g2}`);
5461
let probeResult = await probe(g2);
@@ -58,22 +65,38 @@ module.exports = async ({github, context}) => {
5865
if (probeResult.hUnits != 'px') {
5966
throw `Unexpected probeResult.hUnits (expected px but got ${probeResult.hUnits})`;
6067
}
68+
if (probeResult.height <= 0) {
69+
throw `Unexpected probeResult.height (height is invalid: ${probeResult.height})`;
70+
}
71+
if (probeResult.wUnits != 'px') {
72+
throw `Unexpected probeResult.wUnits (expected px but got ${probeResult.wUnits})`;
73+
}
74+
if (probeResult.width <= 0) {
75+
throw `Unexpected probeResult.width (width is invalid: ${probeResult.width})`;
76+
}
77+
console.log(`Probing resulted in ${probeResult.width}x${probeResult.height}px`);
6178

62-
shouldModifiy = probeResult.height > IMG_MAX_HEIGHT_PX;
79+
shouldModify = probeResult.height > IMG_MAX_HEIGHT_PX && (probeResult.width / probeResult.height) < MIN_ASPECT_RATIO;
6380
} catch(e) {
6481
console.log('Probing failed:', e);
6582
// Immediately abort
6683
return match;
6784
}
6885

69-
if (shouldModifiy) {
86+
if (shouldModify) {
87+
wasMatchModified = true;
7088
console.log(`Modifying match '${match}'`);
7189
return `<img alt="${g1}" src="${g2}" height=${IMG_MAX_HEIGHT_PX} />`;
7290
}
7391

7492
console.log(`Match '${match}' is ok/will not be modified`);
7593
return match;
7694
});
95+
96+
if (!wasMatchModified) {
97+
console.log('Nothing was modified. Skipping update');
98+
return;
99+
}
77100

78101
// Update the corresponding element
79102
if (context.eventName == 'issue_comment') {

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ plugins {
88
}
99

1010
android {
11-
compileSdk 30
11+
compileSdk 31
1212
buildToolsVersion '30.0.3'
1313

1414
defaultConfig {
1515
applicationId "org.schabi.newpipe"
1616
resValue "string", "app_name", "NewPipe"
1717
minSdk 19
1818
targetSdk 29
19-
versionCode 983
20-
versionName "0.22.0"
19+
versionCode 984
20+
versionName "0.22.1"
2121

2222
multiDexEnabled true
2323

@@ -260,7 +260,7 @@ dependencies {
260260
implementation "com.nononsenseapps:filepicker:4.2.1"
261261

262262
// Crash reporting
263-
implementation "ch.acra:acra-core:5.7.0"
263+
implementation "ch.acra:acra-core:5.8.4"
264264

265265
// Properly restarting
266266
implementation 'com.jakewharton:process-phoenix:2.1.2'

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@
1313
import com.jakewharton.processphoenix.ProcessPhoenix;
1414

1515
import org.acra.ACRA;
16-
import org.acra.config.ACRAConfigurationException;
17-
import org.acra.config.CoreConfiguration;
1816
import org.acra.config.CoreConfigurationBuilder;
19-
import org.schabi.newpipe.error.ErrorInfo;
20-
import org.schabi.newpipe.error.ErrorUtil;
2117
import org.schabi.newpipe.error.ReCaptchaActivity;
22-
import org.schabi.newpipe.error.UserAction;
2318
import org.schabi.newpipe.extractor.NewPipe;
2419
import org.schabi.newpipe.extractor.downloader.Downloader;
2520
import org.schabi.newpipe.ktx.ExceptionUtils;
@@ -210,16 +205,9 @@ protected void initACRA() {
210205
return;
211206
}
212207

213-
try {
214-
final CoreConfiguration acraConfig = new CoreConfigurationBuilder(this)
215-
.setBuildConfigClass(BuildConfig.class)
216-
.build();
217-
ACRA.init(this, acraConfig);
218-
} catch (final ACRAConfigurationException exception) {
219-
exception.printStackTrace();
220-
ErrorUtil.openActivity(this, new ErrorInfo(exception,
221-
UserAction.SOMETHING_ELSE, "Could not initialize ACRA crash report"));
222-
}
208+
final CoreConfigurationBuilder acraConfig = new CoreConfigurationBuilder(this)
209+
.withBuildConfigClass(BuildConfig.class);
210+
ACRA.init(this, acraConfig);
223211
}
224212

225213
private void initNotificationChannels() {

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,9 +1994,7 @@ private void showSystemUi() {
19941994
// Prevent jumping of the player on devices with cutout
19951995
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
19961996
activity.getWindow().getAttributes().layoutInDisplayCutoutMode =
1997-
isMultiWindowOrFullscreen()
1998-
? WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
1999-
: WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
1997+
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
20001998
}
20011999
activity.getWindow().getDecorView().setSystemUiVisibility(0);
20022000
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
@@ -2018,9 +2016,7 @@ private void hideSystemUi() {
20182016
// Prevent jumping of the player on devices with cutout
20192017
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
20202018
activity.getWindow().getAttributes().layoutInDisplayCutoutMode =
2021-
isMultiWindowOrFullscreen()
2022-
? WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
2023-
: WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
2019+
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
20242020
}
20252021
int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
20262022
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
@@ -2037,7 +2033,7 @@ private void hideSystemUi() {
20372033
activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
20382034

20392035
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
2040-
&& isMultiWindowOrFullscreen()) {
2036+
&& (isInMultiWindow || (isPlayerAvailable() && player.isFullscreen()))) {
20412037
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
20422038
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
20432039
}
@@ -2053,11 +2049,6 @@ public void hideSystemUiIfNeeded() {
20532049
}
20542050
}
20552051

2056-
private boolean isMultiWindowOrFullscreen() {
2057-
return DeviceUtils.isInMultiWindow(activity)
2058-
|| (isPlayerAvailable() && player.isFullscreen());
2059-
}
2060-
20612052
private boolean playerIsNotStopped() {
20622053
return isPlayerAvailable() && !player.isStopped();
20632054
}

app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import androidx.preference.PreferenceManager;
1818
import androidx.recyclerview.widget.GridLayoutManager;
1919
import androidx.recyclerview.widget.RecyclerView;
20-
import androidx.viewbinding.ViewBinding;
2120

2221
import org.schabi.newpipe.R;
23-
import org.schabi.newpipe.databinding.PignateFooterBinding;
2422
import org.schabi.newpipe.error.ErrorUtil;
2523
import org.schabi.newpipe.extractor.InfoItem;
2624
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
@@ -44,6 +42,7 @@
4442
import java.util.Arrays;
4543
import java.util.List;
4644
import java.util.Queue;
45+
import java.util.function.Supplier;
4746

4847
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
4948
import static org.schabi.newpipe.ktx.ViewUtils.animate;
@@ -79,11 +78,6 @@ public void onAttach(@NonNull final Context context) {
7978
}
8079
}
8180

82-
@Override
83-
public void onDetach() {
84-
super.onDetach();
85-
}
86-
8781
@Override
8882
public void onCreate(final Bundle savedInstanceState) {
8983
super.onCreate(savedInstanceState);
@@ -220,14 +214,10 @@ public void onStart() {
220214
//////////////////////////////////////////////////////////////////////////*/
221215

222216
@Nullable
223-
protected ViewBinding getListHeader() {
217+
protected Supplier<View> getListHeaderSupplier() {
224218
return null;
225219
}
226220

227-
protected ViewBinding getListFooter() {
228-
return PignateFooterBinding.inflate(activity.getLayoutInflater(), itemsList, false);
229-
}
230-
231221
protected RecyclerView.LayoutManager getListLayoutManager() {
232222
return new SuperScrollLayoutManager(activity);
233223
}
@@ -252,11 +242,10 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
252242
itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager());
253243

254244
infoListAdapter.setUseGridVariant(useGrid);
255-
infoListAdapter.setFooter(getListFooter().getRoot());
256245

257-
final ViewBinding listHeader = getListHeader();
258-
if (listHeader != null) {
259-
infoListAdapter.setHeader(listHeader.getRoot());
246+
final Supplier<View> listHeaderSupplier = getListHeaderSupplier();
247+
if (listHeaderSupplier != null) {
248+
infoListAdapter.setHeaderSupplier(listHeaderSupplier);
260249
}
261250

262251
itemsList.setAdapter(infoListAdapter);
@@ -271,7 +260,7 @@ protected void onItemSelected(final InfoItem selectedItem) {
271260
@Override
272261
protected void initListeners() {
273262
super.initListeners();
274-
infoListAdapter.setOnStreamSelectedListener(new OnClickGesture<StreamInfoItem>() {
263+
infoListAdapter.setOnStreamSelectedListener(new OnClickGesture<>() {
275264
@Override
276265
public void selected(final StreamInfoItem selectedItem) {
277266
onStreamSelected(selectedItem);
@@ -315,22 +304,98 @@ public void selected(final PlaylistInfoItem selectedItem) {
315304
}
316305
});
317306

318-
infoListAdapter.setOnCommentsSelectedListener(new OnClickGesture<CommentsInfoItem>() {
307+
infoListAdapter.setOnCommentsSelectedListener(new OnClickGesture<>() {
319308
@Override
320309
public void selected(final CommentsInfoItem selectedItem) {
321310
onItemSelected(selectedItem);
322311
}
323312
});
324313

314+
// Ensure that there is always a scroll listener (e.g. when rotating the device)
315+
useNormalItemListScrollListener();
316+
}
317+
318+
/**
319+
* Removes all listeners and adds the normal scroll listener to the {@link #itemsList}.
320+
*/
321+
protected void useNormalItemListScrollListener() {
322+
if (DEBUG) {
323+
Log.d(TAG, "useNormalItemListScrollListener called");
324+
}
325+
itemsList.clearOnScrollListeners();
326+
itemsList.addOnScrollListener(new DefaultItemListOnScrolledDownListener());
327+
}
328+
329+
/**
330+
* Removes all listeners and adds the initial scroll listener to the {@link #itemsList}.
331+
* <br/>
332+
* Which tries to load more items when not enough are in the view (not scrollable)
333+
* and more are available.
334+
* <br/>
335+
* Note: This method only works because "This callback will also be called if visible
336+
* item range changes after a layout calculation. In that case, dx and dy will be 0."
337+
* - which might be unexpected because no actual scrolling occurs...
338+
* <br/>
339+
* This listener will be replaced by DefaultItemListOnScrolledDownListener when
340+
* <ul>
341+
* <li>the view was actually scrolled</li>
342+
* <li>the view is scrollable</li>
343+
* <li>no more items can be loaded</li>
344+
* </ul>
345+
*/
346+
protected void useInitialItemListLoadScrollListener() {
347+
if (DEBUG) {
348+
Log.d(TAG, "useInitialItemListLoadScrollListener called");
349+
}
325350
itemsList.clearOnScrollListeners();
326-
itemsList.addOnScrollListener(new OnScrollBelowItemsListener() {
351+
itemsList.addOnScrollListener(new DefaultItemListOnScrolledDownListener() {
327352
@Override
328-
public void onScrolledDown(final RecyclerView recyclerView) {
329-
onScrollToBottom();
353+
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
354+
super.onScrolled(recyclerView, dx, dy);
355+
356+
if (dy != 0) {
357+
log("Vertical scroll occurred");
358+
359+
useNormalItemListScrollListener();
360+
return;
361+
}
362+
if (isLoading.get()) {
363+
log("Still loading data -> Skipping");
364+
return;
365+
}
366+
if (!hasMoreItems()) {
367+
log("No more items to load");
368+
369+
useNormalItemListScrollListener();
370+
return;
371+
}
372+
if (itemsList.canScrollVertically(1)
373+
|| itemsList.canScrollVertically(-1)) {
374+
log("View is scrollable");
375+
376+
useNormalItemListScrollListener();
377+
return;
378+
}
379+
380+
log("Loading more data");
381+
loadMoreItems();
382+
}
383+
384+
private void log(final String msg) {
385+
if (DEBUG) {
386+
Log.d(TAG, "initItemListLoadScrollListener - " + msg);
387+
}
330388
}
331389
});
332390
}
333391

392+
class DefaultItemListOnScrolledDownListener extends OnScrollBelowItemsListener {
393+
@Override
394+
public void onScrolledDown(final RecyclerView recyclerView) {
395+
onScrollToBottom();
396+
}
397+
}
398+
334399
private void onStreamSelected(final StreamInfoItem selectedItem) {
335400
onItemSelected(selectedItem);
336401
NavigationHelper.openVideoDetailFragment(requireContext(), getFM(),
@@ -418,6 +483,12 @@ public void onCreateOptionsMenu(@NonNull final Menu menu,
418483
// Load and handle
419484
//////////////////////////////////////////////////////////////////////////*/
420485

486+
@Override
487+
protected void startLoading(final boolean forceLoad) {
488+
useInitialItemListLoadScrollListener();
489+
super.startLoading(forceLoad);
490+
}
491+
421492
protected abstract void loadMoreItems();
422493

423494
protected abstract boolean hasMoreItems();

0 commit comments

Comments
 (0)