Commit d1d44300 authored by wanglei's avatar wanglei

...

parent 8f521e21
...@@ -53,6 +53,7 @@ object ConstObject { ...@@ -53,6 +53,7 @@ object ConstObject {
const val NOTIFICATION_ACTION_IMPORTANT_DOCUMENT = "notification_action_important_document" const val NOTIFICATION_ACTION_IMPORTANT_DOCUMENT = "notification_action_important_document"
const val NOTIFICATION_ACTION_APP_PROCESS = "notification_action_app_process" const val NOTIFICATION_ACTION_APP_PROCESS = "notification_action_app_process"
const val NOTIFICATION_ACTION_CLEAN_JUNK = "notification_action_clean_junk" const val NOTIFICATION_ACTION_CLEAN_JUNK = "notification_action_clean_junk"
const val NOTIFICATION_ACTION_WEATHER = "notification_action_weather"
const val SHORTCUT_SCAN_PDF = "shortcut_scan_pdf" const val SHORTCUT_SCAN_PDF = "shortcut_scan_pdf"
const val SHORTCUT_SPLIT_PDF = "shortcut_split_pdf" const val SHORTCUT_SPLIT_PDF = "shortcut_split_pdf"
......
...@@ -11,6 +11,7 @@ import android.os.Build ...@@ -11,6 +11,7 @@ import android.os.Build
import android.widget.RemoteViews import android.widget.RemoteViews
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.IconCompat import androidx.core.graphics.drawable.IconCompat
import com.base.pdfviewerscannerwhite.BuildConfig
import com.base.pdfviewerscannerwhite.R import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_APP_PROCESS import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_APP_PROCESS
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_CLEAN_JUNK import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_CLEAN_JUNK
...@@ -19,6 +20,8 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_NEW_I ...@@ -19,6 +20,8 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_NEW_I
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_READ_DOCUMENTS import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_READ_DOCUMENTS
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_READ_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_READ_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_UN_VIEW_FILES import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_UN_VIEW_FILES
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_WEATHER
import com.base.pdfviewerscannerwhite.bean.WeatherBean
import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.POPUP_WHERE_FCM import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.POPUP_WHERE_FCM
import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.POPUP_WHERE_LOCK import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.POPUP_WHERE_LOCK
import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.POPUP_WHERE_TIMBER import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.POPUP_WHERE_TIMBER
...@@ -32,12 +35,15 @@ import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_status ...@@ -32,12 +35,15 @@ import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_status
import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_timer_interval import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_timer_interval
import com.base.pdfviewerscannerwhite.helper.EventUtils import com.base.pdfviewerscannerwhite.helper.EventUtils
import com.base.pdfviewerscannerwhite.helper.MyApplication import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.helper.WeatherUtils
import com.base.pdfviewerscannerwhite.ui.cleanjunk.ScanJunkActivity.Companion.fastGetJunkSize import com.base.pdfviewerscannerwhite.ui.cleanjunk.ScanJunkActivity.Companion.fastGetJunkSize
import com.base.pdfviewerscannerwhite.ui.splash.SplashActivity import com.base.pdfviewerscannerwhite.ui.splash.SplashActivity
import com.base.pdfviewerscannerwhite.utils.AppPreferences import com.base.pdfviewerscannerwhite.utils.AppPreferences
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
import com.base.pdfviewerscannerwhite.utils.LogEx import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.RamUtils.ramPair import com.base.pdfviewerscannerwhite.utils.RamUtils.ramPair
import com.base.pdfviewerscannerwhite.utils.TimeUtils.formatATime
import com.base.pdfviewerscannerwhite.utils.TimeUtils.isDayOrNight
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.Locale import java.util.Locale
...@@ -116,9 +122,10 @@ object NotificationUiUtil { ...@@ -116,9 +122,10 @@ object NotificationUiUtil {
if (where == POPUP_WHERE_FCM) { if (where == POPUP_WHERE_FCM) {
interval = AppPreferences.getInstance().getString(popup_fcm_interval, "1").toInt() interval = AppPreferences.getInstance().getString(popup_fcm_interval, "1").toInt()
} }
if (System.currentTimeMillis() - lastPopupTime < interval * 60 * 1000L) { val passedTime = System.currentTimeMillis() - lastPopupTime
EventUtils.event("Notification_Error", "where=$where actionId=$actionId interval=$interval") if (passedTime < interval * 60 * 1000L) {
LogEx.logDebug("canSendNotification", "interval where=$where") EventUtils.event("Notification_Error", "where=$where actionId=$actionId interval=$interval passedTime=$passedTime")
LogEx.logDebug("canSendNotification", "interval where=$where passedTime=$passedTime interval=$interval")
return false return false
} }
...@@ -237,6 +244,50 @@ object NotificationUiUtil { ...@@ -237,6 +244,50 @@ object NotificationUiUtil {
sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar) sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar)
} }
NOTIFICATION_ACTION_WEATHER -> {
val weatherBean: WeatherBean = WeatherUtils.getWeatherEntity() ?: return
if (weatherBean.list.isEmpty()) return
val subBean = weatherBean.list[0]
val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_small)
smallRemoteViewsVar.setTextViewText(R.id.tv_city, weatherBean.city)
val min = subBean.tempMin.toInt()
val max = subBean.tempMax.toInt()
smallRemoteViewsVar.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
}
smallRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon)
smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_range, "$min℃/$max℃")
val bigRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_big)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_11h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_14h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_17h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_20h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_23h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon)
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_11h, Random.nextInt(min, max).toString())
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_14h, Random.nextInt(min, max).toString())
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_17h, Random.nextInt(min, max).toString())
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_20h, Random.nextInt(min, max).toString())
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_23h, Random.nextInt(min, max).toString())
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString())
bigRemoteViewsVar.setTextViewText(R.id.tv_day_desc, if (isDayOrNight()) subBean.textDay else subBean.textNight)
bigRemoteViewsVar.setTextViewText(R.id.tv_weather_info, "$min℃/$max℃ ${formatATime()}")
sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar)
}
else -> { else -> {
EventUtils.event("Notification_Error", "unKnow actionId actionId=$actionId") EventUtils.event("Notification_Error", "unKnow actionId actionId=$actionId")
...@@ -311,7 +362,8 @@ object NotificationUiUtil { ...@@ -311,7 +362,8 @@ object NotificationUiUtil {
NOTIFICATION_ACTION_UN_VIEW_FILES, NOTIFICATION_ACTION_UN_VIEW_FILES,
NOTIFICATION_ACTION_IMPORTANT_DOCUMENT, NOTIFICATION_ACTION_IMPORTANT_DOCUMENT,
NOTIFICATION_ACTION_APP_PROCESS, NOTIFICATION_ACTION_APP_PROCESS,
NOTIFICATION_ACTION_CLEAN_JUNK NOTIFICATION_ACTION_CLEAN_JUNK,
NOTIFICATION_ACTION_WEATHER
) )
var actionIdList = arrayListOf<String>() var actionIdList = arrayListOf<String>()
...@@ -321,6 +373,9 @@ object NotificationUiUtil { ...@@ -321,6 +373,9 @@ object NotificationUiUtil {
} }
val next = actionIdList[0] val next = actionIdList[0]
actionIdList.removeAt(0) actionIdList.removeAt(0)
if (BuildConfig.DEBUG) {
return NOTIFICATION_ACTION_WEATHER
}
return next return next
} }
} }
\ No newline at end of file
...@@ -22,6 +22,7 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_BOOKM ...@@ -22,6 +22,7 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_BOOKM
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_CLEAN_JUNK import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_CLEAN_JUNK
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_DOCUMENT import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_DOCUMENT
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_NEW_IMAGE_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_NEW_IMAGE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_WEATHER
import com.base.pdfviewerscannerwhite.bean.ConstObject.RECENT_DATA_TYPE import com.base.pdfviewerscannerwhite.bean.ConstObject.RECENT_DATA_TYPE
import com.base.pdfviewerscannerwhite.bean.ConstObject.SHORTCUT_MERGE_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.SHORTCUT_MERGE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.SHORTCUT_SCAN_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.SHORTCUT_SCAN_PDF
...@@ -47,6 +48,7 @@ import com.base.pdfviewerscannerwhite.ui.view.DialogView.showNotificationDialog ...@@ -47,6 +48,7 @@ import com.base.pdfviewerscannerwhite.ui.view.DialogView.showNotificationDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showStoragePermission import com.base.pdfviewerscannerwhite.ui.view.DialogView.showStoragePermission
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.ui.view.RateDialog.showRateDialog import com.base.pdfviewerscannerwhite.ui.view.RateDialog.showRateDialog
import com.base.pdfviewerscannerwhite.ui.weather.WeatherInterface
import com.base.pdfviewerscannerwhite.utils.AppPreferences import com.base.pdfviewerscannerwhite.utils.AppPreferences
import com.base.pdfviewerscannerwhite.utils.BarUtils import com.base.pdfviewerscannerwhite.utils.BarUtils
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.shareMutDocuments import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.shareMutDocuments
...@@ -142,10 +144,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView { ...@@ -142,10 +144,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
if (actionId == NOTIFICATION_ACTION_APP_PROCESS) { if (actionId == NOTIFICATION_ACTION_APP_PROCESS) {
startActivity(Intent(this, AppProcessActivity::class.java)) startActivity(Intent(this, AppProcessActivity::class.java))
return
} }
if (actionId == NOTIFICATION_ACTION_CLEAN_JUNK) { if (actionId == NOTIFICATION_ACTION_CLEAN_JUNK) {
startActivity(Intent(this, ScanJunkActivity::class.java)) startActivity(Intent(this, ScanJunkActivity::class.java))
return
} }
if (actionId == NOTIFICATION_ACTION_WEATHER) {
startActivity(Intent(this, WeatherInterface::class.java))
return
}
} }
private fun closeScanGuide() { private fun closeScanGuide() {
......
package com.base.pdfviewerscannerwhite.utils
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)
}
//
// fun isTimeBetweenEightAndTenPM(): Boolean {
// val now = Calendar.getInstance()
// val hour = now[Calendar.HOUR_OF_DAY] // 获取当前小时数(24小时制)
//
// // 检查当前时间是否在 8 点到 22 点之间
// return hour in 8..21
// }
//
// fun isTimeBetweenWan17toWan23(): Boolean {
//
// val calendar = Calendar.getInstance()
// val currentHour = calendar.get(Calendar.HOUR_OF_DAY) // 获取当前小时数(24小时制)
//
// val isEvening = currentHour in 17..22 // Kotlin中的in运算符用于判断范围
// return if (isEvening) {
// // 当前时间是晚上17点到23点之间
// true
// } else {
// // 当前时间不是晚上17点到23点之间
// false
// }
// }
//
//
// @SuppressLint("SimpleDateFormat")
// fun Long.formatTimeH(): String {
// val dateFormat = SimpleDateFormat("yyyy-M-d H")
// return dateFormat.format(this)
// }
}
\ No newline at end of file
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
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"
android:src="@mipmap/fanhui_b" android:src="@mipmap/fanhui_w"
tools:ignore="ContentDescription,MissingPrefix" /> tools:ignore="ContentDescription,MissingPrefix" />
</FrameLayout> </FrameLayout>
......
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/bg_ffffff_15">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="@mipmap/x_tianqibg"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_wendu_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:textColor="@color/white"
android:textSize="30sp"
tools:text="20" />
<TextView
android:id="@+id/tv_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/tv_wendu_now"
android:layout_toEndOf="@id/tv_wendu_now"
android:text="℃"
android:textColor="@color/white"
android:textSize="14sp"
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"
tools:ignore="UseCompoundDrawables">
<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>
</FrameLayout>
\ No newline at end of file
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_weight="1" android:layout_weight="1.3"
android:orientation="vertical" android:orientation="vertical"
tools:ignore="UseCompoundDrawables"> tools:ignore="UseCompoundDrawables">
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
android:id="@+id/ll_3" android:id="@+id/ll_3"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1.3"
android:orientation="vertical" android:orientation="vertical"
tools:ignore="UseCompoundDrawables"> tools:ignore="UseCompoundDrawables">
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
android:id="@+id/ll_4" android:id="@+id/ll_4"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1.3"
android:orientation="vertical" android:orientation="vertical"
tools:ignore="UseCompoundDrawables"> tools:ignore="UseCompoundDrawables">
......
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