Remove unused imports
This commit is contained in:
1 parent
31c99f3e6e
commit
75b3467f89
3 files changed
+61
-31
No files matched your search
@@ -396,7 +396,8 @@ suspend fun getWallpaperFromFolder(folderUri: String, context: Context): List<Wa
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_: SecurityException) {
|
||||
} catch (e: SecurityException) {
|
||||
Log.e("WallpaperUtil", "Error getting wallpapers from folder: ", e)
|
||||
return@withContext emptyList<Wallpaper>()
|
||||
}
|
||||
return@withContext wallpapers
|
||||
@@ -411,11 +412,13 @@ suspend fun getFolderMetadata(folderUri: String, context: Context): Metadata = w
|
||||
try {
|
||||
val file = DocumentFileCompat.fromTreeUri(context, uri)
|
||||
Metadata(file?.name?.substringBeforeLast('.', file.name).toString(), file?.lastModified ?: 0)
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting folder metadata: ", e)
|
||||
val file = DocumentFile.fromTreeUri(context, uri)
|
||||
Metadata(file?.name?.substringBeforeLast('.', file.name.toString()) ?: "", file?.lastModified() ?: 0)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting folder metadata: ", e)
|
||||
Metadata("", 0)
|
||||
}
|
||||
}
|
||||
@@ -431,11 +434,13 @@ suspend fun getImageMetadata(context: Context, uriString: String): Metadata = wi
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(context, uri)
|
||||
Metadata(file?.name?.substringBeforeLast('.', file.name).toString(), file?.lastModified ?: 0)
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting image metadata: ", e)
|
||||
val file = DocumentFile.fromSingleUri(context, uri)
|
||||
Metadata(file?.name?.substringBeforeLast('.', file.name.toString()) ?: "", file?.lastModified() ?: 0)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting image metadata: ", e)
|
||||
Metadata("", 0)
|
||||
}
|
||||
}
|
||||
@@ -448,17 +453,32 @@ suspend fun findFirstValidUri(
|
||||
folders: List<Folder>,
|
||||
wallpapers: List<Wallpaper>
|
||||
): String? = withContext(Dispatchers.IO) {
|
||||
// Check folder wallpapers first
|
||||
folders.forEach { folder ->
|
||||
folder.wallpapers.forEach { wallpaper ->
|
||||
isValidUri(context, wallpaper.wallpaperUri).let { return@withContext wallpaper.wallpaperUri }
|
||||
try {
|
||||
folders.forEach { folder ->
|
||||
folder.wallpapers.forEach { wallpaper ->
|
||||
try {
|
||||
if (isValidUri(context, wallpaper.wallpaperUri)) {
|
||||
return@withContext wallpaper.wallpaperUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error checking URI validity: ${wallpaper.wallpaperUri}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
wallpapers.forEach { wallpaper ->
|
||||
try {
|
||||
if (isValidUri(context, wallpaper.wallpaperUri)) {
|
||||
return@withContext wallpaper.wallpaperUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error checking URI validity: ${wallpaper.wallpaperUri}", e)
|
||||
}
|
||||
}
|
||||
return@withContext null
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error finding valid URI", e)
|
||||
return@withContext null
|
||||
}
|
||||
// Then check individual wallpapers
|
||||
wallpapers.forEach { wallpaper ->
|
||||
isValidUri(context, wallpaper.wallpaperUri).let { return@withContext wallpaper.wallpaperUri }
|
||||
}
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,7 +488,8 @@ fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.decompress("content://com.android.externalstorage.documents/")?.toUri() ?: return false
|
||||
return try {
|
||||
DocumentFileCompat.fromSingleUri(context, uri)?.exists() ?: false
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error checking URI validity: ", e)
|
||||
DocumentFile.fromSingleUri(context, uri)?.exists() ?: false
|
||||
}
|
||||
}
|
||||
@@ -479,8 +500,11 @@ fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
fun isDirectory(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri() ?: return false
|
||||
return try {
|
||||
DocumentFileCompat.fromSingleUri(context, uri)?.isDirectory() ?: false
|
||||
} catch (_: Exception) {
|
||||
val valid = DocumentFile.fromSingleUri(context, uri)?.isDirectory() ?: false
|
||||
Log.d("WallpaperUtil", "URI is directory: $uri")
|
||||
valid
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error checking if URI is a directory: ", e)
|
||||
DocumentFile.fromSingleUri(context, uri)?.isDirectory ?: false
|
||||
}
|
||||
}
|
||||
|
||||
+20
-13
@@ -246,20 +246,27 @@ class WallpaperAlarmSchedulerImpl @Inject constructor(
|
||||
fun scheduleRefresh(refresh: Boolean = true) {
|
||||
cancelAlarm(Type.REFRESH)
|
||||
if (refresh) {
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("refresh", true)
|
||||
// val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
// putExtra("refresh", true)
|
||||
// }
|
||||
val serviceIntent = Intent(context, HomeWallpaperService::class.java).apply {
|
||||
action = HomeWallpaperService.Actions.REFRESH.toString()
|
||||
}
|
||||
val nextMidnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
|
||||
alarmManager.setAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
Type.REFRESH.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
context.startService(serviceIntent)
|
||||
// val nextMidnight = LocalDateTime.now().plusMinutes(1)
|
||||
// val nextMidnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
|
||||
// alarmManager.setInexactRepeating(
|
||||
// AlarmManager.RTC_WAKEUP,
|
||||
// nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
// //AlarmManager.INTERVAL_DAY,
|
||||
// AlarmManager.INTERVAL_FIFTEEN_MINUTES,
|
||||
// PendingIntent.getBroadcast(
|
||||
// context,
|
||||
// Type.REFRESH.ordinal,
|
||||
// intent,
|
||||
// PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
// )
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -30,7 +30,6 @@ class WallpaperReceiver : BroadcastReceiver() {
|
||||
action = HomeWallpaperService.Actions.REFRESH.toString()
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleRefresh(refresh)
|
||||
} else {
|
||||
val homeInterval = intent?.getIntExtra("homeInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val lockInterval = intent?.getIntExtra("lockInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
|
||||
Reference in new issue
Block a user