Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">

<uses-permission
android:name="android.permission.CAMERA"
android:maxSdkVersion="23" />

<uses-permission android:name="android.permission.FLASHLIGHT" />

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package com.simplemobiletools.flashlight.activities

import android.Manifest
import android.annotation.SuppressLint
import android.app.AlarmManager
import android.app.Application
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.content.pm.ShortcutInfo
import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.ManagedActivityResultLauncher
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.runtime.*
import androidx.compose.ui.res.stringResource
import androidx.core.content.ContextCompat
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewModelScope
import com.google.android.material.math.MathUtils
Expand Down Expand Up @@ -64,15 +57,6 @@ class MainActivity : ComponentActivity() {
setContent {
AppThemeSurface {
val showMoreApps = onEventValue { !resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations) }
val sosPermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission(),
onResult = getPermissionResultHandler(true)
)
val stroboscopePermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission(),
onResult = getPermissionResultHandler(false)
)

val sleepTimerCustomDialogState = getSleepTimerCustomDialogState()
val sleepTimerDialogState = getSleepTimerDialogState(showCustomSleepTimerDialog = sleepTimerCustomDialogState::show)
val sleepTimerPermissionDialogState = getSleepTimerPermissionDialogState(showSleepTimerDialog = sleepTimerDialogState::show)
Expand Down Expand Up @@ -104,7 +88,7 @@ class MainActivity : ComponentActivity() {
SosButton(
sosActive = sosActive,
onSosButtonPress = {
toggleStroboscope(true, sosPermissionLauncher)
toggleStroboscope(true)
},
)
}
Expand All @@ -117,7 +101,7 @@ class MainActivity : ComponentActivity() {
StroboscopeButton(
stroboscopeActive = stroboscopeActive,
onStroboscopeButtonPress = {
toggleStroboscope(false, stroboscopePermissionLauncher)
toggleStroboscope(false)
},
)
}
Expand Down Expand Up @@ -315,29 +299,7 @@ class MainActivity : ComponentActivity() {
startAboutActivity(R.string.app_name, 0, BuildConfig.VERSION_NAME, faqItems, true)
}

private fun toggleStroboscope(isSOS: Boolean, launcher: ManagedActivityResultLauncher<String, Boolean>) {
// use the old Camera API for stroboscope, the new Camera Manager is way too slow
if (isNougatPlus()) {
cameraPermissionGranted(isSOS)
} else {
val permission = Manifest.permission.CAMERA
if (ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED) {
cameraPermissionGranted(isSOS)
} else {
launcher.launch(permission)
}
}
}

private fun getPermissionResultHandler(isSos: Boolean): (Boolean) -> Unit = { granted ->
if (granted) {
cameraPermissionGranted(isSos)
} else {
toast(R.string.camera_permission)
}
}

private fun cameraPermissionGranted(isSOS: Boolean) {
private fun toggleStroboscope(isSOS: Boolean) {
if (isSOS) {
viewModel.enableSos()
} else {
Expand Down Expand Up @@ -393,7 +355,7 @@ class MainActivity : ComponentActivity() {
@SuppressLint("NewApi")
private fun checkShortcuts() {
val appIconColor = preferences.appIconColor
if (isNougatMR1Plus() && preferences.lastHandledShortcutColor != appIconColor) {
if (preferences.lastHandledShortcutColor != appIconColor) {
val createNewContact = getBrightDisplayShortcut(appIconColor)

try {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gradlePlugins-agp = "8.6.1"
#build
app-build-compileSDKVersion = "34"
app-build-targetSDK = "34"
app-build-minimumSDK = "23"
app-build-minimumSDK = "26"
app-build-javaVersion = "VERSION_17"
app-build-kotlinJVMTarget = "17"
#versioning
Expand Down
Loading