Commit 4a940003 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 52722928
...@@ -19,16 +19,19 @@ class HomeVideoPageAdapter( ...@@ -19,16 +19,19 @@ class HomeVideoPageAdapter(
private val fragments = mutableMapOf<Int, Fragment>() private val fragments = mutableMapOf<Int, Fragment>()
override fun getItemId(position: Int): Long { override fun getItemId(position: Int): Long {
return data[position].id.toLong() // return data[position].id.toLong()
return 0
} }
override fun getItemCount() = data.size // override fun getItemCount() = data.size
override fun getItemCount() = 10
override fun createFragment(position: Int): Fragment { override fun createFragment(position: Int): Fragment {
val fragment = fragments[position] val fragment = fragments[position]
if (fragment != null) return fragment if (fragment != null) return fragment
val newFragment = MovieFragment.newInstance(data[position].id,position) // val newFragment = MovieFragment.newInstance(data[position].id,position)
val newFragment = MovieFragment.newInstance(1,position)
fragments[position] = newFragment fragments[position] = newFragment
return newFragment return newFragment
} }
......
package com.mints.wisdomclean.ui.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.airbnb.lottie.*
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
import com.itheima.roundedimageview.RoundedImageView
import com.mints.wisdomclean.R
import com.mints.wisdomclean.mvp.model.HotStyleBean
import com.mints.wisdomclean.ui.adapter.base.OnItemClickListener
class HotStyleAdapter(val context: Context, val dataList: ArrayList<HotStyleBean>) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
lateinit var mOnItemClickListener: OnItemClickListener
private var showAnim = true
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val rivXmlyPage: RoundedImageView = view.findViewById(R.id.riv_img)
val ivXmlyPage: ImageView = view.findViewById(R.id.iv_img)
val tvTitle: TextView = view.findViewById(R.id.tv_title)
val tvHotBtn: TextView = view.findViewById(R.id.tv_hot_btn)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.item_hot_style, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val viewHolder = holder as ViewHolder
if (dataList.size > 0) {
val data = dataList[position]
if (position == 0 && showAnim) {
val lottieDrawable = LottieDrawable()
LottieCompositionFactory.fromAsset(context, "guide_template_category.json")
.addListener { result: LottieComposition? ->
lottieDrawable.setImagesAssetsFolder("guild_template_category/")
lottieDrawable.composition = result
lottieDrawable.loop(true)
lottieDrawable.playAnimation()
}
holder.ivXmlyPage.setImageDrawable(lottieDrawable)
holder.ivXmlyPage.visibility = View.VISIBLE
holder.tvHotBtn.visibility = View.VISIBLE
holder.rivXmlyPage.visibility = View.GONE
holder.tvHotBtn.postDelayed({
YoYo.with(Techniques.Pulse).duration(500).repeat(-1).playOn(holder.tvHotBtn)
}, 300)
} else {
// GlideUtils.loadRoundImageViewGif(
// holder.itemView.context,
// data.imageUrl!!,
// holder.rivXmlyPage
// )
holder.ivXmlyPage.visibility = View.GONE
holder.tvHotBtn.visibility = View.GONE
holder.rivXmlyPage.visibility = View.VISIBLE
}
viewHolder.tvTitle.text = data.name
viewHolder.itemView.setOnClickListener {
if (::mOnItemClickListener.isInitialized) {
mOnItemClickListener.onItemClick(holder.itemView, position)
}
}
}
}
override fun getItemCount(): Int = 30
fun setOnItemClickListener(listener: OnItemClickListener) {
mOnItemClickListener = listener
}
fun setShowAnim(showAnim: Boolean) {
this.showAnim = showAnim
}
}
\ No newline at end of file
...@@ -162,7 +162,8 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener, OnRefreshLi ...@@ -162,7 +162,8 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener, OnRefreshLi
TabLayoutMediator(tablayout, vp2) { tab, position -> TabLayoutMediator(tablayout, vp2) { tab, position ->
// 初始化Tab // 初始化Tab
tab.id = position tab.id = position
tab.customView = getTabView(tabsData[position].title) tab.customView = getTabView("123")
// tab.customView = getTabView(tabsData[position].title)
}.attach() }.attach()
tablayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { tablayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) { override fun onTabSelected(tab: TabLayout.Tab?) {
......
...@@ -3,8 +3,10 @@ package com.mints.wisdomclean.ui.fragment ...@@ -3,8 +3,10 @@ package com.mints.wisdomclean.ui.fragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.mints.wisdomclean.R import com.mints.wisdomclean.R
import com.mints.wisdomclean.mvp.model.* import com.mints.wisdomclean.mvp.model.*
import com.mints.wisdomclean.ui.adapter.HotStyleAdapter
import com.mints.wisdomclean.ui.fragment.base.LazyLoadBaseFragment import com.mints.wisdomclean.ui.fragment.base.LazyLoadBaseFragment
import com.scwang.smartrefresh.layout.api.RefreshLayout import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
...@@ -35,7 +37,7 @@ class MovieFragment : LazyLoadBaseFragment(), OnLoadMoreListener { ...@@ -35,7 +37,7 @@ class MovieFragment : LazyLoadBaseFragment(), OnLoadMoreListener {
private var hotPage = 1 // 分页 private var hotPage = 1 // 分页
private val hotList: ArrayList<HotStyleBean> = arrayListOf() private val hotList: ArrayList<HotStyleBean> = arrayListOf()
// private lateinit var hotStyleAdapter: HotStyleAdapter private lateinit var hotStyleAdapter: HotStyleAdapter
private var mCurrentPosition = 0 private var mCurrentPosition = 0
override fun getContentViewLayoutID() = R.layout.fragment_movie override fun getContentViewLayoutID() = R.layout.fragment_movie
...@@ -109,11 +111,11 @@ class MovieFragment : LazyLoadBaseFragment(), OnLoadMoreListener { ...@@ -109,11 +111,11 @@ class MovieFragment : LazyLoadBaseFragment(), OnLoadMoreListener {
// } // }
private fun initView() { private fun initView() {
// val gridLayoutManager = GridLayoutManager(context, 2) val gridLayoutManager = GridLayoutManager(context, 3)
// rv_pic_list.layoutManager = gridLayoutManager rv_pic_list.layoutManager = gridLayoutManager
// hotStyleAdapter = HotStyleAdapter(requireContext(), hotList) hotStyleAdapter = HotStyleAdapter(requireContext(), hotList)
// hotStyleAdapter.setShowAnim(mPosition == 0) hotStyleAdapter.setShowAnim(mPosition == 0)
// rv_pic_list.adapter = hotStyleAdapter rv_pic_list.adapter = hotStyleAdapter
// hotStyleAdapter.setOnItemClickListener(object : OnItemClickListener { // hotStyleAdapter.setOnItemClickListener(object : OnItemClickListener {
// override fun onItemClick(view: View?, position: Int) { // override fun onItemClick(view: View?, position: Int) {
// if (hotList.size > 0) { // if (hotList.size > 0) {
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:minHeight="600dp" android:minHeight="600dp"
android:background="#f00"
android:overScrollMode="never" /> android:overScrollMode="never" />
<com.scwang.smartrefresh.layout.footer.ClassicsFooter <com.scwang.smartrefresh.layout.footer.ClassicsFooter
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@color/red"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="235dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp">
<ImageView
android:id="@+id/iv_img"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/tv_hot_btn"
android:layout_width="134dp"
android:layout_height="28dp"
android:textSize="14sp"
android:visibility="gone"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="24dp"
android:gravity="center"
android:textStyle="bold"
android:textColor="@color/white"
android:text="点击做同款"></TextView>
<com.itheima.roundedimageview.RoundedImageView
android:id="@+id/riv_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:riv_corner_radius="5dp" />
</FrameLayout>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:ellipsize="end"
android:lines="1"
android:singleLine="true"
android:textColor="#A7A8AA"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment