old
zlj 5 years ago
parent 2d6277e6e7
commit 2dcbad56a1
  1. 8
      app/src/main/java/com/novel/read/adapter/BookListAdapter.kt
  2. 15
      app/src/main/java/com/novel/read/adapter/IViewHolder.java
  3. 15
      app/src/main/java/com/novel/read/adapter/IViewHolder.kt
  4. 9
      app/src/main/java/com/novel/read/adapter/RankListAdapter.kt
  5. 35
      app/src/main/java/com/novel/read/adapter/SearchAdapter.kt
  6. 2
      app/src/main/java/com/novel/read/adapter/StackAdapter.kt
  7. 6
      app/src/main/java/com/novel/read/adapter/ViewHolderImpl.java
  8. 13
      app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.java
  9. 6
      app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.kt
  10. 2
      app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.kt
  11. 22
      app/src/main/java/com/novel/read/utlis/Charset.java
  12. 16
      app/src/main/java/com/novel/read/utlis/Charset.kt
  13. 12
      app/src/main/java/com/novel/read/utlis/FileUtils.java
  14. 2
      app/src/main/java/com/novel/read/utlis/GlideImageLoader.kt
  15. 1
      app/src/main/java/com/novel/read/utlis/StringUtils.kt
  16. 14
      app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java

