Commit 8e56217a authored by wanglei's avatar wanglei

...

parent d5784eea
...@@ -15,6 +15,7 @@ import okhttp3.logging.HttpLoggingInterceptor ...@@ -15,6 +15,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import java.io.IOException import java.io.IOException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.concurrent.TimeUnit
//object WeatherUtils { //object WeatherUtils {
...@@ -170,6 +171,40 @@ object WeatherUtils { ...@@ -170,6 +171,40 @@ object WeatherUtils {
}) })
} }
/**
* 同步
*/
fun getWeatherData() {
val client = OkHttpClient.Builder().apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
}
}.connectTimeout(1, TimeUnit.SECONDS)
.readTimeout(1, TimeUnit.SECONDS)
.writeTimeout(1, TimeUnit.SECONDS)
.build()
val request = Request.Builder()
.url(url)
.get()
.build()
val response = client.newCall(request).execute()
response.body?.string()?.let {
val i = Regex("\"data\":\"(.*?)\"").find(it)
if (i.toString() != "null") {
i?.groupValues?.get(1).let {
if (!TextUtils.isEmpty(it)) {
val str = AESHelper.decrypt(it!!)
saveWeatherData(str)
}
}
}
}
}
private fun saveWeatherData(string: String) { private fun saveWeatherData(string: String) {
AppPreferences.getInstance().put(getTodayStr() + "_weather", string) AppPreferences.getInstance().put(getTodayStr() + "_weather", string)
} }
......
...@@ -73,23 +73,30 @@ class Splash2Activity : BaseActivity<ActivitySplash2Binding>(), ...@@ -73,23 +73,30 @@ class Splash2Activity : BaseActivity<ActivitySplash2Binding>(),
closeNotification() closeNotification()
mTaskManager = TaskManager(binding, this) mTaskManager = TaskManager(binding, this)
if (ifAgreePrivacy) { if (ifAgreePrivacy) {
onAgreePrivacy() startAnimation(true) {
onAgreePrivacy()
}
} else { } else {
PrivacyManager(binding, this, this) startAnimation(false) {
PrivacyManager(binding, this, this)
}
} }
}
@SuppressLint("SetTextI18n")
fun startAnimation(isAgree: Boolean, callback: () -> Unit) {
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
if (!WeatherUtils.hasWeatherDataToday()) { if (!WeatherUtils.hasWeatherDataToday()) {
WeatherUtils.requestWeatherData() WeatherUtils.getWeatherData()
} }
val weatherCityBean = WeatherUtils.getWeatherEntity() val weatherCityBean = WeatherUtils.getWeatherEntity()
val weather = weatherCityBean?.list?.random() val weather = weatherCityBean?.list?.random()
if (weather != null) { if (weather != null) {
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
LogEx.logDebug(TAG, "weather 开始 ${weather.fxDate}") LogEx.logDebug(TAG, "weather 开始 ${weather.fxDate}")
...@@ -110,13 +117,13 @@ class Splash2Activity : BaseActivity<ActivitySplash2Binding>(), ...@@ -110,13 +117,13 @@ class Splash2Activity : BaseActivity<ActivitySplash2Binding>(),
AnimationHelper.startAlphaAnimation(binding.ivWeather, 800) { AnimationHelper.startAlphaAnimation(binding.ivWeather, 800) {
AnimationHelper.startAlphaAnimation(binding.tvDate, 800) { AnimationHelper.startAlphaAnimation(binding.tvDate, 800) {
AnimationHelper.startAlphaAnimation(binding.tvTemperature, 800) { AnimationHelper.startAlphaAnimation(binding.tvTemperature, 800) {
if (ifAgreePrivacy) { if (isAgree) {
AnimationHelper.startAlphaAnimation(binding.pb, 800) { AnimationHelper.startAlphaAnimation(binding.pb, 800) {
callback.invoke()
} }
} else { } else {
AnimationHelper.startAlphaAnimation(binding.idTvStart, 800) { AnimationHelper.startAlphaAnimation(binding.idTvStart, 800) {
callback.invoke()
} }
} }
...@@ -129,8 +136,6 @@ class Splash2Activity : BaseActivity<ActivitySplash2Binding>(), ...@@ -129,8 +136,6 @@ class Splash2Activity : BaseActivity<ActivitySplash2Binding>(),
}.start() }.start()
} }
private fun closeNotification() { private fun closeNotification() {
......
...@@ -142,10 +142,15 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -142,10 +142,15 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
binding.llPermission.visibility = View.GONE binding.llPermission.visibility = View.GONE
initData() initData()
} else { } else {
simulateProgress()
binding.llPermission.visibility = View.VISIBLE binding.llPermission.visibility = View.VISIBLE
} }
} }
private fun simulateProgress() {
}
private fun initData() = lifecycleScope.launch(Dispatchers.IO) { private fun initData() = lifecycleScope.launch(Dispatchers.IO) {
val picturePair = requireContext().getMediaPhotoCountSize() val picturePair = requireContext().getMediaPhotoCountSize()
......
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