diff --git a/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherAdapter.kt b/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherAdapter.kt new file mode 100644 index 00000000..e03a037c --- /dev/null +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherAdapter.kt @@ -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): RecyclerView.Adapter(){ + 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(R.id.amOrPm) + .run { + this.text = Instant.ofEpochSecond(it.time_epoch.toLong()) + .atZone(ZoneId.systemDefault()) + .hour + .run { + if (this < 12) "오전" else "오후" + } + } + holder.viewItem.findViewById(R.id.hour) + .run { + val hour = Instant.ofEpochSecond(it.time_epoch.toLong()) + .atZone(ZoneId.systemDefault()) + .hour + .toString() + this.text = "${hour}시" + } + holder.viewItem.findViewById(R.id.imgDress) + .run { this.setImageResource(R.drawable.ico_time) } + holder.viewItem.findViewById(R.id.temperature) + .run { + this.text = "${it.temp_c}도" + } + } + } + } + + override fun getItemCount(): Int = 3 +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_rec_hourly_dress.xml b/app/src/main/res/layout/item_rec_hourly_dress.xml index 74b2ac4a..0f796636 100644 --- a/app/src/main/res/layout/item_rec_hourly_dress.xml +++ b/app/src/main/res/layout/item_rec_hourly_dress.xml @@ -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"> @@ -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"/>