diff --git a/app/src/main/java/com/novel/read/adapter/BookListAdapter.kt b/app/src/main/java/com/novel/read/adapter/BookListAdapter.kt index ea00adf..0ac4941 100644 --- a/app/src/main/java/com/novel/read/adapter/BookListAdapter.kt +++ b/app/src/main/java/com/novel/read/adapter/BookListAdapter.kt @@ -31,12 +31,12 @@ class BookListAdapter(private val mList: List, 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, recyclerView } override fun getItemViewType(position: Int): Int { - if (position == itemCount - 1) { + if (mList.isNotEmpty() &&position == itemCount - 1) { return PROCESS_ITEM } return when { diff --git a/app/src/main/java/com/novel/read/adapter/IViewHolder.java b/app/src/main/java/com/novel/read/adapter/IViewHolder.java deleted file mode 100644 index 874a146..0000000 --- a/app/src/main/java/com/novel/read/adapter/IViewHolder.java +++ /dev/null @@ -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 { - View createItemView(ViewGroup parent); - void initView(); - void onBind(T data, int pos); - void onClick(); -} diff --git a/app/src/main/java/com/novel/read/adapter/IViewHolder.kt b/app/src/main/java/com/novel/read/adapter/IViewHolder.kt new file mode 100644 index 0000000..b69585e --- /dev/null +++ b/app/src/main/java/com/novel/read/adapter/IViewHolder.kt @@ -0,0 +1,15 @@ +package com.novel.read.adapter + +import android.view.View +import android.view.ViewGroup + +/** + * Created by zlj + */ + +interface IViewHolder { + fun createItemView(parent: ViewGroup): View + fun initView() + fun onBind(data: T, pos: Int) + fun onClick() +} diff --git a/app/src/main/java/com/novel/read/adapter/RankListAdapter.kt b/app/src/main/java/com/novel/read/adapter/RankListAdapter.kt index e56f6e3..eddf490 100644 --- a/app/src/main/java/com/novel/read/adapter/RankListAdapter.kt +++ b/app/src/main/java/com/novel/read/adapter/RankListAdapter.kt @@ -31,12 +31,12 @@ class RankListAdapter( val mList: List, 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, recyclerView: } } }) - } } @@ -97,7 +96,7 @@ class RankListAdapter( val mList: List, recyclerView: } override fun getItemViewType(position: Int): Int { - if (position == itemCount - 1) { + if (mList.isNotEmpty() && position == itemCount - 1) { return PROCESS_ITEM } return when { diff --git a/app/src/main/java/com/novel/read/adapter/SearchAdapter.kt b/app/src/main/java/com/novel/read/adapter/SearchAdapter.kt index 848b2e5..a4da871 100644 --- a/app/src/main/java/com/novel/read/adapter/SearchAdapter.kt +++ b/app/src/main/java/com/novel/read/adapter/SearchAdapter.kt @@ -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, recyclerView: RecyclerView) : RecyclerView.Adapter() { +class SearchAdapter(private val mList: List, recyclerView: RecyclerView) : + RecyclerView.Adapter() { private var mContext: Context? = null @@ -35,12 +35,12 @@ class SearchAdapter(private val mList: List, 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, 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, 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, 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 } diff --git a/app/src/main/java/com/novel/read/adapter/StackAdapter.kt b/app/src/main/java/com/novel/read/adapter/StackAdapter.kt index b4475f4..a729319 100644 --- a/app/src/main/java/com/novel/read/adapter/StackAdapter.kt +++ b/app/src/main/java/com/novel/read/adapter/StackAdapter.kt @@ -42,7 +42,7 @@ class StackAdapter(private val mList: List) : Rec } GlideImageLoader.displayCornerImage( mContext!!, - mList[i].cover!!, + mList[i].cover, viewHolder.mIvType, R.drawable.ic_type_default ) diff --git a/app/src/main/java/com/novel/read/adapter/ViewHolderImpl.java b/app/src/main/java/com/novel/read/adapter/ViewHolderImpl.java index 9a8af79..5ba4f86 100644 --- a/app/src/main/java/com/novel/read/adapter/ViewHolderImpl.java +++ b/app/src/main/java/com/novel/read/adapter/ViewHolderImpl.java @@ -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 implements IViewHolder { 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()) diff --git a/app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.java b/app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.java deleted file mode 100644 index 3e15968..0000000 --- a/app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.java +++ /dev/null @@ -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); - } -} diff --git a/app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.kt b/app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.kt new file mode 100644 index 0000000..20736cf --- /dev/null +++ b/app/src/main/java/com/novel/read/adapter/holder/EmptyHolder.kt @@ -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) diff --git a/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.kt b/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.kt index b9ef9c9..634bbcc 100644 --- a/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.kt +++ b/app/src/main/java/com/novel/read/model/protocol/CategoryTypeResp.kt @@ -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 = "" } } diff --git a/app/src/main/java/com/novel/read/utlis/Charset.java b/app/src/main/java/com/novel/read/utlis/Charset.java deleted file mode 100644 index e3e9fcf..0000000 --- a/app/src/main/java/com/novel/read/utlis/Charset.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/com/novel/read/utlis/Charset.kt b/app/src/main/java/com/novel/read/utlis/Charset.kt new file mode 100644 index 0000000..ba67d99 --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/Charset.kt @@ -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 + } +} diff --git a/app/src/main/java/com/novel/read/utlis/FileUtils.java b/app/src/main/java/com/novel/read/utlis/FileUtils.java index 14a6cf4..e2d511c 100644 --- a/app/src/main/java/com/novel/read/utlis/FileUtils.java +++ b/app/src/main/java/com/novel/read/utlis/FileUtils.java @@ -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) { diff --git a/app/src/main/java/com/novel/read/utlis/GlideImageLoader.kt b/app/src/main/java/com/novel/read/utlis/GlideImageLoader.kt index 38a88a4..7feca84 100644 --- a/app/src/main/java/com/novel/read/utlis/GlideImageLoader.kt +++ b/app/src/main/java/com/novel/read/utlis/GlideImageLoader.kt @@ -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 { diff --git a/app/src/main/java/com/novel/read/utlis/StringUtils.kt b/app/src/main/java/com/novel/read/utlis/StringUtils.kt index e55ef6f..0c8a5a4 100644 --- a/app/src/main/java/com/novel/read/utlis/StringUtils.kt +++ b/app/src/main/java/com/novel/read/utlis/StringUtils.kt @@ -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 diff --git a/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java b/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java index 4a8630d..6c0891c 100644 --- a/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java +++ b/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java @@ -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