From 7b627ac2c7573e0931ea9a4d8cc1f06c49f9b665 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 15:03:11 -0400 Subject: [PATCH] Implement ViewBinding in MoreFragment --- .../pennmobile/morefragments/MoreFragment.kt | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt index bf073268..cc93d3bf 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt @@ -12,15 +12,17 @@ import androidx.preference.PreferenceManager import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior +import com.pennapps.labs.pennmobile.databinding.FragmentHomeBinding +import com.pennapps.labs.pennmobile.databinding.FragmentMoreBinding import com.pennapps.labs.pennmobile.utils.Utils -import kotlinx.android.synthetic.main.fragment_home.initials -import kotlinx.android.synthetic.main.fragment_home.profile_background -import kotlinx.android.synthetic.main.fragment_home.view.appbar_home -import kotlinx.android.synthetic.main.fragment_home.view.date_view + class MoreFragment : Fragment() { private lateinit var mActivity: MainActivity + private var _binding: FragmentMoreBinding? = null + val binding get() = _binding!! + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mActivity = activity as MainActivity @@ -31,11 +33,11 @@ class MoreFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ): View? { - val view = inflater.inflate(R.layout.fragment_more, container, false) - - initAppBar(view) - return view + ): View { + _binding = FragmentMoreBinding.inflate(inflater, container, false) + val v = binding.root + initAppBar(v) + return v } override fun onViewCreated( @@ -51,12 +53,12 @@ class MoreFragment : Fragment() { } private fun initAppBar(view: View) { - view.date_view.text = Utils.getCurrentSystemTime() + binding.dateView.text = Utils.getCurrentSystemTime() // Appbar behavior init ( - view.appbar_home.layoutParams - as CoordinatorLayout.LayoutParams - ).behavior = ToolbarBehavior() + binding.appbarHome.layoutParams + as CoordinatorLayout.LayoutParams + ).behavior = ToolbarBehavior() } override fun onResume() { @@ -65,9 +67,9 @@ class MoreFragment : Fragment() { .getDefaultSharedPreferences(mActivity) .getString(getString(R.string.initials), null) if (initials != null && initials.isNotEmpty()) { - this.initials.text = initials + binding.initials.text = initials } else { - this.profile_background.setImageDrawable( + binding.profileBackground.setImageDrawable( ResourcesCompat.getDrawable( resources, R.drawable.ic_guest_avatar, @@ -78,4 +80,9 @@ class MoreFragment : Fragment() { mActivity.setSelectedTab(MainActivity.MORE) super.onResume() } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } }