오전/오후 표시, 날짜 변화 표시

This commit is contained in:
JUNGGWAN KIM 2024-10-04 13:49:00 +09:00
parent 6f3ac6d086
commit 007be81744
3 changed files with 56 additions and 17 deletions

View File

@ -1,6 +1,8 @@
package rasel.lunar.launcher.home.adapters package rasel.lunar.launcher.home.adapters
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.graphics.Color
import android.support.annotation.ColorInt
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -18,7 +20,8 @@ import java.time.Instant
import java.time.ZoneId import java.time.ZoneId
class WeatherAdapter(private val dataSet: ArrayList<Hour>): RecyclerView.Adapter<ViewHolder>(){ 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) { class ViewHolder(view: View): RecyclerView.ViewHolder(view) {
val viewItem: View val viewItem: View
@ -51,34 +54,54 @@ class WeatherAdapter(private val dataSet: ArrayList<Hour>): RecyclerView.Adapter
return ViewHolder(view) return ViewHolder(view)
} }
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val data = dataSet[position] as? Hour val data = dataSet[position] as? Hour
BLog.LOGE("saved weatherForcast >>> asFlow ${dataSet.size}") BLog.LOGE("saved weatherForcast >>> asFlow ${dataSet.size}")
data?.let { data?.let {
holder.viewItem.findViewById<TextView>(R.id.amOrPm) holder.viewItem.findViewById<TextView>(R.id.amOrPm)
.run { .apply {
this.text = Instant.ofEpochSecond(it.time_epoch.toLong()) Instant.ofEpochSecond(it.time_epoch.toLong())
.atZone(ZoneId.systemDefault()) .atZone(ZoneId.systemDefault())
.hour .hour
.run { .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) holder.viewItem.findViewById<TextView>(R.id.hour)
.run { .apply {
val hour = Instant.ofEpochSecond(it.time_epoch.toLong()) this.isSelected = (System.currentTimeMillis() % 3 == 0L)
Instant.ofEpochSecond(it.time_epoch.toLong())
.atZone(ZoneId.systemDefault()) .atZone(ZoneId.systemDefault())
.hour .run {
.toString() if (this.hour == 0) {
this.text = "${hour}" 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 override fun getItemCount(): Int = dataSet.size

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape>
<solid android:color="@android:color/white"/>
<corners android:radius="10dp"/>
</shape>
</item>
<item android:state_selected="false">
<shape>
<solid android:color="@android:color/transparent"/>
<corners android:radius="10dp"/>
</shape>
</item>
</selector>

View File

@ -16,10 +16,11 @@
android:fontFamily="sans-serif-medium" android:fontFamily="sans-serif-medium"
android:textSize="14sp" /> android:textSize="14sp" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="50dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="16시" android:text="16시"
android:id="@+id/hour" android:id="@+id/hour"
android:background="@drawable/date_bg"
android:fontFamily="sans-serif-medium" android:fontFamily="sans-serif-medium"
android:gravity="center" android:gravity="center"
android:textSize="14sp" android:textSize="14sp"