合并代码

old
zlj 5 years ago
parent 241776fbcb
commit f9c396ba0d
  1. 14
      app/src/main/java/com/novel/read/activity/NovelMainActivity.kt
  2. 10
      app/src/main/java/com/novel/read/adapter/BookAdapter.kt

@ -26,7 +26,7 @@ import kotlinx.android.synthetic.main.activity_main.*
class NovelMainActivity : NovelBaseActivity() {
private var mCurrentFrag: Fragment? = null
private lateinit var mCurrentFrag: Fragment
private lateinit var mMainFragment: BookFragment
private lateinit var mRecommendFragment: RecommendFragment
private lateinit var mStackFragment: StackFragment
@ -35,11 +35,6 @@ class NovelMainActivity : NovelBaseActivity() {
//记录用户首次点击返回键的时间
private var firstTime: Long = 0
@SuppressLint("MissingSuperCall")
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
}
override val layoutId: Int get() = R.layout.activity_main
override fun initView() {
@ -84,13 +79,10 @@ class NovelMainActivity : NovelBaseActivity() {
private fun switchFragment(targetFragment: Fragment) {
val transaction = supportFragmentManager.beginTransaction()
if (!targetFragment.isAdded) {
//第一次使用switchFragment()时currentFragment为null,所以要判断一下
if (mCurrentFrag != null) {
transaction.hide(mCurrentFrag!!)
}
transaction.hide(mCurrentFrag)
transaction.add(R.id.fl_content, targetFragment, targetFragment.javaClass.name)
} else {
transaction.hide(mCurrentFrag!!).show(targetFragment)
transaction.hide(mCurrentFrag).show(targetFragment)
}
mCurrentFrag = targetFragment
transaction.commit()

@ -18,7 +18,7 @@ import com.novel.read.utlis.GlideImageLoader
import java.util.ArrayList
class BookAdapter(private val mList: List<CollBookBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var mContext: Context? = null
private lateinit var mContext: Context
private var mClickListener: OnItemClickListener? = null
private var mEdit: Boolean = false
@ -35,9 +35,7 @@ class BookAdapter(private val mList: List<CollBookBean>) : RecyclerView.Adapter<
}
override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): RecyclerView.ViewHolder {
if (mContext == null) {
mContext = viewGroup.context
}
val view: View
if (i == VALUE_ITEM) {
view = LayoutInflater.from(mContext).inflate(R.layout.rlv_item_book, viewGroup, false)
@ -61,7 +59,7 @@ class BookAdapter(private val mList: List<CollBookBean>) : RecyclerView.Adapter<
} else {
viewHolder.mIvGeng.visibility = View.GONE
}
GlideImageLoader.displayCornerImage(mContext!!, mList[i].cover, viewHolder.mIvBook)
GlideImageLoader.displayCornerImage(mContext, mList[i].cover, viewHolder.mIvBook)
viewHolder.itemView.setOnClickListener {
viewHolder.mIvCheck.isSelected = !mList[i].isSelect
mList[i].isSelect = !mList[i].isSelect
@ -88,7 +86,7 @@ class BookAdapter(private val mList: List<CollBookBean>) : RecyclerView.Adapter<
viewHolder.mIvGeng.visibility = View.GONE
}
GlideImageLoader.displayCornerImage(
mContext!!,
mContext,
mList[i].cover,
viewHolder.mIvBook
)
@ -96,7 +94,7 @@ class BookAdapter(private val mList: List<CollBookBean>) : RecyclerView.Adapter<
val intent = Intent(mContext, NovelReadActivity::class.java)
intent.putExtra(NovelReadActivity.EXTRA_IS_COLLECTED, true)
intent.putExtra(NovelReadActivity.EXTRA_COLL_BOOK, mList[i])
mContext!!.startActivity(intent)
mContext.startActivity(intent)
}
}
}

Loading…
Cancel
Save