weather scroll
This commit is contained in:
parent
8fff21a6d8
commit
8cd2ffc16d
@ -97,6 +97,7 @@ dependencies {
|
|||||||
implementation("com.squareup.retrofit2:converter-gson:2.6.4")
|
implementation("com.squareup.retrofit2:converter-gson:2.6.4")
|
||||||
implementation("com.squareup.retrofit2:converter-scalars:2.6.4")
|
implementation("com.squareup.retrofit2:converter-scalars:2.6.4")
|
||||||
implementation("androidx.viewpager2:viewpager2:1.0.0")
|
implementation("androidx.viewpager2:viewpager2:1.0.0")
|
||||||
|
implementation("com.squareup.picasso:picasso:2.71828")
|
||||||
// implementation ("me.everything:providers-android:1.0.1")
|
// implementation ("me.everything:providers-android:1.0.1")
|
||||||
// implementation ("me.everything:providers-core:1.0.1")
|
// implementation ("me.everything:providers-core:1.0.1")
|
||||||
// implementation ("androidx.window:window:1.0.0")
|
// implementation ("androidx.window:window:1.0.0")
|
||||||
|
|||||||
@ -219,6 +219,25 @@ internal class LauncherHome : Fragment() {
|
|||||||
binding.infoList.adapter = mRssAdapter
|
binding.infoList.adapter = mRssAdapter
|
||||||
binding.notiList.adapter = mNotiAdapter
|
binding.notiList.adapter = mNotiAdapter
|
||||||
binding.noticeSummary.weatherViewPager.adapter = mWeatherAdapter
|
binding.noticeSummary.weatherViewPager.adapter = mWeatherAdapter
|
||||||
|
binding.noticeSummary.weatherViewPager.registerOnPageChangeCallback(object: ViewPager2.OnPageChangeCallback() {
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
super.onPageSelected(position)
|
||||||
|
// 페이지가 변경될 때 호출됨
|
||||||
|
mWeatherAdapter?.syncScroll(position)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
|
super.onPageScrollStateChanged(state)
|
||||||
|
// 스크롤 상태가 변경될 때 호출됨
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
|
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
|
||||||
|
// 페이지 스크롤이 발생할 때 호출됨
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
binding.favAppsGroup.setOnClickListener { searchData() }
|
binding.favAppsGroup.setOnClickListener { searchData() }
|
||||||
|
|
||||||
try{binding.mainList.removeOnScrollListener(onScrChanged)}catch (e : Exception){e.printStackTrace()}
|
try{binding.mainList.removeOnScrollListener(onScrChanged)}catch (e : Exception){e.printStackTrace()}
|
||||||
@ -315,16 +334,16 @@ internal class LauncherHome : Fragment() {
|
|||||||
}.find().let {hours ->
|
}.find().let {hours ->
|
||||||
Handler(Looper.getMainLooper()).post {
|
Handler(Looper.getMainLooper()).post {
|
||||||
weatherDressAdapter?.let {
|
weatherDressAdapter?.let {
|
||||||
it.update(
|
it.update(
|
||||||
mutableListOf<Hour>().apply {
|
mutableListOf<Hour>().apply {
|
||||||
this.addAll(
|
this.addAll(
|
||||||
// it.filter(hours)
|
// it.filter(hours)
|
||||||
hours
|
hours
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
it.notifyDataSetChanged()
|
it.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
weatherHourlyAdapter?.let {
|
weatherHourlyAdapter?.let {
|
||||||
it.update(
|
it.update(
|
||||||
mutableListOf<Hour>().apply {
|
mutableListOf<Hour>().apply {
|
||||||
|
|||||||
@ -1,13 +1,18 @@
|
|||||||
package rasel.lunar.launcher.home.adapters
|
package rasel.lunar.launcher.home.adapters
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearSnapHelper
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import rasel.lunar.launcher.R
|
import rasel.lunar.launcher.R
|
||||||
import rasel.lunar.launcher.databinding.WeatherBookBinding
|
import rasel.lunar.launcher.databinding.WeatherBookBinding
|
||||||
|
import rasel.lunar.launcher.utils.BLog
|
||||||
|
|
||||||
class WeatherAdapter(
|
class WeatherAdapter(
|
||||||
private val pages: List<Int>,
|
private val pages: List<Int>,
|
||||||
@ -17,26 +22,86 @@ class WeatherAdapter(
|
|||||||
|
|
||||||
class PageViewHolder(val view: View): RecyclerView.ViewHolder(view)
|
class PageViewHolder(val view: View): RecyclerView.ViewHolder(view)
|
||||||
|
|
||||||
|
|
||||||
|
var childs : ArrayList<RecyclerView> = arrayListOf<RecyclerView>()
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("ResourceType")
|
@SuppressLint("ResourceType")
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PageViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PageViewHolder {
|
||||||
return PageViewHolder(LayoutInflater.from(parent.context).inflate(pages[viewType], parent, false))
|
|
||||||
|
|
||||||
|
val layoutInflater = LayoutInflater.from(parent.context).inflate(pages[viewType], parent, false)
|
||||||
|
// var first = layoutInflater.findViewById<RecyclerView>(R.id.recycler_hourly_weather)
|
||||||
|
// var second = layoutInflater.findViewById<RecyclerView>(R.id.weather_dress_recycller)
|
||||||
|
|
||||||
|
return PageViewHolder(layoutInflater)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun syncScroll(newPosition: Int) {
|
||||||
|
childs[newPosition].let {recyclerView ->
|
||||||
|
BLog.LOGE("recyclerView >>> ${recyclerView} 1 ")
|
||||||
|
if (!isSyncingScroll) {
|
||||||
|
isSyncingScroll = true
|
||||||
|
BLog.LOGE("recyclerView >>> ${recyclerView} 2 ")
|
||||||
|
childs.forEach { c ->
|
||||||
|
// val visibleItemCount = (layoutManager?.findLastVisibleItemPosition() ?: 0) - (layoutManager?.findFirstVisibleItemPosition() ?: 0)
|
||||||
|
if (c != recyclerView) {
|
||||||
|
(c.layoutManager as LinearLayoutManager)?.let {
|
||||||
|
it.findFirstVisibleItemPosition()?.let {
|
||||||
|
(recyclerView?.layoutManager as? LinearLayoutManager)?.let { target ->
|
||||||
|
target.scrollToPositionWithOffset(it, 0)
|
||||||
|
}
|
||||||
|
// .scrollToPosition(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BLog.LOGE("recyclerView >>> ${recyclerView} 3 ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isSyncingScroll = false
|
||||||
|
BLog.LOGE("recyclerView >>> ${recyclerView} 4 ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val mOnScrollListener = object : RecyclerView.OnScrollListener() {
|
||||||
|
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||||
|
super.onScrollStateChanged(recyclerView, newState)
|
||||||
|
// recyclerView.postDelayed({syncScroll(recyclerView)},10L)
|
||||||
|
// recyclerView.post{syncScroll(recyclerView)}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var isSyncingScroll = false
|
||||||
override fun onBindViewHolder(holder: PageViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: PageViewHolder, position: Int) {
|
||||||
if (adatpers[position] != null) {
|
if (adatpers[position] != null) {
|
||||||
when (position) {
|
(holder.view as RecyclerView).apply {
|
||||||
0 -> holder.view.findViewById<RecyclerView>(R.id.recycler_hourly_weather).apply {
|
this.adapter = adatpers[position]
|
||||||
this.adapter = adatpers[position]
|
this.layoutManager = LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
||||||
this.layoutManager =
|
if (!childs.contains(this)) {
|
||||||
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
childs.add(this)
|
||||||
}
|
this.addOnScrollListener(mOnScrollListener)
|
||||||
|
LinearSnapHelper().attachToRecyclerView(this)
|
||||||
else -> holder.view.findViewById<RecyclerView>(R.id.weather_dress_recycller).apply {
|
|
||||||
this.adapter = adatpers[position]
|
|
||||||
this.layoutManager =
|
|
||||||
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// when (position) {
|
||||||
|
// 0 -> holder.view.findViewById<RecyclerView>(R.id.recycler_hourly_weather).apply {
|
||||||
|
// this.adapter = adatpers[position]
|
||||||
|
// this.layoutManager =
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// else -> holder.view.findViewById<RecyclerView>(R.id.weather_dress_recycller).apply {
|
||||||
|
// this.adapter = adatpers[position]
|
||||||
|
// this.layoutManager =
|
||||||
|
// LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,9 @@ import android.graphics.Color
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.net.toUri
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.squareup.picasso.Picasso
|
||||||
import rasel.lunar.launcher.databinding.ItemHourlyWeatherBinding
|
import rasel.lunar.launcher.databinding.ItemHourlyWeatherBinding
|
||||||
import rasel.lunar.launcher.databinding.ItemRecHourlyDressBinding
|
import rasel.lunar.launcher.databinding.ItemRecHourlyDressBinding
|
||||||
import rasel.lunar.launcher.model.Hour
|
import rasel.lunar.launcher.model.Hour
|
||||||
@ -26,6 +28,9 @@ class WeatherHourlyAdapter(private val dataSet: ArrayList<Hour>): RecyclerView.A
|
|||||||
data?.let {
|
data?.let {
|
||||||
WeatherInfoManager.getShowingInfo(it).apply {
|
WeatherInfoManager.getShowingInfo(it).apply {
|
||||||
holder.viewItem.setInfo(this)
|
holder.viewItem.setInfo(this)
|
||||||
|
Picasso.get()
|
||||||
|
.load(this.urlImgWeather)
|
||||||
|
.into(holder.viewItem.imgWeather)
|
||||||
}
|
}
|
||||||
BLog.LOGE("reeeeeeeeeee >>> ${holder.viewItem.hour.text}")
|
BLog.LOGE("reeeeeeeeeee >>> ${holder.viewItem.hour.text}")
|
||||||
holder.viewItem.amOrPm.visibility =
|
holder.viewItem.amOrPm.visibility =
|
||||||
@ -41,7 +46,6 @@ class WeatherHourlyAdapter(private val dataSet: ArrayList<Hour>): RecyclerView.A
|
|||||||
this@apply.isSelected = false
|
this@apply.isSelected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
holder.viewItem.imgDress.setImageLevel(it.temp_c.toInt())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,8 @@ class ShowingWeatherInfo() {
|
|||||||
var dress: String? = null
|
var dress: String? = null
|
||||||
var imgDress: Int? = null
|
var imgDress: Int? = null
|
||||||
var temp: String? = null
|
var temp: String? = null
|
||||||
|
var textCondition: String? = null
|
||||||
|
var urlImgWeather: String? = null
|
||||||
|
|
||||||
fun setLocation(loc: Location?): ShowingWeatherInfo {
|
fun setLocation(loc: Location?): ShowingWeatherInfo {
|
||||||
textLocation = "${loc?.name ?: "도시"} / ${loc?.country ?: "나라"}"
|
textLocation = "${loc?.name ?: "도시"} / ${loc?.country ?: "나라"}"
|
||||||
@ -28,6 +30,8 @@ class ShowingWeatherInfo() {
|
|||||||
setTextHour(hour)
|
setTextHour(hour)
|
||||||
setDress(hour)
|
setDress(hour)
|
||||||
setTemp(hour)
|
setTemp(hour)
|
||||||
|
setTextCondition(hour)
|
||||||
|
setUrlImgWeather(hour)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
private fun setAmOrPm(hour: Hour) = WeatherInfoManager.toZonedDateTime(hour.time_epoch).hour.run {
|
private fun setAmOrPm(hour: Hour) = WeatherInfoManager.toZonedDateTime(hour.time_epoch).hour.run {
|
||||||
@ -69,6 +73,14 @@ class ShowingWeatherInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private fun setTemp(hour: Hour) {temp = "${hour.temp_c}도"}
|
private fun setTemp(hour: Hour) {temp = "${hour.temp_c}도"}
|
||||||
|
|
||||||
|
private fun setTextCondition(hour: Hour) {textCondition = hour.condition?.text}
|
||||||
|
|
||||||
|
private fun setUrlImgWeather(hour: Hour) {
|
||||||
|
hour.condition?.icon?.let {
|
||||||
|
urlImgWeather = if (!it.contains("https:")) "https:$it" else it
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object WeatherInfoManager {
|
object WeatherInfoManager {
|
||||||
|
|||||||
@ -29,7 +29,7 @@
|
|||||||
android:text="@{info.textHour}"
|
android:text="@{info.textHour}"
|
||||||
android:textAlignment="center"/>
|
android:textAlignment="center"/>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imgDress"
|
android:id="@+id/imgWeather"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:src="@drawable/level_dress_img"
|
android:src="@drawable/level_dress_img"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
@ -41,7 +41,7 @@
|
|||||||
android:id="@+id/textDress"
|
android:id="@+id/textDress"
|
||||||
android:fontFamily="sans-serif-light"
|
android:fontFamily="sans-serif-light"
|
||||||
android:textSize="11sp"
|
android:textSize="11sp"
|
||||||
android:text="@{info.dress}"
|
android:text="@{info.textCondition}"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textAlignment="center"/>
|
android:textAlignment="center"/>
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
@ -58,7 +58,7 @@
|
|||||||
<androidx.viewpager2.widget.ViewPager2
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
android:id="@+id/weatherViewPager"
|
android:id="@+id/weatherViewPager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="120dp"
|
android:layout_height="130dp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/header"
|
app:layout_constraintTop_toBottomOf="@+id/header"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user