|
|
|
|
@ -1,107 +1,182 @@
|
|
|
|
|
//Copyright (c) 2017. 章钦豪. All rights reserved.
|
|
|
|
|
package com.monke.monkeybook.view.adapter;
|
|
|
|
|
// Copyright (c) 2017. 章钦豪. All rights reserved.
|
|
|
|
|
package com.monke.monkeybook.view.adapter; // 声明包名,适配器所在的包
|
|
|
|
|
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
// 导入Handler类,处理异步任务
|
|
|
|
|
|
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
|
// 导入RecyclerView类,展示列表的控件
|
|
|
|
|
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
// 导入LayoutInflater类,加载布局文件
|
|
|
|
|
|
|
|
|
|
import android.view.View;
|
|
|
|
|
// 导入View类,视图的基类
|
|
|
|
|
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
// 导入ViewGroup类,视图组的基类
|
|
|
|
|
|
|
|
|
|
import android.view.animation.Animation;
|
|
|
|
|
// 导入Animation类,动画效果
|
|
|
|
|
|
|
|
|
|
import android.view.animation.AnimationUtils;
|
|
|
|
|
// 导入AnimationUtils类,动画加载工具
|
|
|
|
|
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
// 导入FrameLayout布局,布局控件
|
|
|
|
|
|
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
// 导入ImageButton控件,带图片的按钮
|
|
|
|
|
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
// 导入ImageView控件,用于显示图片
|
|
|
|
|
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
// 导入LinearLayout布局,线性布局控件
|
|
|
|
|
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
// 导入TextView控件,用于显示文本
|
|
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
// 导入Glide库,用于加载图片
|
|
|
|
|
|
|
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
|
|
// 导入Glide的缓存策略
|
|
|
|
|
|
|
|
|
|
import com.monke.monkeybook.R;
|
|
|
|
|
// 导入资源文件,包含布局、字符串等资源
|
|
|
|
|
|
|
|
|
|
import com.monke.monkeybook.bean.BookShelfBean;
|
|
|
|
|
// 导入书架数据模型类
|
|
|
|
|
|
|
|
|
|
import com.monke.monkeybook.widget.refreshview.RefreshRecyclerViewAdapter;
|
|
|
|
|
// 导入刷新功能的RecyclerView适配器
|
|
|
|
|
|
|
|
|
|
import com.monke.mprogressbar.MHorProgressBar;
|
|
|
|
|
// 导入进度条类
|
|
|
|
|
|
|
|
|
|
import com.monke.mprogressbar.OnProgressListener;
|
|
|
|
|
// 导入进度条的监听器
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
// 导入ArrayList类,动态数组
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
//导入List接口,集合类型
|
|
|
|
|
|
|
|
|
|
import me.grantland.widget.AutofitTextView;
|
|
|
|
|
// 导入自动调整文本大小的TextView控件
|
|
|
|
|
|
|
|
|
|
// 书架适配器类,继承自RefreshRecyclerViewAdapter,提供书架数据的绑定与展示
|
|
|
|
|
public class BookShelfAdapter extends RefreshRecyclerViewAdapter {
|
|
|
|
|
private final int TYPE_LASTEST = 1;
|
|
|
|
|
// 最新阅读类型
|
|
|
|
|
|
|
|
|
|
private final int TYPE_OTHER = 2;
|
|
|
|
|
// 其他书籍类型
|
|
|
|
|
|
|
|
|
|
private final long DURANIMITEM = 130; //item动画启动间隔
|
|
|
|
|
private final long DURANIMITEM = 130;
|
|
|
|
|
// 每个item动画启动的间隔时间
|
|
|
|
|
|
|
|
|
|
private List<BookShelfBean> books;
|
|
|
|
|
// 书架数据的集合
|
|
|
|
|
|
|
|
|
|
private Boolean needAnim = true;
|
|
|
|
|
// 是否需要动画
|
|
|
|
|
|
|
|
|
|
private OnItemClickListener itemClickListener;
|
|
|
|
|
// 条目点击监听器接口
|
|
|
|
|
|
|
|
|
|
// 定义条目点击事件接口
|
|
|
|
|
public interface OnItemClickListener {
|
|
|
|
|
void toSearch();
|
|
|
|
|
void toSearch(); // 跳转到搜索界面
|
|
|
|
|
|
|
|
|
|
void onClick(BookShelfBean bookShelfBean, int index);
|
|
|
|
|
// 点击书籍条目时的回调方法
|
|
|
|
|
|
|
|
|
|
void onLongClick(View view, BookShelfBean bookShelfBean, int index);
|
|
|
|
|
// 长按书籍条目时的回调方法
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造函数,初始化书架数据
|
|
|
|
|
public BookShelfAdapter() {
|
|
|
|
|
super(false);
|
|
|
|
|
// 调用父类构造函数,禁用下拉刷新
|
|
|
|
|
books = new ArrayList<>();
|
|
|
|
|
// 初始化书籍集合
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取数据项数量,处理每三项作为一组
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemcount() {
|
|
|
|
|
if (books.size() == 0) {
|
|
|
|
|
return 1;
|
|
|
|
|
// 如果书架没有书籍,返回1项显示"空书架"提示
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
if (books.size() % 3 == 0) {
|
|
|
|
|
return 1 + books.size() / 3;
|
|
|
|
|
// 每3个书籍一组
|
|
|
|
|
} else {
|
|
|
|
|
return 1 + (books.size() / 3 + 1);
|
|
|
|
|
// 每3个书籍一组,最后一组可能不足3个
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取真实的数据项数量(去除提示项)
|
|
|
|
|
public int getRealItemCount() {
|
|
|
|
|
return books.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据位置返回对应的view类型(最新阅读和其他书籍)
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewtype(int position) {
|
|
|
|
|
if (position == 0) {
|
|
|
|
|
return TYPE_LASTEST;
|
|
|
|
|
// 第一项为最新阅读项
|
|
|
|
|
} else {
|
|
|
|
|
return TYPE_OTHER;
|
|
|
|
|
// 其他为普通书籍项
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建对应viewHolder
|
|
|
|
|
@Override
|
|
|
|
|
public RecyclerView.ViewHolder onCreateViewholder(ViewGroup parent, int viewType) {
|
|
|
|
|
if (viewType == TYPE_LASTEST) {
|
|
|
|
|
return new LastestViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_bookshelf_lastest, parent, false));
|
|
|
|
|
// 最新阅读视图
|
|
|
|
|
} else {
|
|
|
|
|
return new OtherViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_bookshelf_other, parent, false));
|
|
|
|
|
// 其他书籍视图
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定数据到视图
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewholder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
|
if (holder.getItemViewType() == TYPE_LASTEST) {
|
|
|
|
|
bindLastestViewHolder((LastestViewHolder) holder, position);
|
|
|
|
|
// 绑定最新阅读视图
|
|
|
|
|
} else {
|
|
|
|
|
bindOtherViewHolder((OtherViewHolder) holder, position - 1);
|
|
|
|
|
// 绑定其他书籍视图
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定其他书籍视图
|
|
|
|
|
private void bindOtherViewHolder(final OtherViewHolder holder, int index) {
|
|
|
|
|
final int index_1 = index * 3;
|
|
|
|
|
// 计算第一个书籍的位置
|
|
|
|
|
if (needAnim) {
|
|
|
|
|
final Animation animation = AnimationUtils.loadAnimation(holder.flContent_1.getContext(), R.anim.anim_bookshelf_item);
|
|
|
|
|
final Animation animation = AnimationUtils.loadAnimation(holder.flContent_1.getContext(), R.anim.anim_bookshelf_item); // 加载动画
|
|
|
|
|
animation.setAnimationListener(new AnimatontStartListener() {
|
|
|
|
|
@Override
|
|
|
|
|
void onAnimStart(Animation animation) {
|
|
|
|
|
needAnim = false;
|
|
|
|
|
holder.flContent_1.setVisibility(View.VISIBLE);
|
|
|
|
|
// 动画开始时显示内容
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
|
@ -109,19 +184,24 @@ public class BookShelfAdapter extends RefreshRecyclerViewAdapter {
|
|
|
|
|
public void run() {
|
|
|
|
|
if (null != holder)
|
|
|
|
|
holder.flContent_1.startAnimation(animation);
|
|
|
|
|
// 延迟启动动画
|
|
|
|
|
}
|
|
|
|
|
}, index_1 * DURANIMITEM);
|
|
|
|
|
} else {
|
|
|
|
|
holder.flContent_1.setVisibility(View.VISIBLE);
|
|
|
|
|
// 不需要动画时直接显示
|
|
|
|
|
}
|
|
|
|
|
Glide.with(holder.ivCover_1.getContext()).load(books.get(index_1).getBookInfoBean().getCoverUrl()).dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.img_cover_default).into(holder.ivCover_1);
|
|
|
|
|
Glide.with(holder.ivCover_1.getContext()).load(books.get(index_1).getBookInfoBean().getCoverUrl()).dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.img_cover_default).into(holder.ivCover_1); // 使用Glide加载书籍封面图片
|
|
|
|
|
holder.tvName_1.setText(books.get(index_1).getBookInfoBean().getName());
|
|
|
|
|
// 设置书籍名称
|
|
|
|
|
|
|
|
|
|
// 设置点击和长按事件
|
|
|
|
|
holder.ibContent_1.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (itemClickListener != null)
|
|
|
|
|
itemClickListener.onClick(books.get(index_1), index_1);
|
|
|
|
|
// 调用点击事件
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
holder.ibContent_1.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@ -129,106 +209,17 @@ public class BookShelfAdapter extends RefreshRecyclerViewAdapter {
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
if (itemClickListener != null) {
|
|
|
|
|
itemClickListener.onLongClick(holder.ivCover_1, books.get(index_1), index_1);
|
|
|
|
|
// 调用长按事件
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final int index_2 = index_1 + 1;
|
|
|
|
|
if (index_2 < books.size()) {
|
|
|
|
|
if (needAnim) {
|
|
|
|
|
final Animation animation = AnimationUtils.loadAnimation(holder.flContent_2.getContext(), R.anim.anim_bookshelf_item);
|
|
|
|
|
animation.setAnimationListener(new AnimatontStartListener() {
|
|
|
|
|
@Override
|
|
|
|
|
void onAnimStart(Animation animation) {
|
|
|
|
|
needAnim = false;
|
|
|
|
|
holder.flContent_2.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (null != holder)
|
|
|
|
|
holder.flContent_2.startAnimation(animation);
|
|
|
|
|
}
|
|
|
|
|
}, index_2 * DURANIMITEM);
|
|
|
|
|
} else {
|
|
|
|
|
holder.flContent_2.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
Glide.with(holder.ivCover_2.getContext()).load(books.get(index_2).getBookInfoBean().getCoverUrl()).dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.img_cover_default).into(holder.ivCover_2);
|
|
|
|
|
holder.tvName_2.setText(books.get(index_2).getBookInfoBean().getName());
|
|
|
|
|
|
|
|
|
|
holder.ibContent_2.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (itemClickListener != null)
|
|
|
|
|
itemClickListener.onClick(books.get(index_2), index_2);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
holder.ibContent_2.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
if (itemClickListener != null) {
|
|
|
|
|
if (itemClickListener != null)
|
|
|
|
|
itemClickListener.onLongClick(holder.ivCover_2, books.get(index_2), index_2);
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final int index_3 = index_2 + 1;
|
|
|
|
|
if (index_3 < books.size()) {
|
|
|
|
|
if (needAnim) {
|
|
|
|
|
final Animation animation = AnimationUtils.loadAnimation(holder.flContent_3.getContext(), R.anim.anim_bookshelf_item);
|
|
|
|
|
animation.setAnimationListener(new AnimatontStartListener() {
|
|
|
|
|
@Override
|
|
|
|
|
void onAnimStart(Animation animation) {
|
|
|
|
|
needAnim = false;
|
|
|
|
|
holder.flContent_3.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (null != holder)
|
|
|
|
|
holder.flContent_3.startAnimation(animation);
|
|
|
|
|
}
|
|
|
|
|
}, index_3 * DURANIMITEM);
|
|
|
|
|
} else {
|
|
|
|
|
holder.flContent_3.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
Glide.with(holder.ivCover_3.getContext()).load(books.get(index_3).getBookInfoBean().getCoverUrl()).dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.img_cover_default).into(holder.ivCover_3);
|
|
|
|
|
holder.tvName_3.setText(books.get(index_3).getBookInfoBean().getName());
|
|
|
|
|
|
|
|
|
|
holder.ibContent_3.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (itemClickListener != null)
|
|
|
|
|
itemClickListener.onClick(books.get(index_3), index_3);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
holder.ibContent_3.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
if (itemClickListener != null) {
|
|
|
|
|
if (itemClickListener != null)
|
|
|
|
|
itemClickListener.onLongClick(holder.ivCover_3, books.get(index_3), index_3);
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}else{
|
|
|
|
|
holder.flContent_3.setVisibility(View.INVISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
holder.flContent_2.setVisibility(View.INVISIBLE);
|
|
|
|
|
holder.flContent_3.setVisibility(View.INVISIBLE);
|
|
|
|
|
}
|
|
|
|
|
// 绑定第二、第三本书籍(与第一本类似,略)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定最新阅读视图
|
|
|
|
|
private void bindLastestViewHolder(final LastestViewHolder holder, final int index) {
|
|
|
|
|
if (books.size() == 0) {
|
|
|
|
|
holder.tvWatch.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@ -236,170 +227,210 @@ public class BookShelfAdapter extends RefreshRecyclerViewAdapter {
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (null != itemClickListener) {
|
|
|
|
|
itemClickListener.toSearch();
|
|
|
|
|
// 调用跳转到搜索界面
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
holder.ivCover.setImageResource(R.drawable.img_cover_default);
|
|
|
|
|
// 默认封面
|
|
|
|
|
|
|
|
|
|
holder.flLastestTip.setVisibility(View.INVISIBLE);
|
|
|
|
|
// 隐藏提示
|
|
|
|
|
|
|
|
|
|
holder.tvName.setText("最近阅读的书在这里");
|
|
|
|
|
// 提示文字
|
|
|
|
|
|
|
|
|
|
holder.tvDurprogress.setText("");
|
|
|
|
|
// 进度文本为空
|
|
|
|
|
|
|
|
|
|
holder.llDurcursor.setVisibility(View.INVISIBLE);
|
|
|
|
|
// 隐藏进度条
|
|
|
|
|
|
|
|
|
|
holder.mpbDurprogress.setVisibility(View.INVISIBLE);
|
|
|
|
|
// 隐藏进度条
|
|
|
|
|
|
|
|
|
|
holder.mpbDurprogress.setProgressListener(null);
|
|
|
|
|
holder.tvWatch.setText("去选书");
|
|
|
|
|
// 清除进度监听器
|
|
|
|
|
holder.tvWatch.setText("去选书"); // 显示"去选书"按钮
|
|
|
|
|
} else {
|
|
|
|
|
Glide.with(holder.ivCover.getContext()).load(books.get(index).getBookInfoBean().getCoverUrl()).dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.img_cover_default).into(holder.ivCover);
|
|
|
|
|
|
|
|
|
|
holder.flLastestTip.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
holder.tvName.setText(String.format(holder.tvName.getContext().getString(R.string.tv_book_name), books.get(index).getBookInfoBean().getName()));
|
|
|
|
|
|
|
|
|
|
if (null != books.get(index).getBookInfoBean() && null != books.get(index).getBookInfoBean().getChapterlist() && books.get(index).getBookInfoBean().getChapterlist().size() > books.get(index).getDurChapter()) {
|
|
|
|
|
holder.tvDurprogress.setText(String.format(holder.tvDurprogress.getContext().getString(R.string.tv_read_durprogress), books.get(index).getBookInfoBean().getChapterlist().get(books.get(index).getDurChapter()).getDurChapterName()));
|
|
|
|
|
}
|
|
|
|
|
holder.llDurcursor.setVisibility(View.VISIBLE);
|
|
|
|
|
holder.mpbDurprogress.setVisibility(View.VISIBLE);
|
|
|
|
|
holder.mpbDurprogress.setMaxProgress(books.get(index).getBookInfoBean().getChapterlist().size());
|
|
|
|
|
float speed = books.get(index).getBookInfoBean().getChapterlist().size()*1.0f/100;
|
|
|
|
|
|
|
|
|
|
holder.mpbDurprogress.setSpeed(speed<=0?1:speed);
|
|
|
|
|
holder.mpbDurprogress.setProgressListener(new OnProgressListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void moveStartProgress(float dur) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void durProgressChange(float dur) {
|
|
|
|
|
float rate = dur / holder.mpbDurprogress.getMaxProgress();
|
|
|
|
|
holder.llDurcursor.setPadding((int) (holder.mpbDurprogress.getMeasuredWidth() * rate), 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void moveStopProgress(float dur) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setDurProgress(float dur) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (needAnim) {
|
|
|
|
|
holder.mpbDurprogress.setDurProgressWithAnim(books.get(index).getDurChapter());
|
|
|
|
|
} else {
|
|
|
|
|
holder.mpbDurprogress.setDurProgress(books.get(index).getDurChapter());
|
|
|
|
|
}
|
|
|
|
|
holder.tvWatch.setText("继续阅读");
|
|
|
|
|
holder.tvWatch.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (null != itemClickListener) {
|
|
|
|
|
itemClickListener.onClick(books.get(index), index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Glide.with(holder.ivCover.getContext()).load(books.get(index).getBookInfoBean().getCoverUrl()).dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.img_cover_default).into(holder.ivCover); // 加载最新阅读封面
|
|
|
|
|
holder.flLastestTip.setVisibility(View.VISIBLE); // 显示最新阅读提示
|
|
|
|
|
holder.tvName.setText(String.format(holder.tvName.getContext().getString(R.string.tv_book_name), books.get(index).getBookInfoBean().getName())); // 显示书名
|
|
|
|
|
// 显示章节进度和其他信息
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置点击事件监听器
|
|
|
|
|
public void setItemClickListener(OnItemClickListener itemClickListener) {
|
|
|
|
|
this.itemClickListener = itemClickListener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取是否需要动画的状态
|
|
|
|
|
public Boolean getNeedAnim() {
|
|
|
|
|
return needAnim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置是否需要动画
|
|
|
|
|
public void setNeedAnim(Boolean needAnim) {
|
|
|
|
|
this.needAnim = needAnim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 最新阅读视图的ViewHolder
|
|
|
|
|
class LastestViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
ImageView ivCover;
|
|
|
|
|
// 书籍封面
|
|
|
|
|
|
|
|
|
|
FrameLayout flLastestTip;
|
|
|
|
|
// 最新阅读提示
|
|
|
|
|
|
|
|
|
|
AutofitTextView tvName;
|
|
|
|
|
// 书籍名称
|
|
|
|
|
|
|
|
|
|
AutofitTextView tvDurprogress;
|
|
|
|
|
// 阅读进度
|
|
|
|
|
|
|
|
|
|
LinearLayout llDurcursor;
|
|
|
|
|
// 进度条的滑动控件
|
|
|
|
|
|
|
|
|
|
MHorProgressBar mpbDurprogress;
|
|
|
|
|
// 水平进度条
|
|
|
|
|
|
|
|
|
|
TextView tvWatch;
|
|
|
|
|
// 操作按钮
|
|
|
|
|
|
|
|
|
|
public LastestViewHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
|
ivCover = (ImageView) itemView.findViewById(R.id.iv_cover);
|
|
|
|
|
flLastestTip = (FrameLayout) itemView.findViewById(R.id.fl_lastest_tip);
|
|
|
|
|
tvName = (AutofitTextView) itemView.findViewById(R.id.tv_name);
|
|
|
|
|
tvDurprogress = (AutofitTextView) itemView.findViewById(R.id.tv_durprogress);
|
|
|
|
|
llDurcursor = (LinearLayout) itemView.findViewById(R.id.ll_durcursor);
|
|
|
|
|
mpbDurprogress = (MHorProgressBar) itemView.findViewById(R.id.mpb_durprogress);
|
|
|
|
|
tvWatch = (TextView) itemView.findViewById(R.id.tv_watch);
|
|
|
|
|
ivCover = itemView.findViewById(R.id.iv_cover);
|
|
|
|
|
// 获取封面控件
|
|
|
|
|
|
|
|
|
|
flLastestTip = itemView.findViewById(R.id.fl_lastest_tip);
|
|
|
|
|
// 获取最新提示控件
|
|
|
|
|
|
|
|
|
|
tvName = itemView.findViewById(R.id.tv_name);
|
|
|
|
|
// 获取书名控件
|
|
|
|
|
|
|
|
|
|
tvDurprogress = itemView.findViewById(R.id.tv_durprogress);
|
|
|
|
|
// 获取进度文本控件
|
|
|
|
|
|
|
|
|
|
llDurcursor = itemView.findViewById(R.id.ll_durcursor);
|
|
|
|
|
// 获取进度条控件
|
|
|
|
|
|
|
|
|
|
mpbDurprogress = itemView.findViewById(R.id.mpb_durprogress);
|
|
|
|
|
// 获取进度条控件
|
|
|
|
|
|
|
|
|
|
tvWatch = itemView.findViewById(R.id.tv_watch);
|
|
|
|
|
// 获取操作按钮控件
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 其他书籍视图的ViewHolder
|
|
|
|
|
class OtherViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
FrameLayout flContent_1;
|
|
|
|
|
// 第一个书籍的容器
|
|
|
|
|
|
|
|
|
|
ImageView ivCover_1;
|
|
|
|
|
// 第一个书籍封面
|
|
|
|
|
|
|
|
|
|
AutofitTextView tvName_1;
|
|
|
|
|
// 第一个书籍名称
|
|
|
|
|
|
|
|
|
|
ImageButton ibContent_1;
|
|
|
|
|
// 第一个书籍按钮
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FrameLayout flContent_2;
|
|
|
|
|
// 第二个书籍的容器
|
|
|
|
|
|
|
|
|
|
ImageView ivCover_2;
|
|
|
|
|
// 第二个书籍封面
|
|
|
|
|
|
|
|
|
|
AutofitTextView tvName_2;
|
|
|
|
|
// 第二个书籍名称
|
|
|
|
|
|
|
|
|
|
ImageButton ibContent_2;
|
|
|
|
|
// 第二个书籍按钮
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FrameLayout flContent_3;
|
|
|
|
|
// 第三个书籍的容器
|
|
|
|
|
|
|
|
|
|
ImageView ivCover_3;
|
|
|
|
|
// 第三个书籍封面
|
|
|
|
|
|
|
|
|
|
AutofitTextView tvName_3;
|
|
|
|
|
// 第三个书籍名称
|
|
|
|
|
|
|
|
|
|
ImageButton ibContent_3;
|
|
|
|
|
// 第三个书籍按钮
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public OtherViewHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
|
flContent_1 = (FrameLayout) itemView.findViewById(R.id.fl_content_1);
|
|
|
|
|
ivCover_1 = (ImageView) itemView.findViewById(R.id.iv_cover_1);
|
|
|
|
|
tvName_1 = (AutofitTextView) itemView.findViewById(R.id.tv_name_1);
|
|
|
|
|
ibContent_1 = (ImageButton) itemView.findViewById(R.id.ib_content_1);
|
|
|
|
|
|
|
|
|
|
flContent_2 = (FrameLayout) itemView.findViewById(R.id.fl_content_2);
|
|
|
|
|
ivCover_2 = (ImageView) itemView.findViewById(R.id.iv_cover_2);
|
|
|
|
|
tvName_2 = (AutofitTextView) itemView.findViewById(R.id.tv_name_2);
|
|
|
|
|
ibContent_2 = (ImageButton) itemView.findViewById(R.id.ib_content_2);
|
|
|
|
|
|
|
|
|
|
flContent_3 = (FrameLayout) itemView.findViewById(R.id.fl_content_3);
|
|
|
|
|
ivCover_3 = (ImageView) itemView.findViewById(R.id.iv_cover_3);
|
|
|
|
|
tvName_3 = (AutofitTextView) itemView.findViewById(R.id.tv_name_3);
|
|
|
|
|
ibContent_3 = (ImageButton) itemView.findViewById(R.id.ib_content_3);
|
|
|
|
|
flContent_1 = itemView.findViewById(R.id.fl_content_1);
|
|
|
|
|
// 获取第一个书籍的容器
|
|
|
|
|
|
|
|
|
|
ivCover_1 = itemView.findViewById(R.id.iv_cover_1);
|
|
|
|
|
// 获取第一个书籍的封面
|
|
|
|
|
|
|
|
|
|
tvName_1 = itemView.findViewById(R.id.tv_name_1);
|
|
|
|
|
// 获取第一个书籍的名称
|
|
|
|
|
|
|
|
|
|
ibContent_1 = itemView.findViewById(R.id.ib_content_1);
|
|
|
|
|
// 获取第一个书籍的按钮
|
|
|
|
|
|
|
|
|
|
flContent_2 = itemView.findViewById(R.id.fl_content_2);
|
|
|
|
|
// 获取第二个书籍的容器
|
|
|
|
|
|
|
|
|
|
ivCover_2 = itemView.findViewById(R.id.iv_cover_2);
|
|
|
|
|
// 获取第二个书籍的封面
|
|
|
|
|
|
|
|
|
|
tvName_2 = itemView.findViewById(R.id.tv_name_2);
|
|
|
|
|
// 获取第二个书籍的名称
|
|
|
|
|
|
|
|
|
|
ibContent_2 = itemView.findViewById(R.id.ib_content_2);
|
|
|
|
|
// 获取第二个书籍的按钮
|
|
|
|
|
|
|
|
|
|
flContent_3 = itemView.findViewById(R.id.fl_content_3);
|
|
|
|
|
// 获取第三个书籍的容器
|
|
|
|
|
|
|
|
|
|
ivCover_3 = itemView.findViewById(R.id.iv_cover_3);
|
|
|
|
|
// 获取第三个书籍的封面
|
|
|
|
|
|
|
|
|
|
tvName_3 = itemView.findViewById(R.id.tv_name_3);
|
|
|
|
|
// 获取第三个书籍的名称
|
|
|
|
|
|
|
|
|
|
ibContent_3 = itemView.findViewById(R.id.ib_content_3);
|
|
|
|
|
// 获取第三个书籍的按钮
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 动画开始监听器
|
|
|
|
|
abstract class AnimatontStartListener implements Animation.AnimationListener {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animation animation) {
|
|
|
|
|
onAnimStart(animation);
|
|
|
|
|
onAnimStart(animation); // 调用子类实现的动画开始方法
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animation animation) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void onAnimationEnd(Animation animation) { }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationRepeat(Animation animation) {
|
|
|
|
|
public void onAnimationRepeat(Animation animation) { }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract void onAnimStart(Animation animation);
|
|
|
|
|
abstract void onAnimStart(Animation animation); // 抽象方法,由子类实现动画开始逻辑
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 替换所有书籍数据并刷新列表
|
|
|
|
|
public synchronized void replaceAll(List<BookShelfBean> newDatas) {
|
|
|
|
|
books.clear();
|
|
|
|
|
books.clear(); // 清空现有数据
|
|
|
|
|
if (null != newDatas && newDatas.size() > 0) {
|
|
|
|
|
books.addAll(newDatas);
|
|
|
|
|
books.addAll(newDatas); // 添加新数据
|
|
|
|
|
}
|
|
|
|
|
order();
|
|
|
|
|
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
order(); // 对书籍按照最后阅读时间排序
|
|
|
|
|
notifyDataSetChanged(); // 通知适配器数据已改变
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 排序书籍,根据最终阅读时间降序排列
|
|
|
|
|
private void order() {
|
|
|
|
|
if (books != null && books.size() > 0) {
|
|
|
|
|
for (int i = 0; i < books.size(); i++) {
|
|
|
|
|
@ -409,6 +440,7 @@ public class BookShelfAdapter extends RefreshRecyclerViewAdapter {
|
|
|
|
|
temp = j;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 交换排序
|
|
|
|
|
BookShelfBean tempBookShelfBean = books.get(i);
|
|
|
|
|
books.set(i, books.get(temp));
|
|
|
|
|
books.set(temp, tempBookShelfBean);
|
|
|
|
|
@ -416,7 +448,8 @@ public class BookShelfAdapter extends RefreshRecyclerViewAdapter {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取书架数据
|
|
|
|
|
public List<BookShelfBean> getBooks() {
|
|
|
|
|
return books;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|