Merge branch 'main' of https://dev.lunaticbum.kr/lun_admin/android_multiviewwer
# Conflicts: # app/src/main/kotlin/bums/lunatic/launcher/workers/TorrentManager.kt
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package bums.lunatic.launcher.wall
|
||||
|
||||
import android.app.WallpaperManager
|
||||
import android.content.ContentUris
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Environment
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
@@ -9,6 +11,8 @@ import android.provider.MediaStore
|
||||
import android.service.wallpaper.WallpaperService
|
||||
import android.util.Log
|
||||
import android.view.SurfaceHolder
|
||||
import androidx.work.ListenableWorker
|
||||
import bums.lunatic.launcher.utils.Blog
|
||||
import java.io.File
|
||||
|
||||
class MyWallpaperService : WallpaperService() {
|
||||
@@ -26,7 +30,7 @@ class MyWallpaperService : WallpaperService() {
|
||||
private lateinit var holder: SurfaceHolder
|
||||
private var wasInPreview = false
|
||||
private var nativeRenderer: NativeRenderer? = null
|
||||
private var mediaFiles: List<File> = emptyList()
|
||||
private var mediaFiles: MutableList<File> = mutableListOf()
|
||||
private var isVisible = false
|
||||
private var isSurfaceValid = false
|
||||
|
||||
@@ -187,7 +191,7 @@ class MyWallpaperService : WallpaperService() {
|
||||
nativeRenderer?.setTurnPageDuration(8000)
|
||||
nativeRenderer?.setAnimationMode(NativeRenderer.ANIMATION_MODE_PAN)
|
||||
nativeRenderer?.setTransitionMode(NativeRenderer.TRANSITION_MODE_FADE)
|
||||
nativeRenderer?.setAnimationSpeed(2.0f)
|
||||
nativeRenderer?.setAnimationSpeed(1.0f)
|
||||
NativeRenderer.nativeSetNextMediaCallback(nextMediaCallback)
|
||||
|
||||
|
||||
@@ -198,12 +202,45 @@ class MyWallpaperService : WallpaperService() {
|
||||
// ... loadMediaFiles, nextMediaCallback, getFdFromPath는 이전과 동일 ...
|
||||
private fun loadMediaFiles() {
|
||||
if (!mediaDir.exists()) mediaDir.mkdirs()
|
||||
mediaFiles = mediaDir.listFiles()
|
||||
?.filter { supportedExtensions.contains(it.extension.lowercase()) }
|
||||
?.toList() ?: emptyList()
|
||||
// mediaFiles = mediaDir.listFiles()
|
||||
// ?.filter { supportedExtensions.contains(it.extension.lowercase()) }
|
||||
// ?.toList() ?: emptyList()
|
||||
|
||||
Log.d(TAG, "Found ${mediaFiles.size} media files.")
|
||||
|
||||
val allFiles = mediaDir.listFiles()
|
||||
val trashFolder = File(mediaDir, "low_res_backup")
|
||||
if (!trashFolder.exists()) trashFolder.mkdirs()
|
||||
val invalidImages = mutableListOf<File>()
|
||||
val wm = WallpaperManager.getInstance(this@MyWallpaperService)
|
||||
val minWidth = wm.desiredMinimumWidth
|
||||
val minHeight = wm.desiredMinimumHeight
|
||||
val requiredSize = Math.max(minWidth, minHeight).times(0.6)
|
||||
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))) {
|
||||
|
||||
val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||
BitmapFactory.decodeFile(file.absolutePath, options)
|
||||
Blog.LOGE("requiredSize ${requiredSize} w :${options.outWidth} , h : ${options.outHeight}")
|
||||
if (options.outWidth >= requiredSize && options.outHeight >= requiredSize) {
|
||||
mediaFiles.add(file)
|
||||
} else {
|
||||
invalidImages.add(file) // 조건 미달
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 부적합 이미지 이동 처리 (Job 밖에서 따로 돌려도 무방)
|
||||
invalidImages.forEach { file ->
|
||||
val targetFile = File(trashFolder, file.name)
|
||||
file.renameTo(targetFile) // 파일 이동
|
||||
}
|
||||
|
||||
if (mediaFiles.isNotEmpty()) {
|
||||
val initialFile = mediaFiles.random()
|
||||
Log.d(TAG, "Attempting to load initial random media via preloader: ${initialFile.absolutePath}")
|
||||
@@ -223,9 +260,43 @@ class MyWallpaperService : WallpaperService() {
|
||||
if (!mediaDir.exists()) mediaDir.mkdirs()
|
||||
|
||||
|
||||
mediaFiles = mediaDir.listFiles()
|
||||
?.filter { supportedExtensions.contains(it.extension.lowercase()) }
|
||||
?.toList() ?: emptyList()
|
||||
// mediaFiles = mediaDir.listFiles()
|
||||
// ?.filter { supportedExtensions.contains(it.extension.lowercase()) }
|
||||
// ?.toList() ?: emptyList()
|
||||
|
||||
val allFiles = mediaDir.listFiles()
|
||||
val trashFolder = File(mediaDir, "low_res_backup")
|
||||
if (!trashFolder.exists()) trashFolder.mkdirs()
|
||||
// val validImages = mutableListOf<File>()
|
||||
val invalidImages = mutableListOf<File>()
|
||||
val wm = WallpaperManager.getInstance(this@MyWallpaperService)
|
||||
val minWidth = wm.desiredMinimumWidth
|
||||
val minHeight = wm.desiredMinimumHeight
|
||||
val requiredSize = Math.max(minWidth, minHeight).times(0.6)
|
||||
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))) {
|
||||
|
||||
val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||
BitmapFactory.decodeFile(file.absolutePath, options)
|
||||
Blog.LOGE("requiredSize ${requiredSize} w :${options.outWidth} , h : ${options.outHeight}")
|
||||
if (options.outWidth >= requiredSize && options.outHeight >= requiredSize) {
|
||||
mediaFiles.add(file)
|
||||
} else {
|
||||
invalidImages.add(file) // 조건 미달
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 부적합 이미지 이동 처리 (Job 밖에서 따로 돌려도 무방)
|
||||
invalidImages.forEach { file ->
|
||||
val targetFile = File(trashFolder, file.name)
|
||||
file.renameTo(targetFile) // 파일 이동
|
||||
}
|
||||
|
||||
val nextFile = mediaFiles.random()
|
||||
Log.d(TAG, "Callback: Preloading next random media: ${nextFile.absolutePath}")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package bums.lunatic.launcher.workers
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.*
|
||||
import android.content.*
|
||||
import android.net.*
|
||||
@@ -50,9 +51,10 @@ class TorrentService : Service() {
|
||||
fun getService(): TorrentService = this@TorrentService
|
||||
}
|
||||
|
||||
@SuppressLint("ServiceCast")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
notificationManager = getSystemService(Context.CONNECTIVITY_SERVICE) as NotificationManager
|
||||
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
startForegroundService()
|
||||
initLibTorrent()
|
||||
|
||||
@@ -219,6 +221,29 @@ class TorrentService : Service() {
|
||||
val status = handle.status()
|
||||
val state = status.state()
|
||||
|
||||
val hashStr = status.infoHash().toString()
|
||||
var rawName = status.name()
|
||||
|
||||
if (status.hasMetadata()) {
|
||||
val torrentInfo = handle.torrentFile()
|
||||
if (torrentInfo != null && torrentInfo.isValid) {
|
||||
val realName = torrentInfo.name()
|
||||
if (!realName.isNullOrEmpty()) {
|
||||
rawName = realName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val displayName = if (rawName.isNullOrEmpty() || rawName == hashStr) {
|
||||
if (status.hasMetadata()) {
|
||||
"파일 정보 분석 중..."
|
||||
} else {
|
||||
"메타데이터 수신 중... (${hashStr.take(6)})"
|
||||
}
|
||||
} else {
|
||||
rawName
|
||||
}
|
||||
|
||||
val isPaused = status.flags().and_(libtorrent.getPaused()).nonZero()
|
||||
val isFinished = status.isFinished
|
||||
val isDownloading = (state.swig() == torrent_status.state_t.downloading.swigValue())
|
||||
@@ -233,7 +258,7 @@ class TorrentService : Service() {
|
||||
|
||||
tasks.add(TorrentTask(
|
||||
infoHash = status.infoHash().toString(),
|
||||
name = status.name() ?: "알 수 없음",
|
||||
name = displayName,
|
||||
progress = status.progress() * 100f,
|
||||
isPaused = isPaused,
|
||||
isQueued = !isPaused && !isFinished && !isDownloading,
|
||||
|
||||
Reference in New Issue
Block a user