Merge branch 'dev' into dev

This commit is contained in:
Tobias Groza 2019-04-06 23:23:15 +02:00 committed by GitHub
commit 1afc301432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 15 deletions

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.fragments.detail; package org.schabi.newpipe.fragments.detail;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
@ -61,6 +62,18 @@ public class TabAdaptor extends FragmentPagerAdapter {
else return POSITION_NONE; else return POSITION_NONE;
} }
public int getItemPositionByTitle(String title) {
return mFragmentTitleList.indexOf(title);
}
@Nullable
public String getItemTitle(int position) {
if (position < 0 || position >= mFragmentTitleList.size()) {
return null;
}
return mFragmentTitleList.get(position);
}
public void notifyDataSetUpdate(){ public void notifyDataSetUpdate(){
notifyDataSetChanged(); notifyDataSetChanged();
} }

View File

@ -122,6 +122,7 @@ public class VideoDetailFragment
private boolean autoPlayEnabled; private boolean autoPlayEnabled;
private boolean showRelatedStreams; private boolean showRelatedStreams;
private boolean showComments; private boolean showComments;
private String selectedTabTag;
@State @State
protected int serviceId = Constants.NO_SERVICE_ID; protected int serviceId = Constants.NO_SERVICE_ID;
@ -213,6 +214,9 @@ public class VideoDetailFragment
showComments = PreferenceManager.getDefaultSharedPreferences(activity) showComments = PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(getString(R.string.show_comments_key), true); .getBoolean(getString(R.string.show_comments_key), true);
selectedTabTag = PreferenceManager.getDefaultSharedPreferences(activity)
.getString(getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG);
PreferenceManager.getDefaultSharedPreferences(activity) PreferenceManager.getDefaultSharedPreferences(activity)
.registerOnSharedPreferenceChangeListener(this); .registerOnSharedPreferenceChangeListener(this);
} }
@ -226,6 +230,10 @@ public class VideoDetailFragment
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (currentWorker != null) currentWorker.dispose(); if (currentWorker != null) currentWorker.dispose();
PreferenceManager.getDefaultSharedPreferences(getContext())
.edit()
.putString(getString(R.string.stream_info_selected_tab_key), pageAdapter.getItemTitle(viewPager.getCurrentItem()))
.apply();
} }
@Override @Override
@ -815,6 +823,9 @@ public class VideoDetailFragment
} }
private void initTabs() { private void initTabs() {
if (pageAdapter.getCount() != 0) {
selectedTabTag = pageAdapter.getItemTitle(viewPager.getCurrentItem());
}
pageAdapter.clearAllItems(); pageAdapter.clearAllItems();
if(shouldShowComments()){ if(shouldShowComments()){
@ -835,6 +846,8 @@ public class VideoDetailFragment
if(pageAdapter.getCount() < 2){ if(pageAdapter.getCount() < 2){
tabLayout.setVisibility(View.GONE); tabLayout.setVisibility(View.GONE);
}else{ }else{
int position = pageAdapter.getItemPositionByTitle(selectedTabTag);
if(position != -1) viewPager.setCurrentItem(position);
tabLayout.setVisibility(View.VISIBLE); tabLayout.setVisibility(View.VISIBLE);
} }
} }

View File

@ -6,6 +6,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
@ -45,7 +46,7 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
if(hours != null) timestamp += (Integer.parseInt(hours.replace(":", ""))*3600); if(hours != null) timestamp += (Integer.parseInt(hours.replace(":", ""))*3600);
if(minutes != null) timestamp += (Integer.parseInt(minutes.replace(":", ""))*60); if(minutes != null) timestamp += (Integer.parseInt(minutes.replace(":", ""))*60);
if(seconds != null) timestamp += (Integer.parseInt(seconds)); if(seconds != null) timestamp += (Integer.parseInt(seconds));
return streamUrl + url.replace(match.group(0), "&t=" + String.valueOf(timestamp)); return streamUrl + url.replace(match.group(0), "#timestamp=" + String.valueOf(timestamp));
} }
}; };
@ -76,6 +77,7 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
itemThumbnailView.setOnClickListener(new View.OnClickListener() { itemThumbnailView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if(StringUtil.isBlank(item.getAuthorEndpoint())) return;
try { try {
final AppCompatActivity activity = (AppCompatActivity) itemBuilder.getContext(); final AppCompatActivity activity = (AppCompatActivity) itemBuilder.getContext();
NavigationHelper.openChannelFragment( NavigationHelper.openChannelFragment(
@ -91,10 +93,9 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
streamUrl = item.getUrl(); streamUrl = item.getUrl();
itemContentView.setMaxLines(commentDefaultLines); itemContentView.setLines(commentDefaultLines);
commentText = item.getCommentText(); commentText = item.getCommentText();
itemContentView.setText(commentText); itemContentView.setText(commentText);
linkify();
itemContentView.setOnTouchListener(CommentTextOnTouchListener.INSTANCE); itemContentView.setOnTouchListener(CommentTextOnTouchListener.INSTANCE);
if (itemContentView.getLineCount() == 0) { if (itemContentView.getLineCount() == 0) {
@ -119,15 +120,17 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
private void ellipsize() { private void ellipsize() {
if (itemContentView.getLineCount() > commentDefaultLines){ if (itemContentView.getLineCount() > commentDefaultLines){
int endOfLastLine = itemContentView.getLayout().getLineEnd(commentDefaultLines - 1); int endOfLastLine = itemContentView.getLayout().getLineEnd(commentDefaultLines - 1);
String newVal = itemContentView.getText().subSequence(0, endOfLastLine - 3) + "..."; int end = itemContentView.getText().toString().lastIndexOf(' ', endOfLastLine -2);
if(end == -1) end = Math.max(endOfLastLine -2, 0);
String newVal = itemContentView.getText().subSequence(0, end) + "";
itemContentView.setText(newVal); itemContentView.setText(newVal);
linkify();
} }
linkify();
} }
private void toggleEllipsize() { private void toggleEllipsize() {
if (itemContentView.getText().toString().equals(commentText)) { if (itemContentView.getText().toString().equals(commentText)) {
ellipsize(); if (itemContentView.getLineCount() > commentDefaultLines) ellipsize();
} else { } else {
expand(); expand();
} }

View File

@ -269,6 +269,18 @@ public abstract class BasePlayer implements
final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE, final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE,
getPlaybackSkipSilence()); getPlaybackSkipSilence());
// seek to timestamp if stream is already playing
if (simpleExoPlayer != null
&& queue.size() == 1
&& playQueue != null
&& playQueue.getItem() != null
&& queue.getItem().getUrl().equals(playQueue.getItem().getUrl())
&& queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET
) {
simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition());
return;
}
// Good to go... // Good to go...
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true); /*playOnInit=*/true);

View File

@ -16,6 +16,11 @@ public final class SinglePlayQueue extends PlayQueue {
super(0, Collections.singletonList(new PlayQueueItem(info))); super(0, Collections.singletonList(new PlayQueueItem(info)));
} }
public SinglePlayQueue(final StreamInfo info, final long startPosition) {
super(0, Collections.singletonList(new PlayQueueItem(info)));
getItem().setRecoveryPosition(startPosition);
}
public SinglePlayQueue(final List<StreamInfoItem> items, final int index) { public SinglePlayQueue(final List<StreamInfoItem> items, final int index) {
super(index, playQueueItemsOf(items)); super(index, playQueueItemsOf(items));
} }

View File

@ -31,7 +31,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
public static final CommentTextOnTouchListener INSTANCE = new CommentTextOnTouchListener(); 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 @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
@ -86,6 +86,12 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
private boolean handleUrl(Context context, URLSpan urlSpan) { private boolean handleUrl(Context context, URLSpan urlSpan) {
String url = urlSpan.getURL(); 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 service;
StreamingService.LinkType linkType; StreamingService.LinkType linkType;
try { try {
@ -97,9 +103,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
if(linkType == StreamingService.LinkType.NONE){ if(linkType == StreamingService.LinkType.NONE){
return false; return false;
} }
Matcher matcher = timestampPattern.matcher(url); if(linkType == StreamingService.LinkType.STREAM && seconds != -1){
if(linkType == StreamingService.LinkType.STREAM && matcher.matches()){
int seconds = Integer.parseInt(matcher.group(1));
return playOnPopup(context, url, service, seconds); return playOnPopup(context, url, service, seconds);
}else{ }else{
NavigationHelper.openRouterActivity(context, url); NavigationHelper.openRouterActivity(context, url);
@ -119,9 +123,8 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
single.subscribeOn(Schedulers.io()) single.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(info -> { .subscribe(info -> {
PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info); PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info, seconds*1000);
((StreamInfo) info).setStartPosition(seconds); NavigationHelper.playOnPopupPlayer(context, playQueue);
NavigationHelper.enqueueOnPopupPlayer(context, playQueue, true);
}); });
return true; return true;
} }

View File

@ -139,6 +139,7 @@
<string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string> <string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string>
<string name="show_next_video_key" translatable="false">show_next_video</string> <string name="show_next_video_key" translatable="false">show_next_video</string>
<string name="show_comments_key" translatable="false">show_comments</string> <string name="show_comments_key" translatable="false">show_comments</string>
<string name="stream_info_selected_tab_key" translatable="false">stream_info_selected_tab</string>
<string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string> <string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string>
<string name="default_language_value">en</string> <string name="default_language_value">en</string>
<string name="default_country_value">GB</string> <string name="default_country_value">GB</string>