From 557bcc40ef67fcfc38a03fb499135927d7b26c09 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 3 Aug 2016 00:54:03 +0200 Subject: [PATCH] made detail fragment use recycler view --- .../newpipe/detail/StreamInfoWorker.java | 2 - .../detail/VideoItemDetailFragment.java | 47 +++++++++---------- .../InfoItemHolder.java} | 6 +-- .../InfoListAdapter.java} | 12 ++--- .../SearchInfoItemFragment.java | 13 ++--- .../layout-v18/fragment_videoitem_detail.xml | 10 ++-- .../res/layout/fragment_videoitem_detail.xml | 6 +-- 7 files changed, 45 insertions(+), 51 deletions(-) rename app/src/main/java/org/schabi/newpipe/{search_fragment/StreamInfoItemHolder.java => info_list/InfoItemHolder.java} (86%) rename app/src/main/java/org/schabi/newpipe/{search_fragment/StreamInfoListAdapter.java => info_list/InfoListAdapter.java} (93%) diff --git a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java index e5bb29618..4b94feca8 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java +++ b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java @@ -2,7 +2,6 @@ package org.schabi.newpipe.detail; import android.app.Activity; import android.os.Handler; -import android.preference.PreferenceManager; import android.util.Log; import android.view.View; @@ -15,7 +14,6 @@ import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; -import org.schabi.newpipe.search_fragment.StreamInfoListAdapter; import java.io.IOException; diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java index 65a5437cf..e39228ebf 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -10,12 +10,13 @@ import android.graphics.Point; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.preference.PreferenceManager; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.text.Html; import android.text.method.LinkMovementMethod; import android.util.Log; @@ -28,15 +29,12 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; import android.view.MenuItem; import android.widget.Toast; -import java.io.IOException; - import com.google.android.exoplayer.util.Util; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; @@ -48,7 +46,6 @@ import java.util.Vector; import org.schabi.newpipe.ActivityCommunicator; import org.schabi.newpipe.ChannelActivity; -import org.schabi.newpipe.Downloader; import org.schabi.newpipe.ErrorActivity; import org.schabi.newpipe.ImageErrorLoadingListener; import org.schabi.newpipe.Localization; @@ -57,14 +54,11 @@ import org.schabi.newpipe.StreamInfoItemViewCreator; import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.extractor.AudioStream; import org.schabi.newpipe.extractor.MediaFormat; -import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.ServiceList; -import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.StreamPreviewInfo; -import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.VideoStream; -import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; +import org.schabi.newpipe.info_list.InfoListAdapter; import org.schabi.newpipe.player.BackgroundPlayer; import org.schabi.newpipe.player.PlayVideoActivity; import org.schabi.newpipe.player.ExoPlayerActivity; @@ -123,6 +117,7 @@ public class VideoItemDetailFragment extends Fragment { private View rootView = null; + private InfoListAdapter similarStreamsAdapter = null; public interface OnInvokeCreateOptionsMenuListener { void createOptionsMenu(); @@ -275,7 +270,7 @@ public class VideoItemDetailFragment extends Fragment { initSimilarVideos(info, videoItemViewCreator); } else { activity.findViewById(R.id.detailSimilarTitle).setVisibility(View.GONE); - activity.findViewById(R.id.similarVideosView).setVisibility(View.GONE); + activity.findViewById(R.id.similar_streams_view).setVisibility(View.GONE); } setupActionBarHandler(info); @@ -556,17 +551,7 @@ public class VideoItemDetailFragment extends Fragment { } private void initSimilarVideos(final StreamInfo info, StreamInfoItemViewCreator videoItemViewCreator) { - LinearLayout similarLayout = (LinearLayout) activity.findViewById(R.id.similarVideosView); - ArrayList similarStreamsList = new ArrayList<>(info.related_streams); - - for (final StreamPreviewInfo item : similarStreamsList) { - View itemView = videoItemViewCreator - .getViewFromVideoInfoItem(null, similarLayout, item); - - itemView = videoItemViewCreator.setupView(itemView, item); - - similarLayout.addView(itemView); - } + similarStreamsAdapter.addVideoList(info.related_streams); } private void onErrorBlockedByGema() { @@ -720,6 +705,21 @@ public class VideoItemDetailFragment extends Fragment { } }); } + + similarStreamsAdapter = new InfoListAdapter(getActivity(), rootView); + RecyclerView rv = (RecyclerView) getActivity().findViewById(R.id.similar_streams_view); + rv.setLayoutManager(new LinearLayoutManager(getActivity())); + rv.setAdapter(similarStreamsAdapter); + similarStreamsAdapter.setOnItemSelectedListener(new InfoListAdapter.OnItemSelectedListener() { + @Override + public void selected(String url) { + Intent detailIntent = new Intent(activity, VideoItemDetailActivity.class); + detailIntent.putExtra(VideoItemDetailFragment.VIDEO_URL, url); + detailIntent.putExtra( + VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId); + activity.startActivity(detailIntent); + } + }); } } @@ -821,9 +821,4 @@ public class VideoItemDetailFragment extends Fragment { Toast.makeText(VideoItemDetailFragment.this.getActivity(), stringResource, Toast.LENGTH_LONG).show(); } - - private void postNewErrorToast(final String message) { - Toast.makeText(VideoItemDetailFragment.this.getActivity(), - message, Toast.LENGTH_LONG).show(); - } } \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/StreamInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemHolder.java similarity index 86% rename from app/src/main/java/org/schabi/newpipe/search_fragment/StreamInfoItemHolder.java rename to app/src/main/java/org/schabi/newpipe/info_list/InfoItemHolder.java index 660fa1022..481f383c0 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/StreamInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemHolder.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.search_fragment; +package org.schabi.newpipe.info_list; import android.support.v7.widget.RecyclerView; import android.view.View; @@ -10,7 +10,7 @@ import org.schabi.newpipe.R; /** * Created by the-scrabi on 01.08.16. */ -public class StreamInfoItemHolder extends RecyclerView.ViewHolder { +public class InfoItemHolder extends RecyclerView.ViewHolder { public ImageView itemThumbnailView; public TextView itemVideoTitleView, @@ -20,7 +20,7 @@ public class StreamInfoItemHolder extends RecyclerView.ViewHolder { itemViewCountView; public View mainLayout; - public StreamInfoItemHolder(View v) { + public InfoItemHolder(View v) { super(v); itemThumbnailView = (ImageView) v.findViewById(R.id.itemThumbnailView); itemVideoTitleView = (TextView) v.findViewById(R.id.itemVideoTitleView); diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/StreamInfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java similarity index 93% rename from app/src/main/java/org/schabi/newpipe/search_fragment/StreamInfoListAdapter.java rename to app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 89f006432..75d25e5ee 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/StreamInfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.search_fragment; +package org.schabi.newpipe.info_list; import android.app.Activity; import android.support.v7.widget.RecyclerView; @@ -21,7 +21,7 @@ import java.util.Vector; /** * Created by the-scrabi on 01.08.16. */ -public class StreamInfoListAdapter extends RecyclerView.Adapter { +public class InfoListAdapter extends RecyclerView.Adapter { public interface OnItemSelectedListener { void selected(String url); @@ -37,7 +37,7 @@ public class StreamInfoListAdapter extends RecyclerView.Adapter - - + diff --git a/app/src/main/res/layout/fragment_videoitem_detail.xml b/app/src/main/res/layout/fragment_videoitem_detail.xml index 3ba3168a2..52786333b 100644 --- a/app/src/main/res/layout/fragment_videoitem_detail.xml +++ b/app/src/main/res/layout/fragment_videoitem_detail.xml @@ -267,13 +267,13 @@ android:text="@string/similar_videos_btn_text" android:layout_below="@id/detailNextVidButtonAndContentLayout" android:textAllCaps="true" /> - - +