diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c2448ed..8c29ce17 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: - main - develop pull_request: - types: [opened, synchronize, reopened] + types: [ opened, synchronize, reopened ] jobs: build: name: Build and analyze @@ -36,5 +36,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | - ./gradlew lint --build-cache - ./gradlew build sonar --info --build-cache \ No newline at end of file + ./gradlew lint --build-cache + ./gradlew build sonar --info --build-cache \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9df60b47..c6a475e2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,61 +1,75 @@ -import org.gradle.api.JavaVersion.VERSION_11 +import org.gradle.api.JavaVersion.VERSION_23 plugins { - alias(libs.plugins.android.application) - alias(libs.plugins.kotlin.android) - alias(libs.plugins.kotlin.compose) + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) } android { - namespace = "dev.lexip.hecate" - compileSdk = 34 + namespace = "dev.lexip.hecate" + compileSdk = 36 - defaultConfig { - applicationId = "dev.lexip.hecate" - minSdk = 31 - targetSdk = 34 - versionCode = 1 - versionName = "1.0.0" - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - } + defaultConfig { + applicationId = "dev.lexip.hecate" + minSdk = 31 + targetSdk = 36 + versionCode = 1 + versionName = "1.0.0" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } - compileOptions { - sourceCompatibility = VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = "11" - } - buildFeatures { - compose = true - } - buildToolsVersion = "35.0.0" + buildTypes { + release { + isMinifyEnabled = true + isShrinkResources = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = VERSION_23 + targetCompatibility = VERSION_23 + } + kotlinOptions { + jvmTarget = "23" + } + buildFeatures { + compose = true + } + buildToolsVersion = "35.0.0" + sourceSets { + getByName("main") { + resources { + srcDirs("src/main/resources", "src/main/java/components") + } + } + } } dependencies { - - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.lifecycle.runtime.ktx) - implementation(libs.androidx.activity.compose) - implementation(platform(libs.androidx.compose.bom)) - implementation(libs.androidx.ui) - implementation(libs.androidx.ui.graphics) - implementation(libs.androidx.ui.tooling.preview) - implementation(libs.androidx.material3) - testImplementation(libs.junit) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.espresso.core) - androidTestImplementation(platform(libs.androidx.compose.bom)) - androidTestImplementation(libs.androidx.ui.test.junit4) - debugImplementation(libs.androidx.ui.tooling) - debugImplementation(libs.androidx.ui.test.manifest) + implementation(libs.androidx.localbroadcastmanager) + implementation(libs.androidx.core.splashscreen.v100) + implementation(libs.androidx.activity.compose) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.datastore.preferences) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.lifecycle.viewmodel.compose) + implementation(libs.androidx.material3) + implementation(libs.androidx.preference) + implementation(libs.androidx.ui) + implementation(libs.androidx.ui.graphics) + implementation(libs.androidx.ui.tooling.preview) + implementation(libs.material) + implementation(platform(libs.androidx.compose.bom)) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.ui.test.junit4) + debugImplementation(libs.androidx.ui.tooling) + debugImplementation(libs.androidx.ui.test.manifest) } \ No newline at end of file diff --git a/app/src/androidTest/java/dev/lexip/hecate/ExampleInstrumentedTest.kt b/app/src/androidTest/java/dev/lexip/hecate/ExampleInstrumentedTest.kt index 4554fcbe..afba0405 100644 --- a/app/src/androidTest/java/dev/lexip/hecate/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/dev/lexip/hecate/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package dev.lexip.hecate -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * @@ -15,10 +13,10 @@ import org.junit.Assert.* */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("dev.lexip.hecate", appContext.packageName) - } + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("dev.lexip.hecate", appContext.packageName) + } } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 86edf857..a94fca8e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,28 +1,60 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 00000000..4139987c Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/dev/lexip/hecate/HecateApplication.kt b/app/src/main/java/dev/lexip/hecate/HecateApplication.kt new file mode 100644 index 00000000..99534434 --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/HecateApplication.kt @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2024 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate + +import android.app.Application +import android.content.Context +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.preferencesDataStore + +const val USER_PREFERENCES_NAME = "user_preferences" +private val Context.dataStore by preferencesDataStore(USER_PREFERENCES_NAME) + +class HecateApplication : Application() { + /** + * Top level data store to ensure it is maintained as a singleton + * but still accessible in both the app and service. + */ + val userPreferencesDataStore: DataStore + get() = this.dataStore +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/MainActivity.kt b/app/src/main/java/dev/lexip/hecate/MainActivity.kt deleted file mode 100644 index d6ac52e3..00000000 --- a/app/src/main/java/dev/lexip/hecate/MainActivity.kt +++ /dev/null @@ -1,47 +0,0 @@ -package dev.lexip.hecate - -import android.os.Bundle -import androidx.activity.ComponentActivity -import androidx.activity.compose.setContent -import androidx.activity.enableEdgeToEdge -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview -import dev.lexip.hecate.ui.theme.HecateTheme - -class MainActivity : ComponentActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - enableEdgeToEdge() - setContent { - HecateTheme { - Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> - Greeting( - name = "Android", - modifier = Modifier.padding(innerPadding) - ) - } - } - } - } -} - -@Composable -fun Greeting(name: String, modifier: Modifier = Modifier) { - Text( - text = "Hello $name!", - modifier = modifier - ) -} - -@Preview(showBackground = true) -@Composable -fun GreetingPreview() { - HecateTheme { - Greeting("Android") - } -} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/broadcasts/BootCompletedReceiver.kt b/app/src/main/java/dev/lexip/hecate/broadcasts/BootCompletedReceiver.kt new file mode 100644 index 00000000..2862e8cf --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/broadcasts/BootCompletedReceiver.kt @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.broadcasts + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.util.Log +import dev.lexip.hecate.services.BroadcastReceiverService + +private const val TAG = "BootCompletedReceiver" + +class BootCompletedReceiver : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + if (intent.action == Intent.ACTION_BOOT_COMPLETED) { + Log.i(TAG, "Boot completed, starting broadcast receiver service...") + val serviceIntent = Intent(context, BroadcastReceiverService::class.java) + context.startService(serviceIntent) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/broadcasts/ScreenOnReceiver.kt b/app/src/main/java/dev/lexip/hecate/broadcasts/ScreenOnReceiver.kt new file mode 100644 index 00000000..c523353d --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/broadcasts/ScreenOnReceiver.kt @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2024-2025 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.broadcasts + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.util.Log +import dev.lexip.hecate.util.DarkThemeHandler +import dev.lexip.hecate.util.LightSensorManager +import dev.lexip.hecate.util.ProximitySensorManager + +private const val TAG = "ScreenOnReceiver" + +/** + * Adaptive theme switching logic. Executes when the screen is turned on. + * The theme is switched based on the environment brightness and proximity sensor values. + */ +class ScreenOnReceiver( + private val proximitySensorManager: ProximitySensorManager, + private val lightSensorManager: LightSensorManager, + private val darkThemeHandler: DarkThemeHandler, + private val adaptiveThemeThresholdLux: Float +) : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + if (intent.action == Intent.ACTION_SCREEN_ON) { + Log.d(TAG, "Screen turned on, checking adaptive theme conditions...") + + // Check if the device is covered using the proximity sensor + proximitySensorManager.startListening { distance -> + proximitySensorManager.stopListening() + + // If the device is not covered, change the device theme based on the environment + if (distance >= 5f) { + lightSensorManager.startListening { lightValue -> + lightSensorManager.stopListening() + darkThemeHandler.setDarkTheme(lightValue < adaptiveThemeThresholdLux) + } + } else Log.d(TAG, "Device is covered, skipping adaptive theme checks.") + + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/data/UserPreferencesRepository.kt b/app/src/main/java/dev/lexip/hecate/data/UserPreferencesRepository.kt new file mode 100644 index 00000000..12a0265f --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/data/UserPreferencesRepository.kt @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2024 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.data + +import android.util.Log +import androidx.datastore.core.DataStore +import androidx.datastore.core.IOException +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.booleanPreferencesKey +import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.emptyPreferences +import androidx.datastore.preferences.core.floatPreferencesKey +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map + +private const val TAG = "UserPreferencesRepository" + +data class UserPreferences( + val adaptiveThemeEnabled: Boolean, + val adaptiveThemeThresholdLux: Float +) + +class UserPreferencesRepository(private val dataStore: DataStore) { + + private object PreferencesKeys { + val ADAPTIVE_THEME_ENABLED = booleanPreferencesKey("adaptive_theme_enabled") + val ADAPTIVE_THEME_THRESHOLD_LUX = floatPreferencesKey("adaptive_theme_threshold_lux") + } + + val userPreferencesFlow: Flow = dataStore.data + .catch { exception -> + // dataStore.data throws an IOException when an error is encountered when reading data + if (exception is IOException) { + Log.e(TAG, "Error reading user preferences.", exception) + emit(emptyPreferences()) + } else { + throw exception + } + }.map { preferences -> + mapUserPreferences(preferences) + } + + suspend fun fetchInitialPreferences() = + mapUserPreferences(dataStore.data.first().toPreferences()) + + private fun mapUserPreferences(preferences: Preferences): UserPreferences { + // Get our show completed value, defaulting to false if not set: + preferences[PreferencesKeys.ADAPTIVE_THEME_ENABLED] == true + val adaptiveThemeEnabled = preferences[PreferencesKeys.ADAPTIVE_THEME_ENABLED] == true + val adaptiveThemeThresholdLux = + preferences[PreferencesKeys.ADAPTIVE_THEME_THRESHOLD_LUX] ?: 100f + return UserPreferences(adaptiveThemeEnabled, adaptiveThemeThresholdLux) + } + + suspend fun updateAdaptiveThemeEnabled(enabled: Boolean) { + dataStore.edit { preferences -> + preferences[PreferencesKeys.ADAPTIVE_THEME_ENABLED] = enabled + } + } + + suspend fun updateAdaptiveThemeThresholdLux(lux: Float) { + dataStore.edit { preferences -> + preferences[PreferencesKeys.ADAPTIVE_THEME_THRESHOLD_LUX] = lux + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/services/BroadcastReceiverService.kt b/app/src/main/java/dev/lexip/hecate/services/BroadcastReceiverService.kt new file mode 100644 index 00000000..65f96853 --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/services/BroadcastReceiverService.kt @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2024-2025 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.services + +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.app.Service +import android.content.Intent +import android.content.IntentFilter +import android.os.IBinder +import android.provider.Settings +import android.util.Log +import androidx.core.app.NotificationCompat +import dev.lexip.hecate.HecateApplication +import dev.lexip.hecate.R +import dev.lexip.hecate.broadcasts.ScreenOnReceiver +import dev.lexip.hecate.data.UserPreferencesRepository +import dev.lexip.hecate.util.DarkThemeHandler +import dev.lexip.hecate.util.LightSensorManager +import dev.lexip.hecate.util.ProximitySensorManager +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.launch + +private const val TAG = "BroadcastReceiverService" +private const val NOTIFICATION_CHANNEL_ID = "ForegroundServiceChannel" + +private var screenOnReceiver: ScreenOnReceiver? = null + +private val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Main) + +class BroadcastReceiverService : Service() { + + // Utils + private lateinit var darkThemeHandler: DarkThemeHandler + private lateinit var lightSensorManager: LightSensorManager + private lateinit var proximitySensorManager: ProximitySensorManager + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + Log.i(TAG, "Service starting...") + initializeUtils() + + // Load user preferences from data store + val dataStore = (this.applicationContext as HecateApplication).userPreferencesDataStore + applicationScope.launch { + val userPreferencesRepository = UserPreferencesRepository(dataStore) + val userPreferences = userPreferencesRepository.fetchInitialPreferences() + + // Create screen-on receiver if adaptive theme is enabled + if (userPreferences.adaptiveThemeEnabled) { + createScreenOnReceiver(userPreferences.adaptiveThemeThresholdLux) + } + + // Abort service start when there is no receiver to handle + if (screenOnReceiver == null) { + Log.d(TAG, "No receiver to handle, service start aborted.") + stopSelf() + } else { + // Create service notification and channel + createNotificationChannel() + val notification = buildNotification() + + // Start the service in the foreground + startForeground(1, notification) + } + } + + return START_STICKY + } + + override fun onDestroy() { + super.onDestroy() + Log.i(TAG, "Service is being destroyed...") + screenOnReceiver?.let { + Log.d(TAG, "Unregistering screen-on receiver...") + unregisterReceiver(it) + } + } + + override fun onBind(intent: Intent?): IBinder? { + return null + } + + private fun buildNotification(): Notification { + // Intent to the notification settings + val settingsIntent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + .putExtra(Settings.EXTRA_APP_PACKAGE, packageName) + .putExtra(Settings.EXTRA_CHANNEL_ID, NOTIFICATION_CHANNEL_ID) + val pendingIntent = + PendingIntent.getActivity(this, 0, settingsIntent, PendingIntent.FLAG_IMMUTABLE) + + // Create action to disable the notification + val disableAction = NotificationCompat.Action.Builder( + 0, + getString(R.string.action_disable_notification), + pendingIntent + ).build() + + // Build notification + return NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) + .setContentTitle(getString(R.string.notification_service_running)) + .setCategory(Notification.CATEGORY_SERVICE) + .setSmallIcon(R.drawable.ic_launcher_foreground) + .setContentIntent(pendingIntent) + .addAction(disableAction) + .build() + } + + private fun createNotificationChannel() { + val serviceChannel = NotificationChannel( + "ForegroundServiceChannel", + getString(R.string.notification_channel_service), + NotificationManager.IMPORTANCE_DEFAULT, + + ) + val manager = getSystemService(NotificationManager::class.java) + manager?.createNotificationChannel(serviceChannel) + } + + private fun createScreenOnReceiver(adaptiveThemeThresholdLux: Float) { + screenOnReceiver = screenOnReceiver ?: ScreenOnReceiver( + proximitySensorManager, + lightSensorManager, + darkThemeHandler, + adaptiveThemeThresholdLux + ) + Log.d(TAG, "Registering screen-on receiver...") + registerReceiver(screenOnReceiver, IntentFilter(Intent.ACTION_SCREEN_ON)) + } + + private fun initializeUtils() { + if (!this::darkThemeHandler.isInitialized) + darkThemeHandler = DarkThemeHandler(this) + if (!this::lightSensorManager.isInitialized) + lightSensorManager = LightSensorManager(this) + if (!this::proximitySensorManager.isInitialized) + proximitySensorManager = ProximitySensorManager(this) + } + +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/ui/AdaptiveThemeScreen.kt b/app/src/main/java/dev/lexip/hecate/ui/AdaptiveThemeScreen.kt new file mode 100644 index 00000000..1fec2c3d --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/ui/AdaptiveThemeScreen.kt @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2024-2025 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.ui + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.WindowInsetsSides +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.only +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.systemGestures +import androidx.compose.foundation.layout.windowInsetsPadding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.LargeTopAppBar +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.material3.rememberTopAppBarState +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.input.nestedscroll.nestedScroll +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import dev.lexip.hecate.R +import dev.lexip.hecate.ui.components.SwitchPreferenceCard +import dev.lexip.hecate.ui.theme.hecateTopAppBarColors + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun AdaptiveThemeScreen( + uiState: AdaptiveThemeUiState, + updateAdaptiveThemeEnabled: (Boolean) -> Unit +) { + val scrollBehavior = + TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) + val horizontalOffsetPadding = 4.dp + Scaffold( + modifier = Modifier + .nestedScroll(scrollBehavior.nestedScrollConnection), + containerColor = MaterialTheme.colorScheme.surfaceContainer, + topBar = { + LargeTopAppBar( + modifier = Modifier + .padding(horizontal = horizontalOffsetPadding) + .padding(top = 22.dp, bottom = 12.dp), + colors = hecateTopAppBarColors(), + title = { + Text( + text = stringResource(id = R.string.app_name), + style = MaterialTheme.typography.displaySmall + ) + }, + scrollBehavior = scrollBehavior + ) + } + ) { innerPadding -> + Column( + modifier = Modifier + .windowInsetsPadding(WindowInsets.systemGestures.only(WindowInsetsSides.Horizontal)) + .fillMaxSize() + .padding(innerPadding) + .padding(horizontal = horizontalOffsetPadding) + .verticalScroll(rememberScrollState()), + verticalArrangement = Arrangement.spacedBy(32.dp) + + ) { + Text( + text = stringResource(id = R.string.description_adaptive_theme), + style = MaterialTheme.typography.bodyLarge.copy(lineHeight = 22.sp) + ) + SwitchPreferenceCard( + text = stringResource( + id = R.string.action_use_adaptive_theme + ), + isChecked = uiState.adaptiveThemeEnabled, + onCheckedChange = { checked -> updateAdaptiveThemeEnabled(checked) } + + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/ui/AdaptiveThemeViewModel.kt b/app/src/main/java/dev/lexip/hecate/ui/AdaptiveThemeViewModel.kt new file mode 100644 index 00000000..55682ba6 --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/ui/AdaptiveThemeViewModel.kt @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2024-2025 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.ui + +import android.content.Intent +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.viewModelScope +import dev.lexip.hecate.HecateApplication +import dev.lexip.hecate.data.UserPreferencesRepository +import dev.lexip.hecate.services.BroadcastReceiverService +import dev.lexip.hecate.util.DarkThemeHandler +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch + +private const val TAG = "AdaptiveThemeViewModel" + +data class AdaptiveThemeUiState( + val adaptiveThemeEnabled: Boolean = false +) + +class AdaptiveThemeViewModel( + private val application: HecateApplication, + private val userPreferencesRepository: UserPreferencesRepository, + private var darkThemeHandler: DarkThemeHandler +) : ViewModel() { + + private val _uiState = MutableStateFlow(AdaptiveThemeUiState()) + val uiState: StateFlow = _uiState.asStateFlow() + + init { + viewModelScope.launch { + userPreferencesRepository.userPreferencesFlow.collect { userPreferences -> + _uiState.value = AdaptiveThemeUiState( + adaptiveThemeEnabled = userPreferences.adaptiveThemeEnabled + ) + } + } + } + + fun updateAdaptiveThemeEnabled(enable: Boolean) { + // TODO #30: Check for android.permission.WRITE_SECURE_SETTINGS + viewModelScope.launch { + userPreferencesRepository.updateAdaptiveThemeEnabled(enable) + if (enable) startBroadcastReceiverService() else stopBroadcastReceiverService() + updateAdaptiveThemeThresholdLux(500f) + } + } + + private fun startBroadcastReceiverService() { + val intent = Intent(application.applicationContext, BroadcastReceiverService::class.java) + application.applicationContext.startService(intent) + } + + private fun stopBroadcastReceiverService() { + val intent = Intent(application.applicationContext, BroadcastReceiverService::class.java) + application.applicationContext.stopService(intent) + } + + private suspend fun updateAdaptiveThemeThresholdLux(lux: Float) { + userPreferencesRepository.updateAdaptiveThemeThresholdLux(lux) + } + +} + +class AdaptiveThemeViewModelFactory( + private val application: HecateApplication, + private val userPreferencesRepository: UserPreferencesRepository, + private val darkThemeHandler: DarkThemeHandler +) : ViewModelProvider.Factory { + + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(AdaptiveThemeViewModel::class.java)) { + @Suppress("UNCHECKED_CAST") + return AdaptiveThemeViewModel( + application, + userPreferencesRepository, + darkThemeHandler + ) as T + } + throw IllegalArgumentException("Unknown ViewModel class") + } +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/ui/MainActivity.kt b/app/src/main/java/dev/lexip/hecate/ui/MainActivity.kt new file mode 100644 index 00000000..ec6a116d --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/ui/MainActivity.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.ui + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen +import androidx.lifecycle.viewmodel.compose.viewModel +import dev.lexip.hecate.HecateApplication +import dev.lexip.hecate.data.UserPreferencesRepository +import dev.lexip.hecate.ui.theme.HecateTheme +import dev.lexip.hecate.util.DarkThemeHandler + +class MainActivity : ComponentActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + installSplashScreen() + enableEdgeToEdge() + + setContent { + val dataStore = (this.applicationContext as HecateApplication).userPreferencesDataStore + val adaptiveThemeViewModel: AdaptiveThemeViewModel = viewModel( + factory = AdaptiveThemeViewModelFactory( + this.application as HecateApplication, + UserPreferencesRepository(dataStore), + DarkThemeHandler(applicationContext) + ) + ) + val state by adaptiveThemeViewModel.uiState.collectAsState() + HecateTheme { + AdaptiveThemeScreen(state, adaptiveThemeViewModel::updateAdaptiveThemeEnabled) + } + } + + } +} + diff --git a/app/src/main/java/dev/lexip/hecate/ui/components/SwitchPreferenceCard.kt b/app/src/main/java/dev/lexip/hecate/ui/components/SwitchPreferenceCard.kt new file mode 100644 index 00000000..f1d39fdf --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/ui/components/SwitchPreferenceCard.kt @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2024-2025 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.ui.components + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Switch +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + +@Composable +fun SwitchPreferenceCard(text: String, isChecked: Boolean, onCheckedChange: (Boolean) -> Unit) { + val mainSwitchTextSize = (MaterialTheme.typography.titleLarge.fontSize.value - 2).sp + + Card( + modifier = Modifier + .fillMaxWidth(), + shape = MaterialTheme.shapes.extraLarge, + colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer), + onClick = { onCheckedChange(!isChecked) } + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(PaddingValues(16.dp)) + .padding(start = 4.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween + ) { + Text( + style = MaterialTheme.typography.titleLarge, + fontSize = mainSwitchTextSize, + color = MaterialTheme.colorScheme.onPrimaryContainer, + text = text + ) + Switch(checked = isChecked, onCheckedChange = onCheckedChange) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/ui/theme/Color.kt b/app/src/main/java/dev/lexip/hecate/ui/theme/Color.kt deleted file mode 100644 index ef661dcf..00000000 --- a/app/src/main/java/dev/lexip/hecate/ui/theme/Color.kt +++ /dev/null @@ -1,11 +0,0 @@ -package dev.lexip.hecate.ui.theme - -import androidx.compose.ui.graphics.Color - -val Purple80 = Color(0xFFD0BCFF) -val PurpleGrey80 = Color(0xFFCCC2DC) -val Pink80 = Color(0xFFEFB8C8) - -val Purple40 = Color(0xFF6650a4) -val PurpleGrey40 = Color(0xFF625b71) -val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/ui/theme/Theme.kt b/app/src/main/java/dev/lexip/hecate/ui/theme/Theme.kt index fe37e939..a80b1c07 100644 --- a/app/src/main/java/dev/lexip/hecate/ui/theme/Theme.kt +++ b/app/src/main/java/dev/lexip/hecate/ui/theme/Theme.kt @@ -1,58 +1,50 @@ +/* + * Copyright (C) 2024 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + package dev.lexip.hecate.ui.theme -import android.app.Activity -import android.os.Build +import android.content.Context import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.TopAppBarColors +import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme -import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext -private val DarkColorScheme = darkColorScheme( - primary = Purple80, - secondary = PurpleGrey80, - tertiary = Pink80 -) - -private val LightColorScheme = lightColorScheme( - primary = Purple40, - secondary = PurpleGrey40, - tertiary = Pink40 - - /* Other default colors to override - background = Color(0xFFFFFBFE), - surface = Color(0xFFFFFBFE), - onPrimary = Color.White, - onSecondary = Color.White, - onTertiary = Color.White, - onBackground = Color(0xFF1C1B1F), - onSurface = Color(0xFF1C1B1F), - */ -) - @Composable fun HecateTheme( - darkTheme: Boolean = isSystemInDarkTheme(), - // Dynamic color is available on Android 12+ - dynamicColor: Boolean = true, - content: @Composable () -> Unit + darkTheme: Boolean = isSystemInDarkTheme(), + context: Context = LocalContext.current, + content: @Composable () -> Unit ) { - val colorScheme = when { - dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { - val context = LocalContext.current - if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) - } + val colorScheme = + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) - darkTheme -> DarkColorScheme - else -> LightColorScheme - } + MaterialTheme( + colorScheme = colorScheme, + content = content + ) +} - MaterialTheme( - colorScheme = colorScheme, - typography = Typography, - content = content - ) -} \ No newline at end of file +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun hecateTopAppBarColors(): TopAppBarColors = TopAppBarDefaults.largeTopAppBarColors( + // This represents the top app bar style of the android system settings app in Android 15. + containerColor = MaterialTheme.colorScheme.surfaceContainer, + scrolledContainerColor = MaterialTheme.colorScheme.surfaceVariant, + navigationIconContentColor = MaterialTheme.colorScheme.onSurface, + titleContentColor = MaterialTheme.colorScheme.onSurface, + actionIconContentColor = MaterialTheme.colorScheme.onSurface +) \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/ui/theme/Type.kt b/app/src/main/java/dev/lexip/hecate/ui/theme/Type.kt deleted file mode 100644 index 11ef82aa..00000000 --- a/app/src/main/java/dev/lexip/hecate/ui/theme/Type.kt +++ /dev/null @@ -1,34 +0,0 @@ -package dev.lexip.hecate.ui.theme - -import androidx.compose.material3.Typography -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.sp - -// Set of Material typography styles to start with -val Typography = Typography( - bodyLarge = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 16.sp, - lineHeight = 24.sp, - letterSpacing = 0.5.sp - ) - /* Other default text styles to override - titleLarge = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 22.sp, - lineHeight = 28.sp, - letterSpacing = 0.sp - ), - labelSmall = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Medium, - fontSize = 11.sp, - lineHeight = 16.sp, - letterSpacing = 0.5.sp - ) - */ -) \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/util/DarkThemeHandler.kt b/app/src/main/java/dev/lexip/hecate/util/DarkThemeHandler.kt new file mode 100644 index 00000000..dba8b23a --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/util/DarkThemeHandler.kt @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2024-2025 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.util + +import android.app.UiModeManager +import android.content.Context +import android.provider.Settings.Secure +import android.util.Log +import java.lang.ref.WeakReference + +private const val TAG = "DarkThemeHandler" +private const val SECURE_SETTINGS_KEY = "ui_night_mode" + +/** + * Handler for managing the system dark theme. + */ +class DarkThemeHandler(context: Context) { + private val contextRef = WeakReference(context) + private val contentResolver = contextRef.get()?.contentResolver + private val uiModeManager = + contextRef.get()?.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager + + /** + * @return True if the system dark theme is enabled, false otherwise. + */ + fun isDarkThemeEnabled(): Boolean { + val enabled = + Secure.getInt(contentResolver, SECURE_SETTINGS_KEY) == UiModeManager.MODE_NIGHT_YES + Log.d(TAG, "Device dark theme enabled: $enabled") + return enabled + } + + /** + * Set the system dark theme based on the given parameter. + * @param enable True to enable dark theme, false to disable. + * @throws SecurityException if android.permission.WRITE_SECURE_SETTINGS is not granted. + */ + fun setDarkTheme(enable: Boolean) { + val targetMode = if (enable) UiModeManager.MODE_NIGHT_YES else UiModeManager.MODE_NIGHT_NO + + // Only write the setting and update the UI when the setting has actually changed. + if (enable != isDarkThemeEnabled()) { + Log.i(TAG, "Switching dark theme to: $targetMode") + Secure.putInt(contentResolver, SECURE_SETTINGS_KEY, targetMode) + refreshUi() + } + + } + + /** + * Refreshes the Android UI by briefly enabling and disabling car mode. + * While this is not a good practice the is the the only way to ensure + * that the a theme change is applied to the entire system UI. + * @since API 29 (Android 10) + * @see UiModeManager.setNightMode(int) + */ + private fun refreshUi() { + Log.d(TAG, "Refreshing system UI after dark theme change...") + uiModeManager.enableCarMode(0) + uiModeManager.disableCarMode(UiModeManager.DISABLE_CAR_MODE_GO_HOME) + } +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/util/LightSensorManager.kt b/app/src/main/java/dev/lexip/hecate/util/LightSensorManager.kt new file mode 100644 index 00000000..89072d43 --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/util/LightSensorManager.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.util + +import android.content.Context +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager +import android.util.Log + +private const val TAG = "LightSensorManager" + +class LightSensorManager(private val context: Context) : SensorEventListener { + + private val sensorManager: SensorManager = + context.getSystemService(Context.SENSOR_SERVICE) as SensorManager + private val lightSensor: Sensor? = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT) + private lateinit var callback: (Float) -> Unit + + fun startListening(callback: (Float) -> Unit) { + this.callback = callback + lightSensor?.let { + sensorManager.registerListener(this, it, SensorManager.SENSOR_DELAY_NORMAL) + } + } + + fun stopListening() { + sensorManager.unregisterListener(this) + } + + override fun onSensorChanged(event: SensorEvent) { + val lightValue = event.values[0] + this.callback.invoke(lightValue) + Log.d(TAG, "Light sensor value: $lightValue lx") + } + + override fun onAccuracyChanged(p0: Sensor?, p1: Int) { + return + } + +} \ No newline at end of file diff --git a/app/src/main/java/dev/lexip/hecate/util/ProximitySensorManager.kt b/app/src/main/java/dev/lexip/hecate/util/ProximitySensorManager.kt new file mode 100644 index 00000000..b569f0d1 --- /dev/null +++ b/app/src/main/java/dev/lexip/hecate/util/ProximitySensorManager.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024 xLexip + * + * Licensed under the GNU General Public License, Version 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0 + * + * Please see the License for specific terms regarding permissions and limitations. + */ + +package dev.lexip.hecate.util + +import android.content.Context +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager +import android.util.Log + +private const val TAG = "ProximitySensorManager" + +class ProximitySensorManager(private val context: Context) : SensorEventListener { + + private val sensorManager: SensorManager = + context.getSystemService(Context.SENSOR_SERVICE) as SensorManager + private val proximitySensor: Sensor? = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) + private lateinit var callback: (Float) -> Unit + + fun startListening(callback: (Float) -> Unit) { + this.callback = callback + proximitySensor?.let { + sensorManager.registerListener(this, it, SensorManager.SENSOR_DELAY_NORMAL) + } + } + + fun stopListening() { + sensorManager.unregisterListener(this) + } + + override fun onSensorChanged(event: SensorEvent) { + val distance = event.values[0] + this.callback.invoke(distance) + Log.d(TAG, "Proximity sensor distance: $distance cm") + } + + override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) { + return + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml index 07d5da9c..47be326c 100644 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -1,170 +1,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:width="1dp" + android:height="1dp" + android:viewportWidth="1" + android:viewportHeight="1"> + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml index 2b068d11..42504142 100644 --- a/app/src/main/res/drawable/ic_launcher_foreground.xml +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -1,30 +1,16 @@ - - - - - - - - - - \ No newline at end of file + android:width="108dp" + android:height="108dp" + android:tint="#C2C6D6" + android:viewportWidth="24" + android:viewportHeight="24"> + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..52ac0698 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 00000000..52ac0698 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml deleted file mode 100644 index 6f3b755b..00000000 --- a/app/src/main/res/mipmap-anydpi/ic_launcher.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml deleted file mode 100644 index 6f3b755b..00000000 --- a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp index c209e78e..f3b07686 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.webp and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp index b2dfe3d1..451a6f2b 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp index 4f0f1d64..52d37005 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.webp and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp index 62b611da..f95c47a5 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp index 948a3070..194f6563 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp index 1b9a6956..b4ca1bb0 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp index 28d4b77f..db64c280 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp index 9287f508..95e20fc1 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp index aa7d6427..890a2e5e 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp index 9126ae37..8939e36d 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml deleted file mode 100644 index f8c6127d..00000000 --- a/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - #FFBB86FC - #FF6200EE - #FF3700B3 - #FF03DAC5 - #FF018786 - #FF000000 - #FFFFFFFF - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6d25358d..d66de974 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,8 @@ - Hecate + Adaptive theme + Disable notification + Use adaptive theme + Adaptive Theme automatically adjusts the device theme based on ambient brightness. It enhances visibility in bright conditions while optimizing battery life. + Background Activity + Adaptive theme is active \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 67eab607..0bdbd65e 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,5 +1,13 @@ - + \ No newline at end of file diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml index fa0f996d..3313dd6b 100644 --- a/app/src/main/res/xml/backup_rules.xml +++ b/app/src/main/res/xml/backup_rules.xml @@ -6,7 +6,7 @@ See https://developer.android.com/about/versions/12/backup-restore --> - diff --git a/app/src/main/res/xml/data_extraction_rules.xml b/app/src/main/res/xml/data_extraction_rules.xml index 9ee9997b..fe10fbfa 100644 --- a/app/src/main/res/xml/data_extraction_rules.xml +++ b/app/src/main/res/xml/data_extraction_rules.xml @@ -4,16 +4,16 @@ for details. --> - - - - + + + + \ No newline at end of file diff --git a/app/src/test/java/dev/lexip/hecate/ExampleUnitTest.kt b/app/src/test/java/dev/lexip/hecate/ExampleUnitTest.kt index d638c867..0f573589 100644 --- a/app/src/test/java/dev/lexip/hecate/ExampleUnitTest.kt +++ b/app/src/test/java/dev/lexip/hecate/ExampleUnitTest.kt @@ -1,8 +1,7 @@ package dev.lexip.hecate -import org.junit.Test - import org.junit.Assert.* +import org.junit.Test /** * Example local unit test, which will execute on the development machine (host). @@ -10,8 +9,8 @@ import org.junit.Assert.* * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } } \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 9a3663af..17166eda 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,17 +1,17 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - alias(libs.plugins.android.application) apply false - alias(libs.plugins.kotlin.android) apply false - alias(libs.plugins.kotlin.compose) apply false - id("org.sonarqube") version "5.1.0.4882" + alias(libs.plugins.android.application) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.kotlin.compose) apply false + id("org.sonarqube") version "6.1.0.5360" } sonar { - properties { - property("sonar.projectKey", "xLexip_Hecate") - property("sonar.projectVersion", "1.0.0") - property("sonar.organization", "xlexip") - property("sonar.host.url", "https://sonarcloud.io") - property("sonar.androidLint.reportPaths", "app/build/reports/lint-results-debug.html") - } + properties { + property("sonar.projectKey", "xLexip_Hecate") + property("sonar.projectVersion", "1.0.0") + property("sonar.organization", "xlexip") + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.androidLint.reportPaths", "app/build/reports/lint-results-debug.html") + } } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1b21b23e..b57eb2cd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,32 +1,45 @@ [versions] -agp = "8.7.1" -kotlin = "2.0.20" -coreKtx = "1.13.1" +activityCompose = "1.10.1" +agp = "8.9.2" +appcompat = "1.7.0" +composeBom = "2025.04.01" +coreKtx = "1.16.0" +coreSplashscreenVersion = "1.0.1" +datastorePreferencesCore = "1.1.4" +espressoCore = "3.6.1" junit = "4.13.2" junitVersion = "1.2.1" -espressoCore = "3.6.1" -lifecycleRuntimeKtx = "2.8.6" -activityCompose = "1.9.3" -composeBom = "2024.10.00" +kotlin = "2.1.20" +lifecycleRuntimeKtx = "2.8.7" +lifecycleViewmodelCompose = "2.8.7" +localbroadcastmanager = "1.1.0" +material = "1.12.0" +preference = "1.2.1" [libraries] +androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } -junit = { group = "junit", name = "junit", version.ref = "junit" } -androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } +androidx-core-splashscreen-v100 = { module = "androidx.core:core-splashscreen", version.ref = "coreSplashscreenVersion" } +androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastorePreferencesCore" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } +androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } -androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } -androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } +androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" } +androidx-localbroadcastmanager = { module = "androidx.localbroadcastmanager:localbroadcastmanager", version.ref = "localbroadcastmanager" } +androidx-material3 = { group = "androidx.compose.material3", name = "material3" } +androidx-preference = { group = "androidx.preference", name = "preference", version.ref = "preference" } androidx-ui = { group = "androidx.compose.ui", name = "ui" } androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } +androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } +androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest", version = "1.8.0" } androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } -androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } -androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } -androidx-material3 = { group = "androidx.compose.material3", name = "material3" } +junit = { group = "junit", name = "junit", version.ref = "junit" } +material = { group = "com.google.android.material", name = "material", version.ref = "material" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } - diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c0..1b33c55b 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b9bd6a44..ca025c83 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Sun Oct 27 20:10:08 CET 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c..23d15a93 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,81 +15,115 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +132,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index ac1b06f9..5eed7ee8 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,32 +59,34 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/renovate.json b/renovate.json index 2b15d985..ef1b19c2 100644 --- a/renovate.json +++ b/renovate.json @@ -1,9 +1,28 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ - "config:recommended", - ":semanticCommits" + "config:recommended", + ":semanticCommits" ], - "baseBranches": ["develop"], - "dependencyDashboard": true + "baseBranches": [ + "develop" + ], + "dependencyDashboard": true, + "packageRules": [ + { + "groupName": "Patched Dependencies", + "groupSlug": "patch-updates", + "matchUpdateTypes": [ + "patch" + ] + }, + { + "commitMessageAction": "Apply", + "groupName": "Minor Dependency Updates", + "groupSlug": "minor-updates", + "matchUpdateTypes": [ + "minor" + ] + } + ] } diff --git a/settings.gradle.kts b/settings.gradle.kts index 6863a4cf..65bbffc4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,24 +1,23 @@ pluginManagement { - repositories { - google { - content { - includeGroupByRegex("com\\.android.*") - includeGroupByRegex("com\\.google.*") - includeGroupByRegex("androidx.*") - } - } - mavenCentral() - gradlePluginPortal() - } + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } } dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - } + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } } rootProject.name = "Hecate" -include(":app") - \ No newline at end of file +include(":app") \ No newline at end of file