made detail fragment use recycler view

This commit is contained in:
Christian Schabesberger 2016-08-03 00:54:03 +02:00
parent 06e2e548be
commit 557bcc40ef
7 changed files with 45 additions and 51 deletions

View File

@ -2,7 +2,6 @@ package org.schabi.newpipe.detail;
import android.app.Activity; import android.app.Activity;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.View; 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.StreamInfo;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
import org.schabi.newpipe.search_fragment.StreamInfoListAdapter;
import java.io.IOException; import java.io.IOException;

View File

@ -10,12 +10,13 @@ import android.graphics.Point;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; 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.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log; import android.util.Log;
@ -28,15 +29,12 @@ import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
import java.io.IOException;
import com.google.android.exoplayer.util.Util; import com.google.android.exoplayer.util.Util;
import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoader;
@ -48,7 +46,6 @@ import java.util.Vector;
import org.schabi.newpipe.ActivityCommunicator; import org.schabi.newpipe.ActivityCommunicator;
import org.schabi.newpipe.ChannelActivity; import org.schabi.newpipe.ChannelActivity;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.ErrorActivity; import org.schabi.newpipe.ErrorActivity;
import org.schabi.newpipe.ImageErrorLoadingListener; import org.schabi.newpipe.ImageErrorLoadingListener;
import org.schabi.newpipe.Localization; import org.schabi.newpipe.Localization;
@ -57,14 +54,11 @@ import org.schabi.newpipe.StreamInfoItemViewCreator;
import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.extractor.AudioStream; import org.schabi.newpipe.extractor.AudioStream;
import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.ParsingException;
import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamExtractor;
import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.StreamInfo;
import org.schabi.newpipe.extractor.StreamPreviewInfo; import org.schabi.newpipe.extractor.StreamPreviewInfo;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.VideoStream; 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.BackgroundPlayer;
import org.schabi.newpipe.player.PlayVideoActivity; import org.schabi.newpipe.player.PlayVideoActivity;
import org.schabi.newpipe.player.ExoPlayerActivity; import org.schabi.newpipe.player.ExoPlayerActivity;
@ -123,6 +117,7 @@ public class VideoItemDetailFragment extends Fragment {
private View rootView = null; private View rootView = null;
private InfoListAdapter similarStreamsAdapter = null;
public interface OnInvokeCreateOptionsMenuListener { public interface OnInvokeCreateOptionsMenuListener {
void createOptionsMenu(); void createOptionsMenu();
@ -275,7 +270,7 @@ public class VideoItemDetailFragment extends Fragment {
initSimilarVideos(info, videoItemViewCreator); initSimilarVideos(info, videoItemViewCreator);
} else { } else {
activity.findViewById(R.id.detailSimilarTitle).setVisibility(View.GONE); 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); setupActionBarHandler(info);
@ -556,17 +551,7 @@ public class VideoItemDetailFragment extends Fragment {
} }
private void initSimilarVideos(final StreamInfo info, StreamInfoItemViewCreator videoItemViewCreator) { private void initSimilarVideos(final StreamInfo info, StreamInfoItemViewCreator videoItemViewCreator) {
LinearLayout similarLayout = (LinearLayout) activity.findViewById(R.id.similarVideosView); similarStreamsAdapter.addVideoList(info.related_streams);
ArrayList<StreamPreviewInfo> 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);
}
} }
private void onErrorBlockedByGema() { 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(), Toast.makeText(VideoItemDetailFragment.this.getActivity(),
stringResource, Toast.LENGTH_LONG).show(); stringResource, Toast.LENGTH_LONG).show();
} }
private void postNewErrorToast(final String message) {
Toast.makeText(VideoItemDetailFragment.this.getActivity(),
message, Toast.LENGTH_LONG).show();
}
} }

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.search_fragment; package org.schabi.newpipe.info_list;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
@ -10,7 +10,7 @@ import org.schabi.newpipe.R;
/** /**
* Created by the-scrabi on 01.08.16. * Created by the-scrabi on 01.08.16.
*/ */
public class StreamInfoItemHolder extends RecyclerView.ViewHolder { public class InfoItemHolder extends RecyclerView.ViewHolder {
public ImageView itemThumbnailView; public ImageView itemThumbnailView;
public TextView itemVideoTitleView, public TextView itemVideoTitleView,
@ -20,7 +20,7 @@ public class StreamInfoItemHolder extends RecyclerView.ViewHolder {
itemViewCountView; itemViewCountView;
public View mainLayout; public View mainLayout;
public StreamInfoItemHolder(View v) { public InfoItemHolder(View v) {
super(v); super(v);
itemThumbnailView = (ImageView) v.findViewById(R.id.itemThumbnailView); itemThumbnailView = (ImageView) v.findViewById(R.id.itemThumbnailView);
itemVideoTitleView = (TextView) v.findViewById(R.id.itemVideoTitleView); itemVideoTitleView = (TextView) v.findViewById(R.id.itemVideoTitleView);

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.search_fragment; package org.schabi.newpipe.info_list;
import android.app.Activity; import android.app.Activity;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -21,7 +21,7 @@ import java.util.Vector;
/** /**
* Created by the-scrabi on 01.08.16. * Created by the-scrabi on 01.08.16.
*/ */
public class StreamInfoListAdapter extends RecyclerView.Adapter<StreamInfoItemHolder> { public class InfoListAdapter extends RecyclerView.Adapter<InfoItemHolder> {
public interface OnItemSelectedListener { public interface OnItemSelectedListener {
void selected(String url); void selected(String url);
@ -37,7 +37,7 @@ public class StreamInfoListAdapter extends RecyclerView.Adapter<StreamInfoItemHo
StreamInfoListAdapter(Activity a, View rootView) { public InfoListAdapter(Activity a, View rootView) {
activity = a; activity = a;
this.rootView = rootView; this.rootView = rootView;
} }
@ -62,15 +62,15 @@ public class StreamInfoListAdapter extends RecyclerView.Adapter<StreamInfoItemHo
} }
@Override @Override
public StreamInfoItemHolder onCreateViewHolder(ViewGroup parent, int i) { public InfoItemHolder onCreateViewHolder(ViewGroup parent, int i) {
View itemView = LayoutInflater.from(parent.getContext()) View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.video_item, parent, false); .inflate(R.layout.video_item, parent, false);
return new StreamInfoItemHolder(itemView); return new InfoItemHolder(itemView);
} }
@Override @Override
public void onBindViewHolder(StreamInfoItemHolder holder, int i) { public void onBindViewHolder(InfoItemHolder holder, int i) {
final StreamPreviewInfo info = streamList.get(i); final StreamPreviewInfo info = streamList.get(i);
// fill holder with information // fill holder with information
holder.itemVideoTitleView.setText(info.title); holder.itemVideoTitleView.setText(info.title);

View File

@ -23,6 +23,7 @@ import org.schabi.newpipe.detail.VideoItemDetailActivity;
import org.schabi.newpipe.detail.VideoItemDetailFragment; import org.schabi.newpipe.detail.VideoItemDetailFragment;
import org.schabi.newpipe.extractor.SearchResult; import org.schabi.newpipe.extractor.SearchResult;
import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.info_list.InfoListAdapter;
/** /**
* Created by Christian Schabesberger on 02.08.16. * Created by Christian Schabesberger on 02.08.16.
@ -86,7 +87,7 @@ public class SearchInfoItemFragment extends Fragment {
private SearchView searchView = null; private SearchView searchView = null;
private int pageNumber = 0; private int pageNumber = 0;
private SuggestionListAdapter suggestionListAdapter = null; private SuggestionListAdapter suggestionListAdapter = null;
private StreamInfoListAdapter streamInfoListAdapter = null; private InfoListAdapter infoListAdapter = null;
private LinearLayoutManager streamInfoListLayoutManager = null; private LinearLayoutManager streamInfoListLayoutManager = null;
private RecyclerView recyclerView = null; private RecyclerView recyclerView = null;
@ -132,7 +133,7 @@ public class SearchInfoItemFragment extends Fragment {
sw.setSearchWorkerResultListner(new SearchWorker.SearchWorkerResultListner() { sw.setSearchWorkerResultListner(new SearchWorker.SearchWorkerResultListner() {
@Override @Override
public void onResult(SearchResult result) { public void onResult(SearchResult result) {
streamInfoListAdapter.addVideoList(result.resultList); infoListAdapter.addVideoList(result.resultList);
isLoading = false; isLoading = false;
} }
@ -166,9 +167,9 @@ public class SearchInfoItemFragment extends Fragment {
streamInfoListLayoutManager = new LinearLayoutManager(context); streamInfoListLayoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(streamInfoListLayoutManager); recyclerView.setLayoutManager(streamInfoListLayoutManager);
streamInfoListAdapter = new StreamInfoListAdapter(getActivity(), infoListAdapter = new InfoListAdapter(getActivity(),
getActivity().findViewById(android.R.id.content)); getActivity().findViewById(android.R.id.content));
streamInfoListAdapter.setOnItemSelectedListener(new StreamInfoListAdapter.OnItemSelectedListener() { infoListAdapter.setOnItemSelectedListener(new InfoListAdapter.OnItemSelectedListener() {
@Override @Override
public void selected(String url) { public void selected(String url) {
Intent i = new Intent(getActivity(), VideoItemDetailActivity.class); Intent i = new Intent(getActivity(), VideoItemDetailActivity.class);
@ -177,7 +178,7 @@ public class SearchInfoItemFragment extends Fragment {
getActivity().startActivity(i); getActivity().startActivity(i);
} }
}); });
recyclerView.setAdapter(streamInfoListAdapter); recyclerView.setAdapter(infoListAdapter);
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@ -241,7 +242,7 @@ public class SearchInfoItemFragment extends Fragment {
} }
private void search(String query) { private void search(String query) {
streamInfoListAdapter.clearVideoList(); infoListAdapter.clearVideoList();
pageNumber = 0; pageNumber = 0;
search(query, pageNumber); search(query, pageNumber);
} }

View File

@ -280,13 +280,13 @@
android:text="@string/similar_videos_btn_text" android:text="@string/similar_videos_btn_text"
android:layout_below="@id/detailNextVidButtonAndContentLayout" android:layout_below="@id/detailNextVidButtonAndContentLayout"
android:textAllCaps="true" /> android:textAllCaps="true" />
<LinearLayout <android.support.v7.widget.RecyclerView
android:id="@+id/similarVideosView" android:id="@+id/similar_streams_view"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/detailSimilarTitle"> android:layout_below="@id/detailSimilarTitle">
</LinearLayout> </android.support.v7.widget.RecyclerView>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -267,13 +267,13 @@
android:text="@string/similar_videos_btn_text" android:text="@string/similar_videos_btn_text"
android:layout_below="@id/detailNextVidButtonAndContentLayout" android:layout_below="@id/detailNextVidButtonAndContentLayout"
android:textAllCaps="true" /> android:textAllCaps="true" />
<LinearLayout <android.support.v7.widget.RecyclerView
android:id="@+id/similar_streams_view"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/similarVideosView"
android:layout_below="@id/detailSimilarTitle"> android:layout_below="@id/detailSimilarTitle">
</LinearLayout> </android.support.v7.widget.RecyclerView>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>