merged upstream/dev
This commit is contained in:
commit
b6be586766
361 changed files with 16088 additions and 11403 deletions
|
|
@ -24,10 +24,10 @@ import android.animation.AnimatorListenerAdapter;
|
|||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
|||
|
||||
public static final CommentTextOnTouchListener INSTANCE = new CommentTextOnTouchListener();
|
||||
|
||||
private static final Pattern timestampPattern = Pattern.compile(".*&t=(\\d+)");
|
||||
private static final Pattern timestampPattern = Pattern.compile("(.*)#timestamp=(\\d+)");
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
|
|
@ -86,6 +86,12 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
|||
|
||||
private boolean handleUrl(Context context, URLSpan urlSpan) {
|
||||
String url = urlSpan.getURL();
|
||||
int seconds = -1;
|
||||
Matcher matcher = timestampPattern.matcher(url);
|
||||
if(matcher.matches()){
|
||||
url = matcher.group(1);
|
||||
seconds = Integer.parseInt(matcher.group(2));
|
||||
}
|
||||
StreamingService service;
|
||||
StreamingService.LinkType linkType;
|
||||
try {
|
||||
|
|
@ -97,9 +103,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
|||
if(linkType == StreamingService.LinkType.NONE){
|
||||
return false;
|
||||
}
|
||||
Matcher matcher = timestampPattern.matcher(url);
|
||||
if(linkType == StreamingService.LinkType.STREAM && matcher.matches()){
|
||||
int seconds = Integer.parseInt(matcher.group(1));
|
||||
if(linkType == StreamingService.LinkType.STREAM && seconds != -1){
|
||||
return playOnPopup(context, url, service, seconds);
|
||||
}else{
|
||||
NavigationHelper.openRouterActivity(context, url);
|
||||
|
|
@ -119,9 +123,8 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
|||
single.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(info -> {
|
||||
PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info);
|
||||
((StreamInfo) info).setStartPosition(seconds);
|
||||
NavigationHelper.enqueueOnPopupPlayer(context, playQueue, true);
|
||||
PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info, seconds*1000);
|
||||
NavigationHelper.playOnPopupPlayer(context, playQueue, false);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,6 +228,10 @@ public final class ExtractorHelper {
|
|||
});
|
||||
}
|
||||
|
||||
public static boolean isCached(final int serviceId, final String url, InfoItem.InfoType infoType) {
|
||||
return null != loadFromCache(serviceId, url, infoType).blockingGet();
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple and general error handler that show a Toast for known exceptions, and for others, opens the report error activity with the (optional) error message.
|
||||
*/
|
||||
|
|
@ -243,8 +247,6 @@ public final class ExtractorHelper {
|
|||
context.startActivity(intent);
|
||||
} else if (exception instanceof IOException) {
|
||||
Toast.makeText(context, R.string.network_error, Toast.LENGTH_LONG).show();
|
||||
} else if (exception instanceof YoutubeStreamExtractor.GemaException) {
|
||||
Toast.makeText(context, R.string.blocked_by_gema, Toast.LENGTH_LONG).show();
|
||||
} else if (exception instanceof ContentNotAvailableException) {
|
||||
Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
public class FallbackViewHolder extends RecyclerView.ViewHolder {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ package org.schabi.newpipe.util;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.util.SortedList;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.loader.content.Loader;
|
||||
import androidx.recyclerview.widget.SortedList;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -29,7 +30,7 @@ public class FilePickerActivityHelper extends com.nononsenseapps.filepicker.File
|
|||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
if(ThemeHelper.isLightThemeSelected(this)) {
|
||||
if (ThemeHelper.isLightThemeSelected(this)) {
|
||||
this.setTheme(R.style.FilePickerThemeLight);
|
||||
} else {
|
||||
this.setTheme(R.style.FilePickerThemeDark);
|
||||
|
|
@ -73,6 +74,11 @@ public class FilePickerActivityHelper extends com.nononsenseapps.filepicker.File
|
|||
.putExtra(FilePickerActivityHelper.EXTRA_MODE, FilePickerActivityHelper.MODE_NEW_FILE);
|
||||
}
|
||||
|
||||
public static boolean isOwnFileUri(@NonNull Context context, @NonNull Uri uri) {
|
||||
if (uri.getAuthority() == null) return false;
|
||||
return uri.getAuthority().startsWith(context.getPackageName());
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Internal
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
|
@ -109,6 +115,12 @@ public class FilePickerActivityHelper extends com.nononsenseapps.filepicker.File
|
|||
super.onClickOk(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isItemVisible(@NonNull File file) {
|
||||
if (file.isDirectory() && file.isHidden()) return true;
|
||||
return super.isItemVisible(file);
|
||||
}
|
||||
|
||||
public File getBackTop() {
|
||||
if (getArguments() == null) return Environment.getExternalStorageDirectory();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class FilenameUtils {
|
||||
|
||||
private static final String CHARSET_MOST_SPECIAL = "[\\n\\r|?*<\":\\\\>/']+";
|
||||
private static final String CHARSET_ONLY_LETTERS_AND_DIGITS = "[^\\w\\d]+";
|
||||
|
||||
/**
|
||||
* #143 #44 #42 #22: make sure that the filename does not contain illegal chars.
|
||||
* @param context the context to retrieve strings and preferences from
|
||||
|
|
@ -18,11 +21,28 @@ public class FilenameUtils {
|
|||
*/
|
||||
public static String createFilename(Context context, String title) {
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final String key = context.getString(R.string.settings_file_charset_key);
|
||||
final String value = sharedPreferences.getString(key, context.getString(R.string.default_file_charset_value));
|
||||
Pattern pattern = Pattern.compile(value);
|
||||
|
||||
final String charset_ld = context.getString(R.string.charset_letters_and_digits_value);
|
||||
final String charset_ms = context.getString(R.string.charset_most_special_value);
|
||||
final String defaultCharset = context.getString(R.string.default_file_charset_value);
|
||||
|
||||
final String replacementChar = sharedPreferences.getString(context.getString(R.string.settings_file_replacement_character_key), "_");
|
||||
String selectedCharset = sharedPreferences.getString(context.getString(R.string.settings_file_charset_key), null);
|
||||
|
||||
final String charset;
|
||||
|
||||
if (selectedCharset == null || selectedCharset.isEmpty()) selectedCharset = defaultCharset;
|
||||
|
||||
if (selectedCharset.equals(charset_ld)) {
|
||||
charset = CHARSET_ONLY_LETTERS_AND_DIGITS;
|
||||
} else if (selectedCharset.equals(charset_ms)) {
|
||||
charset = CHARSET_MOST_SPECIAL;
|
||||
} else {
|
||||
charset = selectedCharset;// ¿is the user using a custom charset?
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile(charset);
|
||||
|
||||
return createFilename(title, pattern, replacementChar);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.collection.LruCache;
|
||||
import android.util.Log;
|
||||
|
||||
import org.schabi.newpipe.MainActivity;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package org.schabi.newpipe.util;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.PointF;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.LinearSmoothScroller;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearSmoothScroller;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class LayoutManagerSmoothScroller extends LinearLayoutManager {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.StringRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
|
|
@ -430,24 +430,26 @@ public final class ListHelper {
|
|||
*/
|
||||
private static String getResolutionLimit(Context context) {
|
||||
String resolutionLimit = null;
|
||||
if (!isWifiActive(context)) {
|
||||
if (isMeteredNetwork(context)) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String defValue = context.getString(R.string.limit_data_usage_none_key);
|
||||
String value = preferences.getString(
|
||||
context.getString(R.string.limit_mobile_data_usage_key), defValue);
|
||||
resolutionLimit = value.equals(defValue) ? null : value;
|
||||
resolutionLimit = defValue.equals(value) ? null : value;
|
||||
}
|
||||
return resolutionLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we connected to wifi?
|
||||
* The current network is metered (like mobile data)?
|
||||
* @param context App context
|
||||
* @return {@code true} if connected to wifi
|
||||
* @return {@code true} if connected to a metered network
|
||||
*/
|
||||
private static boolean isWifiActive(Context context)
|
||||
private static boolean isMeteredNetwork(Context context)
|
||||
{
|
||||
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return manager != null && manager.getActiveNetworkInfo() != null && manager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
|
||||
if (manager == null || manager.getActiveNetworkInfo() == null) return false;
|
||||
|
||||
return manager.isActiveNetworkMetered();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.PluralsRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.annotation.StringRes;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
@ -69,12 +69,14 @@ public class NavigationHelper {
|
|||
public static Intent getPlayerIntent(@NonNull final Context context,
|
||||
@NonNull final Class targetClazz,
|
||||
@NonNull final PlayQueue playQueue,
|
||||
@Nullable final String quality) {
|
||||
@Nullable final String quality,
|
||||
final boolean resumePlayback) {
|
||||
Intent intent = new Intent(context, targetClazz);
|
||||
|
||||
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);
|
||||
if (cacheKey != null) intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey);
|
||||
if (quality != null) intent.putExtra(VideoPlayer.PLAYBACK_QUALITY, quality);
|
||||
intent.putExtra(VideoPlayer.RESUME_PLAYBACK, resumePlayback);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
|
@ -82,16 +84,18 @@ public class NavigationHelper {
|
|||
@NonNull
|
||||
public static Intent getPlayerIntent(@NonNull final Context context,
|
||||
@NonNull final Class targetClazz,
|
||||
@NonNull final PlayQueue playQueue) {
|
||||
return getPlayerIntent(context, targetClazz, playQueue, null);
|
||||
@NonNull final PlayQueue playQueue,
|
||||
final boolean resumePlayback) {
|
||||
return getPlayerIntent(context, targetClazz, playQueue, null, resumePlayback);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Intent getPlayerEnqueueIntent(@NonNull final Context context,
|
||||
@NonNull final Class targetClazz,
|
||||
@NonNull final PlayQueue playQueue,
|
||||
final boolean selectOnAppend) {
|
||||
return getPlayerIntent(context, targetClazz, playQueue)
|
||||
final boolean selectOnAppend,
|
||||
final boolean resumePlayback) {
|
||||
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
|
||||
.putExtra(BasePlayer.APPEND_ONLY, true)
|
||||
.putExtra(BasePlayer.SELECT_ON_APPEND, selectOnAppend);
|
||||
}
|
||||
|
|
@ -104,40 +108,41 @@ public class NavigationHelper {
|
|||
final float playbackSpeed,
|
||||
final float playbackPitch,
|
||||
final boolean playbackSkipSilence,
|
||||
@Nullable final String playbackQuality) {
|
||||
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality)
|
||||
@Nullable final String playbackQuality,
|
||||
final boolean resumePlayback) {
|
||||
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback)
|
||||
.putExtra(BasePlayer.REPEAT_MODE, repeatMode)
|
||||
.putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed)
|
||||
.putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch)
|
||||
.putExtra(BasePlayer.PLAYBACK_SKIP_SILENCE, playbackSkipSilence);
|
||||
}
|
||||
|
||||
public static void playOnMainPlayer(final Context context, final PlayQueue queue) {
|
||||
final Intent playerIntent = getPlayerIntent(context, MainVideoPlayer.class, queue);
|
||||
public static void playOnMainPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {
|
||||
final Intent playerIntent = getPlayerIntent(context, MainVideoPlayer.class, queue, resumePlayback);
|
||||
playerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(playerIntent);
|
||||
}
|
||||
|
||||
public static void playOnPopupPlayer(final Context context, final PlayQueue queue) {
|
||||
public static void playOnPopupPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {
|
||||
if (!PermissionHelper.isPopupEnabled(context)) {
|
||||
PermissionHelper.showPopupEnablementToast(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
|
||||
startService(context, getPlayerIntent(context, PopupVideoPlayer.class, queue));
|
||||
startService(context, getPlayerIntent(context, PopupVideoPlayer.class, queue, resumePlayback));
|
||||
}
|
||||
|
||||
public static void playOnBackgroundPlayer(final Context context, final PlayQueue queue) {
|
||||
public static void playOnBackgroundPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {
|
||||
Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT).show();
|
||||
startService(context, getPlayerIntent(context, BackgroundPlayer.class, queue));
|
||||
startService(context, getPlayerIntent(context, BackgroundPlayer.class, queue, resumePlayback));
|
||||
}
|
||||
|
||||
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue) {
|
||||
enqueueOnPopupPlayer(context, queue, false);
|
||||
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {
|
||||
enqueueOnPopupPlayer(context, queue, false, resumePlayback);
|
||||
}
|
||||
|
||||
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue, boolean selectOnAppend) {
|
||||
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue, boolean selectOnAppend, final boolean resumePlayback) {
|
||||
if (!PermissionHelper.isPopupEnabled(context)) {
|
||||
PermissionHelper.showPopupEnablementToast(context);
|
||||
return;
|
||||
|
|
@ -145,17 +150,17 @@ public class NavigationHelper {
|
|||
|
||||
Toast.makeText(context, R.string.popup_playing_append, Toast.LENGTH_SHORT).show();
|
||||
startService(context,
|
||||
getPlayerEnqueueIntent(context, PopupVideoPlayer.class, queue, selectOnAppend));
|
||||
getPlayerEnqueueIntent(context, PopupVideoPlayer.class, queue, selectOnAppend, resumePlayback));
|
||||
}
|
||||
|
||||
public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue) {
|
||||
enqueueOnBackgroundPlayer(context, queue, false);
|
||||
public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {
|
||||
enqueueOnBackgroundPlayer(context, queue, false, resumePlayback);
|
||||
}
|
||||
|
||||
public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue, boolean selectOnAppend) {
|
||||
public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue, boolean selectOnAppend, final boolean resumePlayback) {
|
||||
Toast.makeText(context, R.string.background_player_append, Toast.LENGTH_SHORT).show();
|
||||
startService(context,
|
||||
getPlayerEnqueueIntent(context, BackgroundPlayer.class, queue, selectOnAppend));
|
||||
getPlayerEnqueueIntent(context, BackgroundPlayer.class, queue, selectOnAppend, resumePlayback));
|
||||
}
|
||||
|
||||
public static void startService(@NonNull final Context context, @NonNull final Intent intent) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public abstract class OnClickGesture<T> {
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import android.content.pm.PackageManager;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import android.view.Gravity;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
|
@ -21,10 +21,9 @@ public class PermissionHelper {
|
|||
public static final int DOWNLOAD_DIALOG_REQUEST_CODE = 778;
|
||||
public static final int DOWNLOADS_REQUEST_CODE = 777;
|
||||
|
||||
|
||||
public static boolean checkStoragePermissions(Activity activity, int requestCode) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
if(!checkReadStoragePermissions(activity, requestCode)) return false;
|
||||
if (!checkReadStoragePermissions(activity, requestCode)) return false;
|
||||
}
|
||||
return checkWriteStoragePermissions(activity, requestCode);
|
||||
}
|
||||
|
|
@ -92,7 +91,7 @@ public class PermissionHelper {
|
|||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(i);
|
||||
return false;
|
||||
}else return true;
|
||||
} else return true;
|
||||
}
|
||||
|
||||
public static boolean isPopupEnabled(Context context) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
|
|
@ -38,7 +38,7 @@ public class SecondaryStreamHelper<T extends Stream> {
|
|||
public static AudioStream getAudioStreamFor(@NonNull List<AudioStream> audioStreams, @NonNull VideoStream videoStream) {
|
||||
switch (videoStream.getFormat()) {
|
||||
case WEBM:
|
||||
case MPEG_4:
|
||||
case MPEG_4:// ¿is mpeg-4 DASH?
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.collection.LruCache;
|
||||
import android.util.Log;
|
||||
|
||||
import org.schabi.newpipe.MainActivity;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package org.schabi.newpipe.util;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
|
|
|
|||
22
app/src/main/java/org/schabi/newpipe/util/ShareUtils.java
Normal file
22
app/src/main/java/org/schabi/newpipe/util/ShareUtils.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
|
||||
public class ShareUtils {
|
||||
public static void openUrlInBrowser(Context context, String url) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
context.startActivity(Intent.createChooser(intent, context.getString(R.string.share_dialog_title)));
|
||||
}
|
||||
|
||||
public static void shareUrl(Context context, String subject, String url) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
context.startActivity(Intent.createChooser(intent, context.getString(R.string.share_dialog_title)));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
public abstract class SparseArrayUtils {
|
||||
|
||||
public static <T> void shiftItemsDown(SparseArray<T> sparseArray, int lower, int upper) {
|
||||
for (int i = lower + 1; i <= upper; i++) {
|
||||
final T o = sparseArray.get(i);
|
||||
sparseArray.put(i - 1, o);
|
||||
sparseArray.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void shiftItemsUp(SparseArray<T> sparseArray, int lower, int upper) {
|
||||
for (int i = upper - 1; i >= lower; i--) {
|
||||
final T o = sparseArray.get(i);
|
||||
sparseArray.put(i + 1, o);
|
||||
sparseArray.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> int[] getKeys(SparseArray<T> sparseArray) {
|
||||
final int[] result = new int[sparseArray.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = sparseArray.keyAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,8 +24,8 @@ import android.content.Context;
|
|||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
|
|
|
|||
109
app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
Normal file
109
app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public enum StreamDialogEntry {
|
||||
//////////////////////////////////////
|
||||
// enum values with DEFAULT actions //
|
||||
//////////////////////////////////////
|
||||
|
||||
enqueue_on_background(R.string.enqueue_on_background, (fragment, item) ->
|
||||
NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), false)),
|
||||
|
||||
enqueue_on_popup(R.string.enqueue_on_popup, (fragment, item) ->
|
||||
NavigationHelper.enqueueOnPopupPlayer(fragment.getContext(), new SinglePlayQueue(item), false)),
|
||||
|
||||
start_here_on_background(R.string.start_here_on_background, (fragment, item) ->
|
||||
NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), true)),
|
||||
|
||||
start_here_on_popup(R.string.start_here_on_popup, (fragment, item) ->
|
||||
NavigationHelper.playOnPopupPlayer(fragment.getContext(), new SinglePlayQueue(item), true)),
|
||||
|
||||
set_as_playlist_thumbnail(R.string.set_as_playlist_thumbnail, (fragment, item) -> {}), // has to be set manually
|
||||
|
||||
delete(R.string.delete, (fragment, item) -> {}), // has to be set manually
|
||||
|
||||
append_playlist(R.string.append_playlist, (fragment, item) -> {
|
||||
if (fragment.getFragmentManager() != null) {
|
||||
PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
|
||||
.show(fragment.getFragmentManager(), "StreamDialogEntry@append_playlist");
|
||||
}}),
|
||||
|
||||
share(R.string.share, (fragment, item) ->
|
||||
ShareUtils.shareUrl(fragment.getContext(), item.getName(), item.getUrl()));
|
||||
|
||||
|
||||
///////////////
|
||||
// variables //
|
||||
///////////////
|
||||
|
||||
public interface StreamDialogEntryAction {
|
||||
void onClick(Fragment fragment, final StreamInfoItem infoItem);
|
||||
}
|
||||
|
||||
private final int resource;
|
||||
private final StreamDialogEntryAction defaultAction;
|
||||
private StreamDialogEntryAction customAction;
|
||||
|
||||
private static StreamDialogEntry[] enabledEntries;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// non-static methods to initialize and edit entries //
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
StreamDialogEntry(final int resource, StreamDialogEntryAction defaultAction) {
|
||||
this.resource = resource;
|
||||
this.defaultAction = defaultAction;
|
||||
this.customAction = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used after {@link #setEnabledEntries(StreamDialogEntry...)} has been called
|
||||
*/
|
||||
public void setCustomAction(StreamDialogEntryAction action) {
|
||||
this.customAction = action;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// static methods that act on enabled entries //
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* To be called before using {@link #setCustomAction(StreamDialogEntryAction)}
|
||||
*/
|
||||
public static void setEnabledEntries(StreamDialogEntry... entries) {
|
||||
// cleanup from last time StreamDialogEntry was used
|
||||
for (StreamDialogEntry streamDialogEntry : values()) {
|
||||
streamDialogEntry.customAction = null;
|
||||
}
|
||||
|
||||
enabledEntries = entries;
|
||||
}
|
||||
|
||||
public static String[] getCommands(Context context) {
|
||||
String[] commands = new String[enabledEntries.length];
|
||||
for (int i = 0; i != enabledEntries.length; ++i) {
|
||||
commands[i] = context.getResources().getString(enabledEntries[i].resource);
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static void clickOn(int which, Fragment fragment, StreamInfoItem infoItem) {
|
||||
if (enabledEntries[which].customAction == null) {
|
||||
enabledEntries[which].defaultAction.onClick(fragment, infoItem);
|
||||
} else {
|
||||
enabledEntries[which].customAction.onClick(fragment, infoItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,9 +22,9 @@ package org.schabi.newpipe.util;
|
|||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue