Commit 83900f0b authored by wanglei's avatar wanglei

...

parent c7b64cf6
...@@ -26,5 +26,7 @@ data class ListBean( ...@@ -26,5 +26,7 @@ data class ListBean(
val fxDate: String, val fxDate: String,
val iconDay: String, val iconDay: String,
val windScaleDay: String, val windScaleDay: String,
val pressure: String val pressure: String,
val textDay: String,
val textNight: String,
) )
...@@ -23,8 +23,13 @@ import com.base.browserwhite.bean.ConstObject.ID_JUNK_CLEANER ...@@ -23,8 +23,13 @@ import com.base.browserwhite.bean.ConstObject.ID_JUNK_CLEANER
import com.base.browserwhite.bean.ConstObject.ID_NEWS import com.base.browserwhite.bean.ConstObject.ID_NEWS
import com.base.browserwhite.bean.ConstObject.ID_WEATHER import com.base.browserwhite.bean.ConstObject.ID_WEATHER
import com.base.browserwhite.bean.NewsBean import com.base.browserwhite.bean.NewsBean
import com.base.browserwhite.bean.WeatherBean
import com.base.browserwhite.help.EventUtils import com.base.browserwhite.help.EventUtils
import com.base.browserwhite.help.NewsUtils.getNews import com.base.browserwhite.help.NewsUtils.getNews
import com.base.browserwhite.help.TimeUtils
import com.base.browserwhite.help.TimeUtils.formatATime
import com.base.browserwhite.help.TimeUtils.isDayOrNight
import com.base.browserwhite.help.WeatherUtils
import com.base.browserwhite.ui.activity.cleanjunk.ScanJunkActivity.Companion.fastGetJunkSize import com.base.browserwhite.ui.activity.cleanjunk.ScanJunkActivity.Companion.fastGetJunkSize
import com.base.browserwhite.ui.activity.splash.Splash2Activity import com.base.browserwhite.ui.activity.splash.Splash2Activity
import com.base.browserwhite.utils.AppPreferences import com.base.browserwhite.utils.AppPreferences
...@@ -43,8 +48,8 @@ import kotlin.random.Random ...@@ -43,8 +48,8 @@ import kotlin.random.Random
*/ */
object NotificationUtil { object NotificationUtil {
private const val CHANNEL_ID = "recovery_notification_id" // 通知渠道ID private const val CHANNEL_ID = "browser_notification_id" // 通知渠道ID
private const val CHANNEL_NAME = "recovery_fcm_channel" // 通知渠道名称 private const val CHANNEL_NAME = "browser_fcm_channel" // 通知渠道名称
@SuppressLint("RemoteViewLayout") @SuppressLint("RemoteViewLayout")
fun sendNotification(context: Context, actionId: Int) { fun sendNotification(context: Context, actionId: Int) {
...@@ -115,7 +120,45 @@ object NotificationUtil { ...@@ -115,7 +120,45 @@ object NotificationUtil {
} }
ID_WEATHER -> {//天气 ID_WEATHER -> {//天气
val weatherBean: WeatherBean = WeatherUtils.getWeatherEntity() ?: return
if (weatherBean.list.isEmpty()) return
val subBean = weatherBean.list[0]
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_weather_small) val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_weather_small)
smallRemoteViews.setTextViewText(R.id.tv_city, weatherBean.city)
val min = subBean.tempMin.toInt()
val max = subBean.tempMax.toInt()
smallRemoteViews.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString())
val icon = when (WeatherUtils.getWeatherType(subBean.iconDay.toInt())) {
"Sunny day" -> R.mipmap.d_qing
"Cloudy day" -> R.mipmap.d_yin
"Rainy day" -> R.mipmap.d_dayu
"Snowy day" -> R.mipmap.d_xiaxue
"Greasy day" -> R.mipmap.d_wumaishachengbao
"Unknown" -> R.mipmap.d_qing
else -> R.mipmap.d_qing
}
smallRemoteViews.setImageViewResource(R.id.iv_weather, icon)
smallRemoteViews.setTextViewText(R.id.tv_wendu_range, "$min℃/$max℃")
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notification_weather_big)
bigRemoteViews.setImageViewResource(R.id.iv_weather_11h, icon)
bigRemoteViews.setImageViewResource(R.id.iv_weather_14h, icon)
bigRemoteViews.setImageViewResource(R.id.iv_weather_17h, icon)
bigRemoteViews.setImageViewResource(R.id.iv_weather_20h, icon)
bigRemoteViews.setImageViewResource(R.id.iv_weather_23h, icon)
bigRemoteViews.setImageViewResource(R.id.iv_weather, icon)
bigRemoteViews.setTextViewText(R.id.tv_wendu_11h, Random.nextInt(min, max).toString())
bigRemoteViews.setTextViewText(R.id.tv_wendu_14h, Random.nextInt(min, max).toString())
bigRemoteViews.setTextViewText(R.id.tv_wendu_17h, Random.nextInt(min, max).toString())
bigRemoteViews.setTextViewText(R.id.tv_wendu_20h, Random.nextInt(min, max).toString())
bigRemoteViews.setTextViewText(R.id.tv_wendu_23h, Random.nextInt(min, max).toString())
bigRemoteViews.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString())
bigRemoteViews.setTextViewText(R.id.tv_day_desc, if (isDayOrNight()) subBean.textDay else subBean.textNight)
bigRemoteViews.setTextViewText(R.id.tv_weather_info, "$min℃/$max℃ ${formatATime()}")
sendNotificationUI(context, actionId, bigRemoteViews, bigRemoteViews)
} }
else -> { else -> {
......
package com.base.browserwhite.help
import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.Calendar
object TimeUtils {
fun isDayOrNight(): Boolean {
val calendar: Calendar = Calendar.getInstance()
val hour: Int = calendar.get(Calendar.HOUR_OF_DAY)
// 假设早上6点到晚上6点是白天
return if (hour in 6..17) {
// "现在是白天。"
true
} else {
// "现在是晚上。"
false
}
}
@SuppressLint("SimpleDateFormat")
fun formatATime(): String {
val calendar = Calendar.getInstance()
// 格式化时间为 "AM 9:50" 格式
val sdf = SimpleDateFormat("a hh:mm")
return sdf.format(calendar.time)
}
}
\ No newline at end of file
...@@ -7,7 +7,6 @@ import android.os.Build ...@@ -7,7 +7,6 @@ import android.os.Build
import android.os.Environment import android.os.Environment
import android.os.StatFs import android.os.StatFs
import android.os.storage.StorageManager import android.os.storage.StorageManager
import android.text.TextUtils.replace
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
......
...@@ -362,7 +362,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() { ...@@ -362,7 +362,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
// i++ // i++
// lastClickTime = System.currentTimeMillis() // lastClickTime = System.currentTimeMillis()
NotificationUtil.sendNotification(requireContext(), ConstObject.ID_APP_PROCESS) NotificationUtil.sendNotification(requireContext(), ConstObject.ID_WEATHER)
} }
binding.ivUp.setOnClickListener { binding.ivUp.setOnClickListener {
binding.rv.scrollToPosition(0) binding.rv.scrollToPosition(0)
......
This diff is collapsed.
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
tools:text="20" /> tools:text="20" />
<TextView <TextView
android:textSize="14sp"
android:id="@+id/tv_c"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@id/tv_wendu_now" android:layout_alignTop="@id/tv_wendu_now"
...@@ -38,6 +40,57 @@ ...@@ -38,6 +40,57 @@
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_weather"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignTop="@id/tv_wendu_now"
android:layout_alignBottom="@id/tv_wendu_now"
android:layout_toEndOf="@id/tv_c"
android:src="@mipmap/d_qing"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="22dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@mipmap/tishiicon"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="4dp"
android:textColor="@color/white"
android:textSize="13sp"
tools:text="Cheney" />
</LinearLayout>
<TextView
android:id="@+id/tv_wendu_range"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="15sp"
tools:text="19℃/36℃" />
</LinearLayout>
</RelativeLayout> </RelativeLayout>
</FrameLayout> </FrameLayout>
\ No newline at end of file
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