Skip to content

Commit

Permalink
v3.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sosauce committed Oct 13, 2024
1 parent 77fd18c commit 25465af
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = "com.sosauce.cutecalc"
minSdk = 21
targetSdk = 35
versionCode = 33
versionName = "3.2.1"
versionCode = 34
versionName = "3.2.2"
}

buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
android:theme="@style/Theme.CuteSplash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_CALCULATOR" />
</intent-filter>
</activity>
</application>
Expand Down
17 changes: 5 additions & 12 deletions app/src/main/java/com/sosauce/cutecalc/AppBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

package com.sosauce.cutecalc

import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -40,28 +40,20 @@ import com.sosauce.cutecalc.logic.navigation.Screens
import com.sosauce.cutecalc.logic.rememberSortHistoryASC
import com.sosauce.cutecalc.ui.theme.GlobalFont

@SuppressLint("SuspiciousIndentation")
@Composable
fun AppBar(
title: String? = null,
title: @Composable () -> Unit,
showBackArrow: Boolean,
showSortButton: Boolean = false,
onNavigateUp: () -> Unit,
onNavigate: (Screens) -> Unit
onNavigate: (Screens) -> Unit,
) {
var dropDownExpanded by remember { mutableStateOf(false) }
var sortASC by rememberSortHistoryASC()


TopAppBar(
title = {
title?.let {
Text(
text = it,
fontFamily = GlobalFont
)
}
},
title = { title() },
navigationIcon = {
if (showBackArrow) {
IconButton(onClick = onNavigateUp) {
Expand All @@ -75,6 +67,7 @@ fun AppBar(
colors = TopAppBarDefaults.largeTopAppBarColors(Color.Transparent),
actions = {
if (!showBackArrow) {
Spacer(Modifier.width(5.dp))
IconButton(onClick = { onNavigate(Screens.History) }) {
Icon(
imageVector = Icons.Rounded.History,
Expand Down
49 changes: 34 additions & 15 deletions app/src/main/java/com/sosauce/cutecalc/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,51 +1,70 @@
package com.sosauce.cutecalc

import android.annotation.SuppressLint
import android.content.IntentFilter
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.ui.Modifier
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.sosauce.cutecalc.ecosys.CuteMusicReceiver
import com.sosauce.cutecalc.ecosys.EcosystemViewModel
import com.sosauce.cutecalc.logic.navigation.Nav
import com.sosauce.cutecalc.ui.theme.CuteCalcTheme
import org.koin.androidx.viewmodel.ext.android.viewModel

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
class MainActivity : ComponentActivity() {

//private val cm_receiver = CuteMusicReceiver()

private val ecosystemViewModel by viewModels<EcosystemViewModel>()
private val cmReceiver = CuteMusicReceiver(
action = {
if (it.isEmpty()) {
ecosystemViewModel.currentlyPlaying = null
} else {
ecosystemViewModel.currentlyPlaying = it
}
}
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(
cmReceiver,
IntentFilter("CM_CUR_PLAY_CHANGED"),
RECEIVER_EXPORTED
)
}

installSplashScreen()
enableEdgeToEdge()
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// registerReceiver(
// cm_receiver,
// IntentFilter("CM"), RECEIVER_NOT_EXPORTED
// )
// }
setContent {
CuteCalcTheme {
Scaffold(
modifier = Modifier.fillMaxSize()
) {
) { _ ->
MaterialTheme(
content = {
Nav()
Nav(
ecosystemViewModel
)
}
)
}
}
}
}

// override fun onDestroy() {
// super.onDestroy()
// unregisterReceiver(cm_receiver)
// }
override fun onDestroy() {
super.onDestroy()
unregisterReceiver(cmReceiver)
}
}
17 changes: 13 additions & 4 deletions app/src/main/java/com/sosauce/cutecalc/ecosys/CuteMusicReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class CuteMusicReceiver : BroadcastReceiver() {
class CuteMusicReceiver(
private val action: (String) -> Unit
) : BroadcastReceiver() {

companion object {
private const val CURRENTLY_PLAYING_CHANGED = "CM_CUR_PLAY_CHANGED"
}

override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == "CM") {
//val curplay = intent.getStringExtra("now_playing")
println("notcool")
if (intent?.action == CURRENTLY_PLAYING_CHANGED) {

val data = intent.getStringExtra("currentlyPlaying")

data?.let { action(it) }

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sosauce.cutecalc.ecosys

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel

class EcosystemViewModel: ViewModel() {

var currentlyPlaying by mutableStateOf<String?>(null)

// inner class CuteMusic {
// var currentlyPlaying by mutableStateOf<String?>(null)
// }


}
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
package com.sosauce.cutecalc.logic.navigation

import android.content.Intent
import androidx.compose.foundation.background
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.sosauce.cutecalc.ecosys.EcosystemViewModel
import com.sosauce.cutecalc.history.HistoryViewModel
import com.sosauce.cutecalc.logic.CalcViewModel
import com.sosauce.cutecalc.screens.CalculatorUI
import com.sosauce.cutecalc.screens.HistoryScreen
import com.sosauce.cutecalc.screens.SettingsScreen
import com.sosauce.cutecalc.ui.theme.GlobalFont
import com.sosauce.cutecalc.utils.CUTE_MUSIC
import org.koin.androidx.compose.koinViewModel

@Composable
fun Nav() {
fun Nav(
ecosystemViewModel: EcosystemViewModel
) {
val navController = rememberNavController()
val historyViewModel = koinViewModel<HistoryViewModel>()
val historyState by historyViewModel.state.collectAsStateWithLifecycle()
val context = LocalContext.current

NavHost(
navController = navController,
Expand All @@ -31,7 +50,32 @@ fun Nav() {
historyViewModel = historyViewModel,
historyState = historyState,
onNavigateUp = navController::navigateUp,
onNavigate = { navController.navigate(it) }
onNavigate = { navController.navigate(it) },
cmSongTitle = {
if (ecosystemViewModel.currentlyPlaying != null) {
Box(
modifier = Modifier
.clip(RoundedCornerShape(11.dp))
.background(MaterialTheme.colorScheme.surfaceContainer)
.clickable {
Intent(Intent.ACTION_MAIN).also {
it.`package` = CUTE_MUSIC
it.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
context.startActivity(it)
}
}
) {
Text(
text = ecosystemViewModel.currentlyPlaying!!,
fontFamily = GlobalFont,
maxLines = 1,
modifier = Modifier
.padding(5.dp)
.basicMarquee()
)
}
}
}
)
}
composable<Screens.Settings> {
Expand All @@ -45,7 +89,7 @@ fun Nav() {
state = historyState,
onEvents = historyViewModel::onEvent,
onNavigateUp = navController::navigateUp,
onNavigate = { navController.navigate(it) }
onNavigate = { navController.navigate(it) },
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/sosauce/cutecalc/screens/Calculator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.sosauce.cutecalc.AppBar
import com.sosauce.cutecalc.R
import com.sosauce.cutecalc.components.CuteButton
import com.sosauce.cutecalc.components.CuteIconButton
import com.sosauce.cutecalc.ecosys.EcosystemViewModel
import com.sosauce.cutecalc.history.HistoryEvents
import com.sosauce.cutecalc.history.HistoryState
import com.sosauce.cutecalc.history.HistoryViewModel
Expand All @@ -71,7 +72,8 @@ fun CalculatorUI(
historyViewModel: HistoryViewModel,
historyState: HistoryState,
onNavigateUp: () -> Unit,
onNavigate: (Screens) -> Unit
onNavigate: (Screens) -> Unit,
cmSongTitle: @Composable () -> Unit
) {
val config = LocalConfiguration.current
val portraitMode by remember { mutableIntStateOf(config.orientation) }
Expand Down Expand Up @@ -99,7 +101,8 @@ fun CalculatorUI(
AppBar(
showBackArrow = false,
onNavigate = onNavigate,
onNavigateUp = onNavigateUp
onNavigateUp = onNavigateUp,
title = cmSongTitle
)
}
) { _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ fun HistoryScreen(
topBar = {
AppBar(
showBackArrow = true,
title = "History",
showSortButton = true,
onNavigate = onNavigate,
onNavigateUp = onNavigateUp
onNavigateUp = onNavigateUp,
title = {
Text(
text = "History",
fontFamily = GlobalFont
)
}
)
},
floatingActionButton = {
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/sosauce/cutecalc/screens/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Column
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.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -13,6 +14,7 @@ import com.sosauce.cutecalc.components.History
import com.sosauce.cutecalc.components.Misc
import com.sosauce.cutecalc.components.ThemeManagement
import com.sosauce.cutecalc.logic.navigation.Screens
import com.sosauce.cutecalc.ui.theme.GlobalFont

@Composable
fun SettingsScreen(
Expand All @@ -23,10 +25,15 @@ fun SettingsScreen(
Scaffold(
topBar = {
AppBar(
title = "Settings",
showBackArrow = true,
onNavigateUp = onNavigateUp,
onNavigate = onNavigate
onNavigate = onNavigate,
title = {
Text(
text = "Settings",
fontFamily = GlobalFont
)
}
)
},
) { values ->
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/sosauce/cutecalc/utils/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.sosauce.cutecalc.utils

const val CUTE_MUSIC = "com.sosauce.cutemusic"

0 comments on commit 25465af

Please sign in to comment.