Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Jetpack Compose navigation + New Homescreen UI + Amoled Theme #160

Merged
merged 7 commits into from
Jul 16, 2023
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
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ dependencies {
implementation 'androidx.compose.material3:material3:1.1.1'
implementation 'androidx.compose.material:material-icons-extended:1.4.3'

//Navigation
implementation 'androidx.navigation:navigation-compose:2.6.0'

// Testing
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/bnyro/recorder/enums/ThemeMode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.bnyro.recorder.util.Preferences
enum class ThemeMode {
SYSTEM,
LIGHT,
DARK;
DARK,
AMOLED,
;

companion object {
fun getCurrent() = valueOf(Preferences.getString(Preferences.themeModeKey, SYSTEM.name))
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/bnyro/recorder/ui/Destination.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bnyro.recorder.ui

sealed class Destination(val route: String) {
object Home : Destination("home")
object Settings : Destination("settings")
object RecordingPlayer : Destination("player")
}
27 changes: 17 additions & 10 deletions app/src/main/java/com/bnyro/recorder/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ package com.bnyro.recorder.ui
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
import androidx.navigation.compose.rememberNavController
import com.bnyro.recorder.enums.RecorderType
import com.bnyro.recorder.enums.ThemeMode
import com.bnyro.recorder.ui.models.ThemeModel
import com.bnyro.recorder.ui.screens.RecorderView
import com.bnyro.recorder.ui.theme.RecordYouTheme

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

val themeModel: ThemeModel = ViewModelProvider(this).get()
val themeModel: ThemeModel by viewModels()

val initialRecorder = when (intent?.getStringExtra("action")) {
"audio" -> RecorderType.AUDIO
Expand All @@ -30,16 +29,24 @@ class MainActivity : ComponentActivity() {

setContent {
RecordYouTheme(
when (val mode = themeModel.themeMode) {
when (themeModel.themeMode) {
ThemeMode.SYSTEM -> isSystemInDarkTheme()
else -> mode == ThemeMode.DARK
}
ThemeMode.DARK -> true
else -> false
},
amoledDark = themeModel.themeMode == ThemeMode.AMOLED,
) {
val navController = rememberNavController()
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
modifier = Modifier
.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
RecorderView(initialRecorder)
AppNavHost(
navController = navController,
modifier = Modifier,
initialRecorder = initialRecorder,
)
}
}
}
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/com/bnyro/recorder/ui/NavHost.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.bnyro.recorder.ui

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.bnyro.recorder.enums.RecorderType
import com.bnyro.recorder.ui.screens.HomeScreen
import com.bnyro.recorder.ui.screens.PlayerScreen
import com.bnyro.recorder.ui.screens.SettingsScreen

@Composable
fun AppNavHost(
navController: NavHostController,
modifier: Modifier = Modifier,
initialRecorder: RecorderType,
) {
NavHost(
navController = navController,
startDestination = Destination.Home.route,
modifier = modifier,
) {
composable(route = Destination.Home.route) {
HomeScreen(initialRecorder, onNavigate = { destination ->
navController.navigateTo(destination.route)
})
}

composable(route = Destination.Settings.route) {
SettingsScreen()
}

composable(route = Destination.RecordingPlayer.route) {
PlayerScreen(showVideoModeInitially = false)
}
}
}

fun NavHostController.navigateTo(route: String) = this.navigate(route) {
launchSingleTop = true
restoreState = true
}
39 changes: 39 additions & 0 deletions app/src/main/java/com/bnyro/recorder/ui/common/BlobIconBox.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.bnyro.recorder.ui.common

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.bnyro.recorder.R

@Composable
fun BlobIconBox(@DrawableRes icon: Int) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxSize()
.alpha(0.3f)
) {
Image(
modifier = Modifier.size(350.dp),
painter = painterResource(id = R.drawable.blob),
contentDescription = null,
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.secondaryContainer)
)
Image(
modifier = Modifier.size(250.dp),
painter = painterResource(id = icon),
contentDescription = null,
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSecondaryContainer)
)
}
}
Loading
Loading