Skip to content

Commit

Permalink
Merge pull request #478 from RedrockMobile/lyt/fix/ufield
Browse files Browse the repository at this point in the history
🎨 整理邮乐场模块代码,去除冗余代码
  • Loading branch information
lytMoon authored May 13, 2024
2 parents dca5df0 + c83af01 commit 974cc7a
Show file tree
Hide file tree
Showing 27 changed files with 191 additions and 496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.mredrock.cyxbs.ufield.R
import com.mredrock.cyxbs.ufield.bean.DoneBean
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import com.mredrock.cyxbs.ufield.helper.timeFormat

/**
* author : lytMoon
Expand All @@ -23,36 +21,32 @@ import java.time.format.DateTimeFormatter
* version : 1.0
*/
class DoneRvAdapter :
ListAdapter<DoneBean, DoneRvAdapter.RvDoneViewHolder>((RvDoneDiffCallback())) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RvDoneViewHolder {
return RvDoneViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.ufield_item_rv_done, parent, false)
)
}
ListAdapter<DoneBean, DoneRvAdapter.RvDoneViewHolder>(object :
DiffUtil.ItemCallback<DoneBean>() {
override fun areItemsTheSame(oldItem: DoneBean, newItem: DoneBean) = oldItem.activityId == newItem.activityId
override fun areContentsTheSame(oldItem: DoneBean, newItem: DoneBean) = oldItem == newItem
}) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = RvDoneViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.ufield_item_rv_done, parent, false)
)

@RequiresApi(Build.VERSION_CODES.O)
override fun onBindViewHolder(holder: RvDoneViewHolder, position: Int) {
val itemData = getItem(position)

holder.bind(itemData)
}



/**
* 点击按钮的回调
*/

private var mClick: ((Int) -> Unit)? = null


fun setOnItemClick(listener: (Int) -> Unit){
fun setOnItemClick(listener: (Int) -> Unit) {
mClick = listener
}



inner class RvDoneViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

private val actName: TextView = itemView.findViewById(R.id.uField_done_activity_name)
Expand All @@ -69,46 +63,18 @@ class DoneRvAdapter :
}


/**
* 进行视图的绑定
*/
@RequiresApi(Build.VERSION_CODES.O)
fun bind(itemData: DoneBean) {
actName.text = itemData.activityTitle
actTime.text = timeFormat(itemData.activityCreateTimestamp)
actPhone.text = itemData.activityPhone
actAuthor.text = itemData.activityCreator

when (itemData.state) {
"rejected" -> actImage.setImageResource(R.drawable.ufield_ic_reject)
"published" -> actImage.setImageResource(R.drawable.ufield_ic_pass)
}
}

/**
* 加工时间戳,把时间戳转化为“年.月.日”格式
*/
@RequiresApi(Build.VERSION_CODES.O)
fun timeFormat(time: Long): String {
return Instant
.ofEpochSecond(time)
.atZone(ZoneId.systemDefault())
.toLocalDateTime()
.format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))
}
}

