Skip to content

Commit

Permalink
Merge pull request #19 from Jarvay/develop
Browse files Browse the repository at this point in the history
v2.4.1
  • Loading branch information
Jarvay authored Jan 25, 2025
2 parents 17a7a57 + 7b21abc commit 16c657e
Show file tree
Hide file tree
Showing 31 changed files with 211 additions and 209 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 16
versionName = "2.2.0"
versionName = "2.4.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -116,5 +116,7 @@ dependencies {
implementation(libs.glance.material3)
implementation(libs.androidx.glance.material)

implementation(libs.utilcodex)

implementation(fileTree("libs"))
}
32 changes: 13 additions & 19 deletions app/src/main/java/jarvay/workpaper/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package jarvay.workpaper

import android.annotation.SuppressLint
import android.app.ActivityManager
import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import dagger.hilt.android.AndroidEntryPoint
import jarvay.workpaper.compose.WorkpaperApp
import jarvay.workpaper.data.preferences.RunningPreferencesRepository
Expand All @@ -39,7 +37,6 @@ class MainActivity : ComponentActivity() {

private val downloadStartReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Log.d(javaClass.simpleName, "downloadStartReceiver")
if (context == null || intent == null) return
val id = intent.getLongExtra(APK_DOWNLOAD_ID_KEY, -1)
if (id > -1) {
Expand Down Expand Up @@ -68,8 +65,6 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()

viewModel.settings.observe(this) {
Log.d("settings update", it.toString())

val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
activityManager.let { manager ->
manager.appTasks.forEach { task ->
Expand All @@ -79,7 +74,6 @@ class MainActivity : ComponentActivity() {
}

viewModel.settings.observe(this) {
Log.d(javaClass.simpleName, "setContent")
setContent {
WorkpaperTheme(
dynamicColor = it.enableDynamicColor
Expand All @@ -90,26 +84,26 @@ class MainActivity : ComponentActivity() {
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
private fun registerDownloadStartListener() {
val intentFilter = IntentFilter(ACTION_APK_DOWNLOAD_ID)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(downloadStartReceiver, intentFilter, RECEIVER_EXPORTED)
} else {
registerReceiver(downloadStartReceiver, intentFilter)
}
ContextCompat.registerReceiver(
this,
downloadStartReceiver,
intentFilter,
ContextCompat.RECEIVER_EXPORTED
)
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
private fun registerDownloadCompleteListener() {
val intentFilter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(downloadCompleteReceiver, intentFilter, RECEIVER_EXPORTED)
} else {
registerReceiver(downloadCompleteReceiver, intentFilter)
}
ContextCompat.registerReceiver(
this,
downloadCompleteReceiver,
intentFilter,
ContextCompat.RECEIVER_EXPORTED
)
}

override fun onDestroy() {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/jarvay/workpaper/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import android.content.Intent
import android.content.IntentFilter
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.blankj.utilcode.util.LogUtils
import dagger.hilt.android.HiltAndroidApp
import jarvay.workpaper.data.preferences.RunningPreferencesRepository
import jarvay.workpaper.data.preferences.SettingsPreferencesRepository
import jarvay.workpaper.receiver.UnlockReceiver
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import javax.inject.Inject


@HiltAndroidApp
class MainApplication : Application(), Configuration.Provider {
@Inject
Expand All @@ -21,6 +25,9 @@ class MainApplication : Application(), Configuration.Provider {
@Inject
lateinit var runningPreferencesRepository: RunningPreferencesRepository

@Inject
lateinit var settingsPreferencesRepository: SettingsPreferencesRepository

@Inject
lateinit var workpaper: Workpaper

Expand All @@ -30,9 +37,29 @@ class MainApplication : Application(), Configuration.Provider {
.setMinimumLoggingLevel(if (BuildConfig.DEBUG) android.util.Log.DEBUG else android.util.Log.ERROR)
.build()

private fun initLogUtils() {
LogUtils.getConfig().apply {
saveDays = 7
setConsoleSwitch(true)
isLog2FileSwitch = runBlocking {
settingsPreferencesRepository.settingsPreferencesFlow.first().enableLog
}
}
}

override fun onCreate() {
super.onCreate()

MainScope().launch {
settingsPreferencesRepository.settingsPreferencesFlow.collect {
LogUtils.getConfig().apply {
isLog2FileSwitch = it.enableLog
}
}
}

initLogUtils()

val unlockReceiver = UnlockReceiver()
val unlockFilter = IntentFilter().apply {
addAction(Intent.ACTION_SCREEN_OFF)
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/jarvay/workpaper/Workpaper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.util.Log
import dagger.hilt.android.qualifiers.ApplicationContext
import jarvay.workpaper.data.preferences.RunningPreferencesKeys
import jarvay.workpaper.data.preferences.RunningPreferencesRepository
Expand Down Expand Up @@ -91,8 +90,6 @@ class Workpaper @Inject constructor(
}

fun start() {
Log.d(javaClass.simpleName, "start")

val i = Intent(context, WorkpaperService::class.java)
context.startService(i)

Expand All @@ -114,8 +111,6 @@ class Workpaper @Inject constructor(
}

suspend fun stop() {
Log.d(javaClass.simpleName, "stop")

currentRuleId.value = -1
nextRuleId.value = -1

Expand Down Expand Up @@ -169,8 +164,6 @@ class Workpaper @Inject constructor(
}

fun cancelAlarm(type: AlarmType) {
Log.d("cancelAlarm", type.toString())

val pendingIntent = getPendingIntent(type)
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmManager.cancel(pendingIntent)
Expand Down Expand Up @@ -199,9 +192,6 @@ class Workpaper @Inject constructor(
isManual: Boolean = false,
ruleId: Long? = null
): NextWallpaper? {
val runningPreferences = runningPreferencesRepository.runningPreferencesFlow.first()

Log.d(javaClass.simpleName, runningPreferences.toString())
val index = startIndex ?: nextWallpaper.value?.index ?: -1
val tmpRuleId = ruleId ?: this.currentRuleId.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package jarvay.workpaper.compose.album

import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
Expand Down Expand Up @@ -62,6 +61,7 @@ import coil3.compose.SubcomposeAsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.size.Size
import com.blankj.utilcode.util.LogUtils
import jarvay.workpaper.R
import jarvay.workpaper.compose.components.LocalSimpleSnackbar
import jarvay.workpaper.compose.components.SimpleDialog
Expand Down Expand Up @@ -155,7 +155,6 @@ fun AlbumDetailScreen(
if (permissions.any { it.uri == uri }) {
val file = DocumentFile.fromSingleUri(context, uri)
file?.let {
Log.d("file", it.type.toString())
newWallpapers.add(
Wallpaper(
contentUri = uri.toString(),
Expand Down Expand Up @@ -384,7 +383,7 @@ private fun WallpaperItem(
.crossfade(true)
.build()
} catch (e: Exception) {
Log.w("AlbumDetailScreen", e.toString())
LogUtils.e("AlbumDetailScreen", "Load wallpaper failed", e.toString())
null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jarvay.workpaper.compose.album

import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -35,7 +34,6 @@ fun AlbumUpdateDialog(
}
},
onConfirm = { newName ->
Log.d("album", album.toString())
album?.let {
if (viewModel.exists(newName, album.albumId)) {
errorMessage = context.getString(R.string.album_name_exists)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jarvay.workpaper.compose.components

import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
Expand All @@ -23,6 +22,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import com.blankj.utilcode.util.LogUtils
import jarvay.workpaper.R
import jarvay.workpaper.data.album.Album
import jarvay.workpaper.data.wallpaper.Wallpaper
Expand All @@ -44,7 +44,7 @@ fun AlbumItem(
ImageRequest.Builder(context).data(cover).size(256, 256)
.build()
} catch (e: Exception) {
Log.w("AlbumItem", e.toString())
LogUtils.e("AlbumItem", "Load album cover failed", e.toString())
null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jarvay.workpaper.compose.components

import android.util.Log
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -40,7 +39,6 @@ fun NumberField(
}

val onChange: (Int) -> Unit = { newValue ->
Log.d("onChange", newValue.toString())
var result = newValue

min?.let {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/jarvay/workpaper/compose/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jarvay.workpaper.compose.home
import android.app.AlarmManager
import android.content.Context
import android.os.Build
import android.util.Log
import androidx.annotation.StringRes
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
Expand Down Expand Up @@ -194,7 +193,6 @@ private fun checkPermissions(context: Context, onRequestPermission: () -> Unit):
val alarmManager: AlarmManager =
context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
hasPermission = alarmManager.canScheduleExactAlarms()
Log.d("checkPermissions", hasPermission.toString())

if (!hasPermission) {
onRequestPermission()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Context
import android.service.wallpaper.WallpaperService.ACTIVITY_SERVICE
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
Expand Down Expand Up @@ -78,7 +77,6 @@ fun SettingsScreen(navController: NavController, viewModel: SettingsViewModel =
val deviceAdminLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = { result: ActivityResult ->
Log.d("deviceAdminLauncher", result.toString())
if (result.resultCode == Activity.RESULT_OK) {
viewModel.update(
SettingsPreferencesKeys.DOUBLE_TAP_EVENT,
Expand Down Expand Up @@ -197,11 +195,14 @@ fun SettingsScreen(navController: NavController, viewModel: SettingsViewModel =
}

if (settings.useLiveWallpaper) {
SettingsItem(labelId = R.string.settings_item_live_wallpaper_transition) {
SettingsItem(labelId = R.string.settings_item_video_wallpaper_reset_on_screen_off) {
Switch(
checked = settings.liveWallpaperTransition,
checked = settings.videoResetProgressOnScreenOff,
onCheckedChange = { c ->
viewModel.update(SettingsPreferencesKeys.LIVE_WALLPAPER_TRANSITION, c)
viewModel.update(
SettingsPreferencesKeys.VIDEO_RESET_PROGRESS_ON_SCREEN_OFF,
c
)
})
}

Expand Down Expand Up @@ -264,6 +265,14 @@ fun SettingsScreen(navController: NavController, viewModel: SettingsViewModel =
}
}

SettingsItem(labelId = R.string.settings_item_enable_log) {
Switch(
checked = settings.enableLog,
onCheckedChange = { c ->
viewModel.update(SettingsPreferencesKeys.ENABLE_LOG, c)
})
}

SettingsItem(labelId = R.string.settings_item_auto_check_update) {
Switch(
checked = settings.autoCheckUpdate,
Expand All @@ -284,7 +293,7 @@ fun SettingsScreen(navController: NavController, viewModel: SettingsViewModel =
text = stringResource(id = R.string.permission_request_device_admin),
show = deviceAdminDialogShow,
onDismissRequest = { deviceAdminDialogShow = false }) {
deviceAdminLauncher.launch(deviceAdminIntent(context))
deviceAdminLauncher.launch(deviceAdminIntent(context))
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/jarvay/workpaper/data/Migrations.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jarvay.workpaper.data

import android.util.Log
import androidx.core.database.getLongOrNull
import androidx.core.database.getStringOrNull
import androidx.room.migration.Migration
Expand Down Expand Up @@ -30,7 +29,6 @@ val Migration_1_2 = object : Migration(1, 2) {
}
}
val values = wallpapers.joinToString(separator = ",")
Log.d(javaClass.simpleName, "INSERT INTO wallpapers(albumId, contentUri) VALUES $values;")
db.execSQL("INSERT INTO wallpapers(`albumId`, `contentUri`) VALUES $values;")

db.execSQL("ALTER TABLE albums DROP COLUMN wallpaperUris")
Expand Down
Loading

0 comments on commit 16c657e

Please sign in to comment.