From b41a668ad23c8f879f6599dba0fbd12e8e11de0b Mon Sep 17 00:00:00 2001 From: vavali08 Date: Mon, 4 Dec 2023 13:07:16 -0500 Subject: [PATCH] Finished setting up second tablayout inside SubletterFragment --- .../labs/pennmobile/SubletterFragment.kt | 24 +++++++++++++++---- .../pennmobile/SubletterHolderFragment.kt | 5 +--- .../res/layout/fragment_subletter_view.xml | 4 +++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterFragment.kt index 17348d4a..622a90ac 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterFragment.kt @@ -6,12 +6,12 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout +import com.google.android.material.tabs.TabLayoutMediator import com.pennapps.labs.pennmobile.adapters.SubletterPagerAdapter // TODO: Rename parameter arguments, choose names that match -// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER -private const val ARG_PARAM1 = "param1" -private const val ARG_PARAM2 = "param2" + /** * A simple [Fragment] subclass. @@ -32,7 +32,23 @@ class SubletterFragment : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_subletter_view, container, false) + val rootView = inflater.inflate(R.layout.fragment_subletter_view, container, false) + viewPager = rootView.findViewById(R.id.subletter_view_pager) + subletterPagerAdapter = SubletterPagerAdapter(this) + viewPager.adapter = subletterPagerAdapter + + val tabLayout: TabLayout = rootView.findViewById(R.id.subletter_tab_layout) + TabLayoutMediator(tabLayout, viewPager) { tab, position -> + if(position == 0) { + tab.text = "Posted" + } else { + tab.text = "Drafts" + } + + }.attach() + + return rootView + } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterHolderFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterHolderFragment.kt index 6e75c397..bd494808 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterHolderFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterHolderFragment.kt @@ -34,10 +34,7 @@ class SubletterHolderFragment : Fragment() { subletterPagerAdapter = SubletterPagerAdapter(this) viewPager = view.findViewById(R.id.viewPager2) viewPager.adapter = subletterPagerAdapter - val tabLayout : TabLayout = view.findViewById(R.id.subletting_tab_layout) - TabLayoutMediator(tabLayout, viewPager) { tab, position -> - tab.text = "OBJECT ${(position + 1)}" - }.attach() + } diff --git a/PennMobile/src/main/res/layout/fragment_subletter_view.xml b/PennMobile/src/main/res/layout/fragment_subletter_view.xml index ab3431b5..815cdef6 100644 --- a/PennMobile/src/main/res/layout/fragment_subletter_view.xml +++ b/PennMobile/src/main/res/layout/fragment_subletter_view.xml @@ -34,10 +34,12 @@ android:id="@+id/subletter_tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="20sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/my_listings_text" - /> + app:tabIndicatorColor="@color/color_bottom_nav_selected" + app:tabTextAppearance="@style/TextAppearance.AppCompat.Small" />