mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	made detail fragment use recycler view
This commit is contained in:
		| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -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<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); | ||||
|         } | ||||
|         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(); | ||||
|     } | ||||
| } | ||||
| @@ -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); | ||||
| @@ -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<StreamInfoItemHolder> { | ||||
| public class InfoListAdapter extends RecyclerView.Adapter<InfoItemHolder> { | ||||
| 
 | ||||
|     public interface OnItemSelectedListener { | ||||
|         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; | ||||
|         this.rootView = rootView; | ||||
|     } | ||||
| @@ -62,15 +62,15 @@ public class StreamInfoListAdapter extends RecyclerView.Adapter<StreamInfoItemHo | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public StreamInfoItemHolder onCreateViewHolder(ViewGroup parent, int i) { | ||||
|     public InfoItemHolder onCreateViewHolder(ViewGroup parent, int i) { | ||||
|         View itemView = LayoutInflater.from(parent.getContext()) | ||||
|                 .inflate(R.layout.video_item, parent, false); | ||||
| 
 | ||||
|         return new StreamInfoItemHolder(itemView); | ||||
|         return new InfoItemHolder(itemView); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onBindViewHolder(StreamInfoItemHolder holder, int i) { | ||||
|     public void onBindViewHolder(InfoItemHolder holder, int i) { | ||||
|         final StreamPreviewInfo info = streamList.get(i); | ||||
|         // fill holder with information | ||||
|         holder.itemVideoTitleView.setText(info.title); | ||||
| @@ -23,6 +23,7 @@ import org.schabi.newpipe.detail.VideoItemDetailActivity; | ||||
| import org.schabi.newpipe.detail.VideoItemDetailFragment; | ||||
| import org.schabi.newpipe.extractor.SearchResult; | ||||
| import org.schabi.newpipe.extractor.ServiceList; | ||||
| import org.schabi.newpipe.info_list.InfoListAdapter; | ||||
|  | ||||
| /** | ||||
|  * Created by Christian Schabesberger on 02.08.16. | ||||
| @@ -86,7 +87,7 @@ public class SearchInfoItemFragment extends Fragment { | ||||
|     private SearchView searchView = null; | ||||
|     private int pageNumber = 0; | ||||
|     private SuggestionListAdapter suggestionListAdapter = null; | ||||
|     private StreamInfoListAdapter streamInfoListAdapter = null; | ||||
|     private InfoListAdapter infoListAdapter = null; | ||||
|     private LinearLayoutManager streamInfoListLayoutManager = null; | ||||
|     private RecyclerView recyclerView = null; | ||||
|  | ||||
| @@ -132,7 +133,7 @@ public class SearchInfoItemFragment extends Fragment { | ||||
|         sw.setSearchWorkerResultListner(new SearchWorker.SearchWorkerResultListner() { | ||||
|             @Override | ||||
|             public void onResult(SearchResult result) { | ||||
|                 streamInfoListAdapter.addVideoList(result.resultList); | ||||
|                 infoListAdapter.addVideoList(result.resultList); | ||||
|                 isLoading = false; | ||||
|             } | ||||
|  | ||||
| @@ -166,9 +167,9 @@ public class SearchInfoItemFragment extends Fragment { | ||||
|             streamInfoListLayoutManager = new LinearLayoutManager(context); | ||||
|             recyclerView.setLayoutManager(streamInfoListLayoutManager); | ||||
|  | ||||
|             streamInfoListAdapter = new StreamInfoListAdapter(getActivity(), | ||||
|             infoListAdapter = new InfoListAdapter(getActivity(), | ||||
|                     getActivity().findViewById(android.R.id.content)); | ||||
|             streamInfoListAdapter.setOnItemSelectedListener(new StreamInfoListAdapter.OnItemSelectedListener() { | ||||
|             infoListAdapter.setOnItemSelectedListener(new InfoListAdapter.OnItemSelectedListener() { | ||||
|                 @Override | ||||
|                 public void selected(String url) { | ||||
|                     Intent i = new Intent(getActivity(), VideoItemDetailActivity.class); | ||||
| @@ -177,7 +178,7 @@ public class SearchInfoItemFragment extends Fragment { | ||||
|                     getActivity().startActivity(i); | ||||
|                 } | ||||
|             }); | ||||
|             recyclerView.setAdapter(streamInfoListAdapter); | ||||
|             recyclerView.setAdapter(infoListAdapter); | ||||
|  | ||||
|  | ||||
|             recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { | ||||
| @@ -241,7 +242,7 @@ public class SearchInfoItemFragment extends Fragment { | ||||
|     } | ||||
|  | ||||
|     private void search(String query) { | ||||
|         streamInfoListAdapter.clearVideoList(); | ||||
|         infoListAdapter.clearVideoList(); | ||||
|         pageNumber = 0; | ||||
|         search(query, pageNumber); | ||||
|     } | ||||
|   | ||||
| @@ -280,13 +280,13 @@ | ||||
|                         android:text="@string/similar_videos_btn_text" | ||||
|                         android:layout_below="@id/detailNextVidButtonAndContentLayout" | ||||
|                         android:textAllCaps="true" /> | ||||
|                     <LinearLayout | ||||
|                         android:id="@+id/similarVideosView" | ||||
|                         android:orientation="vertical" | ||||
|                     <android.support.v7.widget.RecyclerView | ||||
|                         android:id="@+id/similar_streams_view" | ||||
|                         android:layout_width="match_parent" | ||||
|                         android:layout_height="match_parent" | ||||
|                         android:layout_height="wrap_content" | ||||
|                         android:orientation="vertical" | ||||
|                         android:layout_below="@id/detailSimilarTitle"> | ||||
|                     </LinearLayout> | ||||
|                     </android.support.v7.widget.RecyclerView> | ||||
|                 </RelativeLayout> | ||||
|             </RelativeLayout> | ||||
|         </RelativeLayout> | ||||
|   | ||||
| @@ -267,13 +267,13 @@ | ||||
|                         android:text="@string/similar_videos_btn_text" | ||||
|                         android:layout_below="@id/detailNextVidButtonAndContentLayout" | ||||
|                         android:textAllCaps="true" /> | ||||
|                     <LinearLayout | ||||
|                     <android.support.v7.widget.RecyclerView | ||||
|                         android:id="@+id/similar_streams_view" | ||||
|                         android:orientation="vertical" | ||||
|                         android:layout_width="match_parent" | ||||
|                         android:layout_height="match_parent" | ||||
|                         android:id="@+id/similarVideosView" | ||||
|                         android:layout_below="@id/detailSimilarTitle"> | ||||
|                     </LinearLayout> | ||||
|                     </android.support.v7.widget.RecyclerView> | ||||
|                 </RelativeLayout> | ||||
|             </RelativeLayout> | ||||
|         </RelativeLayout> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Christian Schabesberger
					Christian Schabesberger