class RvDoneDiffCallback : DiffUtil.ItemCallback<DoneBean>() {

override fun areItemsTheSame(oldItem: DoneBean, newItem: DoneBean): Boolean {
return oldItem == newItem
}


override fun areContentsTheSame(oldItem: DoneBean, newItem: DoneBean): Boolean {
return oldItem.activityId == newItem.activityId && oldItem.activityCreator==newItem.activityCreator && oldItem.activityPhone==newItem.activityPhone
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.mredrock.cyxbs.lib.utils.extensions.setImageFromUrl
import com.mredrock.cyxbs.ufield.R
import com.mredrock.cyxbs.ufield.bean.ItemActivityBean
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import com.mredrock.cyxbs.ufield.helper.formatNumberToTime

/**
* description : 负责展示搜索活动数据的Rv adapter
Expand All @@ -25,24 +23,26 @@ import java.time.format.DateTimeFormatter
* version : 1.0
*/
class SearchRvAdapter :
ListAdapter<ItemActivityBean.ItemAll, SearchRvAdapter.RvSearchActViewHolder>((RvSearchDiffCallback())) {
ListAdapter<ItemActivityBean.ItemAll, SearchRvAdapter.RvSearchActViewHolder>(object :
DiffUtil.ItemCallback<ItemActivityBean.ItemAll>() {
override fun areItemsTheSame(oldItem: ItemActivityBean.ItemAll, newItem: ItemActivityBean.ItemAll) = oldItem.activityId == newItem.activityId
override fun areContentsTheSame(oldItem: ItemActivityBean.ItemAll, newItem: ItemActivityBean.ItemAll) = oldItem == newItem
}) {


/**
* 点击活动的回调
*/
private var mActivityClick: ((Int) -> Unit)? = null

fun setOnActivityClick(listener: (Int) -> Unit) {
mActivityClick = listener
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RvSearchActViewHolder {
return RvSearchActViewHolder(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
RvSearchActViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.ufield_item_rv_search, parent, false)
)
}

@RequiresApi(Build.VERSION_CODES.O)
override fun onBindViewHolder(holder: RvSearchActViewHolder, position: Int) {
Expand All @@ -54,16 +54,8 @@ class SearchRvAdapter :
inner class RvSearchActViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

private val actPic: ImageView = itemView.findViewById(R.id.uField_search_act_image)
private val actName: TextView =
itemView.findViewById<TextView?>(R.id.Ufield_search_act_ame).apply {
//视觉不让开启跑马灯
// isSelected = true
}
private val actHint: TextView =
itemView.findViewById<TextView?>(R.id.Ufield_search_act_what)
.apply {
// isSelected = true
}
private val actName: TextView = itemView.findViewById(R.id.Ufield_search_act_ame)
private val actHint: TextView = itemView.findViewById(R.id.Ufield_search_act_what)
private val actIsGoing: ImageView = itemView.findViewById(R.id.uField_search_isGoing)
private val actTime: TextView = itemView.findViewById(R.id.uField_search_ddl)

Expand All @@ -73,14 +65,11 @@ class SearchRvAdapter :
}
}

/**
* 进行视图的绑定
*/
@RequiresApi(Build.VERSION_CODES.O)
fun bind(itemData: ItemActivityBean.ItemAll) {
actName.text = itemData.activityTitle
actHint.text = itemData.activityDetail.trimStart()
actTime.text = timeFormat(itemData.activityStartAt)
actTime.text = formatNumberToTime(itemData.activityStartAt)
actPic.setImageFromUrl(itemData.activityCoverUrl)
when (itemData.ended) {
false -> actIsGoing.setImageResource(R.drawable.ufield_ic_activity_on)
Expand All @@ -89,36 +78,6 @@ class SearchRvAdapter :
}


/**
* 加工时间戳,把时间戳转化为“年.月.日”格式
*/
@RequiresApi(Build.VERSION_CODES.O)
fun timeFormat(time: Long): String {
return Instant
.ofEpochSecond(time)
.atZone(ZoneId.systemDefault())
.toLocalDateTime()
.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))
}
}


class RvSearchDiffCallback : DiffUtil.ItemCallback<ItemActivityBean.ItemAll>() {
override fun areItemsTheSame(
oldItem: ItemActivityBean.ItemAll,
newItem: ItemActivityBean.ItemAll
): Boolean {
return oldItem == newItem
}


override fun areContentsTheSame(
oldItem: ItemActivityBean.ItemAll,
newItem: ItemActivityBean.ItemAll
): Boolean {
return oldItem.activityId == newItem.activityId && oldItem.activityCreator == newItem.activityCreator && oldItem.activityStartAt == newItem.activityStartAt
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.mredrock.cyxbs.lib.utils.extensions.setOnSingleClickListener
import com.mredrock.cyxbs.ufield.R
import com.mredrock.cyxbs.ufield.bean.TodoBean
import com.mredrock.cyxbs.ufield.helper.timeFormat
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand All @@ -25,17 +26,17 @@ import java.time.format.DateTimeFormatter
* version : 1.0
*/
class TodoRvAdapter :
ListAdapter<TodoBean, TodoRvAdapter.RvTodoViewHolder>((RvTodoDiffCallback())) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RvTodoViewHolder {
return RvTodoViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.ufield_item_rv_todo, parent, false)
)
}
ListAdapter<TodoBean, TodoRvAdapter.RvTodoViewHolder>(object :
DiffUtil.ItemCallback<TodoBean>() {
override fun areItemsTheSame(oldItem: TodoBean, newItem: TodoBean)=oldItem.activityId == newItem.activityId
override fun areContentsTheSame(oldItem: TodoBean, newItem: TodoBean)=oldItem.activityId == newItem.activityId && oldItem.activityCreator == newItem.activityCreator && oldItem.activityStartAt == newItem.activityStartAt
}) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = RvTodoViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.ufield_item_rv_todo, parent, false)
)

@RequiresApi(Build.VERSION_CODES.O)
override fun onBindViewHolder(holder: RvTodoViewHolder, position: Int) {

val itemData = getItem(position)
holder.bind(itemData)
}
Expand Down Expand Up @@ -72,22 +73,19 @@ class TodoRvAdapter :

inner class RvTodoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {


private val actName: TextView = itemView.findViewById(R.id.uField_todo_activity_name)
private val actTime: TextView = itemView.findViewById(R.id.uField_todo_activity_time)
private val actType: TextView = itemView.findViewById(R.id.uField_todo_activity_type)
private val actAuthor: TextView = itemView.findViewById(R.id.uField_todo_activity_author)
private val actPhone: TextView = itemView.findViewById(R.id.uField_todo_activity_phone)
private val actPass: Button = itemView.findViewById(R.id.uField_todo_btn_accept)
private val actReject: Button = itemView.findViewById(R.id.uField_todo_btn_reject)
private val actItem: ConstraintLayout =
itemView.findViewById(R.id.ufield_check_constraintlayout)
private val actItem: ConstraintLayout = itemView.findViewById(R.id.ufield_check_constraintlayout)

init {
/**
* 当我们点击通过或者不通过活动的时候,列表会刷新,数组会改变。防止用户多次点击,这里使用单次点击的监听事件
*/

actPass.setOnSingleClickListener {
mOnPassClick?.invoke(absoluteAdapterPosition)
}
Expand All @@ -114,29 +112,6 @@ class TodoRvAdapter :
}


/**
* 加工时间戳,把时间戳转化为“年.月.日”格式
*/
@RequiresApi(Build.VERSION_CODES.O)
fun timeFormat(time: Long): String {
return Instant
.ofEpochSecond(time)
.atZone(ZoneId.systemDefault())
.toLocalDateTime()
.format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))
}
}


class RvTodoDiffCallback : DiffUtil.ItemCallback<TodoBean>() {
override fun areItemsTheSame(oldItem: TodoBean, newItem: TodoBean): Boolean {
return oldItem == newItem
}


override fun areContentsTheSame(oldItem: TodoBean, newItem: TodoBean): Boolean {
return oldItem.activityId == newItem.activityId && oldItem.activityCreator == newItem.activityCreator && oldItem.activityStartAt == newItem.activityStartAt
}

}

Expand Down
Loading

0 comments on commit 974cc7a

Please sign in to comment.