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

[FEAT/#8] Week2 / 심화 과제 #11

Merged
merged 8 commits into from
Oct 29, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.sopt.dosopttemplate.data

import org.sopt.dosopttemplate.R

object DummyFriendsData {
object DummyFriendData {
val dummyFriendList = listOf(
FriendsSealed.FriendsMe(
profileImage = R.drawable.img_main_profile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.sopt.dosopttemplate.presentation
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import org.sopt.dosopttemplate.R
import org.sopt.dosopttemplate.databinding.ActivityBnvBinding
import org.sopt.dosopttemplate.util.BackPressedUtil
Expand All @@ -15,46 +16,35 @@ class BnvActivity : AppCompatActivity() {
binding = ActivityBnvBinding.inflate(layoutInflater)
setContentView(binding.root)

// 처음에 보여주어야 하는 프래그먼트를 변수로
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_home)
// 만약 프래그먼트가 끼워지지 않았다면 프래그먼트메이저를 사용하여 끼워보기
if (currentFragment == null) {
supportFragmentManager.beginTransaction()
.add(R.id.fcv_home, HomeFragment())
.commit()
} // Fragment의 재생성과 newInstance() 알아보기
initialFragment(R.id.fcv_home, HomeFragment())

clickBnv()

updown_Listener(RecyclerView(this))
}

private fun clickBnv() {
binding.bnvHome.setOnItemSelectedListener {
when (it.itemId) {
R.id.menu_home -> {
replaceFragment(HomeFragment())
val fragment = HomeFragment.newInstance()
replaceFragment(fragment)
true
}

R.id.menu_do_android -> {
replaceFragment(DoAndroidFragment())
val fragment = DoAndroidFragment.newInstance()
replaceFragment(fragment)
true
}

R.id.menu_mypage -> {
val fragment = MypageFragment()

val getId = intent.getStringExtra("ID")
val getNickname = intent.getStringExtra("Nickname")
val getAge = intent.getStringExtra("Age")

// 자동 로그인이 아닌 경우 프래그먼트로 유저 정보 전달
val bundle = Bundle().apply {
putString("userId", getId)
putString("userNickname", getNickname)
putString("userAge", getAge)
}

fragment.arguments = bundle
val fragment = MypageFragment.newInstance(getId, getNickname, getAge)

replaceFragment(fragment)
true
Expand All @@ -69,10 +59,27 @@ class BnvActivity : AppCompatActivity() {
backPressedUtil.BackButton()
}

fun updown_Listener(view: RecyclerView?) {
binding.bnvHome.setOnClickListener {
view?.smoothScrollToPosition(0)
}
}
Comment on lines +62 to +66
Copy link
Member

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.

헉 수정하도록 하겠습니답


private fun replaceFragment(fragment: Fragment) {
supportFragmentManager
.beginTransaction()
.replace(R.id.fcv_home, fragment)
.commit()
}

// 프래그먼트 초기화 함수
private fun initialFragment(containerViewId: Int, fragment: Fragment) {
val currentFragment = supportFragmentManager.findFragmentById(containerViewId)

if (currentFragment == null) {
supportFragmentManager.beginTransaction()
.add(containerViewId, fragment)
.commit()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import androidx.fragment.app.Fragment
import org.sopt.dosopttemplate.databinding.FragmentDoAndroidBinding

class DoAndroidFragment : Fragment() {
companion object {
fun newInstance(): DoAndroidFragment {
return DoAndroidFragment()
}
}

private var _binding: FragmentDoAndroidBinding? = null
private val binding: FragmentDoAndroidBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.sopt.dosopttemplate.data.DummyFriendsData
import org.sopt.dosopttemplate.data.DummyFriendData
import org.sopt.dosopttemplate.databinding.FragmentHomeBinding
import org.sopt.dosopttemplate.presentation.adapter.FriendsSealedAdapter

class HomeFragment : Fragment() {
companion object {
fun newInstance(): HomeFragment {
return HomeFragment()
}
}

private var _binding: FragmentHomeBinding? = null
private val binding: FragmentHomeBinding
Expand All @@ -28,9 +33,9 @@ class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

var friendsSealedAdapter = FriendsSealedAdapter(requireContext())
val friendsSealedAdapter = FriendsSealedAdapter(requireContext())
binding.rvFriends.adapter = friendsSealedAdapter
friendsSealedAdapter.addFriendsData(ArrayList(DummyFriendsData.dummyFriendList))
friendsSealedAdapter.setFriendsData(ArrayList(DummyFriendData.dummyFriendList))
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import org.sopt.dosopttemplate.di.UserSharedPreferences
import org.sopt.dosopttemplate.presentation.auth.LoginActivity

class MypageFragment : Fragment() {
companion object {
fun newInstance(userId: String?, userNickname: String?, userAge: String?): MypageFragment {
val fragment = MypageFragment()
val args = Bundle()
args.putString("userId", userId)
args.putString("userNickname", userNickname)
args.putString("userAge", userAge)
Comment on lines +18 to +21
Copy link
Member

Choose a reason for hiding this comment

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

스코프 함수 써주면 더 예쁠듯 ~~

fragment.arguments = args
return fragment
}
}

private var _binding: FragmentMypageBinding? = null
private val binding: FragmentMypageBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FriendsSealedAdapter(context: Context) : RecyclerView.Adapter<RecyclerView

private var friendList: ArrayList<FriendsSealed> = ArrayList()

fun addFriendsData(list: ArrayList<FriendsSealed>) {
fun setFriendsData(list: ArrayList<FriendsSealed>) {
friendList.clear()
friendList.addAll(list)
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/color/bnv_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:state_checked="true"
android:color="@color/bnv_dark_purple" />

<item
android:state_checked="false"
android:color="@color/bnv_light_purple" />

</selector>
Comment on lines +2 to +12
Copy link
Member

Choose a reason for hiding this comment

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

오호 ~~~~~~~~ 좋아요

6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_bnv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
android:id="@+id/fcv_home"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="15dp"
app:layout_constraintBottom_toTopOf="@+id/bnv_home"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="15dp"/>
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_home"
android:layout_width="match_parent"
android:layout_height="80dp"
app:itemIconTint="@color/bnv_selector"
app:itemTextColor="@color/bnv_selector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<color name="text_gray">#808080</color>
<color name="birthday_red">#ff3300</color>
<color name="btn_light_gray">#D9D9D9</color>
<color name="bnv_dark_purple">#4D377B</color>
<color name="bnv_light_purple">#D1C4E9</color>
</resources>