From 6d82052c64c7170d798edaeea02dd0248db1c921 Mon Sep 17 00:00:00 2001 From: Sangwook123 Date: Mon, 23 Oct 2023 14:13:23 +0900 Subject: [PATCH 01/56] =?UTF-8?q?[add]=20icon=20=EB=A6=AC=EC=86=8C?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/drawable/baseline_alternate_email_24.xml | 5 +++++ app/src/main/res/drawable/baseline_home_24.xml | 5 +++++ app/src/main/res/drawable/baseline_person_24.xml | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 app/src/main/res/drawable/baseline_alternate_email_24.xml create mode 100644 app/src/main/res/drawable/baseline_home_24.xml create mode 100644 app/src/main/res/drawable/baseline_person_24.xml diff --git a/app/src/main/res/drawable/baseline_alternate_email_24.xml b/app/src/main/res/drawable/baseline_alternate_email_24.xml new file mode 100644 index 0000000..e6182db --- /dev/null +++ b/app/src/main/res/drawable/baseline_alternate_email_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/baseline_home_24.xml b/app/src/main/res/drawable/baseline_home_24.xml new file mode 100644 index 0000000..4c5e854 --- /dev/null +++ b/app/src/main/res/drawable/baseline_home_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/baseline_person_24.xml b/app/src/main/res/drawable/baseline_person_24.xml new file mode 100644 index 0000000..bd8dc80 --- /dev/null +++ b/app/src/main/res/drawable/baseline_person_24.xml @@ -0,0 +1,5 @@ + + + From e6dc0b9879e3a743994f9496b04b0aa767b9ab47 Mon Sep 17 00:00:00 2001 From: Sangwook123 Date: Mon, 23 Oct 2023 14:15:09 +0900 Subject: [PATCH 02/56] =?UTF-8?q?[add]=20menu=20=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=95=84=EC=9B=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/menu/main_menu.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/src/main/res/menu/main_menu.xml diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml new file mode 100644 index 0000000..d371b21 --- /dev/null +++ b/app/src/main/res/menu/main_menu.xml @@ -0,0 +1,17 @@ + + + + + + + + \ No newline at end of file From 43fcf306599ac3110b2b2c762489bf6797520849 Mon Sep 17 00:00:00 2001 From: Sangwook123 Date: Mon, 23 Oct 2023 14:15:33 +0900 Subject: [PATCH 03/56] =?UTF-8?q?[add]=20binding=20fragment=20=EC=9C=A0?= =?UTF-8?q?=ED=8B=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/binding/BindingFragment.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/src/main/java/org/sopt/dosopttemplate/util/binding/BindingFragment.kt diff --git a/app/src/main/java/org/sopt/dosopttemplate/util/binding/BindingFragment.kt b/app/src/main/java/org/sopt/dosopttemplate/util/binding/BindingFragment.kt new file mode 100644 index 0000000..0ac0c88 --- /dev/null +++ b/app/src/main/java/org/sopt/dosopttemplate/util/binding/BindingFragment.kt @@ -0,0 +1,33 @@ +package org.sopt.dosopttemplate.util.binding + +import android.os.Bundle +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 + +abstract class BindingFragment( + @LayoutRes private val layoutResId: Int +) : Fragment() { + private var _binding: T? = null + protected val binding: T + get() = requireNotNull(_binding) { "binding object is not initialized" } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + _binding = DataBindingUtil.inflate(inflater, layoutResId, container, false) + binding.lifecycleOwner = viewLifecycleOwner + return binding.root + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file From 20d19dbf05ffcc42819b0a36e753ee066412f109 Mon Sep 17 00:00:00 2001 From: Sangwook123 Date: Mon, 23 Oct 2023 14:19:57 +0900 Subject: [PATCH 04/56] =?UTF-8?q?[refactor]=20main=20activity=EC=97=90?= =?UTF-8?q?=EC=84=9C=20mypage=20fragment=EB=A1=9C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/main/MainActivity.kt | 59 ++++----- .../main/mypage/MyPageFragment.kt | 48 +++++++ app/src/main/res/layout/activity_main.xml | 104 ++------------- app/src/main/res/layout/fragment_mypage.xml | 118 ++++++++++++++++++ 4 files changed, 207 insertions(+), 122 deletions(-) create mode 100644 app/src/main/java/org/sopt/dosopttemplate/presentation/main/mypage/MyPageFragment.kt create mode 100644 app/src/main/res/layout/fragment_mypage.xml diff --git a/app/src/main/java/org/sopt/dosopttemplate/presentation/main/MainActivity.kt b/app/src/main/java/org/sopt/dosopttemplate/presentation/main/MainActivity.kt index 67d1390..b654db3 100644 --- a/app/src/main/java/org/sopt/dosopttemplate/presentation/main/MainActivity.kt +++ b/app/src/main/java/org/sopt/dosopttemplate/presentation/main/MainActivity.kt @@ -4,16 +4,18 @@ import android.content.Intent import android.os.Bundle import androidx.activity.OnBackPressedCallback import androidx.activity.viewModels +import androidx.fragment.app.Fragment +import androidx.fragment.app.commit +import androidx.fragment.app.replace import dagger.hilt.android.AndroidEntryPoint import org.sopt.dosopttemplate.R import org.sopt.dosopttemplate.databinding.ActivityMainBinding import org.sopt.dosopttemplate.presentation.login.LoginActivity -import org.sopt.dosopttemplate.presentation.main.MainViewModel.Companion.CODE_LOGOUT -import org.sopt.dosopttemplate.presentation.main.MainViewModel.Companion.CODE_WITHDRAW -import org.sopt.dosopttemplate.presentation.model.UserModel +import org.sopt.dosopttemplate.presentation.main.doandroid.DoAndroidFragment +import org.sopt.dosopttemplate.presentation.main.home.HomeFragment +import org.sopt.dosopttemplate.presentation.main.mypage.MyPageFragment import org.sopt.dosopttemplate.util.binding.BindingActivity import org.sopt.dosopttemplate.util.context.toast -import org.sopt.dosopttemplate.util.intent.getParcelable import org.sopt.dosopttemplate.util.view.UiState import org.sopt.dosopttemplate.util.view.snackBar @@ -36,34 +38,19 @@ class MainActivity : BindingActivity(R.layout.activity_main override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - getUserInfo() - initLogoutButtonClickListener() - initWithdrawButtonClickListener() - initLogoutStateObserver() initAddCallback() + initFragment() + initBnvItemSelectedListener() + initLogoutStateObserver() } private fun initAddCallback() { this.onBackPressedDispatcher.addCallback(this, callback)//콜백 등록 } - private fun getUserInfo() { - val intent = intent - val userModel = intent.getParcelable(USER_KEY, UserModel::class.java) - - binding.data = userModel - } - - private fun initLogoutButtonClickListener() { - binding.btnMainLogout.setOnClickListener { - viewModel.logout() - } - } - - private fun initWithdrawButtonClickListener() { - binding.btnMainWithdraw.setOnClickListener { - viewModel.withdraw() - } + private fun initFragment() { + navigateTo() + binding.bnvMain.selectedItemId = R.id.menu_home } private fun initLogoutStateObserver() { @@ -71,8 +58,8 @@ class MainActivity : BindingActivity(R.layout.activity_main when (state) { is UiState.Success -> { when (state.data) { - CODE_LOGOUT -> this.toast(getString(R.string.main_success_logout)) - CODE_WITHDRAW -> this.toast(getString(R.string.main_success_withdraw)) + MainViewModel.CODE_LOGOUT -> this.toast(getString(R.string.main_success_logout)) + MainViewModel.CODE_WITHDRAW -> this.toast(getString(R.string.main_success_withdraw)) } navigateToLoginScreen() } @@ -81,15 +68,29 @@ class MainActivity : BindingActivity(R.layout.activity_main } } } - private fun navigateToLoginScreen() { val intent = Intent(this, LoginActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) } + private fun initBnvItemSelectedListener() { + binding.bnvMain.setOnItemSelectedListener { item -> + when(item.itemId) { + R.id.menu_do_android -> navigateTo() + R.id.menu_home -> navigateTo() + R.id.menu_my_page -> navigateTo() + } + true + } + } + + private inline fun navigateTo() { + supportFragmentManager.commit { + replace(R.id.fcv_main, T::class.simpleName) + } + } companion object { private const val MIN_TOUCH_DURATION = 1500 - private const val USER_KEY = "user" } } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/dosopttemplate/presentation/main/mypage/MyPageFragment.kt b/app/src/main/java/org/sopt/dosopttemplate/presentation/main/mypage/MyPageFragment.kt new file mode 100644 index 0000000..a37d820 --- /dev/null +++ b/app/src/main/java/org/sopt/dosopttemplate/presentation/main/mypage/MyPageFragment.kt @@ -0,0 +1,48 @@ +package org.sopt.dosopttemplate.presentation.main.mypage + +import android.os.Bundle +import android.view.View +import androidx.fragment.app.activityViewModels +import dagger.hilt.android.AndroidEntryPoint +import org.sopt.dosopttemplate.R +import org.sopt.dosopttemplate.databinding.FragmentMypageBinding +import org.sopt.dosopttemplate.presentation.main.MainViewModel +import org.sopt.dosopttemplate.presentation.model.UserModel +import org.sopt.dosopttemplate.util.binding.BindingFragment +import org.sopt.dosopttemplate.util.intent.getParcelable + +@AndroidEntryPoint +class MyPageFragment : BindingFragment(R.layout.fragment_mypage) { + private val viewModel by activityViewModels() + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + getUserInfo() + initLogoutButtonClickListener() + initWithdrawButtonClickListener() + } + + private fun getUserInfo() { + val intent = requireActivity().intent + val userModel = intent.getParcelable(USER_KEY, UserModel::class.java) + + binding.data = userModel + } + + private fun initLogoutButtonClickListener() { + binding.btnMainLogout.setOnClickListener { + viewModel.logout() + } + } + + private fun initWithdrawButtonClickListener() { + binding.btnMainWithdraw.setOnClickListener { + viewModel.withdraw() + } + } + + companion object { + private const val USER_KEY = "user" + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2c2fac6..89a982e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,9 +5,6 @@ - - - - - - - - - - - - - - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" /> - -