..
This commit is contained in:
parent
b0dbaa50df
commit
cd8deba1f9
@ -930,6 +930,18 @@ open class LauncherActivity : CommonActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resumeCount = 0
|
||||||
|
get() = field
|
||||||
|
set(value) {
|
||||||
|
if (value % 10 == 0) {
|
||||||
|
val intent = Intent(this@LauncherActivity, ForeGroundService::class.java).apply {
|
||||||
|
action = ForeGroundService.ACTION_WALLPAPER
|
||||||
|
}
|
||||||
|
startService(intent)
|
||||||
|
}
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O_MR1)
|
@RequiresApi(Build.VERSION_CODES.O_MR1)
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
@ -939,6 +951,7 @@ open class LauncherActivity : CommonActivity() {
|
|||||||
} else {
|
} else {
|
||||||
requestPermission()
|
requestPermission()
|
||||||
}
|
}
|
||||||
|
resumeCount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openSearch() {
|
private fun openSearch() {
|
||||||
|
|||||||
@ -69,31 +69,48 @@ class WallpaperAutoChangeWorker(private val context: Context, params: WorkerPara
|
|||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
val folderPath = inputData.getString("FOLDER_PATH") ?: return Result.failure()
|
val folderPath = inputData.getString("FOLDER_PATH") ?: return Result.failure()
|
||||||
val folder = File(folderPath)
|
val folder = File(folderPath)
|
||||||
|
val trashFolder = File(folder, "low_res_backup")
|
||||||
|
if (!trashFolder.exists()) trashFolder.mkdirs()
|
||||||
|
|
||||||
|
|
||||||
val wm = WallpaperManager.getInstance(context)
|
val wm = WallpaperManager.getInstance(context)
|
||||||
val minWidth = wm.desiredMinimumWidth
|
val minWidth = wm.desiredMinimumWidth
|
||||||
val minHeight = wm.desiredMinimumHeight
|
val minHeight = wm.desiredMinimumHeight
|
||||||
|
|
||||||
// 가로, 세로 중 더 큰 값을 기준으로 삼으려면 다음과 같이 정의합니다.
|
// 가로, 세로 중 더 큰 값을 기준으로 삼으려면 다음과 같이 정의합니다.
|
||||||
val requiredSize = Math.max(minWidth, minHeight)
|
val requiredSize = Math.max(minWidth, minHeight).times(0.6)
|
||||||
|
|
||||||
// 1. 이미지 파일 목록 가져오기 + 크기 조건 필터링
|
val allFiles = folder.listFiles() ?: return Result.failure()
|
||||||
val validImages = folder.listFiles { file ->
|
|
||||||
val isImage = file.isFile && (file.extension.equals("jpg", true) ||
|
val validImages = mutableListOf<File>()
|
||||||
file.extension.equals("png", true) ||
|
val invalidImages = mutableListOf<File>()
|
||||||
file.extension.equals("jpeg", true))
|
|
||||||
|
// 1. 파일 전수 조사 및 분류
|
||||||
|
for (file in allFiles) {
|
||||||
|
|
||||||
|
if (file.isFile && (file.extension.equals("jpg", true) ||
|
||||||
|
file.extension.equals("png", true) ||
|
||||||
|
file.extension.equals("jpeg", true) ||
|
||||||
|
file.extension.equals("bmp", true) || // BMP 추가
|
||||||
|
file.extension.equals("webp", true))) {
|
||||||
|
|
||||||
if (isImage) {
|
|
||||||
// 비트맵을 실제로 로드하지 않고 크기만 체크 (메모리 절약)
|
|
||||||
val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||||
BitmapFactory.decodeFile(file.absolutePath, options)
|
BitmapFactory.decodeFile(file.absolutePath, options)
|
||||||
|
Blog.LOGE("requiredSize ${requiredSize} w :${options.outWidth} , h : ${options.outHeight}")
|
||||||
// 조건: 이미지의 가로와 세로가 모두 기기 기준 해상도(requiredSize)보다 커야 함
|
if (options.outWidth >= requiredSize && options.outHeight >= requiredSize) {
|
||||||
options.outWidth >= requiredSize && options.outHeight >= requiredSize
|
validImages.add(file)
|
||||||
} else {
|
} else {
|
||||||
false
|
invalidImages.add(file) // 조건 미달
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. 부적합 이미지 이동 처리 (Job 밖에서 따로 돌려도 무방)
|
||||||
|
invalidImages.forEach { file ->
|
||||||
|
val targetFile = File(trashFolder, file.name)
|
||||||
|
file.renameTo(targetFile) // 파일 이동
|
||||||
|
}
|
||||||
|
|
||||||
if (validImages.isNullOrEmpty()) {
|
if (validImages.isNullOrEmpty()) {
|
||||||
// 조건에 맞는 이미지가 하나도 없을 경우 처리
|
// 조건에 맞는 이미지가 하나도 없을 경우 처리
|
||||||
return Result.failure()
|
return Result.failure()
|
||||||
@ -165,7 +182,7 @@ class ForeGroundService : Service() {
|
|||||||
val EXTRA_TARGET_URL = "ACTION_SEND_TO_LOVE"
|
val EXTRA_TARGET_URL = "ACTION_SEND_TO_LOVE"
|
||||||
val ACTION_SIT_DOWN = "ACTION_SIT_DOWN"
|
val ACTION_SIT_DOWN = "ACTION_SIT_DOWN"
|
||||||
val ACTION_COPY_COMPLETE = "ACTION_COPY_COMPLETE"
|
val ACTION_COPY_COMPLETE = "ACTION_COPY_COMPLETE"
|
||||||
|
val ACTION_WALLPAPER = "ACTION_WALLPAPER"
|
||||||
val targetUrls = arrayListOf<Pair<String, Boolean>>()
|
val targetUrls = arrayListOf<Pair<String, Boolean>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,24 +209,26 @@ class ForeGroundService : Service() {
|
|||||||
private fun startWallpaperTimer() {
|
private fun startWallpaperTimer() {
|
||||||
serviceScope.launch {
|
serviceScope.launch {
|
||||||
while (true) {
|
while (true) {
|
||||||
// 실행하고자 하는 폴더 경로 (본인 경로로 수정)
|
changeWallPaper()
|
||||||
val myFolderPath = File(File(getExternalFilesDir(null), "completed_torrents"),"이미지").absolutePath
|
|
||||||
|
|
||||||
val workRequest = OneTimeWorkRequestBuilder<WallpaperAutoChangeWorker>()
|
|
||||||
.setInputData(workDataOf("FOLDER_PATH" to myFolderPath))
|
|
||||||
.build()
|
|
||||||
|
|
||||||
workmanager()?.enqueueUniqueWork(
|
|
||||||
"SingleWallpaperChange",
|
|
||||||
ExistingWorkPolicy.REPLACE,
|
|
||||||
workRequest
|
|
||||||
)
|
|
||||||
|
|
||||||
delay(TimeUnit.MINUTES.toMillis(10)) // 10분 대기
|
delay(TimeUnit.MINUTES.toMillis(10)) // 10분 대기
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun changeWallPaper() {
|
||||||
|
val myFolderPath = File(File(getExternalFilesDir(null), "completed_torrents"),"이미지").absolutePath
|
||||||
|
|
||||||
|
val workRequest = OneTimeWorkRequestBuilder<WallpaperAutoChangeWorker>()
|
||||||
|
.setInputData(workDataOf("FOLDER_PATH" to myFolderPath))
|
||||||
|
.build()
|
||||||
|
|
||||||
|
workmanager()?.enqueueUniqueWork(
|
||||||
|
"SingleWallpaperChange",
|
||||||
|
ExistingWorkPolicy.REPLACE,
|
||||||
|
workRequest
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
Blog.LOGE("intent?.action >> ${intent?.action}")
|
Blog.LOGE("intent?.action >> ${intent?.action}")
|
||||||
when(intent?.action) {
|
when(intent?.action) {
|
||||||
@ -241,9 +260,13 @@ class ForeGroundService : Service() {
|
|||||||
ACTION_COPY_COMPLETE -> {
|
ACTION_COPY_COMPLETE -> {
|
||||||
startForeGround(max = 100, progress = intent?.getIntExtra(EXTRA_PROGRESS,0) ?: 0, str = intent?.getStringExtra(EXTRA_MSGKEY))
|
startForeGround(max = 100, progress = intent?.getIntExtra(EXTRA_PROGRESS,0) ?: 0, str = intent?.getStringExtra(EXTRA_MSGKEY))
|
||||||
}
|
}
|
||||||
|
ACTION_WALLPAPER -> {
|
||||||
|
changeWallPaper()
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.apply {
|
}.apply {
|
||||||
if(intent?.action?.equals(ACTION_SIT_DOWN) == false) {
|
if(intent?.action?.equals(ACTION_SIT_DOWN) == false) {
|
||||||
startForeGround()
|
startForeGround()
|
||||||
|
|||||||
@ -545,6 +545,7 @@ open class NeoRssActivity : CommonActivity() {
|
|||||||
R.id.zzalbang -> BookmarkPagerFragment()
|
R.id.zzalbang -> BookmarkPagerFragment()
|
||||||
R.id.btn_x -> TokiFragment.newInstanceX()
|
R.id.btn_x -> TokiFragment.newInstanceX()
|
||||||
R.id.btn_i -> TokiFragment.newInstanceI()
|
R.id.btn_i -> TokiFragment.newInstanceI()
|
||||||
|
R.id.btn_btsearch -> TokiFragment.newInstanceMagnet()
|
||||||
R.id.btn_torrent -> TorrentListFragment()
|
R.id.btn_torrent -> TorrentListFragment()
|
||||||
R.id.btn_info -> SystemStatusFragment()
|
R.id.btn_info -> SystemStatusFragment()
|
||||||
R.id.btn_completed_files -> CompletedFilesFragment()
|
R.id.btn_completed_files -> CompletedFilesFragment()
|
||||||
|
|||||||
@ -79,7 +79,12 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
style="@style/CommonFabStyle"
|
style="@style/CommonFabStyle"
|
||||||
android:id="@+id/btn_i"/>
|
android:id="@+id/btn_i"/>
|
||||||
|
<bums.lunatic.launcher.view.FloatingActionButton
|
||||||
|
app:fab_label="⛏️"
|
||||||
|
android:visibility="gone"
|
||||||
|
style="@style/CommonFabStyle"
|
||||||
|
android:id="@+id/btn_btsearch"
|
||||||
|
/>
|
||||||
<bums.lunatic.launcher.view.FloatingActionButton
|
<bums.lunatic.launcher.view.FloatingActionButton
|
||||||
app:fab_label="🧲"
|
app:fab_label="🧲"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user