Skip to content

Commit

Permalink
Quick fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesPvx committed May 28, 2024
1 parent 675b02c commit dbdf446
Show file tree
Hide file tree
Showing 46 changed files with 3,750 additions and 3,750 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import org.junit.runner.RunWith
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("fr.angel.soundtap", appContext.packageName)
}
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("fr.angel.soundtap", appContext.packageName)
}
}
64 changes: 32 additions & 32 deletions app/src/main/java/fr/angel/soundtap/ColorExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ package fr.angel.soundtap
import androidx.compose.ui.graphics.Color

fun Color.hue(): Float {
val r = red / 255.0
val g = green / 255.0
val b = blue / 255.0
val max = maxOf(r, g, b)
val min = minOf(r, g, b)
val c = max - min
var hue: Double = 0.0
if (c == 0.0) {
hue = 0.0
} else {
when (max) {
r -> {
val segment = (g - b) / c
var shift = 0.0 / 60.0 // R° / (360° / hex sides)
if (segment < 0.0) { // hue > 180, full rotation
shift = 360.0 / 60.0 // R° / (360° / hex sides)
}
hue = segment + shift
}
val r = red / 255.0
val g = green / 255.0
val b = blue / 255.0
val max = maxOf(r, g, b)
val min = minOf(r, g, b)
val c = max - min
var hue: Double = 0.0
if (c == 0.0) {
hue = 0.0
} else {
when (max) {
r -> {
val segment = (g - b) / c
var shift = 0.0 / 60.0 // R° / (360° / hex sides)
if (segment < 0.0) { // hue > 180, full rotation
shift = 360.0 / 60.0 // R° / (360° / hex sides)
}
hue = segment + shift
}

g -> {
val segment = (b - r) / c
val shift = 120.0 / 60.0 // G° / (360° / hex sides)
hue = segment + shift
}
g -> {
val segment = (b - r) / c
val shift = 120.0 / 60.0 // G° / (360° / hex sides)
hue = segment + shift
}

b -> {
val segment = (r - g) / c
val shift = 240.0 / 60.0 // B° / (360° / hex sides)
hue = segment + shift
}
}
}
return (hue * 60.0).toFloat() // hue is in [0,6], scale it up
b -> {
val segment = (r - g) / c
val shift = 240.0 / 60.0 // B° / (360° / hex sides)
hue = segment + shift
}
}
}
return (hue * 60.0).toFloat() // hue is in [0,6], scale it up
}
80 changes: 40 additions & 40 deletions app/src/main/java/fr/angel/soundtap/GlobalHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,54 @@ import android.provider.Settings
import android.view.KeyEvent

val supportedStartMediaPlayerPackages = listOf(
"com.spotify.music"
"com.spotify.music"
)

