Skip to content

Commit 161007f

Browse files
Merge branch 'dev' into Refactor_VideoPlayerUi
2 parents a798979 + 4a27d37 commit 161007f

212 files changed

Lines changed: 3238 additions & 702 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/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ jobs:
126126
env:
127127
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
128128
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
129-
run: ./gradlew build sonarqube --info
129+
run: ./gradlew build sonar --info

.github/workflows/image-minimizer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module.exports = async ({github, context}) => {
5555
return match;
5656
}
5757

58+
let probeAspectRatio = 0;
5859
let shouldModify = false;
5960
try {
6061
console.log(`Probing ${g2}`);
@@ -76,7 +77,8 @@ module.exports = async ({github, context}) => {
7677
}
7778
console.log(`Probing resulted in ${probeResult.width}x${probeResult.height}px`);
7879

79-
shouldModify = probeResult.height > IMG_MAX_HEIGHT_PX && (probeResult.width / probeResult.height) < MIN_ASPECT_RATIO;
80+
probeAspectRatio = probeResult.width / probeResult.height;
81+
shouldModify = probeResult.height > IMG_MAX_HEIGHT_PX && probeAspectRatio < MIN_ASPECT_RATIO;
8082
} catch(e) {
8183
console.log('Probing failed:', e);
8284
// Immediately abort
@@ -86,7 +88,7 @@ module.exports = async ({github, context}) => {
8688
if (shouldModify) {
8789
wasMatchModified = true;
8890
console.log(`Modifying match '${match}'`);
89-
return `<img alt="${g1}" src="${g2}" height=${IMG_MAX_HEIGHT_PX} />`;
91+
return `<img alt="${g1}" src="${g2}" width=${Math.min(600, (IMG_MAX_HEIGHT_PX * probeAspectRatio).toFixed(0))} />`;
9092
}
9193

9294
console.log(`Match '${match}' is ok/will not be modified`);

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id "kotlin-kapt"
55
id "kotlin-parcelize"
66
id "checkstyle"
7-
id "org.sonarqube" version "3.3"
7+
id "org.sonarqube" version "3.5.0.2730"
88
}
99

1010
android {
@@ -169,7 +169,7 @@ afterEvaluate {
169169
preDebugBuild.dependsOn runCheckstyle, runKtlint
170170
}
171171

172-
sonarqube {
172+
sonar {
173173
properties {
174174
property "sonar.projectKey", "TeamNewPipe_NewPipe"
175175
property "sonar.organization", "teamnewpipe"

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@
337337
<data android:host="peertube.mastodon.host" />
338338
<data android:host="peertube.fr" />
339339
<data android:host="tilvids.com" />
340-
<data android:host="tube.privacytools.io" />
341340
<data android:host="video.ploud.fr" />
342341
<data android:host="video.lqdn.fr" />
343342
<data android:host="skeptikon.fr" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected void onPostCreate(final Bundle savedInstanceState) {
172172
if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) {
173173
// Start the worker which is checking all conditions
174174
// and eventually searching for a new version.
175-
NewVersionWorker.enqueueNewVersionCheckingWork(app);
175+
NewVersionWorker.enqueueNewVersionCheckingWork(app, false);
176176
}
177177
}
178178

app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package org.schabi.newpipe
33
import android.content.Context
44
import android.content.Intent
55
import android.util.Log
6+
import android.widget.Toast
67
import androidx.core.app.NotificationCompat
78
import androidx.core.app.NotificationManagerCompat
9+
import androidx.core.content.ContextCompat
810
import androidx.core.content.edit
911
import androidx.core.net.toUri
1012
import androidx.preference.PreferenceManager
11-
import androidx.work.OneTimeWorkRequest
13+
import androidx.work.OneTimeWorkRequestBuilder
1214
import androidx.work.WorkManager
13-
import androidx.work.WorkRequest
1415
import androidx.work.Worker
1516
import androidx.work.WorkerParameters
17+
import androidx.work.workDataOf
1618
import com.grack.nanojson.JsonParser
1719
import com.grack.nanojson.JsonParserException
1820
import org.schabi.newpipe.extractor.downloader.Response
@@ -42,26 +44,40 @@ class NewVersionWorker(
4244
versionCode: Int
4345
) {
4446
if (BuildConfig.VERSION_CODE >= versionCode) {
47+
if (inputData.getBoolean(IS_MANUAL, false)) {
48+
// Show toast stating that the app is up-to-date if the update check was manual.
49+
ContextCompat.getMainExecutor(applicationContext).execute {
50+
Toast.makeText(
51+
applicationContext, R.string.app_update_unavailable_toast,
52+
Toast.LENGTH_SHORT
53+
).show()
54+
}
55+
}
4556
return
4657
}
47-
val app = App.getApp()
4858

4959
// A pending intent to open the apk location url in the browser.
5060
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
5161
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
52-
val pendingIntent = PendingIntentCompat.getActivity(app, 0, intent, 0)
53-
val channelId = app.getString(R.string.app_update_notification_channel_id)
54-
val notificationBuilder = NotificationCompat.Builder(app, channelId)
62+
val pendingIntent = PendingIntentCompat.getActivity(
63+
applicationContext, 0, intent, 0
64+
)
65+
val channelId = applicationContext.getString(R.string.app_update_notification_channel_id)
66+
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
5567
.setSmallIcon(R.drawable.ic_newpipe_update)
5668
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
57-
.setContentIntent(pendingIntent)
5869
.setAutoCancel(true)
59-
.setContentTitle(app.getString(R.string.app_update_notification_content_title))
70+
.setContentIntent(pendingIntent)
71+
.setContentTitle(
72+
applicationContext.getString(R.string.app_update_available_notification_title)
73+
)
6074
.setContentText(
61-
app.getString(R.string.app_update_notification_content_text) +
62-
" " + versionName
75+
applicationContext.getString(
76+
R.string.app_update_available_notification_text, versionName
77+
)
6378
)
64-
val notificationManager = NotificationManagerCompat.from(app)
79+
80+
val notificationManager = NotificationManagerCompat.from(applicationContext)
6581
notificationManager.notify(2000, notificationBuilder.build())
6682
}
6783

@@ -72,12 +88,14 @@ class NewVersionWorker(
7288
return
7389
}
7490

75-
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
76-
// Check if the last request has happened a certain time ago
77-
// to reduce the number of API requests.
78-
val expiry = prefs.getLong(applicationContext.getString(R.string.update_expiry_key), 0)
79-
if (!isLastUpdateCheckExpired(expiry)) {
80-
return
91+
if (!inputData.getBoolean(IS_MANUAL, false)) {
92+
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
93+
// Check if the last request has happened a certain time ago
94+
// to reduce the number of API requests.
95+
val expiry = prefs.getLong(applicationContext.getString(R.string.update_expiry_key), 0)
96+
if (!isLastUpdateCheckExpired(expiry)) {
97+
return
98+
}
8199
}
82100

83101
// Make a network request to get latest NewPipe data.
@@ -120,43 +138,42 @@ class NewVersionWorker(
120138
}
121139

122140
override fun doWork(): Result {
123-
try {
141+
return try {
124142
checkNewVersion()
143+
Result.success()
125144
} catch (e: IOException) {
126145
Log.w(TAG, "Could not fetch NewPipe API: probably network problem", e)
127-
return Result.failure()
146+
Result.failure()
128147
} catch (e: ReCaptchaException) {
129148
Log.e(TAG, "ReCaptchaException should never happen here.", e)
130-
return Result.failure()
149+
Result.failure()
131150
}
132-
return Result.success()
133151
}
134152

135153
companion object {
136154
private val DEBUG = MainActivity.DEBUG
137155
private val TAG = NewVersionWorker::class.java.simpleName
138156
private const val NEWPIPE_API_URL = "https://newpipe.net/api/data.json"
157+
private const val IS_MANUAL = "isManual"
139158

140159
/**
141-
* Start a new worker which
142-
* checks if all conditions for performing a version check are met,
143-
* fetches the API endpoint [.NEWPIPE_API_URL] containing info
144-
* about the latest NewPipe version
145-
* and displays a notification about ana available update.
160+
* Start a new worker which checks if all conditions for performing a version check are met,
161+
* fetches the API endpoint [.NEWPIPE_API_URL] containing info about the latest NewPipe
162+
* version and displays a notification about an available update if one is available.
146163
* <br></br>
147-
* Following conditions need to be met, before data is request from the server:
164+
* Following conditions need to be met, before data is requested from the server:
148165
*
149166
* * The app is signed with the correct signing key (by TeamNewPipe / schabi).
150167
* If the signing key differs from the one used upstream, the update cannot be installed.
151168
* * The user enabled searching for and notifying about updates in the settings.
152169
* * The app did not recently check for updates.
153170
* We do not want to make unnecessary connections and DOS our servers.
154-
*
155171
*/
156172
@JvmStatic
157-
fun enqueueNewVersionCheckingWork(context: Context) {
158-
val workRequest: WorkRequest =
159-
OneTimeWorkRequest.Builder(NewVersionWorker::class.java).build()
173+
fun enqueueNewVersionCheckingWork(context: Context, isManual: Boolean) {
174+
val workRequest = OneTimeWorkRequestBuilder<NewVersionWorker>()
175+
.setInputData(workDataOf(IS_MANUAL to isManual))
176+
.build()
160177
WorkManager.getInstance(context).enqueue(workRequest)
161178
}
162179
}

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,9 +1561,9 @@ public void handleResult(@NonNull final StreamInfo info) {
15611561
binding.detailSubChannelThumbnailView.setVisibility(View.GONE);
15621562

15631563
if (!isEmpty(info.getSubChannelName())) {
1564-
displayBothUploaderAndSubChannel(info);
1564+
displayBothUploaderAndSubChannel(info, activity);
15651565
} else if (!isEmpty(info.getUploaderName())) {
1566-
displayUploaderAsSubChannel(info);
1566+
displayUploaderAsSubChannel(info, activity);
15671567
} else {
15681568
binding.detailUploaderTextView.setVisibility(View.GONE);
15691569
binding.detailUploaderThumbnailView.setVisibility(View.GONE);
@@ -1676,23 +1676,42 @@ public void handleResult(@NonNull final StreamInfo info) {
16761676
noVideoStreams ? R.drawable.ic_headset_shadow : R.drawable.ic_play_arrow_shadow);
16771677
}
16781678

1679-
private void displayUploaderAsSubChannel(final StreamInfo info) {
1679+
private void displayUploaderAsSubChannel(final StreamInfo info, final Context context) {
16801680
binding.detailSubChannelTextView.setText(info.getUploaderName());
16811681
binding.detailSubChannelTextView.setVisibility(View.VISIBLE);
16821682
binding.detailSubChannelTextView.setSelected(true);
1683-
binding.detailUploaderTextView.setVisibility(View.GONE);
1683+
1684+
if (info.getUploaderSubscriberCount() > -1) {
1685+
binding.detailUploaderTextView.setText(
1686+
Localization.shortSubscriberCount(context, info.getUploaderSubscriberCount()));
1687+
binding.detailUploaderTextView.setVisibility(View.VISIBLE);
1688+
} else {
1689+
binding.detailUploaderTextView.setVisibility(View.GONE);
1690+
}
16841691
}
16851692

1686-
private void displayBothUploaderAndSubChannel(final StreamInfo info) {
1693+
private void displayBothUploaderAndSubChannel(final StreamInfo info, final Context context) {
16871694
binding.detailSubChannelTextView.setText(info.getSubChannelName());
16881695
binding.detailSubChannelTextView.setVisibility(View.VISIBLE);
16891696
binding.detailSubChannelTextView.setSelected(true);
16901697

16911698
binding.detailSubChannelThumbnailView.setVisibility(View.VISIBLE);
16921699

1700+
final StringBuilder subText = new StringBuilder();
16931701
if (!isEmpty(info.getUploaderName())) {
1694-
binding.detailUploaderTextView.setText(
1702+
subText.append(
16951703
String.format(getString(R.string.video_detail_by), info.getUploaderName()));
1704+
}
1705+
if (info.getUploaderSubscriberCount() > -1) {
1706+
if (subText.length() > 0) {
1707+
subText.append(Localization.DOT_SEPARATOR);
1708+
}
1709+
subText.append(
1710+
Localization.shortSubscriberCount(context, info.getUploaderSubscriberCount()));
1711+
}
1712+
1713+
if (subText.length() > 0) {
1714+
binding.detailUploaderTextView.setText(subText);
16961715
binding.detailUploaderTextView.setVisibility(View.VISIBLE);
16971716
binding.detailUploaderTextView.setSelected(true);
16981717
} else {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ protected RecyclerView.LayoutManager getGridLayoutManager() {
215215
final Resources resources = activity.getResources();
216216
int width = resources.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width);
217217
width += (24 * resources.getDisplayMetrics().density);
218-
final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels
219-
/ (double) width);
218+
final int spanCount = Math.floorDiv(resources.getDisplayMetrics().widthPixels, width);
220219
final GridLayoutManager lm = new GridLayoutManager(activity, spanCount);
221220
lm.setSpanSizeLookup(infoListAdapter.getSpanSizeLookup(spanCount));
222221
return lm;

app/src/main/java/org/schabi/newpipe/info_list/dialog/InfoItemDialog.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ public Builder setAction(@NonNull final StreamDialogDefaultEntry entry,
252252
* @return the current {@link Builder} instance
253253
*/
254254
public Builder addEnqueueEntriesIfNeeded() {
255-
if (PlayerHolder.getInstance().isPlayQueueReady()) {
255+
final PlayerHolder holder = PlayerHolder.getInstance();
256+
if (holder.isPlayQueueReady()) {
256257
addEntry(StreamDialogDefaultEntry.ENQUEUE);
257258

258-
if (PlayerHolder.getInstance().getQueueSize() > 1) {
259+
if (holder.getQueuePosition() < holder.getQueueSize() - 1) {
259260
addEntry(StreamDialogDefaultEntry.ENQUEUE_NEXT);
260261
}
261262
}

app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ protected RecyclerView.LayoutManager getGridLayoutManager() {
104104
final Resources resources = activity.getResources();
105105
int width = resources.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width);
106106
width += (24 * resources.getDisplayMetrics().density);
107-
final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels
108-
/ (double) width);
107+
final int spanCount = Math.floorDiv(resources.getDisplayMetrics().widthPixels, width);
109108
final GridLayoutManager lm = new GridLayoutManager(activity, spanCount);
110109
lm.setSpanSizeLookup(itemListAdapter.getSpanSizeLookup(spanCount));
111110
return lm;

0 commit comments

Comments
 (0)