오전/오후 표시, 날짜 변화 표시
This commit is contained in:
parent
6f3ac6d086
commit
007be81744
@ -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
|
||||||
|
|||||||
15
app/src/main/res/drawable/date_bg.xml
Normal file
15
app/src/main/res/drawable/date_bg.xml
Normal 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>
|
||||||
@ -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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user