object GlobalHelper {

const val PRIVACY_POLICY_URL =
"https://github.com/Angel-Studio/SoundTap/blob/master/PRIVACY-POLICY.MD"
const val TERMS_OF_SERVICE_URL =
"https://github.com/Angel-Studio/SoundTap/blob/master/TERMS-CONDITIONS.MD"
const val PRIVACY_POLICY_URL =
"https://github.com/Angel-Studio/SoundTap/blob/master/PRIVACY-POLICY.MD"
const val TERMS_OF_SERVICE_URL =
"https://github.com/Angel-Studio/SoundTap/blob/master/TERMS-CONDITIONS.MD"

fun openAccessibilitySettings(context: Context) {
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
fun openAccessibilitySettings(context: Context) {
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}

fun openNotificationListenerSettings(context: Context) {
val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
context.startActivity(intent)
}
fun openNotificationListenerSettings(context: Context) {
val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
context.startActivity(intent)
}

fun hasNotificationListenerPermission(context: Context): Boolean {
val contentResolver = context.contentResolver
val enabledNotificationListeners =
Settings.Secure.getString(contentResolver, "enabled_notification_listeners")
val packageName = context.packageName
return enabledNotificationListeners != null && enabledNotificationListeners.contains(
packageName
)
}
fun hasNotificationListenerPermission(context: Context): Boolean {
val contentResolver = context.contentResolver
val enabledNotificationListeners =
Settings.Secure.getString(contentResolver, "enabled_notification_listeners")
val packageName = context.packageName
return enabledNotificationListeners != null && enabledNotificationListeners.contains(
packageName
)
}

fun requestBatteryOptimization(context: Context) {
val batteryOptimizationIntent = Intent().apply {
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
data = Uri.parse("package:${context.packageName}")
}
fun requestBatteryOptimization(context: Context) {
val batteryOptimizationIntent = Intent().apply {
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
data = Uri.parse("package:${context.packageName}")
}

context.startActivity(batteryOptimizationIntent)
}
context.startActivity(batteryOptimizationIntent)
}

fun startMediaPlayer(context: Context, packageName: String) {
val startMediaPlayer = Intent(Intent.ACTION_MEDIA_BUTTON).apply {
putExtra(
Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY)
)
`package` = packageName
}
context.sendOrderedBroadcast(startMediaPlayer, null)
}
fun startMediaPlayer(context: Context, packageName: String) {
val startMediaPlayer = Intent(Intent.ACTION_MEDIA_BUTTON).apply {
putExtra(
Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY)
)
`package` = packageName
}
context.sendOrderedBroadcast(startMediaPlayer, null)
}
}
176 changes: 88 additions & 88 deletions app/src/main/java/fr/angel/soundtap/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,102 +67,102 @@ import fr.angel.soundtap.ui.theme.SoundTapTheme
class MainActivity : ComponentActivity() {


private lateinit var mainViewModel: MainViewModel
private var shouldKeepSplashScreenOn = mutableStateOf(true)
private lateinit var mainViewModel: MainViewModel
private var shouldKeepSplashScreenOn = mutableStateOf(true)

@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
installSplashScreen()
.setKeepOnScreenCondition { shouldKeepSplashScreenOn.value }
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
installSplashScreen()
.setKeepOnScreenCondition { shouldKeepSplashScreenOn.value }

setContent {
mainViewModel = hiltViewModel<MainViewModel>()
val uiState by mainViewModel.uiState.collectAsStateWithLifecycle()
setContent {
mainViewModel = hiltViewModel<MainViewModel>()
val uiState by mainViewModel.uiState.collectAsStateWithLifecycle()

LaunchedEffect(key1 = Unit) {
mainViewModel.updatePermissionStates(this@MainActivity)
}
LaunchedEffect(key1 = Unit) {
mainViewModel.updatePermissionStates(this@MainActivity)
}

val navController = rememberNavController()
val currentBackStack by navController.currentBackStackEntryAsState()
val currentDestination = currentBackStack?.destination
val currentScreen: Screens =
Screens.fromRoute(currentDestination?.route ?: uiState.defaultScreen.route)
val navController = rememberNavController()
val currentBackStack by navController.currentBackStackEntryAsState()
val currentDestination = currentBackStack?.destination
val currentScreen: Screens =
Screens.fromRoute(currentDestination?.route ?: uiState.defaultScreen.route)

val serviceUiState by SoundTapAccessibilityService.uiState.collectAsState()
val serviceUiState by SoundTapAccessibilityService.uiState.collectAsState()

LaunchedEffect(key1 = uiState.finishedInitializations) {
shouldKeepSplashScreenOn.value = !uiState.finishedInitializations
}
LaunchedEffect(key1 = uiState.finishedInitializations) {
shouldKeepSplashScreenOn.value = !uiState.finishedInitializations
}

LaunchedEffect(key1 = Unit) {
mainViewModel.updatePermissionStates(this@MainActivity)
}
LaunchedEffect(key1 = Unit) {
mainViewModel.updatePermissionStates(this@MainActivity)
}

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())

SoundTapTheme {
Scaffold(
modifier = Modifier
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
CenterAlignedTopAppBar(
navigationIcon = {
AnimatedVisibility(
visible = currentScreen.showBackArrow,
enter = scaleIn(),
exit = scaleOut()
) {
IconButton(onClick = { navController.popBackStack() }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Back"
)
}
}
},
title = {
Text(
modifier = Modifier.padding(
horizontal = 16.dp,
vertical = 8.dp
),
text = "SoundTap",
style = MaterialTheme.typography.displayMedium,
fontFamily = FontPilowlava,
fontWeight = FontWeight.ExtraBold
)
}
)
},
bottomBar = {
AnimatedVisibility(
visible = currentScreen == Screens.App.Home,
enter = slideInVertically { it } + expandVertically() + fadeIn(),
exit = slideOutVertically { it } + shrinkVertically() + fadeOut()
) {
BottomControlBar(
serviceUiState = serviceUiState
)
}
}
) { innerPadding ->
SoundTapNavGraph(
modifier = Modifier.padding(innerPadding),
navController = navController,
)
}
}
}
}
SoundTapTheme {
Scaffold(
modifier = Modifier
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
CenterAlignedTopAppBar(
navigationIcon = {
AnimatedVisibility(
visible = currentScreen.showBackArrow,
enter = scaleIn(),
exit = scaleOut()
) {
IconButton(onClick = { navController.popBackStack() }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Back"
)
}
}
},
title = {
Text(
modifier = Modifier.padding(
horizontal = 16.dp,
vertical = 8.dp
),
text = "SoundTap",
style = MaterialTheme.typography.displayMedium,
fontFamily = FontPilowlava,
fontWeight = FontWeight.ExtraBold
)
}
)
},
bottomBar = {
AnimatedVisibility(
visible = currentScreen == Screens.App.Home,
enter = slideInVertically { it } + expandVertically() + fadeIn(),
exit = slideOutVertically { it } + shrinkVertically() + fadeOut()
) {
BottomControlBar(
serviceUiState = serviceUiState
)
}
}
) { innerPadding ->
SoundTapNavGraph(
modifier = Modifier.padding(innerPadding),
navController = navController,
)
}
}
}
}

override fun onResume() {
if (::mainViewModel.isInitialized) {
mainViewModel.updatePermissionStates(this)
}
super.onResume()
}
override fun onResume() {
if (::mainViewModel.isInitialized) {
mainViewModel.updatePermissionStates(this)
}
super.onResume()
}
}
Loading

0 comments on commit dbdf446

Please sign in to comment.