fix bug and add footer cycle to channel
This commit is contained in:
parent
800e7bcb7a
commit
8f734737f0
3 changed files with 63 additions and 18 deletions
|
@ -95,6 +95,8 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
recyclerView.setLayoutManager(layoutManager);
|
||||
header = getLayoutInflater().inflate(R.layout.channel_header, recyclerView, false);
|
||||
infoListAdapter.setHeader(header);
|
||||
infoListAdapter.setFooter(
|
||||
getLayoutInflater().inflate(R.layout.pignate_footer, recyclerView, false));
|
||||
recyclerView.setAdapter(infoListAdapter);
|
||||
infoListAdapter.setOnStreamInfoItemSelectedListener(
|
||||
new InfoItemBuilder.OnInfoItemSelectedListener() {
|
||||
|
@ -236,16 +238,17 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
//delete already displayed content
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
infoListAdapter.clearSteamItemList();
|
||||
if (SDK_INT >= 21) {
|
||||
channelBanner.setImageDrawable(getDrawable(R.drawable.channel_banner));
|
||||
avatarView.setImageDrawable(getDrawable(R.drawable.buddy));
|
||||
pageNumber = 0;
|
||||
subscriberLayout.setVisibility(View.GONE);
|
||||
titleView.setText("");
|
||||
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() {
|
||||
Handler h = new Handler();
|
||||
|
||||
|
@ -266,8 +269,12 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
isLoading = false;
|
||||
if(!onlyVideos) {
|
||||
updateUi(info);
|
||||
infoListAdapter.showFooter(true);
|
||||
}
|
||||
hasNextPage = info.hasNextPage;
|
||||
if(!hasNextPage) {
|
||||
infoListAdapter.showFooter(false);
|
||||
}
|
||||
addVideos(info);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -38,16 +38,23 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
|
||||
private final InfoItemBuilder infoItemBuilder;
|
||||
private final List<InfoItem> infoItemList;
|
||||
private boolean showFooter = false;
|
||||
private View header = null;
|
||||
private View footer = null;
|
||||
|
||||
public class HeaderHolder extends RecyclerView.ViewHolder {
|
||||
public HeaderHolder(View v) {
|
||||
public class HFHolder extends RecyclerView.ViewHolder {
|
||||
public HFHolder(View v) {
|
||||
super(v);
|
||||
view = v;
|
||||
}
|
||||
public View view;
|
||||
}
|
||||
|
||||
public void showFooter(boolean show) {
|
||||
showFooter = show;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public InfoListAdapter(Activity a, View rootView) {
|
||||
infoItemBuilder = new InfoItemBuilder(a, rootView);
|
||||
infoItemList = new Vector<>();
|
||||
|
@ -63,9 +70,9 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
infoItemBuilder.setOnChannelInfoItemSelectedListener(listener);
|
||||
}
|
||||
|
||||
public void addInfoItemList(List<InfoItem> videos) {
|
||||
if(videos!= null) {
|
||||
infoItemList.addAll(videos);
|
||||
public void addInfoItemList(List<InfoItem> data) {
|
||||
if(data != null) {
|
||||
infoItemList.addAll(data);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
@ -77,11 +84,20 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
|
||||
public void setHeader(View header) {
|
||||
this.header = header;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setFooter(View view) {
|
||||
this.footer = view;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
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 -.-
|
||||
|
@ -92,13 +108,16 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
} else if(header != null) {
|
||||
position--;
|
||||
}
|
||||
if(footer != null && position == infoItemList.size() && showFooter) {
|
||||
return 1;
|
||||
}
|
||||
switch(infoItemList.get(position).infoType()) {
|
||||
case STREAM:
|
||||
return 1;
|
||||
case CHANNEL:
|
||||
return 2;
|
||||
case PLAYLIST:
|
||||
case CHANNEL:
|
||||
return 3;
|
||||
case PLAYLIST:
|
||||
return 4;
|
||||
default:
|
||||
Log.e(TAG, "Trollolo");
|
||||
return -1;
|
||||
|
@ -109,14 +128,16 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) {
|
||||
switch(type) {
|
||||
case 0:
|
||||
return new HeaderHolder(header);
|
||||
return new HFHolder(header);
|
||||
case 1:
|
||||
return new HFHolder(footer);
|
||||
case 2:
|
||||
return new StreamInfoItemHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.stream_item, parent, false));
|
||||
case 2:
|
||||
case 3:
|
||||
return new ChannelInfoItemHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.channel_item, parent, false));
|
||||
case 3:
|
||||
case 4:
|
||||
Log.e(TAG, "Playlist is not yet implemented");
|
||||
return null;
|
||||
default:
|
||||
|
@ -133,8 +154,10 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
i--;
|
||||
}
|
||||
infoItemBuilder.buildByHolder((InfoItemHolder) holder, infoItemList.get(i));
|
||||
} else if(holder instanceof HeaderHolder && i == 0 && header != null) {
|
||||
((HeaderHolder) holder).view = header;
|
||||
} else if(holder instanceof HFHolder && i == 0 && header != null) {
|
||||
((HFHolder) holder).view = header;
|
||||
} else if(holder instanceof HFHolder && i == infoItemList.size() && footer != null && showFooter) {
|
||||
((HFHolder) holder).view = footer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
app/src/main/res/layout/pignate_footer.xml
Normal file
15
app/src/main/res/layout/pignate_footer.xml
Normal 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>
|
Loading…
Reference in a new issue