From f4a3fab3416fc243ac8e6d5e14f4cf12cf1205b5 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Wed, 15 May 2024 17:51:38 +0900 Subject: [PATCH] =?UTF-8?q?[mod]=20#8=20BindingActivity,=20BindingFragment?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/main/MainActivity.kt | 20 ++--------- .../main/home/recommend/RecommendFragment.kt | 24 ++------------ .../ui/main/home/release/ReleaseFragment.kt | 24 ++------------ .../ui/productdetail/ProductDetailFragment.kt | 33 ++----------------- .../presentation/ui/search/SearchFragment.kt | 33 ++----------------- 5 files changed, 10 insertions(+), 124 deletions(-) diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/MainActivity.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/MainActivity.kt index 0b1e6a1..07def1b 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/MainActivity.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/MainActivity.kt @@ -1,22 +1,6 @@ package org.sopt.kream.presentation.ui.main -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import org.sopt.kream.databinding.ActivityMainBinding +import org.sopt.kream.util.base.BindingActivity -class MainActivity : AppCompatActivity() { - private var _binding: ActivityMainBinding? = null - private val binding: ActivityMainBinding - get() = requireNotNull(_binding) - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - _binding = ActivityMainBinding.inflate(layoutInflater) - setContentView(binding.root) - } - - override fun onDestroy() { - super.onDestroy() - _binding = null - } -} +class MainActivity : BindingActivity({ ActivityMainBinding.inflate(it) }) diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt index 210e1b2..1718811 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/recommend/RecommendFragment.kt @@ -1,28 +1,13 @@ package org.sopt.kream.presentation.ui.main.home.recommend import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import org.sopt.kream.R import org.sopt.kream.databinding.FragmentRecommendBinding +import org.sopt.kream.util.base.BindingFragment -class RecommendFragment : Fragment() { - private var _binding: FragmentRecommendBinding? = null - private val binding: FragmentRecommendBinding - get() = requireNotNull(_binding) { } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View? { - _binding = FragmentRecommendBinding.inflate(inflater, container, false) - return binding.root - } - +class RecommendFragment : BindingFragment({ FragmentRecommendBinding.inflate(it) }) { override fun onViewCreated( view: View, savedInstanceState: Bundle?, @@ -33,9 +18,4 @@ class RecommendFragment : Fragment() { findNavController().navigate(R.id.releaseFragment) } } - - override fun onDestroy() { - super.onDestroy() - _binding = null - } } diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt index d8b3ecd..db71c1c 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/main/home/release/ReleaseFragment.kt @@ -1,28 +1,13 @@ package org.sopt.kream.presentation.ui.main.home.release import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.fragment.app.Fragment import org.sopt.kream.databinding.FragmentReleaseBinding +import org.sopt.kream.util.base.BindingFragment -class ReleaseFragment : Fragment() { - private var _binding: FragmentReleaseBinding? = null - private val binding: FragmentReleaseBinding - get() = requireNotNull(_binding) { } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View? { - _binding = FragmentReleaseBinding.inflate(inflater, container, false) - return binding.root - } - +class ReleaseFragment : BindingFragment({ FragmentReleaseBinding.inflate(it) }) { override fun onViewCreated( view: View, savedInstanceState: Bundle?, @@ -33,11 +18,6 @@ class ReleaseFragment : Fragment() { } } - override fun onDestroy() { - super.onDestroy() - _binding = null - } - @Composable fun releaseScreen() { Text(text = "Release") diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/productdetail/ProductDetailFragment.kt b/app/src/main/java/org/sopt/kream/presentation/ui/productdetail/ProductDetailFragment.kt index 51b4093..91ab71b 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/productdetail/ProductDetailFragment.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/productdetail/ProductDetailFragment.kt @@ -1,35 +1,6 @@ package org.sopt.kream.presentation.ui.productdetail -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment import org.sopt.kream.databinding.FragmentProductDetailBinding +import org.sopt.kream.util.base.BindingFragment -class ProductDetailFragment : Fragment() { - private var _binding: FragmentProductDetailBinding? = null - private val binding: FragmentProductDetailBinding - get() = requireNotNull(_binding) { } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View? { - _binding = FragmentProductDetailBinding.inflate(inflater, container, false) - return binding.root - } - - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { - super.onViewCreated(view, savedInstanceState) - } - - override fun onDestroy() { - super.onDestroy() - _binding = null - } -} +class ProductDetailFragment : BindingFragment({ FragmentProductDetailBinding.inflate(it) }) diff --git a/app/src/main/java/org/sopt/kream/presentation/ui/search/SearchFragment.kt b/app/src/main/java/org/sopt/kream/presentation/ui/search/SearchFragment.kt index 0ddc87a..764193f 100644 --- a/app/src/main/java/org/sopt/kream/presentation/ui/search/SearchFragment.kt +++ b/app/src/main/java/org/sopt/kream/presentation/ui/search/SearchFragment.kt @@ -1,35 +1,6 @@ package org.sopt.kream.presentation.ui.search -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment import org.sopt.kream.databinding.FragmentSearchBinding +import org.sopt.kream.util.base.BindingFragment -class SearchFragment : Fragment() { - private var _binding: FragmentSearchBinding? = null - private val binding: FragmentSearchBinding - get() = requireNotNull(_binding) { } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View? { - _binding = FragmentSearchBinding.inflate(inflater, container, false) - return binding.root - } - - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { - super.onViewCreated(view, savedInstanceState) - } - - override fun onDestroy() { - super.onDestroy() - _binding = null - } -} +class SearchFragment : BindingFragment({ FragmentSearchBinding.inflate(it) })