diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8079389..7c55dbd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -96,7 +96,7 @@ dependencies { implementation("com.squareup.retrofit2:retrofit:2.9.0") implementation("com.squareup.retrofit2:converter-gson:2.6.4") implementation("com.squareup.retrofit2:converter-scalars:2.6.4") - + implementation("androidx.viewpager2:viewpager2:1.0.0") // implementation ("me.everything:providers-android:1.0.1") // implementation ("me.everything:providers-core:1.0.1") // implementation ("androidx.window:window:1.0.0") 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 06948d9..7f2309f 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt @@ -39,7 +39,6 @@ import android.view.View import android.view.ViewGroup import android.widget.CheckBox import android.widget.EditText -import android.widget.RadioButton import android.widget.TableRow import android.widget.Toast import androidx.appcompat.app.AlertDialog @@ -51,31 +50,18 @@ import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import androidx.work.OneTimeWorkRequest +import androidx.viewpager2.widget.ViewPager2 import androidx.work.WorkManager -import io.realm.kotlin.Realm -import io.realm.kotlin.ext.asFlow import io.realm.kotlin.ext.query -import io.realm.kotlin.notifications.InitialObject import io.realm.kotlin.notifications.InitialResults -import io.realm.kotlin.notifications.ObjectChange import io.realm.kotlin.notifications.ResultsChange -import io.realm.kotlin.notifications.UpdatedObject import io.realm.kotlin.notifications.UpdatedResults -import io.realm.kotlin.query.RealmQuery import io.realm.kotlin.query.RealmResults import io.realm.kotlin.query.Sort import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch -import okhttp3.ConnectionPool -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.Response -import okhttp3.ResponseBody import org.json.JSONArray import org.json.JSONObject import rasel.lunar.launcher.LauncherActivity.Companion.lActivity @@ -94,14 +80,16 @@ import rasel.lunar.launcher.home.adapters.RecentCallsAdapter import rasel.lunar.launcher.home.adapters.RssItemAdapter import rasel.lunar.launcher.home.adapters.SmsLogsAdapter import rasel.lunar.launcher.home.adapters.WeatherAdapter +import rasel.lunar.launcher.home.adapters.WeatherDressAdatper +import rasel.lunar.launcher.home.adapters.WeatherHourlyAdapter import rasel.lunar.launcher.model.CurrentPlayItem import rasel.lunar.launcher.model.Hour -import rasel.lunar.launcher.model.Location import rasel.lunar.launcher.model.NotificationItem import rasel.lunar.launcher.model.RssData import rasel.lunar.launcher.model.RssDataInterface import rasel.lunar.launcher.model.RssDataType import rasel.lunar.launcher.model.WeatherForcast +import rasel.lunar.launcher.model.WeatherInfoManager import rasel.lunar.launcher.qaccess.QuickAccess import rasel.lunar.launcher.settings.SettingsActivity import rasel.lunar.launcher.utils.BLog @@ -111,10 +99,8 @@ import rasel.lunar.launcher.utils.SimpleFingerGestures import rasel.lunar.launcher.utils.beforeDay import rasel.lunar.launcher.view.TableRadioGroup import rasel.lunar.launcher.workers.LocationGetter -import rasel.lunar.launcher.workers.OpenWeatherGetter import rasel.lunar.launcher.workers.RecentCall import rasel.lunar.launcher.workers.RecentSms -import rasel.lunar.launcher.workers.TelegramBotGetter import rasel.lunar.launcher.workers.WorkersDb import java.math.BigDecimal import java.net.URLEncoder @@ -192,7 +178,23 @@ internal class LauncherHome : Fragment() { mSmsLogsAdapter = SmsLogsAdapter(arrayListOf(), requireContext()) mNotiAdapter = NotificationItemAdapter(requireContext()) mRssAdapter = RssItemAdapter(requireContext()) - mWeatherAdapter = WeatherAdapter(arrayListOf(),binding.noticeSummary) + + weatherDressAdapter = WeatherDressAdatper(arrayListOf()) + weatherHourlyAdapter = WeatherHourlyAdapter(arrayListOf()) + mWeatherAdapter = WeatherAdapter( + listOf( + R.layout.hourly_weather, + R.layout.recommended_hourly_dress + ), + listOf( + weatherDressAdapter, + weatherHourlyAdapter + ), + binding.noticeSummary) + + binding.noticeSummary.weatherViewPager.offscreenPageLimit = 2 + +// mWeatherAdapter = WeatherAdapter(arrayListOf(),binding.noticeSummary) // WorkersDb.getRealm().query().first().find()?.forecast?.let { // mWeatherAdapter?.update(it.forecastday) // BLog.LOGE("saved weatherForcast >>> ${it.forecastday}") @@ -210,13 +212,13 @@ internal class LauncherHome : Fragment() { binding.mainList.layoutManager = GridLayoutManager(requireContext(),2) binding.smsList.layoutManager = GridLayoutManager(requireContext(),2) binding.infoList.layoutManager = LinearLayoutManager(requireContext()) - binding.noticeSummary.weatherRecycller.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + binding.noticeSummary.weatherViewPager.orientation = ViewPager2.ORIENTATION_VERTICAL binding.mainList.adapter = mRecentCallsAdapter binding.smsList.adapter = mSmsLogsAdapter binding.infoList.adapter = mRssAdapter binding.notiList.adapter = mNotiAdapter - binding.noticeSummary.weatherRecycller.adapter = mWeatherAdapter + binding.noticeSummary.weatherViewPager.adapter = mWeatherAdapter binding.favAppsGroup.setOnClickListener { searchData() } try{binding.mainList.removeOnScrollListener(onScrChanged)}catch (e : Exception){e.printStackTrace()} @@ -312,15 +314,34 @@ internal class LauncherHome : Fragment() { BLog.LOGE("re >>> ${it.description()}") }.find().let {hours -> Handler(Looper.getMainLooper()).post { - mWeatherAdapter?.let { + weatherDressAdapter?.let { it.update( mutableListOf().apply { - this.addAll(it.filter(hours)) + this.addAll( +// it.filter(hours) + hours + ) } ) it.notifyDataSetChanged() } + weatherHourlyAdapter?.let { + it.update( + mutableListOf().apply { + this.addAll( +// it.filter(hours) + hours + ) + } + ) + BLog.LOGE("hour ${hours}") + it.notifyDataSetChanged() } + mWeatherAdapter?.let { + binding.noticeSummary.textLocation = if (hours.isNotEmpty()) WeatherInfoManager.getShowingInfo(hours.first()).textLocation else "도시 / 나라" + it.notifyDataSetChanged() + } + } } // .asFlow() // .collect { changes -> @@ -574,6 +595,8 @@ internal class LauncherHome : Fragment() { lateinit var mRssAdapter : RssItemAdapter lateinit var mNotiAdapter : NotificationItemAdapter var mWeatherAdapter: WeatherAdapter? =null + var weatherDressAdapter: WeatherDressAdatper? = null + var weatherHourlyAdapter: WeatherHourlyAdapter? = null var mRssDataResult : RealmResults? = null var mNotificationResult : RealmResults? = null 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 9099255..3766afd 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 @@ -1,99 +1,46 @@ 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.LinearLayoutManager 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.model.WeatherInfoManager -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 +import rasel.lunar.launcher.databinding.WeatherBookBinding class WeatherAdapter( - private val dataSet: ArrayList, private val total : RecommendedHourlyDressBinding): RecyclerView.Adapter(){ - var isChangedAmOrPm: Boolean = true + private val pages: List, + private val adatpers: List?>, + private val weatherBook: WeatherBookBinding? = null) + : RecyclerView.Adapter() { - class ViewHolder(val viewItem: ItemRecHourlyDressBinding): RecyclerView.ViewHolder(viewItem.root) + class PageViewHolder(val view: View): RecyclerView.ViewHolder(view) - // @SuppressLint("NotifyDataSetChanged") - fun update(li: Collection) { - li.toList() - this.dataSet.clear() - this.dataSet.addAll(li) -// notifyDataSetChanged() + @SuppressLint("ResourceType") + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PageViewHolder { + return PageViewHolder(LayoutInflater.from(parent.context).inflate(pages[viewType], parent, false)) } - fun filter(arr: Collection) = mutableListOf() - .apply { - arr.forEach { - if (it.time_epoch >= (System.currentTimeMillis() / 1000)) { - this.add(it) + override fun onBindViewHolder(holder: PageViewHolder, position: Int) { + if (adatpers[position] != null) { + when (position) { + 0 -> holder.view.findViewById(R.id.recycler_hourly_weather).apply { + this.adapter = adatpers[position] + this.layoutManager = + LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false) + } + + else -> holder.view.findViewById(R.id.weather_dress_recycller).apply { + this.adapter = adatpers[position] + this.layoutManager = + LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false) } } } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { -// 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) + override fun getItemCount(): Int = pages.size - @SuppressLint("SetTextI18n") - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val data = dataSet[position] as? Hour - BLog.LOGE("saved weatherForcast >>> asFlow ${dataSet.size}") -// val today = Calendar.getInstance() -// today.time = Date(data?.time_epoch?.toLong()?.times(1000L) ?: 0L) -// val dayOfItem = today.get(Calendar.DAY_OF_YEAR) - data?.let { -// total.loc = WorkersDb.getRealm().query().also { -// BLog.LOGE("re >>> ${it.description()}") // 쿼리 로그 -// }.find().first() - WeatherInfoManager.getShowingInfo(it).apply { - total.setInfo(this) - holder.viewItem.setInfo(this) - } - BLog.LOGE("reeeeeeeeeee >>> ${holder.viewItem.hour.text}") - holder.viewItem.amOrPm.visibility = - if (arrayListOf(12, 0).contains(WeatherInfoManager.toZonedDateTime(it.time_epoch).hour) || position == 0) { - View.VISIBLE - } else View.INVISIBLE - holder.viewItem.hour.apply { - if (WeatherInfoManager.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.imgDress.setImageLevel(it.temp_c.toInt()) - } - } - - override fun getItemCount(): Int = dataSet.size + override fun getItemViewType(position: Int): Int = position } \ No newline at end of file diff --git a/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherDressAdatper.kt b/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherDressAdatper.kt new file mode 100644 index 0000000..7e340be --- /dev/null +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherDressAdatper.kt @@ -0,0 +1,73 @@ +package rasel.lunar.launcher.home.adapters + +import android.annotation.SuppressLint +import android.graphics.Color +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import rasel.lunar.launcher.databinding.ItemRecHourlyDressBinding +import rasel.lunar.launcher.databinding.RecommendedHourlyDressBinding +import rasel.lunar.launcher.model.Hour +import rasel.lunar.launcher.model.WeatherInfoManager +import rasel.lunar.launcher.utils.BLog +import java.util.Calendar + +class WeatherDressAdatper (private val dataSet: ArrayList) : RecyclerView.Adapter(){ + var isChangedAmOrPm: Boolean = true + + class ViewHolder(val viewItem: ItemRecHourlyDressBinding): RecyclerView.ViewHolder(viewItem.root) + + // @SuppressLint("NotifyDataSetChanged") + fun update(li: Collection) { + li.toList() + this.dataSet.clear() + this.dataSet.addAll(li) +// notifyDataSetChanged() + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WeatherDressAdatper.ViewHolder { +// 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 WeatherDressAdatper.ViewHolder(binding) + } + + fun getToday() = Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: WeatherDressAdatper.ViewHolder, position: Int) { + val data = dataSet[position] as? Hour + BLog.LOGE("saved weatherForcast >>> asFlow ${dataSet.size}") +// val today = Calendar.getInstance() +// today.time = Date(data?.time_epoch?.toLong()?.times(1000L) ?: 0L) +// val dayOfItem = today.get(Calendar.DAY_OF_YEAR) + data?.let { +// total.loc = WorkersDb.getRealm().query().also { +// BLog.LOGE("re >>> ${it.description()}") // 쿼리 로그 +// }.find().first() + WeatherInfoManager.getShowingInfo(it).apply { +// total.setInfo(this) + holder.viewItem.setInfo(this) + } + BLog.LOGE("reeeeeeeeeee >>> ${holder.viewItem.hour.text}") + holder.viewItem.amOrPm.visibility = + if (arrayListOf(12, 0).contains(WeatherInfoManager.toZonedDateTime(it.time_epoch).hour) || position == 0) { + View.VISIBLE + } else View.INVISIBLE + holder.viewItem.hour.apply { + if (WeatherInfoManager.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.imgDress.setImageLevel(it.temp_c.toInt()) + } + } + + override fun getItemCount(): Int = dataSet.size +} \ No newline at end of file diff --git a/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherHourlyAdater.kt b/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherHourlyAdater.kt new file mode 100644 index 0000000..c8bc136 --- /dev/null +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/adapters/WeatherHourlyAdater.kt @@ -0,0 +1,56 @@ +package rasel.lunar.launcher.home.adapters + +import android.annotation.SuppressLint +import android.graphics.Color +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import rasel.lunar.launcher.databinding.ItemHourlyWeatherBinding +import rasel.lunar.launcher.databinding.ItemRecHourlyDressBinding +import rasel.lunar.launcher.model.Hour +import rasel.lunar.launcher.model.WeatherInfoManager +import rasel.lunar.launcher.utils.BLog + +class WeatherHourlyAdapter(private val dataSet: ArrayList): RecyclerView.Adapter() { + class ViewHolder(val viewItem: ItemHourlyWeatherBinding): RecyclerView.ViewHolder(viewItem.root) + + override fun onCreateViewHolder(parent: ViewGroup, type: Int): WeatherHourlyAdapter.ViewHolder { + val binding = ItemHourlyWeatherBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return WeatherHourlyAdapter.ViewHolder(binding) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val data = dataSet[position] as? Hour + BLog.LOGE("saved weatherForcast >>> asFlow ${dataSet.size}") + data?.let { + WeatherInfoManager.getShowingInfo(it).apply { + holder.viewItem.setInfo(this) + } + BLog.LOGE("reeeeeeeeeee >>> ${holder.viewItem.hour.text}") + holder.viewItem.amOrPm.visibility = + if (arrayListOf(12, 0).contains(WeatherInfoManager.toZonedDateTime(it.time_epoch).hour) || position == 0) { + View.VISIBLE + } else View.INVISIBLE + holder.viewItem.hour.apply { + if (WeatherInfoManager.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.imgDress.setImageLevel(it.temp_c.toInt()) + } + } + + override fun getItemCount(): Int = dataSet.size + + fun update(li: Collection) { + BLog.LOGE("${this.javaClass.simpleName} update") + li.toList() + this.dataSet.clear() + this.dataSet.addAll(li) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/hourly_weather.xml b/app/src/main/res/layout/hourly_weather.xml new file mode 100644 index 0000000..1a7df97 --- /dev/null +++ b/app/src/main/res/layout/hourly_weather.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_hourly_weather.xml b/app/src/main/res/layout/item_hourly_weather.xml new file mode 100644 index 0000000..25ebaf1 --- /dev/null +++ b/app/src/main/res/layout/item_hourly_weather.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/launcher_home.xml b/app/src/main/res/layout/launcher_home.xml index 92d142d..9bd8bc1 100644 --- a/app/src/main/res/layout/launcher_home.xml +++ b/app/src/main/res/layout/launcher_home.xml @@ -130,7 +130,7 @@ - - - - - - - - - - + android:layout_height="match_parent"> + \ No newline at end of file diff --git a/app/src/main/res/layout/weather_book.xml b/app/src/main/res/layout/weather_book.xml new file mode 100644 index 0000000..ce45f2d --- /dev/null +++ b/app/src/main/res/layout/weather_book.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + +