From 1ab82dfa32d99db08a33b28db3097ae590c3cfdb Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 3 Aug 2016 13:09:48 +0200 Subject: [PATCH] made channel activity use recycler view --- .../org/schabi/newpipe/ChannelActivity.java | 32 +++++++++++++------ .../detail/VideoItemDetailFragment.java | 2 +- .../newpipe/info_list/InfoListAdapter.java | 4 +-- .../SearchInfoItemFragment.java | 4 +-- .../layout-v18/fragment_videoitem_detail.xml | 3 +- app/src/main/res/layout/activity_channel.xml | 7 ++-- .../res/layout/fragment_videoitem_detail.xml | 3 +- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ChannelActivity.java b/app/src/main/java/org/schabi/newpipe/ChannelActivity.java index 33c7c8eb8..332c00e92 100644 --- a/app/src/main/java/org/schabi/newpipe/ChannelActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ChannelActivity.java @@ -7,6 +7,8 @@ import android.os.Handler; import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.LayoutInflater; @@ -18,6 +20,8 @@ import android.widget.Toast; import com.nostra13.universalimageloader.core.ImageLoader; +import org.schabi.newpipe.detail.VideoItemDetailActivity; +import org.schabi.newpipe.detail.VideoItemDetailFragment; import org.schabi.newpipe.extractor.ChannelExtractor; import org.schabi.newpipe.extractor.ChannelInfo; import org.schabi.newpipe.extractor.ExtractionException; @@ -25,6 +29,7 @@ import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamPreviewInfo; import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.info_list.InfoListAdapter; import java.io.IOException; import java.util.ArrayList; @@ -43,6 +48,7 @@ public class ChannelActivity extends AppCompatActivity { private String channelUrl = ""; private ImageLoader imageLoader = ImageLoader.getInstance(); + private InfoListAdapter infoListAdapter = null; @Override protected void onCreate(Bundle savedInstanceState) { @@ -55,6 +61,21 @@ public class ChannelActivity extends AppCompatActivity { channelUrl = i.getStringExtra(CHANNEL_URL); serviceId = i.getIntExtra(SERVICE_ID, -1); + infoListAdapter = new InfoListAdapter(this, rootView); + RecyclerView recyclerView = (RecyclerView) findViewById(R.id.channel_streams_view); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.setAdapter(infoListAdapter); + infoListAdapter.setOnItemSelectedListener(new InfoListAdapter.OnItemSelectedListener() { + @Override + public void selected(String url) { + Intent detailIntent = new Intent(ChannelActivity.this, VideoItemDetailActivity.class); + detailIntent.putExtra(VideoItemDetailFragment.VIDEO_URL, url); + detailIntent.putExtra( + VideoItemDetailFragment.STREAMING_SERVICE, serviceId); + startActivity(detailIntent); + } + }); + // start processing Thread channelExtractorThread = new Thread(new Runnable() { Handler h = new Handler(); @@ -109,13 +130,11 @@ public class ChannelActivity extends AppCompatActivity { CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.channel_toolbar_layout); ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar); ImageView channelBanner = (ImageView) findViewById(R.id.channel_banner_image); - View channelContentView = findViewById(R.id.channel_content_view); FloatingActionButton feedButton = (FloatingActionButton) findViewById(R.id.channel_rss_fab); ImageView avatarView = (ImageView) findViewById(R.id.channel_avatar_view); ImageView haloView = (ImageView) findViewById(R.id.channel_avatar_halo); progressBar.setVisibility(View.GONE); - channelContentView.setVisibility(View.VISIBLE); if(info.channel_name != null && !info.channel_name.isEmpty()) { ctl.setTitle(info.channel_name); @@ -150,14 +169,7 @@ public class ChannelActivity extends AppCompatActivity { } private void initVideos(final ChannelInfo info, StreamInfoItemViewCreator viCreator) { - LinearLayout streamLayout = (LinearLayout) findViewById(R.id.channel_streams_view); - ArrayList streamsList = new ArrayList<>(info.related_streams); - - for(final StreamPreviewInfo streamInfo : streamsList) { - View itemView = viCreator.getViewFromVideoInfoItem(null, streamLayout, streamInfo); - itemView = viCreator.setupView(itemView, streamInfo); - streamLayout.addView(itemView); - } + infoListAdapter.addStreamItemList(info.related_streams); } private void postNewErrorToast(Handler h, final int stringResource) { 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 e39228ebf..0310113c4 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -551,7 +551,7 @@ public class VideoItemDetailFragment extends Fragment { } private void initSimilarVideos(final StreamInfo info, StreamInfoItemViewCreator videoItemViewCreator) { - similarStreamsAdapter.addVideoList(info.related_streams); + similarStreamsAdapter.addStreamItemList(info.related_streams); } private void onErrorBlockedByGema() { diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 75d25e5ee..8c0550b13 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -46,12 +46,12 @@ public class InfoListAdapter extends RecyclerView.Adapter { this.onItemSelectedListener = onItemSelectedListener; } - public void addVideoList(List videos) { + public void addStreamItemList(List videos) { streamList.addAll(videos); notifyDataSetChanged(); } - public void clearVideoList() { + public void clearSteamItemList() { streamList = new Vector<>(); notifyDataSetChanged(); } diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java index 37a4a2b84..6a6e6f7c1 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java @@ -133,7 +133,7 @@ public class SearchInfoItemFragment extends Fragment { sw.setSearchWorkerResultListner(new SearchWorker.SearchWorkerResultListner() { @Override public void onResult(SearchResult result) { - infoListAdapter.addVideoList(result.resultList); + infoListAdapter.addStreamItemList(result.resultList); isLoading = false; } @@ -242,7 +242,7 @@ public class SearchInfoItemFragment extends Fragment { } private void search(String query) { - infoListAdapter.clearVideoList(); + infoListAdapter.clearSteamItemList(); pageNumber = 0; search(query, pageNumber); } diff --git a/app/src/main/res/layout-v18/fragment_videoitem_detail.xml b/app/src/main/res/layout-v18/fragment_videoitem_detail.xml index 9a2bbced9..898a6f9c3 100644 --- a/app/src/main/res/layout-v18/fragment_videoitem_detail.xml +++ b/app/src/main/res/layout-v18/fragment_videoitem_detail.xml @@ -285,8 +285,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:layout_below="@id/detailSimilarTitle"> - + android:layout_below="@id/detailSimilarTitle"/> diff --git a/app/src/main/res/layout/activity_channel.xml b/app/src/main/res/layout/activity_channel.xml index 3e061a76a..e1df67b3c 100644 --- a/app/src/main/res/layout/activity_channel.xml +++ b/app/src/main/res/layout/activity_channel.xml @@ -96,11 +96,12 @@ android:id="@+id/channel_content_view" android:visibility="visible"> - - + app:layout_behavior="@string/appbar_scrolling_view_behavior"/> diff --git a/app/src/main/res/layout/fragment_videoitem_detail.xml b/app/src/main/res/layout/fragment_videoitem_detail.xml index 52786333b..b155110e3 100644 --- a/app/src/main/res/layout/fragment_videoitem_detail.xml +++ b/app/src/main/res/layout/fragment_videoitem_detail.xml @@ -272,8 +272,7 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_below="@id/detailSimilarTitle"> - + android:layout_below="@id/detailSimilarTitle"/>