fix bug and add footer cycle to channel

This commit is contained in:
Christian Schabesberger 2017-02-28 12:13:29 +01:00
parent 800e7bcb7a
commit 8f734737f0
3 changed files with 63 additions and 18 deletions

View file

@ -95,6 +95,8 @@ public class ChannelActivity extends AppCompatActivity {
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
header = getLayoutInflater().inflate(R.layout.channel_header, recyclerView, false); header = getLayoutInflater().inflate(R.layout.channel_header, recyclerView, false);
infoListAdapter.setHeader(header); infoListAdapter.setHeader(header);
infoListAdapter.setFooter(
getLayoutInflater().inflate(R.layout.pignate_footer, recyclerView, false));
recyclerView.setAdapter(infoListAdapter); recyclerView.setAdapter(infoListAdapter);
infoListAdapter.setOnStreamInfoItemSelectedListener( infoListAdapter.setOnStreamInfoItemSelectedListener(
new InfoItemBuilder.OnInfoItemSelectedListener() { new InfoItemBuilder.OnInfoItemSelectedListener() {
@ -236,16 +238,17 @@ public class ChannelActivity extends AppCompatActivity {
//delete already displayed content //delete already displayed content
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
infoListAdapter.clearSteamItemList(); infoListAdapter.clearSteamItemList();
if (SDK_INT >= 21) { pageNumber = 0;
channelBanner.setImageDrawable(getDrawable(R.drawable.channel_banner));
avatarView.setImageDrawable(getDrawable(R.drawable.buddy));
subscriberLayout.setVisibility(View.GONE); subscriberLayout.setVisibility(View.GONE);
titleView.setText(""); titleView.setText("");
getSupportActionBar().setTitle(""); getSupportActionBar().setTitle("");
if (SDK_INT >= 21) {
channelBanner.setImageDrawable(getDrawable(R.drawable.channel_banner));
avatarView.setImageDrawable(getDrawable(R.drawable.buddy));
} }
infoListAdapter.showFooter(false);
} }
Thread channelExtractorThread = new Thread(new Runnable() { Thread channelExtractorThread = new Thread(new Runnable() {
Handler h = new Handler(); Handler h = new Handler();
@ -266,8 +269,12 @@ public class ChannelActivity extends AppCompatActivity {
isLoading = false; isLoading = false;
if(!onlyVideos) { if(!onlyVideos) {
updateUi(info); updateUi(info);
infoListAdapter.showFooter(true);
} }
hasNextPage = info.hasNextPage; hasNextPage = info.hasNextPage;
if(!hasNextPage) {
infoListAdapter.showFooter(false);
}
addVideos(info); addVideos(info);
} }
}); });

View file

@ -38,16 +38,23 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private final InfoItemBuilder infoItemBuilder; private final InfoItemBuilder infoItemBuilder;
private final List<InfoItem> infoItemList; private final List<InfoItem> infoItemList;
private boolean showFooter = false;
private View header = null; private View header = null;
private View footer = null;
public class HeaderHolder extends RecyclerView.ViewHolder { public class HFHolder extends RecyclerView.ViewHolder {
public HeaderHolder(View v) { public HFHolder(View v) {
super(v); super(v);
view = v; view = v;
} }
public View view; public View view;
} }
public void showFooter(boolean show) {
showFooter = show;
notifyDataSetChanged();
}
public InfoListAdapter(Activity a, View rootView) { public InfoListAdapter(Activity a, View rootView) {
infoItemBuilder = new InfoItemBuilder(a, rootView); infoItemBuilder = new InfoItemBuilder(a, rootView);
infoItemList = new Vector<>(); infoItemList = new Vector<>();
@ -63,9 +70,9 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
infoItemBuilder.setOnChannelInfoItemSelectedListener(listener); infoItemBuilder.setOnChannelInfoItemSelectedListener(listener);
} }
public void addInfoItemList(List<InfoItem> videos) { public void addInfoItemList(List<InfoItem> data) {
if(videos!= null) { if(data != null) {
infoItemList.addAll(videos); infoItemList.addAll(data);
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }
@ -77,11 +84,20 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
public void setHeader(View header) { public void setHeader(View header) {
this.header = header; this.header = header;
notifyDataSetChanged();
}
public void setFooter(View view) {
this.footer = view;
notifyDataSetChanged();
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return (header == null) ? infoItemList.size() : (infoItemList.size() + 1); int cound = infoItemList.size();
if(header != null) cound++;
if(footer != null && showFooter) cound++;
return cound;
} }
// don't ask why we have to do that this way... it's android accept it -.- // don't ask why we have to do that this way... it's android accept it -.-
@ -92,13 +108,16 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
} else if(header != null) { } else if(header != null) {
position--; position--;
} }
if(footer != null && position == infoItemList.size() && showFooter) {
return 1;
}
switch(infoItemList.get(position).infoType()) { switch(infoItemList.get(position).infoType()) {
case STREAM: case STREAM:
return 1;
case CHANNEL:
return 2; return 2;
case PLAYLIST: case CHANNEL:
return 3; return 3;
case PLAYLIST:
return 4;
default: default:
Log.e(TAG, "Trollolo"); Log.e(TAG, "Trollolo");
return -1; return -1;
@ -109,14 +128,16 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) { public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) {
switch(type) { switch(type) {
case 0: case 0:
return new HeaderHolder(header); return new HFHolder(header);
case 1: case 1:
return new HFHolder(footer);
case 2:
return new StreamInfoItemHolder(LayoutInflater.from(parent.getContext()) return new StreamInfoItemHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.stream_item, parent, false)); .inflate(R.layout.stream_item, parent, false));
case 2: case 3:
return new ChannelInfoItemHolder(LayoutInflater.from(parent.getContext()) return new ChannelInfoItemHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.channel_item, parent, false)); .inflate(R.layout.channel_item, parent, false));
case 3: case 4:
Log.e(TAG, "Playlist is not yet implemented"); Log.e(TAG, "Playlist is not yet implemented");
return null; return null;
default: default:
@ -133,8 +154,10 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
i--; i--;
} }
infoItemBuilder.buildByHolder((InfoItemHolder) holder, infoItemList.get(i)); infoItemBuilder.buildByHolder((InfoItemHolder) holder, infoItemList.get(i));
} else if(holder instanceof HeaderHolder && i == 0 && header != null) { } else if(holder instanceof HFHolder && i == 0 && header != null) {
((HeaderHolder) holder).view = header; ((HFHolder) holder).view = header;
} else if(holder instanceof HFHolder && i == infoItemList.size() && footer != null && showFooter) {
((HFHolder) holder).view = footer;
} }
} }
} }

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ProgressBar
android:id="@+id/paginate_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dp"/>
</LinearLayout>