Skip to content

Commit

Permalink
Fix WindowSize and JDK/proguard issue
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Oct 24, 2023
1 parent f503c69 commit cbac36d
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 20 deletions.
17 changes: 15 additions & 2 deletions androidApp/src/main/kotlin/com/prof18/feedflow/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.Modifier
Expand All @@ -29,6 +32,7 @@ import com.prof18.feedflow.settings.about.LicensesScreen
import com.prof18.feedflow.settings.importexport.ImportExportScreen

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

Expand All @@ -44,22 +48,30 @@ class MainActivity : ComponentActivity() {
onDispose {}
}

val windowSize = calculateWindowSizeClass(this@MainActivity)

FeedFlowTheme {
val navController = rememberNavController()

Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
FeedFlowNavigation(navController)
FeedFlowNavigation(
windowSizeClass = windowSize,
navController = navController,
)
}
}
}
}

@Suppress("LongMethod")
@Composable
private fun FeedFlowNavigation(navController: NavHostController) {
private fun FeedFlowNavigation(
windowSizeClass: WindowSizeClass,
navController: NavHostController,
) {
NavHost(
navController = navController,
startDestination = Screen.Home.name,
Expand All @@ -70,6 +82,7 @@ class MainActivity : ComponentActivity() {
) {
composable(Screen.Home.name) {
HomeScreen(
windowSizeClass = windowSizeClass,
onSettingsButtonClicked = {
navController.navigate(Screen.Settings.name)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDrawerState
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -74,6 +74,7 @@ import org.koin.compose.koinInject
@Suppress("LongMethod")
@Composable
internal fun HomeScreen(
windowSizeClass: WindowSizeClass,
onSettingsButtonClicked: () -> Unit,
) {
val homeViewModel = koinViewModel<HomeViewModel>()
Expand Down Expand Up @@ -103,14 +104,13 @@ internal fun HomeScreen(

val scope = rememberCoroutineScope()

val windowSize = calculateWindowSizeClass()
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)

var isDrawerMenuFullVisible by remember {
mutableStateOf(true)
}

when (windowSize.widthSizeClass) {
when (windowSizeClass.widthSizeClass) {
WindowWidthSizeClass.Compact -> {
ModalNavigationDrawer(
drawerContent = {
Expand Down
1 change: 0 additions & 1 deletion desktopApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ kotlin {
implementation(libs.bundles.about.libraries)
implementation(libs.jsoup)
implementation(libs.slf4j.nop)
implementation(libs.material.window.size)
}
}
val jvmTest by getting
Expand Down
4 changes: 2 additions & 2 deletions desktopApp/src/jvmMain/kotlin/com/prof18/feedflow/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.material.Surface
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
Expand Down Expand Up @@ -207,7 +206,6 @@ fun main() = application {
}
}

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Composable
private fun MainContent(
rootComponentContext: DefaultComponentContext,
Expand Down Expand Up @@ -237,6 +235,7 @@ private fun MainContent(
Column {
if (newVersionState is NewVersionState.NewVersion) {
NewVersionBanner(
window = window,
onDownloadLinkClick = {
openInBrowser(newVersionState.downloadLink)
},
Expand All @@ -245,6 +244,7 @@ private fun MainContent(
}

HomeScreen(
window = window,
paddingValues = paddingValues,
homeViewModel = homeViewModel,
snackbarHostState = snackbarHostState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.rememberDrawerState
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand All @@ -45,6 +42,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposeWindow
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.prof18.feedflow.MR
Expand All @@ -62,12 +60,14 @@ import com.prof18.feedflow.ui.home.components.FeedItemView
import com.prof18.feedflow.ui.home.components.FeedList
import com.prof18.feedflow.ui.home.components.NoFeedsSourceView
import com.prof18.feedflow.ui.style.Spacing
import com.prof18.feedflow.utils.WindowWidthSizeClass
import com.prof18.feedflow.utils.calculateWindowSizeClass
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Composable
internal fun HomeScreen(
window: ComposeWindow,
paddingValues: PaddingValues,
homeViewModel: HomeViewModel,
snackbarHostState: SnackbarHostState,
Expand All @@ -88,7 +88,7 @@ internal fun HomeScreen(
}
}

val windowSize = calculateWindowSizeClass()
val windowSize = calculateWindowSizeClass(window)

when (windowSize.widthSizeClass) {
WindowWidthSizeClass.Compact -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposeWindow
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -27,15 +25,17 @@ import androidx.compose.ui.text.withStyle
import com.prof18.feedflow.MR
import com.prof18.feedflow.ui.style.FeedFlowTheme
import com.prof18.feedflow.ui.style.Spacing
import com.prof18.feedflow.utils.WindowWidthSizeClass
import com.prof18.feedflow.utils.calculateWindowSizeClass
import dev.icerock.moko.resources.compose.stringResource

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Composable
internal fun NewVersionBanner(
window: ComposeWindow,
onDownloadLinkClick: () -> Unit,
onCloseClick: () -> Unit,
) {
val windowSize = calculateWindowSizeClass()
val windowSize = calculateWindowSizeClass(window)

when (windowSize.widthSizeClass) {
WindowWidthSizeClass.Compact -> {
Expand Down Expand Up @@ -167,6 +167,7 @@ private fun AnnotatedClickableText(
private fun NewVersionBannerPreview() {
FeedFlowTheme {
NewVersionBanner(
window = ComposeWindow(),
onDownloadLinkClick = {},
onCloseClick = {},
)
Expand Down
Loading

0 comments on commit cbac36d

Please sign in to comment.