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

DEP-51 feat: Navigator 구현 #17

Merged
merged 8 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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>
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 transaction 이 있네요. 신기하네요 ㅋㅋ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flutter에도 있나보군요! ㅋㅋㅋ

}
}
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에서 클릭리스너를 달아줄지 등을 협의하고 확정되면 추후에 수정하겠습니다.
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewModel에서 클릭리스너를 다는 방식은 어떤건가용 ?.?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

양방향 바인딩이용!
xml 에서 onClick에 람다식 넣어주는 거요!

Copy link
Contributor

@kimhyeing kimhyeing Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하!! 흠 그러게요,,.. 섞어서 써도 괜찮을 것 같고 그냥 하나로 정하는 것도 좋을 것 같아요!
서버 호출 생각하면 setOnSingleClickListener를 쓰는게 좋을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setOnSingleClickListener 이거 interval을 주고 그러던데 정확히 무엇을 위한 커스텀인가요? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 굳이 interval 값을 고정하는게 아니라 파라미터로서 주는 이유는 잘 모르겠습니닷.....

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="홈" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title 값은 string.xml 에 정의하는 것보다 bottom_nav_menu.xml 에서 관리하는게 나을까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 노란색으로 경고표시..?가 뜬다면 추출하고 아니라면 굳이 안해도 되지 않을까 싶습니닷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

노란색 경고 뜨긴합니다... ㅎㅎ...
정석은 이런 거 다 string.xml에 놓는 게 맞긴 한데
저번에 oo회사에서는 이런 걸 정말 다 일일이 string.xml에 넣어 놓고 사용하나 봤는데
그냥 이렇게 짜는 것 같더라구요 🤔

<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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
현재 위와 같이 빨간색 동그라미가 보이는데요, 여기에 마우스를 가져다대면 No newline at end of file이라고 되어있습니다! 머지하는 과정에서 파일 끝에 개행이 있으면 오류가 날 가능성이 있다고 하더라구요 (근데 오류가 나는걸 본 적이 없긴 합니다 ㅎㅎ)

아래는 안드로이드 스튜디오에서 파일 개행추가를 자동으로 설정해주는 방법과 그 이유입니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 친절하게 설명과 링크까지... 감사합니다 ㅎㅎ!

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