Skip to content

Commit

Permalink
DEP-51 feat: Navigator ๊ตฌํ˜„ (#17)
Browse files Browse the repository at this point in the history
* feat: ํ†ต๊ณ„, ๋งˆ์ด ํŽ˜์ด์ง€ ์ƒ์„ฑ

* fix: BaseFragment binding ์˜ค๋ฅ˜ ์ˆ˜์ •

* feat: Navigator์™€ hilt ์„ค์ •

* feat: BottomNavigationView ๊ตฌํ˜„

* ui: StatusBar ํฐ์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝ

* chore: ํ•„์š”ํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ ์‚ญ์ œ

* fix: build ์‹คํŒจ๋ฅผ ๊ณ ์น˜๊ธฐ ์œ„ํ•ด gradle dependency ๋ณต๊ตฌ

* fix: ์ค‘๋ณต๋œ dependency ์‚ญ์ œ์™€ initView ์‚ฌ์šฉ ์ฝ”๋“œ ์ถ”๊ฐ€
  • Loading branch information
juhwankim-dev authored Oct 17, 2022
1 parent 7ed1ae7 commit 5cc4ca4
Show file tree
Hide file tree
Showing 35 changed files with 488 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.depromeet.threedays

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class ThreeDaysApplication : Application() {
}
6 changes: 4 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ThreeDays" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.ThreeDays" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand All @@ -10,7 +10,9 @@
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor" tools:targetApi="l">@color/white</item>
<!-- Customize your theme here. -->

<item name = "android:windowLightStatusBar">true</item>
</style>
</resources>
12 changes: 9 additions & 3 deletions core/src/main/java/com/depromeet/threedays/core/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import java.lang.IllegalStateException

abstract class BaseFragment<VB : ViewDataBinding, VM : BaseViewModel>(@LayoutRes layout: Int) : Fragment(layout) {
abstract class BaseFragment<VB : ViewDataBinding, VM : BaseViewModel>(@LayoutRes private val layout: Int) : Fragment(layout) {

protected var _binding: VB? = null
val binding: VB
Expand All @@ -22,8 +23,13 @@ abstract class BaseFragment<VB : ViewDataBinding, VM : BaseViewModel>(@LayoutRes
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding.lifecycleOwner = viewLifecycleOwner
return binding.root
_binding = DataBindingUtil.inflate(inflater, layout, container, false)
return _binding!!.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding?.lifecycleOwner = viewLifecycleOwner
}

protected fun onBind(body: VB.() -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.depromeet.threedays.navigator

interface HomeNavigator : Navigator
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.depromeet.threedays.navigator

import android.content.Context
import android.content.Intent

interface Navigator {
fun intent(context: Context): Intent
}
5 changes: 2 additions & 3 deletions presentation/home/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ dependencies {
implementation(project(":core-design-system"))
implementation(project(":navigator"))
implementation(project(":domain"))
implementation(project(":presentation:statistics"))
implementation(project(":presentation:my"))

implementation(jetpackDeps)
implementation(coroutines)

implementation deps.hilt.core
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
kapt deps.hilt.compiler

testImplementation(testDeps)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
package com.depromeet.threedays.home

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.depromeet.threedays.core.BaseActivity
import com.depromeet.threedays.home.databinding.ActivityMainBinding
import com.depromeet.threedays.home.home.HomeFragment
import com.depromeet.threedays.my.MyFragment
import com.depromeet.threedays.statistics.StatisticsFragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

initNavigationBar()
}

private fun initNavigationBar() {
binding.bnvMain.run {
setOnItemSelectedListener {
when (it.itemId) {
R.id.homeFragment -> {
changeFragment(HomeFragment())
}
R.id.statisticsFragment -> {
changeFragment(StatisticsFragment())
}
R.id.myFragment -> {
changeFragment(MyFragment())
}
}
true
}
selectedItemId = R.id.homeFragment
}
}

private fun changeFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction().replace(binding.flMain.id, fragment).commit()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
package com.depromeet.threedays.home.home

import androidx.fragment.app.Fragment
import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import com.depromeet.threedays.core.BaseFragment
import com.depromeet.threedays.home.R
import com.depromeet.threedays.home.databinding.FragmentHomeBinding
import dagger.hilt.android.AndroidEntryPoint

class HomeFragment : Fragment() {
@AndroidEntryPoint
class HomeFragment: BaseFragment<FragmentHomeBinding, HomeViewModel>(R.layout.fragment_home) {
override val viewModel by viewModels<HomeViewModel>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initView()
}

private fun initView() {
// ์šฐ์„  ์ž„์‹œ๋กœ setOnClickListener๋ฅผ ๋‹ฌ์•„๋†จ์Šต๋‹ˆ๋‹ค.
// ํ˜œ์ธ๋‹˜ ๋ ˆํฌ์— ์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ setOnSingleClickListener๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•  ์ง€ ์—ฌ๋ถ€์™€
// viewModel์—์„œ ํด๋ฆญ๋ฆฌ์Šค๋„ˆ๋ฅผ ๋‹ฌ์•„์ค„์ง€ ๋“ฑ์„ ํ˜‘์˜ํ•˜๊ณ  ํ™•์ •๋˜๋ฉด ์ถ”ํ›„์— ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
binding.btnMakeGoal.setOnClickListener {
// TODO: ๋งŒ๋“ค๊ธฐ ํŽ˜์ด์ง€๋กœ ์ด๋™
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.depromeet.threedays.home.home

import com.depromeet.threedays.navigator.HomeNavigator
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
internal abstract class HomeModule {
@Binds
abstract fun bindHomeNavigator(navigator: HomeNavigatorImpl): HomeNavigator
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.depromeet.threedays.home.home

import android.content.Context
import android.content.Intent
import com.depromeet.threedays.home.MainActivity
import com.depromeet.threedays.navigator.HomeNavigator
import javax.inject.Inject

internal class HomeNavigatorImpl @Inject constructor() : HomeNavigator {
override fun intent(context: Context): Intent {
return Intent(context, MainActivity::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.depromeet.threedays.home.home

import com.depromeet.threedays.core.BaseViewModel

class HomeViewModel : BaseViewModel() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#1A1F27" android:state_checked="true" />
<item android:color="#B0B8C1" />
</selector>
34 changes: 28 additions & 6 deletions presentation/home/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
xmlns:tools="http://schemas.android.com/tools">

</androidx.constraintlayout.widget.ConstraintLayout>
<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<FrameLayout
android:id="@+id/fl_main"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/bnv_main"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconTint="@drawable/selector_menu_color"
app:itemTextColor="@drawable/selector_menu_color"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_nav_menu"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
16 changes: 16 additions & 0 deletions presentation/home/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/homeFragment"
android:icon="@drawable/ic_tab_home"
android:title="ํ™ˆ" />
<item
android:id="@+id/statisticsFragment"
android:icon="@drawable/ic_tab_statistics"
android:title="ํ†ต๊ณ„" />
<item
android:id="@+id/myFragment"
android:icon="@drawable/ic_tab_my"
android:title="๋งˆ์ดํŽ˜์ด์ง€" />
</menu>
1 change: 1 addition & 0 deletions presentation/my/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
52 changes: 52 additions & 0 deletions presentation/my/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id "kotlin-kapt"
id 'dagger.hilt.android.plugin'
}

android {
compileSdk 32

defaultConfig {
minSdk 24
targetSdk 32

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding true
}
}

dependencies {

implementation(project(":core"))
implementation(project(":navigator"))
implementation(project(":domain"))
implementation(project(":core-design-system"))

implementation(jetpackDeps)
implementation(coroutines)

implementation deps.hilt.core
kapt deps.hilt.compiler

testImplementation(testDeps)
androidTestImplementation(androidTestDeps)
}
Empty file.
21 changes: 21 additions & 0 deletions presentation/my/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.depromeet.threedays.my

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.depromeet.threedays.my.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions presentation/my/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.depromeet.threedays.my">

</manifest>
Loading

0 comments on commit 5cc4ca4

Please sign in to comment.