Revert RecyclerView to LinearLayout

This commit is contained in:
Coffeemakr 2017-06-17 13:43:09 +02:00
parent 6d74038866
commit 89b680f6d9
3 changed files with 61 additions and 22 deletions

View File

@ -51,6 +51,7 @@ import org.schabi.newpipe.ImageErrorLoadingListener;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.stream_info.AudioStream; import org.schabi.newpipe.extractor.stream_info.AudioStream;
@ -97,6 +98,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
private ArrayList<VideoStream> sortedStreamVideosList; private ArrayList<VideoStream> sortedStreamVideosList;
private ActionBarHandler actionBarHandler; private ActionBarHandler actionBarHandler;
private InfoItemBuilder infoItemBuilder = null;
private StreamInfo currentStreamInfo = null; private StreamInfo currentStreamInfo = null;
private StreamExtractorWorker curExtractorWorker; private StreamExtractorWorker curExtractorWorker;
@ -150,9 +152,9 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
private TextView nextStreamTitle; private TextView nextStreamTitle;
private LinearLayout relatedStreamRootLayout; private LinearLayout relatedStreamRootLayout;
private LinearLayout relatedStreamsView;
private ImageButton relatedStreamExpandButton; private ImageButton relatedStreamExpandButton;
private Handler uiHandler; private Handler uiHandler;
private InfoListAdapter relatedStreamsAdapter;
private Handler backgroundHandler; private Handler backgroundHandler;
private HandlerThread backgroundHandlerThread; private HandlerThread backgroundHandlerThread;
@ -214,7 +216,6 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
backgroundHandlerThread = handlerThread; backgroundHandlerThread = handlerThread;
backgroundHandler = new Handler(handlerThread.getLooper(), new BackgroundCallback(uiHandler, getContext())); backgroundHandler = new Handler(handlerThread.getLooper(), new BackgroundCallback(uiHandler, getContext()));
} }
relatedStreamsAdapter = new InfoListAdapter(getActivity());
} }
@Override @Override
@ -274,7 +275,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
public void onDestroyView() { public void onDestroyView() {
if (DEBUG) Log.d(TAG, "onDestroyView() called"); if (DEBUG) Log.d(TAG, "onDestroyView() called");
thumbnailImageView.setImageBitmap(null); thumbnailImageView.setImageBitmap(null);
relatedStreamsAdapter.clearStreamItemList(); relatedStreamsView.removeAllViews();
spinnerToolbar.setOnItemSelectedListener(null); spinnerToolbar.setOnItemSelectedListener(null);
spinnerToolbar = null; spinnerToolbar = null;
@ -310,6 +311,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
nextStreamTitle = null; nextStreamTitle = null;
relatedStreamRootLayout = null; relatedStreamRootLayout = null;
relatedStreamsView = null;
relatedStreamExpandButton = null; relatedStreamExpandButton = null;
super.onDestroyView(); super.onDestroyView();
@ -324,7 +326,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
outState.putSerializable(STACK_KEY, stack); outState.putSerializable(STACK_KEY, stack);
int nextCount = currentStreamInfo != null && currentStreamInfo.next_video != null ? 2 : 0; int nextCount = currentStreamInfo != null && currentStreamInfo.next_video != null ? 2 : 0;
if (relatedStreamsAdapter != null && relatedStreamsAdapter.getItemCount() > INITIAL_RELATED_VIDEOS + nextCount) { if (relatedStreamsView != null && relatedStreamsView.getChildCount() > INITIAL_RELATED_VIDEOS + nextCount) {
outState.putSerializable(WAS_RELATED_EXPANDED_KEY, true); outState.putSerializable(WAS_RELATED_EXPANDED_KEY, true);
} }
@ -487,13 +489,19 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
int nextCount = info.next_video != null ? 2 : 0; int nextCount = info.next_video != null ? 2 : 0;
int initialCount = INITIAL_RELATED_VIDEOS + nextCount; int initialCount = INITIAL_RELATED_VIDEOS + nextCount;
if (relatedStreamsAdapter.getItemCount() > initialCount) { if (relatedStreamsView.getChildCount() > initialCount) {
relatedStreamsAdapter.removeItemRange(initialCount, relatedStreamsAdapter.getItemCount()); relatedStreamsView.removeViews(initialCount, relatedStreamsView.getChildCount() - (initialCount));
relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(activity, getResourceIdFromAttr(R.attr.expand))); relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(activity, getResourceIdFromAttr(R.attr.expand)));
} else { return;
relatedStreamsAdapter.addInfoItemList(info.related_streams.subList(INITIAL_RELATED_VIDEOS, info.related_streams.size()));
relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(activity, getResourceIdFromAttr(R.attr.collapse)));
} }
//Log.d(TAG, "toggleExpandRelatedVideos() called with: info = [" + info + "], from = [" + INITIAL_RELATED_VIDEOS + "]");
for (int i = INITIAL_RELATED_VIDEOS; i < info.related_streams.size(); i++) {
InfoItem item = info.related_streams.get(i);
//Log.d(TAG, "i = " + i);
relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, item));
}
relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(activity, getResourceIdFromAttr(R.attr.collapse)));
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -538,23 +546,21 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
relatedStreamRootLayout = (LinearLayout) rootView.findViewById(R.id.detail_related_streams_root_layout); relatedStreamRootLayout = (LinearLayout) rootView.findViewById(R.id.detail_related_streams_root_layout);
nextStreamTitle = (TextView) rootView.findViewById(R.id.detail_next_stream_title); nextStreamTitle = (TextView) rootView.findViewById(R.id.detail_next_stream_title);
RecyclerView relatedStreamsView = (RecyclerView) rootView.findViewById(R.id.detail_related_streams_view); relatedStreamsView = (LinearLayout) rootView.findViewById(R.id.detail_related_streams_view);
LinearLayoutManager llm = new LinearLayoutManager(rootView.getContext());
llm.setOrientation(LinearLayoutManager.VERTICAL);
relatedStreamsView.setLayoutManager(llm);
relatedStreamsView.setAdapter(relatedStreamsAdapter);
relatedStreamExpandButton = ((ImageButton) rootView.findViewById(R.id.detail_related_streams_expand)); relatedStreamExpandButton = ((ImageButton) rootView.findViewById(R.id.detail_related_streams_expand));
actionBarHandler = new ActionBarHandler(activity); actionBarHandler = new ActionBarHandler(activity);
videoDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); videoDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
infoItemBuilder = new InfoItemBuilder(activity);
setHeightThumbnail(); setHeightThumbnail();
} }
protected void initListeners() { protected void initListeners() {
super.initListeners(); super.initListeners();
relatedStreamsAdapter.setOnStreamInfoItemSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() { infoItemBuilder.setOnStreamInfoItemSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() {
@Override @Override
public void selected(int serviceId, String url, String title) { public void selected(int serviceId, String url, String title) {
//NavigationHelper.openVideoDetail(activity, url, serviceId); //NavigationHelper.openVideoDetail(activity, url, serviceId);
@ -587,18 +593,24 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
} }
private void initRelatedVideos(StreamInfo info) { private void initRelatedVideos(StreamInfo info) {
relatedStreamsAdapter.clearStreamItemList(); if (relatedStreamsView.getChildCount() > 0) relatedStreamsView.removeAllViews();
if (info.next_video != null && showRelatedStreams) { if (info.next_video != null && showRelatedStreams) {
nextStreamTitle.setVisibility(View.VISIBLE); nextStreamTitle.setVisibility(View.VISIBLE);
relatedStreamsAdapter.addInfoItem(info.next_video); relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, info.next_video));
relatedStreamsView.addView(getSeparatorView());
relatedStreamRootLayout.setVisibility(View.VISIBLE); relatedStreamRootLayout.setVisibility(View.VISIBLE);
} else nextStreamTitle.setVisibility(View.GONE); } else nextStreamTitle.setVisibility(View.GONE);
if (info.related_streams != null && !info.related_streams.isEmpty() && showRelatedStreams) { if (info.related_streams != null && !info.related_streams.isEmpty() && showRelatedStreams) {
//long first = System.nanoTime(), each; //long first = System.nanoTime(), each;
int to = info.related_streams.size() >= INITIAL_RELATED_VIDEOS ? INITIAL_RELATED_VIDEOS : info.related_streams.size(); int to = info.related_streams.size() >= INITIAL_RELATED_VIDEOS ? INITIAL_RELATED_VIDEOS : info.related_streams.size();
relatedStreamsAdapter.addInfoItemList(info.related_streams.subList(0, to)); for (int i = 0; i < to; i++) {
InfoItem item = info.related_streams.get(i);
//each = System.nanoTime();
relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, item));
//if (DEBUG) Log.d(TAG, "each took " + ((System.nanoTime() - each) / 1000000L) + "ms");
}
//if (DEBUG) Log.d(TAG, "Total time " + ((System.nanoTime() - first) / 1000000L) + "ms"); //if (DEBUG) Log.d(TAG, "Total time " + ((System.nanoTime() - first) / 1000000L) + "ms");
relatedStreamRootLayout.setVisibility(View.VISIBLE); relatedStreamRootLayout.setVisibility(View.VISIBLE);
@ -611,6 +623,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
} }
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Menu // Menu
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/

View File

@ -117,6 +117,31 @@ public class InfoItemBuilder {
} }
} }
public View buildView(ViewGroup parent, final InfoItem info) {
View itemView = null;
InfoItemHolder holder = null;
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
switch (info.infoType()) {
case STREAM:
//long start = System.nanoTime();
itemView = inflater.inflate(R.layout.stream_item, parent, false);
//Log.d(TAG, "time to inflate: " + ((System.nanoTime() - start) / 1000000L) + "ms");
holder = new StreamInfoItemHolder(itemView);
break;
case CHANNEL:
itemView = inflater.inflate(R.layout.channel_item, parent, false);
holder = new ChannelInfoItemHolder(itemView);
break;
case PLAYLIST:
Log.e(TAG, "Not yet implemented");
default:
Log.e(TAG, "Trollolo");
}
buildByHolder(holder, info);
return itemView;
}
private String getStreamInfoDetailLine(final StreamInfoItem info) { private String getStreamInfoDetailLine(final StreamInfoItem info) {
String viewsAndDate = ""; String viewsAndDate = "";
if(info.view_count >= 0) { if(info.view_count >= 0) {

View File

@ -355,12 +355,13 @@
android:textSize="@dimen/video_item_detail_next_text_size" android:textSize="@dimen/video_item_detail_next_text_size"
tools:ignore="RtlHardcoded"/> tools:ignore="RtlHardcoded"/>
<android.support.v7.widget.RecyclerView <LinearLayout
android:id="@+id/detail_related_streams_view" android:id="@+id/detail_related_streams_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
tools:listitem="@layout/stream_item" /> android:orientation="vertical"
tools:minHeight="50dp"/>
<ImageButton <ImageButton
android:id="@+id/detail_related_streams_expand" android:id="@+id/detail_related_streams_expand"