Skip to content

Commit

Permalink
Merge pull request #48 from Javernaut/modularization/settings
Browse files Browse the repository at this point in the history
Modularization. Settings UI
  • Loading branch information
Javernaut authored Jun 2, 2024
2 parents 962fe49 + b60193b commit b53ae28
Show file tree
Hide file tree
Showing 41 changed files with 473 additions and 304 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ hilt {
dependencies {
implementation(project(":features:settings:api"))
implementation(project(":features:settings:data"))
implementation(project(":features:settings:ui"))
implementation(project(":features:home:localization"))

ksp(libs.dagger.compiler)
ksp(libs.dagger.hilt.compiler)
implementation(libs.dagger.hilt.android)
Expand All @@ -150,7 +153,6 @@ dependencies {
implementation(libs.bundles.androidx.lifecycle)
implementation(libs.androidx.palette)
implementation(libs.androidx.savedstate)
implementation(libs.androidx.browser)
implementation(libs.androidx.window)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.hilt.navigation.compose)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.javernaut.whatthecodec.compose.theme.WhatTheCodecTheme
import com.javernaut.whatthecodec.compose.theme.dynamic.ThemeViewModel
import com.javernaut.whatthecodec.feature.settings.api.content.AudioStreamFeature
import com.javernaut.whatthecodec.feature.settings.api.content.SubtitleStreamFeature
import com.javernaut.whatthecodec.feature.settings.api.content.VideoStreamFeature
import com.javernaut.whatthecodec.feature.settings.api.theme.AppTheme
import com.javernaut.whatthecodec.feature.settings.data.content.completeEnumSet
import com.javernaut.whatthecodec.feature.settings.presentation.SettingsViewModel
import com.javernaut.whatthecodec.feature.settings.ui.SettingsScreen
import com.javernaut.whatthecodec.home.presentation.model.ActualFrame
import com.javernaut.whatthecodec.home.presentation.model.ActualPreview
import com.javernaut.whatthecodec.home.presentation.model.AudioPage
Expand All @@ -24,8 +25,6 @@ import com.javernaut.whatthecodec.home.presentation.model.SubtitlesPage
import com.javernaut.whatthecodec.home.presentation.model.VideoPage
import com.javernaut.whatthecodec.home.ui.screen.EmptyHomeScreen
import com.javernaut.whatthecodec.home.ui.screen.MainHomeScreen
import com.javernaut.whatthecodec.settings.presentation.SettingsViewModel
import com.javernaut.whatthecodec.settings.ui.SettingsScreen
import io.github.javernaut.mediafile.AudioStream
import io.github.javernaut.mediafile.BasicStreamInfo
import io.github.javernaut.mediafile.VideoStream
Expand Down Expand Up @@ -184,12 +183,11 @@ class ScreenshotsTestSuite(

@Test
fun settingsScreen() {
val appThemeFlow = MutableStateFlow(AppTheme.Auto)
val themeViewModel = mockk<ThemeViewModel>()
every { themeViewModel.appTheme } returns appThemeFlow

val settingsViewModel = mockk<SettingsViewModel>()

val appThemeFlow = MutableStateFlow(AppTheme.Auto)
every { settingsViewModel.appTheme } returns appThemeFlow

val videoFeatures = MutableStateFlow(completeEnumSet<VideoStreamFeature>())
val audioFeatures = MutableStateFlow(completeEnumSet<AudioStreamFeature>())
val subtitleFeatures = MutableStateFlow(completeEnumSet<SubtitleStreamFeature>())
Expand All @@ -199,7 +197,7 @@ class ScreenshotsTestSuite(
every { settingsViewModel.subtitleStreamFeatures } returns subtitleFeatures

makeScreenshotOf("settings") {
SettingsScreen(themeViewModel, settingsViewModel, {}, {})
SettingsScreen(settingsViewModel, {}, {})
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
package com.javernaut.whatthecodec.compose.theme.dynamic

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.javernaut.whatthecodec.feature.settings.api.theme.AppTheme
import com.javernaut.whatthecodec.feature.settings.api.theme.ThemeSettingsRepository
import com.javernaut.whatthecodec.settings.presentation.stateIn
import com.javernaut.whatthecodec.feature.settings.presentation.stateIn
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ThemeViewModel @Inject constructor(
private val themeSettingsRepository: ThemeSettingsRepository
themeSettingsRepository: ThemeSettingsRepository
) : ViewModel() {

val appTheme = themeSettingsRepository.themeSettings
.map { it.selectedTheme }
.stateIn(AppTheme.Auto)

fun setAppTheme(newAppTheme: AppTheme) {
viewModelScope.launch {
themeSettingsRepository.setSelectedTheme(newAppTheme)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import com.javernaut.whatthecodec.compose.navigation.MaterialNavHost
import com.javernaut.whatthecodec.feature.settings.navigation.navigateToSettings
import com.javernaut.whatthecodec.feature.settings.navigation.settingsScreen
import com.javernaut.whatthecodec.home.ui.navigation.HomeRoute
import com.javernaut.whatthecodec.home.ui.navigation.homeScreen
import com.javernaut.whatthecodec.settings.navigation.navigateToSettings
import com.javernaut.whatthecodec.settings.navigation.settingsScreen

@Composable
fun WhatTheCodecApp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package com.javernaut.whatthecodec.home.ui.audio

import android.content.res.Resources
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.javernaut.whatthecodec.R
import com.javernaut.whatthecodec.feature.home.stream.toDisplayableStreamFeature
import com.javernaut.whatthecodec.feature.settings.api.content.AudioStreamFeature
import com.javernaut.whatthecodec.home.presentation.model.AudioPage
import com.javernaut.whatthecodec.home.ui.stream.DisplayableStreamFeature
import com.javernaut.whatthecodec.home.ui.stream.SimplePage
import com.javernaut.whatthecodec.home.ui.stream.StreamFeaturesGrid
import io.github.javernaut.mediafile.AudioStream
import io.github.javernaut.mediafile.displayable.displayableLanguage
import io.github.javernaut.mediafile.displayable.getDisplayableDisposition
import io.github.javernaut.mediafile.displayable.toDisplayable

@Composable
fun AudioPage(
Expand Down Expand Up @@ -49,34 +44,3 @@ private fun AudioCardContent(
modifier
)
}

fun AudioStreamFeature.toDisplayableStreamFeature(
stream: AudioStream,
resources: Resources
) = when (this) {
AudioStreamFeature.Codec -> stream.basicInfo.codecName
AudioStreamFeature.Bitrate -> stream.bitRate.toDisplayable(resources)
AudioStreamFeature.Channels -> stream.channels.toString()
AudioStreamFeature.ChannelLayout -> stream.channelLayout
AudioStreamFeature.SampleFormat -> stream.sampleFormat
AudioStreamFeature.SampleRate -> stream.sampleRate.toDisplayable(resources)
AudioStreamFeature.Language -> stream.basicInfo.displayableLanguage
AudioStreamFeature.Disposition -> stream.basicInfo.getDisplayableDisposition(resources)
}?.let {
DisplayableStreamFeature(
name = resources.getString(displayableResource),
value = it
)
}

val AudioStreamFeature.displayableResource: Int
get() = when (this) {
AudioStreamFeature.Codec -> R.string.page_audio_codec_name
AudioStreamFeature.Bitrate -> R.string.page_audio_bit_rate
AudioStreamFeature.Channels -> R.string.page_audio_channels
AudioStreamFeature.ChannelLayout -> R.string.page_audio_channel_layout
AudioStreamFeature.SampleFormat -> R.string.page_audio_sample_format
AudioStreamFeature.SampleRate -> R.string.page_audio_sample_rate
AudioStreamFeature.Language -> R.string.page_stream_language
AudioStreamFeature.Disposition -> R.string.page_stream_disposition
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.javernaut.whatthecodec.home.presentation.model.ScreenMessage
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.launch
import com.javernaut.whatthecodec.feature.settings.ui.R as RSettings

@Composable
fun EmptyHomeScreen(
Expand Down Expand Up @@ -100,7 +101,7 @@ private fun EmptyScreenContent(
Row(verticalAlignment = Alignment.CenterVertically) {
EmptyScreenMainAction(
Icons.Filled.Videocam,
R.string.tab_video,
RSettings.string.tab_video,
onVideoIconClick
)
Text(
Expand All @@ -111,7 +112,7 @@ private fun EmptyScreenContent(
)
EmptyScreenMainAction(
Icons.Filled.MusicNote,
R.string.tab_audio,
RSettings.string.tab_audio,
onAudioIconClick
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.javernaut.whatthecodec.home.ui.subtitle.SubtitlePage
import com.javernaut.whatthecodec.home.ui.video.VideoPage
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import com.javernaut.whatthecodec.feature.settings.ui.R as RSettings

@Composable
fun MainHomeScreen(
Expand Down Expand Up @@ -386,9 +387,9 @@ private fun SideMainAction(

private val AvailableTab.title: Int
get() = when (this) {
AvailableTab.VIDEO -> R.string.tab_video
AvailableTab.AUDIO -> R.string.tab_audio
AvailableTab.SUBTITLES -> R.string.tab_subtitles
AvailableTab.VIDEO -> RSettings.string.tab_video
AvailableTab.AUDIO -> RSettings.string.tab_audio
AvailableTab.SUBTITLES -> RSettings.string.tab_subtitles
}

private val AvailableTab.icon: ImageVector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.ui.unit.dp
import com.javernaut.whatthecodec.R
import com.javernaut.whatthecodec.compose.common.GridLayout
import com.javernaut.whatthecodec.compose.theme.WhatTheCodecTheme
import com.javernaut.whatthecodec.feature.home.stream.DisplayableStreamFeature
import io.github.javernaut.mediafile.BasicStreamInfo
import io.github.javernaut.mediafile.MediaStream

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun PreviewStreamFeature() {
WhatTheCodecTheme.Static {
Surface {
StreamFeatureContent(
stringResource(id = R.string.page_audio_codec_name),
"Some title",
"Some value"
) { }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.javernaut.whatthecodec.home.ui.subtitle

import android.content.res.Resources
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.javernaut.whatthecodec.R
import com.javernaut.whatthecodec.feature.home.stream.toDisplayableStreamFeature
import com.javernaut.whatthecodec.feature.settings.api.content.SubtitleStreamFeature
import com.javernaut.whatthecodec.home.presentation.model.SubtitlesPage
import com.javernaut.whatthecodec.home.ui.stream.DisplayableStreamFeature
import com.javernaut.whatthecodec.home.ui.stream.SimplePage
import com.javernaut.whatthecodec.home.ui.stream.StreamFeaturesGrid
import io.github.javernaut.mediafile.SubtitleStream
import io.github.javernaut.mediafile.displayable.displayableLanguage
import io.github.javernaut.mediafile.displayable.getDisplayableDisposition

@Composable
fun SubtitlePage(
Expand Down Expand Up @@ -48,25 +44,3 @@ private fun SubtitleCardContent(
modifier
)
}

fun SubtitleStreamFeature.toDisplayableStreamFeature(
stream: SubtitleStream,
resources: Resources
) = when (this) {
SubtitleStreamFeature.Codec -> stream.basicInfo.codecName
SubtitleStreamFeature.Language -> stream.basicInfo.displayableLanguage
SubtitleStreamFeature.Disposition -> stream.basicInfo.getDisplayableDisposition(resources)
}?.let {
DisplayableStreamFeature(
name = resources.getString(displayableResource),
value = it
)
}


val SubtitleStreamFeature.displayableResource: Int
get() = when (this) {
SubtitleStreamFeature.Codec -> R.string.page_subtitle_codec_name
SubtitleStreamFeature.Language -> R.string.page_stream_language
SubtitleStreamFeature.Disposition -> R.string.page_stream_disposition
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.javernaut.whatthecodec.home.ui.video

import android.content.res.Resources
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -12,17 +11,14 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.javernaut.whatthecodec.R
import com.javernaut.whatthecodec.feature.home.stream.toDisplayableStreamFeature
import com.javernaut.whatthecodec.feature.settings.api.content.VideoStreamFeature
import com.javernaut.whatthecodec.home.presentation.model.VideoPage
import com.javernaut.whatthecodec.home.ui.stream.DisplayableStreamFeature
import com.javernaut.whatthecodec.home.ui.stream.StreamCard
import com.javernaut.whatthecodec.home.ui.stream.StreamFeatureItem
import com.javernaut.whatthecodec.home.ui.stream.StreamFeaturesGrid
import com.javernaut.whatthecodec.home.ui.stream.makeCardTitle
import io.github.javernaut.mediafile.VideoStream
import io.github.javernaut.mediafile.displayable.displayableLanguage
import io.github.javernaut.mediafile.displayable.getDisplayableDisposition
import io.github.javernaut.mediafile.displayable.toDisplayable

@Composable
fun VideoPage(
Expand Down Expand Up @@ -119,32 +115,3 @@ private fun VideoStream(
)
}
}

fun VideoStreamFeature.toDisplayableStreamFeature(
stream: VideoStream,
resources: Resources
) = when (this) {
VideoStreamFeature.Codec -> stream.basicInfo.codecName
VideoStreamFeature.Bitrate -> stream.bitRate.toDisplayable(resources)
VideoStreamFeature.FrameRate -> stream.frameRate.toDisplayable(resources)
VideoStreamFeature.FrameWidth -> stream.frameWidth.toString()
VideoStreamFeature.FrameHeight -> stream.frameHeight.toString()
VideoStreamFeature.Language -> stream.basicInfo.displayableLanguage
VideoStreamFeature.Disposition -> stream.basicInfo.getDisplayableDisposition(resources)
}?.let {
DisplayableStreamFeature(
name = resources.getString(displayableResource),
value = it
)
}

val VideoStreamFeature.displayableResource: Int
get() = when (this) {
VideoStreamFeature.Codec -> R.string.page_video_codec_name
VideoStreamFeature.Bitrate -> R.string.page_video_bit_rate
VideoStreamFeature.FrameRate -> R.string.page_video_frame_rate
VideoStreamFeature.FrameWidth -> R.string.page_video_frame_width
VideoStreamFeature.FrameHeight -> R.string.page_video_frame_height
VideoStreamFeature.Language -> R.string.page_stream_language
VideoStreamFeature.Disposition -> R.string.page_stream_disposition
}
Loading

0 comments on commit b53ae28

Please sign in to comment.