Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#546 [layout] Home Screen #554

Merged
merged 25 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cb46dbd
#546 [layout] Add Emoji View
yuni-ju Feb 12, 2024
390fabc
#546 [layout] add category menu
yuni-ju Feb 20, 2024
4641a04
#546 [layout] Top App Bar in Home Screen
yuni-ju Feb 20, 2024
d27e249
#546 [layout] Main Bottom Navigation
yuni-ju Feb 21, 2024
a6195a5
#546 [layout] Set bottom sheet dialog to appear above bottom navigati…
yuni-ju Feb 21, 2024
58170d8
#546 [layout] dayo pick description placement
yuni-ju Feb 21, 2024
efa15b8
#546 [layout] Show Dayo Pick Post List
yuni-ju Feb 21, 2024
2c888a7
#546 [layout] Implementing a HomePostView
yuni-ju Feb 28, 2024
af325f7
#546 [feature] Add HomeNewScreen
yuni-ju Feb 28, 2024
7d69f90
#546 [layout] Home Empty View
yuni-ju Feb 29, 2024
c6e4b73
#546 [layout] Add Emoji View
yuni-ju Feb 12, 2024
1f0d3fc
#546 [layout] add category menu
yuni-ju Feb 20, 2024
9c49aac
#546 [layout] Top App Bar in Home Screen
yuni-ju Feb 20, 2024
7718623
#546 [layout] Main Bottom Navigation
yuni-ju Feb 21, 2024
c7d0555
#546 [layout] Set bottom sheet dialog to appear above bottom navigati…
yuni-ju Feb 21, 2024
dc2af25
#546 [layout] dayo pick description placement
yuni-ju Feb 21, 2024
2df8512
#546 [layout] Show Dayo Pick Post List
yuni-ju Feb 21, 2024
0a1e9f2
#546 [layout] Implementing a HomePostView
yuni-ju Feb 28, 2024
3ba1fd6
#546 [feature] Add HomeNewScreen
yuni-ju Feb 28, 2024
5742bb1
#546 [layout] Home Empty View
yuni-ju Feb 29, 2024
5303e49
Merge branch 'layout/issue-546' of https://github.com/Daily-DAYO/DAYO…
yuni-ju Mar 6, 2024
79e87e1
[feature] Add a parameter to modify the default and check colors in B…
Feb 24, 2024
0a79e38
[feature] Add left checked icon buttons parameter
Mar 24, 2024
e83b18f
[feature] Change Icon Default Color from black to unspecified
DongJun-H Mar 27, 2024
1662293
#546 [layout] Checked Category Icon
yuni-ju Mar 27, 2024
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
15 changes: 12 additions & 3 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {
versionCode 10000
versionName "1.0.0"

buildConfigField ("String", "NATIVE_APP_KEY", properties['NATIVE_APP_KEY_STR'])
buildConfigField("String", "NATIVE_APP_KEY", properties['NATIVE_APP_KEY_STR'])
manifestPlaceholders = [NATIVE_APP_KEY: NATIVE_APP_KEY]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -93,6 +93,7 @@ dependencies {
def landscapist_glide_version = "2.2.5"
def fragment_version = "1.6.1"
def activity_version = "1.7.2"
def emoji_version = "1.0.0-alpha03"

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.10.1'
Expand All @@ -111,7 +112,7 @@ dependencies {
// Jetpack Compose
// Material
implementation("androidx.compose.material3:material3")
implementation ("androidx.compose.material:material-icons-extended:1.5.3")
implementation("androidx.compose.material:material-icons-extended:1.5.3")
// Android Studio Preview support
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
Expand Down Expand Up @@ -139,7 +140,8 @@ dependencies {
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
// Jetpack Compose Integration
implementation("androidx.navigation:navigation-compose:$nav_version")
implementation "androidx.navigation:navigation-compose:$nav_version"
implementation "androidx.hilt:hilt-navigation-compose:1.1.0"

// ViewPager2
implementation "androidx.viewpager2:viewpager2:1.0.0"
Expand Down Expand Up @@ -198,6 +200,9 @@ dependencies {
// Glide-For-Compose
implementation "com.github.skydoves:landscapist-glide:$landscapist_glide_version"

// Coil
implementation "io.coil-kt:coil-compose:2.5.0"

// Preference
implementation 'androidx.preference:preference-ktx:1.1.1'

Expand All @@ -221,6 +226,10 @@ dependencies {
// optional - Jetpack Compose integration
implementation "androidx.paging:paging-compose:3.2.0"

// emoji
implementation "androidx.emoji2:emoji2:$emoji_version"
implementation "androidx.emoji2:emoji2-views:$emoji_version"

testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package daily.dayo.presentation.activity

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Rect
Expand All @@ -11,22 +12,63 @@ import android.view.MotionEvent
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.view.forEach
import androidx.navigation.NavController
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import dagger.hilt.android.AndroidEntryPoint
import daily.dayo.presentation.R
import daily.dayo.presentation.databinding.ActivityMainBinding
import daily.dayo.presentation.fragment.home.HomeFragmentDirections
import daily.dayo.presentation.viewmodel.SettingNotificationViewModel
import dagger.hilt.android.AndroidEntryPoint
import daily.dayo.presentation.screen.home.HomeScreen
import daily.dayo.presentation.theme.Gray1_313131
import daily.dayo.presentation.theme.Gray2_767B83
import daily.dayo.presentation.theme.White_FFFFFF
import daily.dayo.presentation.view.getBottomSheetDialogState
import daily.dayo.presentation.viewmodel.AccountViewModel
import daily.dayo.presentation.viewmodel.SettingNotificationViewModel
import kotlinx.coroutines.CoroutineScope

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
Expand All @@ -36,14 +78,127 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
// setContentView(binding.root)
setSystemBackClickListener()
checkCurrentNotification()
initBottomNavigation()
setBottomNaviVisibility()
disableBottomNaviTooltip()
getNotificationData()
askNotificationPermission()
setContent {
MainScreen()
}
}

@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun MainScreen() {
val navController = rememberNavController()
val coroutineScope = rememberCoroutineScope()
val bottomSheetState = getBottomSheetDialogState()
var bottomSheet: (@Composable () -> Unit)? by remember { mutableStateOf(null) }
val bottomSheetContent: (@Composable () -> Unit) -> Unit = {
bottomSheet = it
}

Scaffold(
bottomBar = { bottomSheet?.let { it() } }
) {
Scaffold(
bottomBar = {
MainBottomNavigation(navController = navController)

}
) { innerPadding ->
Box(Modifier.padding(innerPadding)) {
NavigationGraph(navController = navController, coroutineScope, bottomSheetState, bottomSheetContent)
}
}
}
}

@Composable
fun MainBottomNavigation(navController: NavController) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
val items = listOf(
Screen.Home,
Screen.Feed,
Screen.Write,
Screen.Notification,
Screen.MyPage
)

BottomNavigation(
backgroundColor = White_FFFFFF,
contentColor = Gray2_767B83,
modifier = Modifier.height(73.dp)
) {
items.forEach { screen ->
val selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true
BottomNavigationItem(
icon = {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
imageVector = ImageVector.vectorResource(id = if (selected) screen.selectedIcon else screen.defaultIcon),
contentDescription = stringResource(id = screen.resourceId),
modifier = Modifier
.size(if (screen.route != Screen.Write.route) 24.dp else 36.dp)
)

if (screen.route != Screen.Write.route) {
Text(text = stringResource(screen.resourceId), style = MaterialTheme.typography.caption)
}
}
},
selected = selected,
selectedContentColor = Gray1_313131,
onClick = {
navController.navigate(screen.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
)
}
}
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun NavigationGraph(
navController: NavHostController,
coroutineScope: CoroutineScope,
bottomSheetState: ModalBottomSheetState,
bottomSheetContent: (@Composable () -> Unit) -> Unit
) {
NavHost(
navController = navController,
startDestination = Screen.Home.route
) {
composable(Screen.Home.route) {
HomeScreen(navController, coroutineScope, bottomSheetState, bottomSheetContent)
}
composable(Screen.Feed.route) {

}
composable(Screen.Write.route) {

}
composable(Screen.Notification.route) {

}
composable(Screen.MyPage.route) {

}
}
}

private fun setSystemBackClickListener() {
Expand Down Expand Up @@ -137,6 +292,7 @@ class MainActivity : AppCompatActivity() {
).show()
}
}

else -> {
//All request are permitted
// 알림 최초 허용시에 모든 알림 허용처리
Expand Down Expand Up @@ -204,12 +360,14 @@ class MainActivity : AppCompatActivity() {
isInside = true
return true
}

MotionEvent.ACTION_MOVE -> {
isInside =
rect.contains(v!!.left + event.x.toInt(), v.top + event.y.toInt())
binding.bottomNavigationMainBar.clearFocus()
return false
}

MotionEvent.ACTION_UP -> {
binding.bottomNavigationMainBar.menu.findItem(R.id.WriteFragment)
.setIcon(R.drawable.ic_write)
Expand All @@ -223,6 +381,7 @@ class MainActivity : AppCompatActivity() {
}
return true
}

else -> return true
}
}
Expand All @@ -249,4 +408,12 @@ class MainActivity : AppCompatActivity() {
companion object {
val notificationPermission = arrayOf(Manifest.permission.POST_NOTIFICATIONS)
}

sealed class Screen(val route: String, @StringRes val resourceId: Int, @DrawableRes val defaultIcon: Int, @DrawableRes val selectedIcon: Int) {
object Home : Screen("home", R.string.home, R.drawable.ic_home, R.drawable.ic_home_filled)
object Feed : Screen("feed", R.string.feed, R.drawable.ic_feed, R.drawable.ic_feed_filled)
object Write : Screen("write", R.string.write, R.drawable.ic_write, R.drawable.ic_write_filled)
object Notification : Screen("notification", R.string.notification, R.drawable.ic_notification, R.drawable.ic_notification_filled)
object MyPage : Screen("mypage", R.string.my_page, R.drawable.ic_my_page, R.drawable.ic_my_page_filled)
}
}
Loading
Loading