Commit 9c686599 authored by wanglei's avatar wanglei

...

parent e5c7dbbb
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
tools:targetApi="34"> tools:targetApi="34">
<activity <activity
android:name=".ui.activity.splash.Splash2Activity" android:name=".ui.activity.MainActivity"
android:exported="true" android:exported="true"
android:launchMode="singleTask"> android:launchMode="singleTask">
<intent-filter> <intent-filter>
...@@ -41,29 +41,30 @@ ...@@ -41,29 +41,30 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".ui.activity.download.WebDownloadManagerActivity" android:name=".ui.activity.splash.Splash2Activity"
android:exported="false" android:exported="false"
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".ui.activity.download.WebDownloadGuideActivity" android:name=".ui.activity.download.WebDownloadManagerActivity"
android:exported="false" android:exported="false"
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".ui.activity.news.NewsDetailActivity" android:name=".ui.activity.download.WebDownloadGuideActivity"
android:exported="false" android:exported="false"
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".ui.activity.MainActivity" android:name=".ui.activity.news.NewsDetailActivity"
android:exported="false" android:exported="false"
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".ui.activity.result.ResultActivity" android:name=".ui.activity.result.ResultActivity"
android:exported="false" android:exported="false"
......
...@@ -12,6 +12,7 @@ object ConstObject { ...@@ -12,6 +12,7 @@ object ConstObject {
const val BAIDU = "Baidu" const val BAIDU = "Baidu"
const val ID_JUNK_CLEANER = 12001 const val ID_JUNK_CLEANER = 12001
const val ID_CLEAN_JUNK_MEMORY = 12009
const val ID_NEWS = 12002 const val ID_NEWS = 12002
const val ID_SCAN_CODE = 12003 const val ID_SCAN_CODE = 12003
const val ID_APP_PROCESS = 12004 const val ID_APP_PROCESS = 12004
......
package com.base.browserwhite.bean package com.base.browserwhite.bean
import android.graphics.Bitmap
class NewsBean( class NewsBean(
val newsId: Long = 0, val newsId: Long = 0,
val publishTime: Long = 0, val publishTime: Long = 0,
...@@ -11,6 +13,7 @@ class NewsBean( ...@@ -11,6 +13,7 @@ class NewsBean(
val type: Int = 0, val type: Int = 0,
val linkPath: String = "",//网站链接 val linkPath: String = "",//网站链接
) { ) {
} }
// 栏目类别 0:最新 , 101 :政治, 301:体育 ,娱乐:501 , // 栏目类别 0:最新 , 101 :政治, 301:体育 ,娱乐:501 ,
......
package com.base.browserwhite.fcm package com.base.browserwhite.fcm
import CloseNotificationReceiver import CloseNotificationReceiver
import android.annotation.SuppressLint
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.app.PendingIntent import android.app.PendingIntent
...@@ -10,18 +11,28 @@ import android.graphics.drawable.Icon ...@@ -10,18 +11,28 @@ import android.graphics.drawable.Icon
import android.os.Build import android.os.Build
import android.os.Handler import android.os.Handler
import android.os.HandlerThread import android.os.HandlerThread
import android.os.Looper
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.browserwhite.MyApplication import com.base.browserwhite.MyApplication
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.bean.ConstObject.ID_CLEAN_JUNK_MEMORY
import com.base.browserwhite.bean.ConstObject.ID_JUNK_CLEANER
import com.base.browserwhite.bean.ConstObject.ID_NEWS
import com.base.browserwhite.bean.NewsBean
import com.base.browserwhite.help.EventUtils import com.base.browserwhite.help.EventUtils
import com.base.browserwhite.help.NewsUtils.getNews
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
import com.base.browserwhite.utils.ImageUtils.getBitmapFromURL
import com.base.browserwhite.utils.KotlinExt.toFormatSize
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.Locale import java.util.Locale
import java.util.Random import kotlin.random.Random
/** /**
* 构建发送通知 * 构建发送通知
...@@ -32,37 +43,77 @@ object NotificationUtil { ...@@ -32,37 +43,77 @@ object NotificationUtil {
private const val CHANNEL_ID = "recovery_notification_id" // 通知渠道ID private const val CHANNEL_ID = "recovery_notification_id" // 通知渠道ID
private const val CHANNEL_NAME = "recovery_fcm_channel" // 通知渠道名称 private const val CHANNEL_NAME = "recovery_fcm_channel" // 通知渠道名称
@SuppressLint("RemoteViewLayout")
fun sendNotification(context: Context, actionId: Int) { fun sendNotification(context: Context, actionId: Int) {
val bigRemoteViews = RemoteViews(context.packageName, 0)
val smallRemoteViews = RemoteViews(context.packageName, 0)
var icon = 0
var desc = ""
var btn = ""
when (actionId) { when (actionId) {
ID_JUNK_CLEANER -> {
var size = fastGetJunkSize(context)
if (size == 0L) {
size = Random.nextLong(1024 * 5, 1024 * 10)
}
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notification_junk_big)
bigRemoteViews.setTextViewText(R.id.tv_size, size.toFormatSize())
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_junk_small)
sendNotificationUI(context, actionId, bigRemoteViews, smallRemoteViews)
}
ID_CLEAN_JUNK_MEMORY -> {
var size = fastGetJunkSize(context)
if (size == 0L) {
size = Random.nextLong(1024 * 5, 1024 * 10)
}
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notification_junk_memory_small)
bigRemoteViews.setTextViewText(R.id.tv_size, size.toFormatSize())
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_junk_memory_small)
smallRemoteViews.setTextViewText(R.id.tv_size, size.toFormatSize())
sendNotificationUI(context, actionId, bigRemoteViews, smallRemoteViews)
}
ID_NEWS -> {
val mainHandler = Handler(Looper.getMainLooper())
Thread {
val news: NewsBean = getNews()?.random() ?: return@Thread
val bitmap = getBitmapFromURL(news.orgImgPath) ?: return@Thread
mainHandler.post {
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notification_big_small)
bigRemoteViews.setTextViewText(R.id.tv_head_line, news.headline)
bigRemoteViews.setImageViewBitmap(R.id.iv_media, bitmap)
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_news_small)
smallRemoteViews.setTextViewText(R.id.tv_head_line, news.headline)
smallRemoteViews.setImageViewBitmap(R.id.iv_media, bitmap)
sendNotificationUI(context, actionId, bigRemoteViews, smallRemoteViews)
}
}.start()
}
else -> {
}
} }
bigRemoteViews.setImageViewResource(R.id.iv_icon, icon)
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
bigRemoteViews.setTextViewText(R.id.tv_btn, btn)
smallRemoteViews.setImageViewResource(R.id.iv_icon, icon)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btn)
//取消按钮 }
bigRemoteViews.setOnClickPendingIntent(0, cancelNotificationPendingIntent(context, actionId))
/**
* UI操作
*/
private fun sendNotificationUI(context: Context, actionId: Int, bigRemoteViews: RemoteViews, smallRemoteViews: RemoteViews) {
//跳转 //跳转
val intent = Intent(context, Splash2Activity::class.java) val intent = Intent(context, Splash2Activity::class.java)
intent.putExtra("actionId", actionId) intent.putExtra("actionId", actionId)
val btnRequestCode = Random().nextInt(1000) val btnRequestCode = Random.nextInt(1000)
val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE) val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE)
bigRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent) bigRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent)
smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent) smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent)
//构建发送通知
sendCustomNotification(context, actionId, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, actionId, intent, bigRemoteViews, smallRemoteViews)
} }
...@@ -70,7 +121,7 @@ object NotificationUtil { ...@@ -70,7 +121,7 @@ object NotificationUtil {
val cancelIntent = Intent(context, CloseNotificationReceiver::class.java) val cancelIntent = Intent(context, CloseNotificationReceiver::class.java)
cancelIntent.setAction(CloseNotificationReceiver.Action) cancelIntent.setAction(CloseNotificationReceiver.Action)
cancelIntent.putExtra(CloseNotificationReceiver.NotificationId, actionId) cancelIntent.putExtra(CloseNotificationReceiver.NotificationId, actionId)
val broadcastRequestCode = Random().nextInt(1000) val broadcastRequestCode = Random.nextInt(1000)
return PendingIntent.getBroadcast(context, broadcastRequestCode, cancelIntent, PendingIntent.FLAG_IMMUTABLE) return PendingIntent.getBroadcast(context, broadcastRequestCode, cancelIntent, PendingIntent.FLAG_IMMUTABLE)
} }
...@@ -103,7 +154,7 @@ object NotificationUtil { ...@@ -103,7 +154,7 @@ object NotificationUtil {
//设置状态栏内的小图标 //设置状态栏内的小图标
val smallIcon = IconCompat.createFromIcon( val smallIcon = IconCompat.createFromIcon(
context, Icon.createWithResource( context, Icon.createWithResource(
context, 0 context, R.mipmap.logo_notification_small
) )
) )
smallIcon?.let { smallIcon?.let {
...@@ -112,7 +163,7 @@ object NotificationUtil { ...@@ -112,7 +163,7 @@ object NotificationUtil {
builder.setContentTitle(context.resources.getString(R.string.app_name)) builder.setContentTitle(context.resources.getString(R.string.app_name))
.setContentText("notification") .setContentText("notification")
val requestCode = kotlin.random.Random.nextInt(1000) val requestCode = Random.nextInt(1000)
val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE) val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE)
builder.setContentIntent(pendingIntent) builder.setContentIntent(pendingIntent)
.setDeleteIntent(cancelNotificationPendingIntent(context, actionId)) .setDeleteIntent(cancelNotificationPendingIntent(context, actionId))
...@@ -180,22 +231,27 @@ object NotificationUtil { ...@@ -180,22 +231,27 @@ object NotificationUtil {
val num: Int = AppPreferences.getInstance().getString("num", "0").toIntOrNull() ?: 0 val num: Int = AppPreferences.getInstance().getString("num", "0").toIntOrNull() ?: 0
val delay: Long = AppPreferences.getInstance().getString("delay", "0").toLongOrNull() ?: 0L val delay: Long = AppPreferences.getInstance().getString("delay", "0").toLongOrNull() ?: 0L
handlerThread = HandlerThread("NotificationHandlerThread") handlerThread = HandlerThread("NotificationHandlerThread")
handlerThread!!.start() handlerThread?.start()
// 创建 Handler // 创建 Handler
handler = Handler(handlerThread!!.looper) handler = Handler(handlerThread!!.looper)
for (i in 1..num) { for (i in 1..num) {
val time = i * delay val time = i * delay
handler?.postDelayed(Runnable { handler?.postDelayed(Runnable {
if (MyApplication.PAUSED_VALUE === 1) {
if (MyApplication.PAUSED_VALUE != 1
&& ScreenStatusReceiver.isDeviceInteractive()
&& !ScreenStatusReceiver.isSecureLockActive()
) {
sendNotification(context, actionId)
}
if (MyApplication.PAUSED_VALUE == 1) {
if (handler != null) { if (handler != null) {
handler?.removeCallbacksAndMessages(null) handler?.removeCallbacksAndMessages(null)
} }
return@Runnable return@Runnable
} }
if (MyApplication.PAUSED_VALUE !== 1 && ScreenStatusReceiver.isDeviceInteractive() && !ScreenStatusReceiver.isSecureLockActive()) {
sendNotification(context, actionId)
}
}, time) }, time)
} }
} }
......
...@@ -21,6 +21,7 @@ import okhttp3.logging.HttpLoggingInterceptor ...@@ -21,6 +21,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONObject import org.json.JSONObject
import java.io.IOException import java.io.IOException
import java.lang.reflect.Type import java.lang.reflect.Type
import java.util.concurrent.TimeUnit
object NewsUtils { object NewsUtils {
...@@ -37,7 +38,7 @@ object NewsUtils { ...@@ -37,7 +38,7 @@ object NewsUtils {
fun requestNews( fun requestNews(
categoryId: Int = 0, categoryId: Int = 0,
pageNumber: Long? = null, pageNumber: Long? = null,
errorCallBack: () -> Unit, errorCallBack: (() -> Unit)? = null,
beanCallBack: (beanList: List<NewsBean>) -> Unit beanCallBack: (beanList: List<NewsBean>) -> Unit
) { ) {
val pkg = ConfigHelper.packageName val pkg = ConfigHelper.packageName
...@@ -85,7 +86,7 @@ object NewsUtils { ...@@ -85,7 +86,7 @@ object NewsUtils {
client.newCall(request).enqueue(object : Callback { client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
LogEx.logDebug(TAG, "onFailure $e") LogEx.logDebug(TAG, "onFailure $e")
errorCallBack.invoke() errorCallBack?.invoke()
} }
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
...@@ -103,6 +104,60 @@ object NewsUtils { ...@@ -103,6 +104,60 @@ object NewsUtils {
} }
fun getNews(): List<NewsBean>? {
val pkg = ConfigHelper.packageName
val s = JSONObject()
s.put("categoryId", 0)
val s2 = JSONObject()
.put("${pkg}_3", AppPreferences.getInstance().getString("Equipment", ""))
.put("${pkg}_4", AppPreferences.getInstance().getString("Manufacturer", ""))
.put("${pkg}_5", AppPreferences.getInstance().getString("svn", ""))
.put("${pkg}_8", BuildConfig.VERSION_NAME)
.put("${pkg}_9", AppPreferences.getInstance().getString("uuid", ""))
.put("${pkg}_10", AppPreferences.getInstance().getString("gid", ""))
.put("${pkg}_13", "android")
.put("${pkg}_14", BuildConfig.VERSION_CODE)
.put("${pkg}_15", "google")
.put("${pkg}_24", BuildConfig.BUILD_TYPE)
val data = JSONObject()
.put("data", s)
.put("bp", s2)
.toString()
val body = AESHelper.encrypt(data)
.toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
val client = OkHttpClient.Builder()
.apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
}
connectTimeout(10, TimeUnit.SECONDS)
readTimeout(20, TimeUnit.SECONDS)
writeTimeout(15, TimeUnit.SECONDS)
}.build()
val request = Request.Builder()
.url(url)
.post(body)
.build()
val response = client.newCall(request).execute()
response.body?.string()?.let {
LogEx.logDebug(TAG, "NewsUtils it=$it")
val dataJson = getDataJson(it)
LogEx.logDebug(TAG, "dataJson dataJson=$dataJson")
val list = parseNewsBean(dataJson)
LogEx.logDebug(TAG, "${list.size}")
return list
}
return null
}
private fun getDataJson(jsonString: String): String { private fun getDataJson(jsonString: String): String {
val jsonRootObject = JsonParser.parseString(jsonString).getAsJsonObject() val jsonRootObject = JsonParser.parseString(jsonString).getAsJsonObject()
return jsonRootObject["result"].getAsJsonObject()["data"].toString() return jsonRootObject["result"].getAsJsonObject()["data"].toString()
......
...@@ -37,7 +37,7 @@ class StayNotificationService : Service() { ...@@ -37,7 +37,7 @@ class StayNotificationService : Service() {
fun Context.startStayNotification() { fun Context.startStayNotification() {
val intent = Intent(this, StayNotificationService::class.java) val intent = Intent(this, StayNotificationService::class.java)
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
return
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
...@@ -144,13 +144,13 @@ class StayNotificationService : Service() { ...@@ -144,13 +144,13 @@ class StayNotificationService : Service() {
val smallIcon = IconCompat.createFromIcon( val smallIcon = IconCompat.createFromIcon(
context, Icon.createWithResource( context, Icon.createWithResource(
this, R.mipmap.news this, R.mipmap.logo_notification_small
) )
) )
smallIcon?.let { smallIcon?.let {
builder.setSmallIcon(smallIcon) //设置状态栏内的小图标 builder.setSmallIcon(smallIcon) //设置状态栏内的小图标
} }
builder.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.news)) builder.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.logo))
builder.setContentTitle(context.resources.getString(R.string.app_name)) builder.setContentTitle(context.resources.getString(R.string.app_name))
builder.setContentIntent(pendingIntent) //设置PendingIntent builder.setContentIntent(pendingIntent) //设置PendingIntent
builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) //设置通知公开可见 builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) //设置通知公开可见
......
...@@ -3,6 +3,7 @@ package com.base.browserwhite.ui.activity.cleanjunk ...@@ -3,6 +3,7 @@ package com.base.browserwhite.ui.activity.cleanjunk
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.Color import android.graphics.Color
...@@ -14,6 +15,7 @@ import android.view.animation.LinearInterpolator ...@@ -14,6 +15,7 @@ import android.view.animation.LinearInterpolator
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.MyApplication
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.bean.ChildBean import com.base.browserwhite.bean.ChildBean
import com.base.browserwhite.bean.ConstObject import com.base.browserwhite.bean.ConstObject
...@@ -216,4 +218,33 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() { ...@@ -216,4 +218,33 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() {
return null return null
} }
companion object {
fun fastGetJunkSize(context: Context = MyApplication.context): Long {
var size = 0L
val emptyFolder = arrayListOf<File>()
arrayOf(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
).forEach { dir ->
val list = getFileFolder(dir, filter = { it.listFiles().isNullOrEmpty() })
emptyFolder.addAll(list)
}
size = emptyFolder.sumOf { it.length() }
val apkList = queryFiles(context, ".apk")
size += apkList.sumOf { it.length() }
val tempList = queryFiles(context, ".apk")
size += tempList.sumOf { it.length() }
val logList = queryFiles(context, ".apk")
size += logList.sumOf { it.length() }
return size
}
}
} }
\ No newline at end of file
package com.base.browserwhite.ui.adapter package com.base.browserwhite.ui.adapter
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.bean.NewsBean import com.base.browserwhite.bean.NewsBean
import com.base.browserwhite.databinding.ItemNewsBinding import com.base.browserwhite.databinding.ItemNewsBinding
import com.base.browserwhite.utils.KotlinExt.toFormatTime import com.base.browserwhite.utils.KotlinExt.toFormatTime
import com.base.browserwhite.utils.LogEx
import com.base.browserwhite.utils.XmlEx.inflate import com.base.browserwhite.utils.XmlEx.inflate
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.DataSource
......
...@@ -9,6 +9,7 @@ import android.widget.TextView ...@@ -9,6 +9,7 @@ import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.bean.ConstObject
import com.base.browserwhite.bean.ConstObject.BAIDU import com.base.browserwhite.bean.ConstObject.BAIDU
import com.base.browserwhite.bean.ConstObject.BING import com.base.browserwhite.bean.ConstObject.BING
import com.base.browserwhite.bean.ConstObject.DUCKDUCKGO import com.base.browserwhite.bean.ConstObject.DUCKDUCKGO
...@@ -21,6 +22,7 @@ import com.base.browserwhite.bean.WebSiteBean ...@@ -21,6 +22,7 @@ import com.base.browserwhite.bean.WebSiteBean
import com.base.browserwhite.bean.defaultValue import com.base.browserwhite.bean.defaultValue
import com.base.browserwhite.bean.webSiteGroupBeanList import com.base.browserwhite.bean.webSiteGroupBeanList
import com.base.browserwhite.databinding.FragmentHomeBinding import com.base.browserwhite.databinding.FragmentHomeBinding
import com.base.browserwhite.fcm.NotificationUtil
import com.base.browserwhite.service.StayNotificationService.Companion.restartStartStayNotification import com.base.browserwhite.service.StayNotificationService.Companion.restartStartStayNotification
import com.base.browserwhite.ui.activity.cleanjunk.ScanJunkActivity import com.base.browserwhite.ui.activity.cleanjunk.ScanJunkActivity
import com.base.browserwhite.ui.activity.news.NewsActivity import com.base.browserwhite.ui.activity.news.NewsActivity
...@@ -261,17 +263,20 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() { ...@@ -261,17 +263,20 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
requireContext().startActivity(Intent(requireContext(), ScanQRCActivity::class.java)) requireContext().startActivity(Intent(requireContext(), ScanQRCActivity::class.java))
} }
binding.tvName.setOnClickListener { binding.tvName.setOnClickListener {
if (System.currentTimeMillis() - lastClickTime > 5 * 1000 && i != 0) { // if (System.currentTimeMillis() - lastClickTime > 5 * 1000 && i != 0) {
lastClickTime = 0 // lastClickTime = 0
i = 0 // i = 0
} // }
if (i == 20) { // if (i == 20) {
copyUuidGid() // copyUuidGid()
i = 0 // i = 0
} // }
i++ // i++
lastClickTime = System.currentTimeMillis() // lastClickTime = System.currentTimeMillis()
NotificationUtil.sendNotification(requireContext(), ConstObject.ID_NEWS)
} }
} }
private fun copyUuidGid() { private fun copyUuidGid() {
......
...@@ -9,7 +9,7 @@ import java.util.LinkedList ...@@ -9,7 +9,7 @@ import java.util.LinkedList
object FileHelp { object FileHelp {
fun CoroutineScope.getFileFolder( fun CoroutineScope.getFileFolder(
flow: MutableSharedFlow<String>, flow: MutableSharedFlow<String>? = null,
file: File, file: File,
filter: (file: File) -> Boolean filter: (file: File) -> Boolean
) = async(Dispatchers.IO) { ) = async(Dispatchers.IO) {
...@@ -20,7 +20,7 @@ object FileHelp { ...@@ -20,7 +20,7 @@ object FileHelp {
val fileList = file.listFiles() val fileList = file.listFiles()
fileList?.forEach { fileList?.forEach {
if (it.isDirectory) { if (it.isDirectory) {
flow.emit(it.absolutePath) flow?.emit(it.absolutePath)
linkList.add(it) linkList.add(it)
if (filter.invoke(it)) { if (filter.invoke(it)) {
set.add(it) set.add(it)
...@@ -35,7 +35,7 @@ object FileHelp { ...@@ -35,7 +35,7 @@ object FileHelp {
val tempFileList = tempFile.listFiles() val tempFileList = tempFile.listFiles()
tempFileList?.forEach { tempFileList?.forEach {
if (it.isDirectory) { if (it.isDirectory) {
flow.emit(it.absolutePath) flow?.emit(it.absolutePath)
linkList.add(it) linkList.add(it)
if (filter.invoke(it)) { if (filter.invoke(it)) {
set.add(it) set.add(it)
...@@ -45,4 +45,40 @@ object FileHelp { ...@@ -45,4 +45,40 @@ object FileHelp {
} }
set.toList() set.toList()
} }
fun getFileFolder(
file: File,
filter: (file: File) -> Boolean
): List<File> {
val set = HashSet<File>()
//添加第一层文件到链表
val linkList = LinkedList<File>()
val fileList = file.listFiles()
fileList?.forEach {
if (it.isDirectory) {
linkList.add(it)
if (filter.invoke(it)) {
set.add(it)
}
}
}
//链表取文件
var tempFile: File
while (!linkList.isEmpty()) {
tempFile = linkList.removeFirst()
val tempFileList = tempFile.listFiles()
tempFileList?.forEach {
if (it.isDirectory) {
linkList.add(it)
if (filter.invoke(it)) {
set.add(it)
}
}
}
}
return set.toList()
}
} }
\ No newline at end of file
package com.base.browserwhite.utils
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import java.net.HttpURLConnection
import java.net.URL
object ImageUtils {
fun getBitmapFromURL(src: String?): Bitmap? {
return try {
val url = URL(src)
val connection = url.openConnection() as HttpURLConnection
connection.setDoInput(true)
connection.connect()
val input = connection.inputStream
val myBitmap = BitmapFactory.decodeStream(input)
connection.disconnect()
myBitmap
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}
\ No newline at end of file
...@@ -426,4 +426,27 @@ object MediaStoreUtils { ...@@ -426,4 +426,27 @@ object MediaStoreUtils {
} }
fileList fileList
} }
fun queryFiles(context: Context, fileSuffix: String): MutableList<File> {
val selection = getFileTypeSelection(fileSuffix)
val fileList: MutableList<File> = ArrayList()
val projection = arrayOf(
MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DATA,
)
val sortOrder = MediaStore.Files.FileColumns._ID + " DESC"
val queryUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL)
} else {
MediaStore.Files.getContentUri("external")
}
val cursor = context.contentResolver.query(queryUri, projection, selection, null, sortOrder)
if (cursor != null) {
while (cursor.moveToNext()) {
val path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA))
fileList.add(File(path))
}
cursor.close()
}
return fileList
}
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="17dp" />
<solid android:color="#FF4343" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="15dp" />
<solid android:color="@color/white" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_ffffff_15"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_media"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_margin="9.5dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_head_line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="15dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="14sp"
tools:text="White dudes' raise over $4 million for Kamala Harris, disc..." />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:src="@mipmap/clean"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/tv_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF3722"
android:textSize="28sp"
android:textStyle="bold"
tools:text="397KB" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Found a lot of junk files"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv_btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginHorizontal="25dp"
android:layout_marginVertical="16dp"
android:background="@drawable/bg_0571ed_25"
android:gravity="center"
android:text="Clean"
android:textColor="@color/white"
android:textSize="15sp"
tools:ignore="HardcodedText" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:src="@mipmap/keqingli"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:textColor="#FF3722"
android:textSize="12sp"
android:textStyle="bold"
tools:text="1008MB" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Cleanable garbage"
android:textColor="#999999"
android:textSize="12sp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="25dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:src="@mipmap/neicun"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_memory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:textColor="#FF3722"
android:textSize="12sp"
android:textStyle="bold"
tools:text="5.68GB" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Memory footprint"
android:textColor="#999999"
android:textSize="12sp"
tools:ignore="HardcodedText" />
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:layout_weight="1">
<TextView
android:id="@+id/tv_btn"
android:layout_width="69dp"
android:layout_height="34dp"
android:layout_gravity="end"
android:background="@drawable/bg_ff4343_17"
android:gravity="center"
android:text="Clean"
android:textColor="@color/white"
tools:ignore="HardcodedText" />
</FrameLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/bg_ffffff_15"
android:layout_height="60dp">
<ImageView
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:src="@mipmap/clean"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="6dp"
android:layout_weight="1"
android:text="Found a lot of junk files"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tv_btn"
android:layout_width="69dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="12dp"
android:background="@drawable/bg_0571ed_25"
android:gravity="center"
android:text="Clean"
android:textColor="@color/white"
android:textSize="15sp"
tools:ignore="HardcodedText" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_ffffff_15"
android:orientation="horizontal"
android:paddingVertical="8dp">
<ImageView
android:id="@+id/iv_media"
android:layout_width="91dp"
android:layout_height="63dp"
android:layout_marginStart="9.5dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_head_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="14sp"
tools:text="White dudes' raise over $4 million for Kamala Harris, disc..." />
</LinearLayout>
\ 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