diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0d4476f..cbb93fc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -60,6 +60,7 @@ android { buildFeatures { viewBinding = true + dataBinding = true } compileOptions { diff --git a/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt b/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt index f46d2ec..6851576 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt @@ -83,6 +83,7 @@ import rasel.lunar.launcher.apps.AppDrawer import rasel.lunar.launcher.apps.DismissCalback import rasel.lunar.launcher.apps.SearchMenu import rasel.lunar.launcher.databinding.LauncherActivityBinding +import rasel.lunar.launcher.databinding.RecommendedHourlyDressBinding import rasel.lunar.launcher.feeds.Feeds import rasel.lunar.launcher.feeds.WidgetHost import rasel.lunar.launcher.helpers.Constants.Companion.KEY_APPLICATION_THEME @@ -411,7 +412,6 @@ internal class LauncherActivity : AppCompatActivity() { } } } - } override fun onDestroy() { diff --git a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt index d633efd..d56b144 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt @@ -191,7 +191,7 @@ internal class LauncherHome : Fragment() { mSmsLogsAdapter = SmsLogsAdapter(arrayListOf(), requireContext()) mNotiAdapter = NotificationItemAdapter(requireContext()) mRssAdapter = RssItemAdapter(requireContext()) - mWeatherAdapter = WeatherAdapter(arrayListOf()) + mWeatherAdapter = WeatherAdapter(arrayListOf(),binding.noticeSummary) // WorkersDb.getRealm().query().first().find()?.forecast?.let { // mWeatherAdapter?.update(it.forecastday) // BLog.LOGE("saved weatherForcast >>> ${it.forecastday}") 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 index fffd2f2..07f73c5 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherAdapter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherAdapter.kt @@ -2,34 +2,39 @@ package rasel.lunar.launcher.home.adapters import android.annotation.SuppressLint import android.graphics.Color +import android.os.Handler +import android.os.Looper import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.RecyclerView +import io.realm.kotlin.ext.query import rasel.lunar.launcher.R +import rasel.lunar.launcher.databinding.ItemRecHourlyDressBinding +import rasel.lunar.launcher.databinding.ListItemWithBinding +import rasel.lunar.launcher.databinding.RecommendedHourlyDressBinding import rasel.lunar.launcher.home.adapters.WeatherAdapter.ViewHolder import rasel.lunar.launcher.model.Day import rasel.lunar.launcher.model.Hour +import rasel.lunar.launcher.model.Location +import rasel.lunar.launcher.model.WeatherForcast import rasel.lunar.launcher.utils.BLog +import rasel.lunar.launcher.workers.WorkersDb import java.time.Instant import java.time.ZoneId import java.util.Calendar import java.util.Date -class WeatherAdapter(private val dataSet: ArrayList): RecyclerView.Adapter(){ +class WeatherAdapter( + private val dataSet: ArrayList, private val total : RecommendedHourlyDressBinding): RecyclerView.Adapter(){ var isChangedAmOrPm: Boolean = true - class ViewHolder(view: View): RecyclerView.ViewHolder(view) { - val viewItem: View + class ViewHolder(val viewItem: ItemRecHourlyDressBinding): RecyclerView.ViewHolder(viewItem.root) - init { - viewItem = view.findViewById(R.id.weather_item) - } - } - -// @SuppressLint("NotifyDataSetChanged") + // @SuppressLint("NotifyDataSetChanged") fun update(li: Collection) { li.toList() this.dataSet.clear() @@ -47,9 +52,11 @@ class WeatherAdapter(private val dataSet: ArrayList): RecyclerView.Adapter } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(parent.context) - .inflate(R.layout.item_rec_hourly_dress, parent, false) - return ViewHolder(view) +// val view = LayoutInflater.from(parent.context) +// .inflate(R.layout.item_rec_hourly_dress, parent, false) +// val itemBinding: ItemRecHourlyDressBinding = DataBindingUtil. + val binding = ItemRecHourlyDressBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return ViewHolder(binding) } fun getToday() = Calendar.getInstance().get(Calendar.DAY_OF_YEAR) @@ -62,68 +69,26 @@ class WeatherAdapter(private val dataSet: ArrayList): RecyclerView.Adapter // today.time = Date(data?.time_epoch?.toLong()?.times(1000L) ?: 0L) // val dayOfItem = today.get(Calendar.DAY_OF_YEAR) data?.let { - holder.viewItem.findViewById(R.id.amOrPm) - .apply { - Instant.ofEpochSecond(it.time_epoch.toLong()) - .atZone(ZoneId.systemDefault()) - .hour - .run { - 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 + total.loc = WorkersDb.getRealm().query().also { + BLog.LOGE("re >>> ${it.description()}") // 쿼리 로그 + }.find().first() + + holder.viewItem.setHour(it) + BLog.LOGE("reeeeeeeeeee >>> ${holder.viewItem.hour.text}") + holder.viewItem.amOrPm.visibility = + if (arrayListOf(12, 0).contains(data.toZonedDateTime(it.time_epoch).hour) || position == 0) { + View.VISIBLE + } else View.INVISIBLE + holder.viewItem.hour.apply { + if (data.toZonedDateTime(it.time_epoch).hour == 0) { + this@apply.setTextColor(Color.BLACK) + this@apply.isSelected = true + } else { + this@apply.setTextColor(Color.WHITE) + this@apply.isSelected = false } - holder.viewItem.findViewById(R.id.hour) - .apply { - Instant.ofEpochSecond(it.time_epoch.toLong()) - .atZone(ZoneId.systemDefault()) - .run { - if (this.hour == 0) { - this@apply.setTextColor(Color.BLACK) - this@apply.isSelected = true - this@apply.text = when (this.dayOfYear - getToday()) { - 1 -> "내일" - 2 -> "모레" - 3 -> "글피" - else -> "${this.dayOfMonth}일" - } - } else { - this@apply.setTextColor(Color.WHITE) - this@apply.isSelected = false - this@apply.text = "${this.hour}시" - } - } - } - var img: Int? = null - var textDress: String? = null - if (it.temp_c >= 23) { - img = R.drawable.dress_short_sleeves - textDress = "반팔" - } else if ((23 > it.temp_c) && (it.temp_c >= 20)) { - img = R.drawable.dress_long_sleeves - textDress = "긴팔" - } else if ((20 > it.temp_c) && (it.temp_c >= 17)) { - img = R.drawable.dress_knitwear - textDress = "니트" - } else if ((17 > it.temp_c) && (it.temp_c >= 12)) { - img = R.drawable.dress_flimsy_outer - textDress = "얇은겉옷" - } else if ((12 > it.temp_c) && (it.temp_c >= 6)) { - img = R.drawable.dress_heavy_outer - textDress = "두꺼운겉옷" - } else { - img = R.drawable.dress_padded_coat - textDress = "패딩" } - holder.viewItem.findViewById(R.id.imgDress) - .setImageResource(img ?: R.drawable.dress_padded_coat) - holder.viewItem.findViewById(R.id.textDress) - .text = textDress - holder.viewItem.findViewById(R.id.temperature) - .text = "${it.temp_c}도" + holder.viewItem.imgDress.setImageLevel(it.temp_c.toInt()) } } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/model/WeatherForcast.kt b/app/src/main/kotlin/rasel/lunar/launcher/model/WeatherForcast.kt index ecbc02b..c7bc58a 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/model/WeatherForcast.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/model/WeatherForcast.kt @@ -5,6 +5,10 @@ import io.realm.kotlin.types.RealmList import io.realm.kotlin.types.RealmObject import io.realm.kotlin.types.annotations.Ignore import io.realm.kotlin.types.annotations.PrimaryKey +import rasel.lunar.launcher.R +import java.time.Instant +import java.time.ZoneId +import java.util.Calendar class WeatherForcast: RealmObject { @@ -32,6 +36,8 @@ class Location: RealmObject { var tz_id: String? = null var localtime_epoch = 0 var localtime: String? = null + + fun getTextLocation(): String = "$name / $country" } class Current: RealmObject { @@ -176,4 +182,57 @@ class Hour: RealmObject { var gust_mph = 0.0 var gust_kph = 0.0 var uv = 0.0 + + fun toZonedDateTime(timeEpoch: Int) = Instant.ofEpochSecond(timeEpoch.toLong()) + .atZone(ZoneId.systemDefault()) + + fun getAmOrPm(): String = toZonedDateTime(time_epoch).hour.run { + if (this < 12) "오전" else "오후" + } + + fun getTextHour(): String = toZonedDateTime(time_epoch) + .run { + if (this.hour == 0) { + when (this.dayOfYear - Calendar.getInstance().get(Calendar.DAY_OF_YEAR)) { + 1 -> "내일" + 2 -> "모레" + 3 -> "글피" + else -> "${this.dayOfMonth}일" + } + } else { + "${this.hour}시" + } + } + + fun getDress(): String = + if (temp_c >= 23) { + "반팔" + } else if ((23 > temp_c) && (temp_c >= 20)) { + "긴팔" + } else if ((20 > temp_c) && (temp_c >= 17)) { + "니트" + } else if ((17 > temp_c) && (temp_c >= 12)) { + "얇은겉옷" + } else if ((12 > temp_c) && (temp_c >= 6)) { + "두꺼운겉옷" + } else { + "패딩" + } + + fun getImgDress() = + if (temp_c >= 23) { + R.drawable.dress_short_sleeves + } else if ((23 > temp_c) && (temp_c >= 20)) { + "긴팔" + } else if ((20 > temp_c) && (temp_c >= 17)) { + "니트" + } else if ((17 > temp_c) && (temp_c >= 12)) { + "얇은겉옷" + } else if ((12 > temp_c) && (temp_c >= 6)) { + "두꺼운겉옷" + } else { + "패딩" + } + + fun getTemp(): String = "${temp_c}도" } \ No newline at end of file diff --git a/app/src/main/res/drawable/level_dress_img.xml b/app/src/main/res/drawable/level_dress_img.xml new file mode 100644 index 0000000..70744c7 --- /dev/null +++ b/app/src/main/res/drawable/level_dress_img.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ 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 3303be5..e60bd27 100644 --- a/app/src/main/res/layout/item_rec_hourly_dress.xml +++ b/app/src/main/res/layout/item_rec_hourly_dress.xml @@ -1,48 +1,58 @@ - + + + + + - - - - - - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/recommended_hourly_dress.xml b/app/src/main/res/layout/recommended_hourly_dress.xml index 50db6d7..cc8c54d 100644 --- a/app/src/main/res/layout/recommended_hourly_dress.xml +++ b/app/src/main/res/layout/recommended_hourly_dress.xml @@ -1,45 +1,68 @@ - - - - - - + + + + - - \ No newline at end of file + android:layout_height="match_parent" + android:textAlignment="center"> + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0387eab..3edead3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -166,4 +166,5 @@ Wiki +