Commit 467cee2b authored by 周文华's avatar 周文华

【调整】调整天气显示逻辑。

parent 13ab945d
...@@ -15,6 +15,7 @@ import com.base.filerecoveryrecyclebin.help.BaseApplication ...@@ -15,6 +15,7 @@ import com.base.filerecoveryrecyclebin.help.BaseApplication
import com.base.filerecoveryrecyclebin.help.BlackUtils import com.base.filerecoveryrecyclebin.help.BlackUtils
import com.base.filerecoveryrecyclebin.help.ConfigHelper import com.base.filerecoveryrecyclebin.help.ConfigHelper
import com.base.filerecoveryrecyclebin.help.InstallHelps import com.base.filerecoveryrecyclebin.help.InstallHelps
import com.base.filerecoveryrecyclebin.help.WeatherUtils
import com.base.filerecoveryrecyclebin.service.StayJobService.Companion.startJob import com.base.filerecoveryrecyclebin.service.StayJobService.Companion.startJob
import com.base.filerecoveryrecyclebin.utils.ActivityManagerUtils import com.base.filerecoveryrecyclebin.utils.ActivityManagerUtils
import com.base.filerecoveryrecyclebin.utils.AppPreferences import com.base.filerecoveryrecyclebin.utils.AppPreferences
...@@ -81,6 +82,7 @@ class MyApplication : BaseApplication() { ...@@ -81,6 +82,7 @@ class MyApplication : BaseApplication() {
initLifeListener() initLifeListener()
schedulePeriodicWork(this) schedulePeriodicWork(this)
startJob() startJob()
WeatherUtils.requestWeatherData()
} }
if (ifAgreePrivacy) { if (ifAgreePrivacy) {
......
...@@ -15,6 +15,7 @@ import android.view.View ...@@ -15,6 +15,7 @@ import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.filerecoveryrecyclebin.R
import com.base.filerecoveryrecyclebin.activity.MainActivity import com.base.filerecoveryrecyclebin.activity.MainActivity
import com.base.filerecoveryrecyclebin.activity.SettingActivity import com.base.filerecoveryrecyclebin.activity.SettingActivity
import com.base.filerecoveryrecyclebin.activity.XzLoadingActivity import com.base.filerecoveryrecyclebin.activity.XzLoadingActivity
...@@ -40,6 +41,7 @@ import com.base.filerecoveryrecyclebin.view.WeatherInterface ...@@ -40,6 +41,7 @@ import com.base.filerecoveryrecyclebin.view.WeatherInterface
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.File import java.io.File
import kotlin.random.Random
class HomeFragment : BaseFragment<FragmentHome3Binding>() { class HomeFragment : BaseFragment<FragmentHome3Binding>() {
private val TAG = "HomeFragment" private val TAG = "HomeFragment"
...@@ -54,7 +56,26 @@ class HomeFragment : BaseFragment<FragmentHome3Binding>() { ...@@ -54,7 +56,26 @@ class HomeFragment : BaseFragment<FragmentHome3Binding>() {
binding.tvTitle.text = "Dumpster" binding.tvTitle.text = "Dumpster"
val bean = WeatherUtils.getWeatherEntity()?.list?.get(0) val bean = WeatherUtils.getWeatherEntity()?.list?.get(0)
bean?.let { bean?.let {
binding.tvWendu.text = (it.tempMax.toInt() + it.tempMin.toInt() / 2).toString() var value = 22
val min = bean.tempMin.toInt()
val max = bean.tempMax.toInt()
if (min == max) {
value = max
}
if (min < max) {
value = Random.nextInt(min, max)
}
val icon = when (WeatherUtils.getWeatherType(bean.iconDay.toInt())) {
"Sunny day" -> R.mipmap.x_qing
"Cloudy day" -> R.mipmap.x_yin
"Rainy day" -> R.mipmap.x_dayu
"Snowy day" -> R.mipmap.x_xiaxue
"Greasy day" -> R.mipmap.x_wumaishachengbao
"Unknown" -> R.mipmap.x_qing
else -> R.mipmap.x_qing
}
binding.tvWendu.text = value.toString()
binding.ivWeather.setImageResource(icon)
} }
binding.lottie.repeatCount = ValueAnimator.INFINITE binding.lottie.repeatCount = ValueAnimator.INFINITE
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
<ImageView <ImageView
android:id="@+id/iv_weather"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment