오전/오후 표시, 날짜 변화 표시
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package rasel.lunar.launcher.home.adapters
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Color
|
||||
import android.support.annotation.ColorInt
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -18,7 +20,8 @@ import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
|
||||
class WeatherAdapter(private val dataSet: ArrayList<Hour>): RecyclerView.Adapter<ViewHolder>(){
|
||||
var isShowAmOrPm: Boolean = true
|
||||
var isChangedAmOrPm: Boolean = true
|
||||
var day: Int = 0
|
||||
|
||||
class ViewHolder(view: View): RecyclerView.ViewHolder(view) {
|
||||
val viewItem: View
|
||||
@@ -51,34 +54,54 @@ class WeatherAdapter(private val dataSet: ArrayList<Hour>): RecyclerView.Adapter
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val data = dataSet[position] as? Hour
|
||||
BLog.LOGE("saved weatherForcast >>> asFlow ${dataSet.size}")
|
||||
data?.let {
|
||||
holder.viewItem.findViewById<TextView>(R.id.amOrPm)
|
||||
.run {
|
||||
this.text = Instant.ofEpochSecond(it.time_epoch.toLong())
|
||||
.apply {
|
||||
Instant.ofEpochSecond(it.time_epoch.toLong())
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.hour
|
||||
.run {
|
||||
if (this < 12) "오전" else "오후"
|
||||
this@apply.text = if (this < 12) "오전" else "오후"
|
||||
isChangedAmOrPm = when (this) {
|
||||
12, 0 -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
this.visibility = if (isChangedAmOrPm || position == 0) View.VISIBLE else View.INVISIBLE
|
||||
}
|
||||
holder.viewItem.findViewById<TextView>(R.id.hour)
|
||||
.run {
|
||||
val hour = Instant.ofEpochSecond(it.time_epoch.toLong())
|
||||
.apply {
|
||||
this.isSelected = (System.currentTimeMillis() % 3 == 0L)
|
||||
Instant.ofEpochSecond(it.time_epoch.toLong())
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.hour
|
||||
.toString()
|
||||
this.text = "${hour}시"
|
||||
.run {
|
||||
if (this.hour == 0) {
|
||||
this@apply.setTextColor(Color.BLACK)
|
||||
this@apply.isSelected = true
|
||||
this@apply.text = when (day++) {
|
||||
1 -> "내일"
|
||||
2 -> "모레"
|
||||
3 -> "글피"
|
||||
else -> "${this.dayOfMonth}일"
|
||||
}
|
||||
} else {
|
||||
this@apply.setTextColor(Color.WHITE)
|
||||
this@apply.isSelected = false
|
||||
this@apply.text = "${this.hour}시"
|
||||
}
|
||||
}
|
||||
holder.viewItem.findViewById<ImageView>(R.id.imgDress)
|
||||
.run { this.setImageResource(R.drawable.ico_time) }
|
||||
holder.viewItem.findViewById<TextView>(R.id.temperature)
|
||||
.run {
|
||||
this.text = "${it.temp_c}도"
|
||||
}
|
||||
}
|
||||
holder.viewItem.findViewById<ImageView>(R.id.imgDress)
|
||||
.run { this.setImageResource(R.drawable.ico_time) }
|
||||
holder.viewItem.findViewById<TextView>(R.id.temperature)
|
||||
.run {
|
||||
this.text = "${it.temp_c}도"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = dataSet.size
|
||||
|
||||
Reference in New Issue
Block a user