From 5ca58410f392aa515e67caa1f82eaee8de0cd63b Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Sat, 8 Apr 2023 14:52:09 +0900 Subject: [PATCH 01/23] =?UTF-8?q?[ADD/#3]=20gallery,=20home,=20search=20Fr?= =?UTF-8?q?agment=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../go/sopt/presentation/main/MainActivity.kt | 26 -------- .../main/gallery/GalleryFragment.kt | 17 ++++++ .../presentation/main/home/HomeFragment.kt | 17 ++++++ .../main/search/SearchFragment.kt | 15 +++++ .../go/sopt/util/binding/BindingFragment.kt | 33 +++++++++++ app/src/main/res/layout/activity_main.xml | 59 ------------------- app/src/main/res/layout/fragment_gallery.xml | 20 +++++++ app/src/main/res/layout/fragment_home.xml | 21 +++++++ app/src/main/res/layout/fragment_search.xml | 21 +++++++ app/src/main/res/values/strings.xml | 3 + 10 files changed, 147 insertions(+), 85 deletions(-) create mode 100644 app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt create mode 100644 app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt create mode 100644 app/src/main/java/org/android/go/sopt/presentation/main/search/SearchFragment.kt create mode 100644 app/src/main/java/org/android/go/sopt/util/binding/BindingFragment.kt create mode 100644 app/src/main/res/layout/fragment_gallery.xml create mode 100644 app/src/main/res/layout/fragment_home.xml create mode 100644 app/src/main/res/layout/fragment_search.xml diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt index 1601192..f631898 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt @@ -1,15 +1,11 @@ package org.android.go.sopt.presentation.main -import android.content.Intent import android.os.Bundle import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.ActivityMainBinding -import org.android.go.sopt.presentation.login.LoginActivity import org.android.go.sopt.util.binding.BindingActivity -import org.android.go.sopt.util.extension.setOnSingleClickListener -import org.android.go.sopt.util.extension.showToast @AndroidEntryPoint class MainActivity : BindingActivity(R.layout.activity_main) { @@ -17,27 +13,5 @@ class MainActivity : BindingActivity(R.layout.activity_main override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - - getUserData() - initLogoutAndLeaveBtnClickListener() - } - - private fun getUserData() { - viewModel.getSignedUpUser().also { user -> - with(binding) { - tvMainName.text = getString(R.string.main_name, user.name) - tvMainSpecialty.text = getString(R.string.main_specialty, user.specialty) - tvMainMbti.text = getString(R.string.main_mbti, user.mbti ?: "") - } - } - } - - private fun initLogoutAndLeaveBtnClickListener() { - binding.btnMainLogoutAndLeave.setOnSingleClickListener { - viewModel.clearLocalPref() - showToast(getString(R.string.main_logout_and_leave_msg)) - startActivity(Intent(this, LoginActivity::class.java)) - finish() - } } } diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt new file mode 100644 index 0000000..f34375c --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/presentation/main/gallery/GalleryFragment.kt @@ -0,0 +1,17 @@ +package org.android.go.sopt.presentation.main.gallery + +import android.os.Bundle +import android.view.View +import org.android.go.sopt.R +import org.android.go.sopt.databinding.FragmentGalleryBinding +import org.android.go.sopt.util.binding.BindingFragment + +class GalleryFragment : BindingFragment(R.layout.fragment_gallery) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } + + companion object { + fun newInstance() = GalleryFragment() + } +} diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt new file mode 100644 index 0000000..64f5c6c --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeFragment.kt @@ -0,0 +1,17 @@ +package org.android.go.sopt.presentation.main.home + +import android.os.Bundle +import android.view.View +import org.android.go.sopt.R +import org.android.go.sopt.databinding.FragmentHomeBinding +import org.android.go.sopt.util.binding.BindingFragment + +class HomeFragment : BindingFragment(R.layout.fragment_home) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } + + companion object { + fun newInstance() = HomeFragment() + } +} diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/search/SearchFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/search/SearchFragment.kt new file mode 100644 index 0000000..1ad4217 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/presentation/main/search/SearchFragment.kt @@ -0,0 +1,15 @@ +package org.android.go.sopt.presentation.main.search + +import android.os.Bundle +import android.view.View +import org.android.go.sopt.R +import org.android.go.sopt.databinding.FragmentSearchBinding +import org.android.go.sopt.util.binding.BindingFragment + +class SearchFragment : BindingFragment(R.layout.fragment_search) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } + + fun newInstance() = SearchFragment() +} diff --git a/app/src/main/java/org/android/go/sopt/util/binding/BindingFragment.kt b/app/src/main/java/org/android/go/sopt/util/binding/BindingFragment.kt new file mode 100644 index 0000000..be790ed --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/util/binding/BindingFragment.kt @@ -0,0 +1,33 @@ +package org.android.go.sopt.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 +import org.android.go.sopt.R + +abstract class BindingFragment( + @LayoutRes private val layoutRes: Int, +) : Fragment() { + private var _binding: T? = null + protected val binding get() = _binding ?: error(getString(R.string.binding_error_msg)) + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View? { + _binding = DataBindingUtil.inflate(inflater, layoutRes, container, false) + binding.lifecycleOwner = viewLifecycleOwner + return binding.root + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 522e850..36d851b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ @@ -13,63 +12,5 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - - - -