1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2026-04-18 21:01:23 +00:00

Merge branch 'dev' into unhook-save-restore

This commit is contained in:
Tobias Groza
2020-02-23 00:19:44 +01:00
committed by GitHub
68 changed files with 1170 additions and 1332 deletions

View File

@@ -453,15 +453,9 @@ public class MainActivity extends AppCompatActivity {
NavigationHelper.openMainActivity(this);
}
if (sharedPreferences.getBoolean(Constants.KEY_ENABLE_WATCH_HISTORY, true)) {
if (DEBUG) Log.d(TAG, "do not show History-menu as its disabled in settings");
drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(true);
}
if (!sharedPreferences.getBoolean(Constants.KEY_ENABLE_WATCH_HISTORY, true)) {
if (DEBUG) Log.d(TAG, "show History-menu as its enabled in settings");
drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(false);
}
final boolean isHistoryEnabled = sharedPreferences.getBoolean(
getString(R.string.enable_watch_history_key), true);
drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(isHistoryEnabled);
}
@Override

View File

@@ -18,7 +18,7 @@ import android.webkit.WebViewClient;
import org.schabi.newpipe.util.ThemeHelper;
import javax.annotation.Nonnull;
import androidx.annotation.NonNull;
/*
* Created by beneth <bmauduit@beneth.fr> on 06.12.16.
@@ -147,7 +147,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
// add other methods to extract cookies here
}
private void addYoutubeCookies(@Nonnull String cookies) {
private void addYoutubeCookies(@NonNull String cookies) {
if (cookies.contains("s_gl=") || cookies.contains("goojf=") || cookies.contains("VISITOR_INFO1_LIVE=")) {
// youtube seems to also need the other cookies:
addCookie(cookies);

View File

@@ -88,13 +88,6 @@ public class AboutActivity extends AppCompatActivity {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_about, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {

View File

@@ -12,6 +12,7 @@ import android.view.MenuItem;
import android.view.ViewTreeObserver;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ThemeHelper;
import us.shandian.giga.service.DownloadManagerService;
@@ -76,11 +77,9 @@ public class DownloadActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
case android.R.id.home:
onBackPressed();
return true;
}
default:
return super.onOptionsItemSelected(item);
}

View File

@@ -600,22 +600,27 @@ public class VideoDetailFragment
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (isLoading.get()) {
// if is still loading block menu
int id = item.getItemId();
if (id == R.id.action_settings) {
NavigationHelper.openSettings(requireContext());
return true;
}
if (isLoading.get()) {
// if still loading, block menu buttons related to video info
return true;
}
int id = item.getItemId();
switch (id) {
case R.id.menu_item_share: {
if (currentInfo != null) {
ShareUtils.shareUrl(this.getContext(), currentInfo.getName(), currentInfo.getOriginalUrl());
ShareUtils.shareUrl(requireContext(), currentInfo.getName(), currentInfo.getOriginalUrl());
}
return true;
}
case R.id.menu_item_openInBrowser: {
if (currentInfo != null) {
ShareUtils.openUrlInBrowser(this.getContext(), currentInfo.getOriginalUrl());
ShareUtils.openUrlInBrowser(requireContext(), currentInfo.getOriginalUrl());
}
return true;
}
@@ -1074,7 +1079,7 @@ public class VideoDetailFragment
if (info.getStreamType().equals(StreamType.AUDIO_LIVE_STREAM)) {
videoCountView.setText(Localization.listeningCount(activity, info.getViewCount()));
} else if (info.getStreamType().equals(StreamType.LIVE_STREAM)) {
videoCountView.setText(Localization.watchingCount(activity, info.getViewCount()));
videoCountView.setText(Localization.localizeWatchingCount(activity, info.getViewCount()));
} else {
videoCountView.setText(Localization.localizeViewCount(activity, info.getViewCount()));
}

View File

@@ -175,17 +175,20 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
NavigationHelper.openSettings(requireContext());
break;
case R.id.menu_item_rss:
openRssFeed();
break;
case R.id.menu_item_openInBrowser:
if (currentInfo != null) {
ShareUtils.openUrlInBrowser(this.getContext(), currentInfo.getOriginalUrl());
ShareUtils.openUrlInBrowser(requireContext(), currentInfo.getOriginalUrl());
}
break;
case R.id.menu_item_share:
if (currentInfo != null) {
ShareUtils.shareUrl(this.getContext(), name, currentInfo.getOriginalUrl());
ShareUtils.shareUrl(requireContext(), name, currentInfo.getOriginalUrl());
}
break;
default:
@@ -370,7 +373,7 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
headerSubscribersTextView.setVisibility(View.VISIBLE);
if (result.getSubscriberCount() >= 0) {
headerSubscribersTextView.setText(Localization.localizeSubscribersCount(activity, result.getSubscriberCount()));
headerSubscribersTextView.setText(Localization.shortSubscriberCount(activity, result.getSubscriberCount()));
} else {
headerSubscribersTextView.setText(R.string.subscribers_count_not_available);
}

View File

@@ -222,11 +222,14 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
NavigationHelper.openSettings(requireContext());
break;
case R.id.menu_item_openInBrowser:
ShareUtils.openUrlInBrowser(this.getContext(), url);
ShareUtils.openUrlInBrowser(requireContext(), url);
break;
case R.id.menu_item_share:
ShareUtils.shareUrl(this.getContext(), name, url);
ShareUtils.shareUrl(requireContext(), name, url);
break;
case R.id.menu_item_bookmark:
onBookmarkClicked();

View File

@@ -190,7 +190,7 @@ public class SearchFragment
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
isSuggestionsEnabled = preferences.getBoolean(getString(R.string.show_search_suggestions_key), true);
contentCountry = preferences.getString(getString(R.string.content_country_key), getString(R.string.default_country_value));
contentCountry = preferences.getString(getString(R.string.content_country_key), getString(R.string.default_localization_key));
}
@Override

View File

@@ -60,7 +60,7 @@ public class StreamInfoItemHolder extends StreamMiniInfoItemHolder {
if (infoItem.getStreamType().equals(StreamType.AUDIO_LIVE_STREAM)) {
viewsAndDate = Localization.listeningCount(itemBuilder.getContext(), infoItem.getViewCount());
} else if (infoItem.getStreamType().equals(StreamType.LIVE_STREAM)) {
viewsAndDate = Localization.watchingCount(itemBuilder.getContext(), infoItem.getViewCount());
viewsAndDate = Localization.shortWatchingCount(itemBuilder.getContext(), infoItem.getViewCount());
} else {
viewsAndDate = Localization.shortViewCount(itemBuilder.getContext(), infoItem.getViewCount());
}

View File

@@ -55,7 +55,13 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity {
return true;
}
return switchTo(PopupVideoPlayer.class);
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(
getSwitchIntent(PopupVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
}
return false;
}

View File

@@ -909,6 +909,18 @@ public final class MainVideoPlayer extends AppCompatActivity
final float currentVolumeNormalized = (float) getAudioReactor().getVolume() / getAudioReactor().getMaxVolume();
volumeProgressBar.setProgress((int) (volumeProgressBar.getMax() * currentVolumeNormalized));
}
float screenBrightness = getWindow().getAttributes().screenBrightness;
if (screenBrightness < 0)
screenBrightness = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, 0) / 255.0f;
brightnessProgressBar.setProgress((int) (brightnessProgressBar.getMax() * screenBrightness));
if (DEBUG) Log.d(TAG, "setInitialGestureValues: volumeProgressBar.getProgress() ["
+ volumeProgressBar.getProgress() + "] "
+ "brightnessProgressBar.getProgress() ["
+ brightnessProgressBar.getProgress() + "]");
}
@Override

View File

@@ -48,7 +48,13 @@ public final class PopupVideoPlayerActivity extends ServicePlayerActivity {
@Override
public boolean onPlayerOptionSelected(MenuItem item) {
if (item.getItemId() == R.id.action_switch_background) {
return switchTo(BackgroundPlayer.class);
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(
getSwitchIntent(BackgroundPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
}
return false;
}

View File

@@ -156,6 +156,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
case android.R.id.home:
finish();
return true;
case R.id.action_settings:
NavigationHelper.openSettings(this);
return true;
case R.id.action_append_playlist:
appendAllToPlaylist();
return true;
@@ -163,7 +166,13 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
return true;
case R.id.action_switch_main:
return switchTo(MainVideoPlayer.class);
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startActivity(
getSwitchIntent(MainVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
}
return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item);
}
@@ -187,14 +196,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
false,
false
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying());
}
protected boolean switchTo(final Class clazz) {
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startActivity(getSwitchIntent(clazz));
return true;
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying());
}
////////////////////////////////////////////////////////////////////////////

View File

@@ -43,6 +43,7 @@ import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Vector;
@@ -93,7 +94,7 @@ public class ErrorActivity extends AppCompatActivity {
if (rootView != null) {
Snackbar.make(rootView, R.string.error_snackbar_message, 3 * 1000)
.setActionTextColor(Color.YELLOW)
.setAction(R.string.error_snackbar_action, v ->
.setAction(context.getString(R.string.error_snackbar_action).toUpperCase(), v ->
startErrorActivity(returnActivity, context, errorInfo, el)).show();
} else {
startErrorActivity(returnActivity, context, errorInfo, el);
@@ -377,8 +378,12 @@ public class ErrorActivity extends AppCompatActivity {
}
private String getContentLangString() {
return PreferenceManager.getDefaultSharedPreferences(this)
String contentLanguage = PreferenceManager.getDefaultSharedPreferences(this)
.getString(this.getString(R.string.content_country_key), "none");
if (contentLanguage.equals(getString(R.string.default_localization_key))) {
contentLanguage = Locale.getDefault().toString();
}
return contentLanguage;
}
private String getOsString() {

View File

@@ -1,12 +1,13 @@
package org.schabi.newpipe.settings;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import com.google.android.material.snackbar.Snackbar;
@@ -21,6 +22,24 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initializing R.array.seek_duration_description to display the translation of seconds
Resources res = getResources();
String[] durationsValues = res.getStringArray(R.array.seek_duration_value);
String[] durationsDescriptions = res.getStringArray(R.array.seek_duration_description);
int currentDurationValue;
for (int i = 0; i < durationsDescriptions.length; i++) {
currentDurationValue = Integer.parseInt(durationsValues[i]) / 1000;
try {
durationsDescriptions[i] = String.format(
res.getQuantityString(R.plurals.dynamic_seek_duration_description, currentDurationValue),
currentDurationValue);
} catch (Resources.NotFoundException ignored) {
//if this happens, the translation is missing, and the english string will be displayed instead
}
}
ListPreference durations = (ListPreference) findPreference(getString(R.string.seek_duration_key));
durations.setEntries(durationsDescriptions);
listener = (sharedPreferences, s) -> {
// on M and above, if user chooses to minimise to popup player on exit and the app doesn't have

View File

@@ -291,7 +291,9 @@ public class Mp4FromDashWriter {
sampleCount[i] = 1;// the index is not base zero
sampleExtra[i] = -1;
}
writeEntryArray(tablesInfo[i].sbgp, 1, sampleCount[i]);
if (tablesInfo[i].sbgp > 0) {
writeEntryArray(tablesInfo[i].sbgp, 1, sampleCount[i]);
}
}
if (auxBuffer == null) {

View File

@@ -11,7 +11,5 @@ public class Constants {
public static final String KEY_THEME_CHANGE = "key_theme_change";
public static final String KEY_MAIN_PAGE_CHANGE = "key_main_page_change";
public static final String KEY_ENABLE_WATCH_HISTORY = "enable_watch_history";
public static final int NO_SERVICE_ID = -1;
}

View File

@@ -48,8 +48,8 @@ import java.util.Locale;
public class Localization {
private static PrettyTime prettyTime;
private static final String DOT_SEPARATOR = "";
private static PrettyTime prettyTime;
private Localization() {
}
@@ -83,14 +83,20 @@ public class Localization {
public static org.schabi.newpipe.extractor.localization.Localization getPreferredLocalization(final Context context) {
final String contentLanguage = PreferenceManager
.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.content_language_key), context.getString(R.string.default_language_value));
.getString(context.getString(R.string.content_language_key), context.getString(R.string.default_localization_key));
if (contentLanguage.equals(context.getString(R.string.default_localization_key))) {
return org.schabi.newpipe.extractor.localization.Localization.fromLocale(Locale.getDefault());
}
return org.schabi.newpipe.extractor.localization.Localization.fromLocalizationCode(contentLanguage);
}
public static ContentCountry getPreferredContentCountry(final Context context) {
final String contentCountry = PreferenceManager
.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.content_country_key), context.getString(R.string.default_country_value));
.getString(context.getString(R.string.content_country_key), context.getString(R.string.default_localization_key));
if (contentCountry.equals(context.getString(R.string.default_localization_key))) {
return new ContentCountry(Locale.getDefault().getCountry());
}
return new ContentCountry(contentCountry);
}
@@ -98,7 +104,7 @@ public class Localization {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String languageCode = sp.getString(context.getString(R.string.content_language_key),
context.getString(R.string.default_language_value));
context.getString(R.string.default_localization_key));
try {
if (languageCode.length() == 2) {
@@ -114,8 +120,7 @@ public class Localization {
}
public static String localizeNumber(Context context, long number) {
Locale locale = getPreferredLocale(context);
NumberFormat nf = NumberFormat.getInstance(locale);
NumberFormat nf = NumberFormat.getInstance(getAppLocale(context));
return nf.format(number);
}
@@ -132,14 +137,14 @@ public class Localization {
return getQuantity(context, R.plurals.views, R.string.no_views, viewCount, localizeNumber(context, viewCount));
}
public static String localizeSubscribersCount(Context context, long subscriberCount) {
return getQuantity(context, R.plurals.subscribers, R.string.no_subscribers, subscriberCount, localizeNumber(context, subscriberCount));
}
public static String localizeStreamCount(Context context, long streamCount) {
return getQuantity(context, R.plurals.videos, R.string.no_videos, streamCount, localizeNumber(context, streamCount));
}
public static String localizeWatchingCount(Context context, long watchingCount) {
return getQuantity(context, R.plurals.watching, R.string.no_one_watching, watchingCount, localizeNumber(context, watchingCount));
}
public static String shortCount(Context context, long count) {
if (count >= 1000000000) {
return Long.toString(count / 1000000000) + context.getString(R.string.short_billion);
@@ -156,7 +161,7 @@ public class Localization {
return getQuantity(context, R.plurals.listening, R.string.no_one_listening, listeningCount, shortCount(context, listeningCount));
}
public static String watchingCount(Context context, long watchingCount) {
public static String shortWatchingCount(Context context, long watchingCount) {
return getQuantity(context, R.plurals.watching, R.string.no_one_watching, watchingCount, shortCount(context, watchingCount));
}
@@ -215,7 +220,9 @@ public class Localization {
}
public static String relativeTime(Calendar calendarTime) {
return getPrettyTime().formatUnrounded(calendarTime);
String time = getPrettyTime().formatUnrounded(calendarTime);
return time.startsWith("-") ? time.substring(1) : time;
//workaround fix for russian showing -1 day ago, -19hrs ago…
}
private static void changeAppLanguage(Locale loc, Resources res) {
@@ -226,10 +233,10 @@ public class Localization {
}
public static Locale getAppLocale(Context context) {
SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context);
String lang = prefs.getString("app_language_key", "en");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String lang = prefs.getString(context.getString(R.string.app_language_key), "en");
Locale loc;
if (lang.equals("system")) {
if (lang.equals(context.getString(R.string.default_localization_key))) {
loc = Locale.getDefault();
} else if (lang.matches(".*-.*")) {
//to differentiate different versions of the language

View File

@@ -44,7 +44,7 @@ public class ServiceHelper {
public static String getTranslatedFilterString(String filter, Context c) {
switch (filter) {
case "all": return c.getString(R.string.all);
case "videos": return c.getString(R.string.videos);
case "videos": return c.getString(R.string.videos_string);
case "channels": return c.getString(R.string.channels);
case "playlists": return c.getString(R.string.playlists);
case "tracks": return c.getString(R.string.tracks);