@ -31,12 +31,12 @@ class BookListAdapter(private val mList: List<SearchResp.BookBean>, recyclerView
init {
if (recyclerView.layoutManager is LinearLayoutManager) {
val llMangager = recyclerView.layoutManager as LinearLayoutManager?
val manager = recyclerView.layoutManager as LinearLayoutManager?
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
totalItemCount = llMangager!!.itemCount
lastVisibleItem = llMangager.findLastVisibleItemPosition()
totalItemCount = manager!!.itemCount
lastVisibleItem = manager.findLastVisibleItemPosition()
if (!isLoadingMore && totalItemCount == lastVisibleItem + visibleThreshold && totalItemCount >= COMMENT_SIZE) {
if (mOnLoadMoreListener != null) {
mOnLoadMoreListener!!.onLoadMore()
@ -98,7 +98,7 @@ class BookListAdapter(private val mList: List<SearchResp.BookBean>, recyclerView
}
override fun getItemViewType(position: Int): Int {
if (position == itemCount - 1) {
if (mList.isNotEmpty() &&position == itemCount - 1) {
return PROCESS_ITEM
}
return when {

@ -1,15 +0,0 @@
package com.novel.read.adapter;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by newbiechen on 17-5-17.
*/
public interface IViewHolder<T> {
View createItemView(ViewGroup parent);
void initView();
void onBind(T data, int pos);
void onClick();
}

@ -0,0 +1,15 @@
package com.novel.read.adapter
import android.view.View
import android.view.ViewGroup
/**
* Created by zlj
*/
interface IViewHolder<T> {
fun createItemView(parent: ViewGroup): View
fun initView()
fun onBind(data: T, pos: Int)
fun onClick()
}

@ -31,12 +31,12 @@ class RankListAdapter( val mList: List<RankByUpdateResp.BookBean>, recyclerView:
init {
if (recyclerView.layoutManager is LinearLayoutManager) {
val llMangager = recyclerView.layoutManager as LinearLayoutManager?
val manager = recyclerView.layoutManager as LinearLayoutManager?
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
totalItemCount = llMangager!!.itemCount
lastVisibleItem = llMangager.findLastVisibleItemPosition()
totalItemCount = manager!!.itemCount
lastVisibleItem = manager.findLastVisibleItemPosition()
if (!isLoadingMore && totalItemCount == lastVisibleItem + visibleThreshold && totalItemCount >= COMMENT_SIZE) {
if (mOnLoadMoreListener != null) {
mOnLoadMoreListener!!.onLoadMore()
@ -44,7 +44,6 @@ class RankListAdapter( val mList: List<RankByUpdateResp.BookBean>, recyclerView:
}
}
})
}
}
@ -97,7 +96,7 @@ class RankListAdapter( val mList: List<RankByUpdateResp.BookBean>, recyclerView:
}
override fun getItemViewType(position: Int): Int {
if (position == itemCount - 1) {
if (mList.isNotEmpty() && position == itemCount - 1) {
return PROCESS_ITEM
}
return when {

@ -9,18 +9,18 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.novel.read.R
import com.novel.read.activity.NovelBookDetailActivity
import com.novel.read.adapter.holder.EmptyHolder
import com.novel.read.adapter.holder.MoreHolder
import com.novel.read.constants.Constant
import com.novel.read.constants.Constant.COMMENT_SIZE
import com.novel.read.inter.OnLoadMoreListener
import com.novel.read.model.protocol.SearchResp
import com.novel.read.utlis.GlideImageLoader
import com.novel.read.constants.Constant.COMMENT_SIZE
class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: RecyclerView) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: RecyclerView) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var mContext: Context? = null
@ -35,12 +35,12 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView:
init {
if (recyclerView.layoutManager is LinearLayoutManager) {
val llMangager = recyclerView.layoutManager as LinearLayoutManager?
val manager = recyclerView.layoutManager as LinearLayoutManager?
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
totalItemCount = llMangager!!.itemCount
lastVisibleItem = llMangager.findLastVisibleItemPosition()
totalItemCount = manager!!.itemCount
lastVisibleItem = manager.findLastVisibleItemPosition()
if (!isLoadingMore && totalItemCount == lastVisibleItem + visibleThreshold && totalItemCount >= COMMENT_SIZE) {
if (mOnLoadMoreListener != null) {
mOnLoadMoreListener!!.onLoadMore()
@ -63,19 +63,23 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView:
val view: View
when (i) {
VALUE_ITEM -> {
view = LayoutInflater.from(mContext).inflate(R.layout.rlv_item_search, viewGroup, false)
view = LayoutInflater.from(mContext)
.inflate(R.layout.rlv_item_search, viewGroup, false)
return ViewHolder(view)
}
BOOK_ITEM -> {
view = LayoutInflater.from(mContext).inflate(R.layout.rlv_item_book_list_search, viewGroup, false)
view = LayoutInflater.from(mContext)
.inflate(R.layout.rlv_item_book_list_search, viewGroup, false)
return BookHolder(view)
}
EMPTY_ITEM -> {
view = LayoutInflater.from(mContext).inflate(R.layout.rlv_empty_view, viewGroup, false)
view =
LayoutInflater.from(mContext).inflate(R.layout.rlv_empty_view, viewGroup, false)
return EmptyHolder(view)
}
PROCESS_ITEM -> {
view = LayoutInflater.from(mContext).inflate(R.layout.load_more_layout, viewGroup, false)
view = LayoutInflater.from(mContext)
.inflate(R.layout.load_more_layout, viewGroup, false)
return MoreHolder(view)
}
else -> throw IllegalArgumentException()
@ -87,7 +91,12 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView:
is ViewHolder -> {
val bookBean = mList[i]
viewHolder.mTvBookName.text = bookBean.title
viewHolder.itemView.setOnClickListener { view -> mClickListener!!.onItemClick(view, i) }
viewHolder.itemView.setOnClickListener { view ->
mClickListener!!.onItemClick(
view,
i
)
}
}
is BookHolder -> {
val bookBean = mList[i]
@ -108,11 +117,11 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView:
override fun getItemCount(): Int {
return if (mList.isEmpty()) {
1
} else mList.size+1
} else mList.size + 1
}
override fun getItemViewType(position: Int): Int {
if (position == itemCount - 1) {
if (mList.isNotEmpty() && position == itemCount - 1) {
return PROCESS_ITEM
}

@ -42,7 +42,7 @@ class StackAdapter(private val mList: List<CategoryTypeResp.CategoryBean>) : Rec
}
GlideImageLoader.displayCornerImage(
mContext!!,
mList[i].cover!!,
mList[i].cover,
viewHolder.mIvType,
R.drawable.ic_type_default
)

@ -5,13 +5,15 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.jetbrains.annotations.NotNull;
public abstract class ViewHolderImpl<T> implements IViewHolder<T> {
private View view;
private Context context;
/****************************************************/
protected abstract int getItemLayoutId();
protected abstract int getItemLayoutId();
@NotNull
@Override
public View createItemView(ViewGroup parent) {
view = LayoutInflater.from(parent.getContext())

@ -1,13 +0,0 @@
package com.novel.read.adapter.holder;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class EmptyHolder extends RecyclerView.ViewHolder {
public EmptyHolder(@NonNull View itemView) {
super(itemView);
}
}

@ -0,0 +1,6 @@
package com.novel.read.adapter.holder
import android.view.View
import androidx.recyclerview.widget.RecyclerView
class EmptyHolder(itemView: View) : RecyclerView.ViewHolder(itemView)

@ -20,6 +20,6 @@ class CategoryTypeResp : Serializable {
var id: Int = 0
var title: String = ""
get() = StringUtils.convertCC(field)
var cover: String? = null
var cover: String = ""
}
}

@ -1,22 +0,0 @@
package com.novel.read.utlis;
/**
* 编码类型
*/
public enum Charset {
UTF8("UTF-8"),
UTF16LE("UTF-16LE"),
UTF16BE("UTF-16BE"),
GBK("GBK");
public String mName;
public static final byte BLANK = 0x0a;
Charset(String name) {
mName = name;
}
public String getName() {
return mName;
}
}

@ -0,0 +1,16 @@
package com.novel.read.utlis
/**
* 编码类型
*/
enum class Charset private constructor(var code: String) {
UTF8("UTF-8"),
UTF16LE("UTF-16LE"),
UTF16BE("UTF-16BE"),
GBK("GBK");
companion object {
val BLANK: Byte = 0x0a
}
}

@ -132,7 +132,7 @@ public class FileUtils {
}
//判断是否挂载了SD卡
public static boolean isSdCardExist(){
private static boolean isSdCardExist(){
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
return true;
}
@ -224,16 +224,6 @@ public class FileUtils {
charset = Charset.UTF8;
checked = true;
}
/*
* 不支持 UTF16LE UTF16BE
else if (first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE) {
charset = Charset.UTF16LE;
checked = true;
} else if (first3Bytes[0] == (byte) 0xFE
&& first3Bytes[1] == (byte) 0xFF) {
charset = Charset.UTF16BE;
checked = true;
} else */
bis.mark(0);
if (!checked) {

@ -16,7 +16,7 @@ import com.novel.read.R
/**
* create by 赵利君 on 2018/11/21
* create by zlj on 2018/11/21
* describe:
*/
object GlideImageLoader {

@ -1,6 +1,5 @@
package com.novel.read.utlis
import android.content.Context
import android.text.TextUtils
import com.novel.read.widget.page.ReadSettingManager.Companion.SHARED_READ_CONVERT_TYPE

@ -112,7 +112,7 @@ public class LocalPageLoader extends PageLoader {
//如果存在Chapter
if (hasChapter) {
//将数据转换成String
String blockContent = new String(buffer, 0, length, mCharset.getName());
String blockContent = new String(buffer, 0, length, mCharset.getCode());
//当前Block下使过的String的指针
int seekPos = 0;
//进行正则匹配
@ -136,7 +136,7 @@ public class LocalPageLoader extends PageLoader {
TxtChapter preChapter = new TxtChapter();
preChapter.title = "序章";
preChapter.start = 0;
preChapter.end = chapterContent.getBytes(mCharset.getName()).length; //获取String的byte值,作为最终值
preChapter.end = chapterContent.getBytes(mCharset.getCode()).length; //获取String的byte值,作为最终值
//如果序章大小大于30才添加进去
if (preChapter.end - preChapter.start > 30) {
@ -154,7 +154,7 @@ public class LocalPageLoader extends PageLoader {
//获取上一章节
TxtChapter lastChapter = chapters.get(chapters.size() - 1);
//将当前段落添加上一章去
lastChapter.end += chapterContent.getBytes(mCharset.getName()).length;
lastChapter.end += chapterContent.getBytes(mCharset.getCode()).length;
//如果章节内容太小,则移除
if (lastChapter.end - lastChapter.start < 30) {
@ -176,7 +176,7 @@ public class LocalPageLoader extends PageLoader {
//获取上一章节
TxtChapter lastChapter = chapters.get(chapters.size() - 1);
lastChapter.end = lastChapter.start + chapterContent.getBytes(mCharset.getName()).length;
lastChapter.end = lastChapter.start + chapterContent.getBytes(mCharset.getCode()).length;
//如果章节内容太小,则移除
if (lastChapter.end - lastChapter.start < 30) {
@ -216,7 +216,7 @@ public class LocalPageLoader extends PageLoader {
int end = length;
//寻找换行符作为终止点
for (int i = chapterOffset + MAX_LENGTH_WITH_NO_CHAPTER; i < length; ++i) {
if (buffer[i] == Charset.BLANK) {
if (buffer[i] == Charset.Companion.getBLANK()) {
end = i;
break;
}
@ -303,7 +303,7 @@ public class LocalPageLoader extends PageLoader {
//进行章节匹配
for (String str : CHAPTER_PATTERNS) {
Pattern pattern = Pattern.compile(str, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(new String(buffer, 0, length, mCharset.getName()));
Matcher matcher = pattern.matcher(new String(buffer, 0, length, mCharset.getCode()));
//如果匹配存在,那么就表示当前章节使用这种匹配方式
if (matcher.find()) {
mChapterPattern = pattern;
@ -432,7 +432,7 @@ public class LocalPageLoader extends PageLoader {
test = StringUtils.INSTANCE.convertCC(test);
content = test.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(content);
return new BufferedReader(new InputStreamReader(bais, mCharset.getName()));
return new BufferedReader(new InputStreamReader(bais, mCharset.getCode()));
}
@Override

Loading…
Cancel
Save