Skip to content

Commit

Permalink
Merge pull request #1 from AVidhanR/master
Browse files Browse the repository at this point in the history
Updating main branch
  • Loading branch information
AVidhanR authored Jan 24, 2024
2 parents 5e7bd78 + fbff059 commit cbd8d07
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 29 deletions.
17 changes: 1 addition & 16 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
Expand Down Expand Up @@ -67,6 +51,7 @@ android {
}

dependencies {
implementation("androidx.compose.material3:material3-window-size-class")
implementation(platform("androidx.compose:compose-bom:2023.06.00"))
implementation("androidx.activity:activity-compose:1.7.2")
implementation("androidx.compose.material:material-icons-extended")
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/example/reply/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Surface
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.tooling.preview.Preview
import com.example.reply.ui.ReplyApp
import com.example.reply.ui.theme.ReplyTheme

class MainActivity : ComponentActivity() {

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

setContent {
val windowSize = calculateWindowSizeClass(this)
ReplyTheme {
Surface {
ReplyApp()
ReplyApp( // I am using the width only.
windowSize = windowSize.widthSizeClass
)
}
}
}
Expand All @@ -29,7 +36,9 @@ class MainActivity : ComponentActivity() {
fun ReplyAppCompactPreview() {
ReplyTheme {
Surface {
ReplyApp()
ReplyApp(
windowSize = WindowWidthSizeClass.Compact
)
}
}
}
21 changes: 19 additions & 2 deletions app/src/main/java/com/example/reply/ui/ReplyApp.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package com.example.reply.ui

import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.reply.data.Email
import com.example.reply.data.MailboxType

import com.example.reply.ui.utils.ReplyNavigationType
@Composable
fun ReplyApp(
windowSize: WindowWidthSizeClass,
modifier: Modifier = Modifier,
) {
val viewModel: ReplyViewModel = viewModel()
val replyUiState = viewModel.uiState.collectAsState().value
val navigationType: ReplyNavigationType = when (windowSize) {
WindowWidthSizeClass.Compact -> {
ReplyNavigationType.BOTTOM_NAVIGATION
}
WindowWidthSizeClass.Medium -> {
ReplyNavigationType.NAVIGATION_RAIL
}
WindowWidthSizeClass.Expanded -> {
ReplyNavigationType.PERMANENT_NAVIGATION_DRAWER
}
else -> {
ReplyNavigationType.BOTTOM_NAVIGATION
}
}

ReplyHomeScreen(
replyUiState = replyUiState,
Expand All @@ -28,6 +44,7 @@ fun ReplyApp(
onDetailScreenBackPressed = {
viewModel.resetHomeScreenStates()
},
modifier = modifier
modifier = modifier,
navigationType = navigationType
)
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/example/reply/ui/ReplyDetailsScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.reply.ui

import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -38,6 +39,9 @@ fun ReplyDetailsScreen(
onBackPressed: () -> Unit,
modifier: Modifier = Modifier
) {
BackHandler {
onBackPressed()
}
Box(modifier = modifier) {
LazyColumn(
modifier = Modifier
Expand Down
65 changes: 56 additions & 9 deletions app/src/main/java/com/example/reply/ui/ReplyHomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Drafts
import androidx.compose.material.icons.filled.Inbox
Expand All @@ -22,6 +25,8 @@ import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.NavigationDrawerItemDefaults
import androidx.compose.material3.NavigationRail
import androidx.compose.material3.NavigationRailItem
import androidx.compose.material3.PermanentDrawerSheet
import androidx.compose.material3.PermanentNavigationDrawer
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -35,14 +40,16 @@ import com.example.reply.R
import com.example.reply.data.Email
import com.example.reply.data.MailboxType
import com.example.reply.data.local.LocalAccountsDataProvider
import com.example.reply.ui.utils.ReplyNavigationType

@Composable
fun ReplyHomeScreen(
replyUiState: ReplyUiState,
onTabPressed: (MailboxType) -> Unit,
onEmailCardPressed: (Email) -> Unit,
onDetailScreenBackPressed: () -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
navigationType: ReplyNavigationType
) {
val navigationItemContentList = listOf(
NavigationItemContent(
Expand All @@ -66,13 +73,52 @@ fun ReplyHomeScreen(
text = stringResource(id = R.string.tab_spam)
)
)
ReplyAppContent(
replyUiState = replyUiState,
onTabPressed = onTabPressed,
onEmailCardPressed = onEmailCardPressed,
navigationItemContentList = navigationItemContentList,
modifier = modifier
)
if (navigationType == ReplyNavigationType.PERMANENT_NAVIGATION_DRAWER &&
replyUiState.isShowingHomepage) {
PermanentNavigationDrawer(
drawerContent = {
PermanentDrawerSheet(
Modifier.width(dimensionResource(R.dimen.drawer_width))
) {
NavigationDrawerContent(
selectedDestination = replyUiState.currentMailbox,
onTabPressed = onTabPressed,
navigationItemContentList = navigationItemContentList,
modifier = Modifier
.wrapContentWidth()
.fillMaxHeight()
.background(MaterialTheme.colorScheme.inverseOnSurface)
.padding(dimensionResource(R.dimen.drawer_padding_content))
)
}
}
) {
ReplyAppContent(
replyUiState = replyUiState,
onTabPressed = onTabPressed,
onEmailCardPressed = onEmailCardPressed,
navigationItemContentList = navigationItemContentList,
modifier = modifier
)
}

}

if (replyUiState.isShowingHomepage) {
ReplyAppContent(
replyUiState = replyUiState,
onTabPressed = onTabPressed,
onEmailCardPressed = onEmailCardPressed,
navigationItemContentList = navigationItemContentList,
modifier = modifier
)
} else {
ReplyDetailsScreen(
replyUiState = replyUiState,
onBackPressed = onDetailScreenBackPressed,
modifier = modifier
)
}
}

@Composable
Expand Down Expand Up @@ -100,7 +146,8 @@ private fun ReplyAppContent(
ReplyListOnlyContent(
replyUiState = replyUiState,
onEmailCardPressed = onEmailCardPressed,
modifier = Modifier.weight(1f)
modifier = Modifier
.weight(1f)
.padding(
horizontal = dimensionResource(R.dimen.email_list_only_horizontal_padding)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.reply.ui.utils

enum class ReplyNavigationType {
BOTTOM_NAVIGATION,
NAVIGATION_RAIL,
PERMANENT_NAVIGATION_DRAWER
}

0 comments on commit cbd8d07

Please sign in to comment.