recyclerView
This commit is contained in:
parent
6e34a6cad6
commit
3561137c6b
@ -0,0 +1,65 @@
|
||||
package rasel.lunar.launcher.home.adapters
|
||||
|
||||
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 rasel.lunar.launcher.R
|
||||
import rasel.lunar.launcher.home.adapters.WeatherAdapter.ViewHolder
|
||||
import rasel.lunar.launcher.model.Hour
|
||||
import rasel.lunar.launcher.model.WeatherForcast
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
|
||||
class WeatherAdapter(private val dataSet: Array<String>): RecyclerView.Adapter<ViewHolder>(){
|
||||
var isShowAmOrPm: Boolean = true
|
||||
|
||||
class ViewHolder(view: View): RecyclerView.ViewHolder(view) {
|
||||
val viewItem: View
|
||||
|
||||
init {
|
||||
viewItem = view.findViewById(R.id.weather_item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.recommended_hourly_dress, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val data = dataSet[position] as? Hour
|
||||
data?.let {
|
||||
if (it.time_epoch >= (System.currentTimeMillis() / 1000)) {
|
||||
holder.viewItem.findViewById<TextView>(R.id.amOrPm)
|
||||
.run {
|
||||
this.text = Instant.ofEpochSecond(it.time_epoch.toLong())
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.hour
|
||||
.run {
|
||||
if (this < 12) "오전" else "오후"
|
||||
}
|
||||
}
|
||||
holder.viewItem.findViewById<TextView>(R.id.hour)
|
||||
.run {
|
||||
val hour = Instant.ofEpochSecond(it.time_epoch.toLong())
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.hour
|
||||
.toString()
|
||||
this.text = "${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}도"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 3
|
||||
}
|
||||
@ -4,12 +4,14 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center">
|
||||
android:gravity="center"
|
||||
android:id="@+id/weather_item">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="오후"
|
||||
android:id="@+id/amOrPm"
|
||||
android:gravity="center"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textSize="14sp" />
|
||||
@ -17,12 +19,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="16시"
|
||||
android:id="@+id/hour"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"
|
||||
android:textAlignment="center"/>
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
android:id="@+id/imgDress"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:contentDescription="시계 아이콘"
|
||||
@ -31,6 +34,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="27도"
|
||||
android:id="@+id/temperature"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textSize="14sp"
|
||||
android:gravity="center"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user