Skip to content

Commit

Permalink
update dataModel stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
vavali08 committed Jan 26, 2024
1 parent 53afc43 commit 4f5439b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
private var description: String? = null
private lateinit var amenities: List<AmenitiesItem>

private lateinit var mActivity: MainActivity



override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -108,9 +111,22 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
endDate : String, beds: Int?, baths: Int?, amenities: List<AmenitiesItem>,
description: String?) {

Sublet newSublet =

//dataModel.postSublet(mActivity, )
val newSublet = Sublet(
endDate = endDate,
amenities = amenities,
baths = baths,
address = address,
maxPrice = price,//fix
expiresAt = " ",
minPrice = 0, // fix
description = description,
title = title,
beds = beds,
externalLink = " ", // fix
startDate = startDate
)

dataModel.postSublet(mActivity, newSublet)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.pennapps.labs.pennmobile.classes.SublettingViewModel
import com.pennapps.labs.pennmobile.databinding.FragmentSubletterDraftListingsBinding
import com.pennapps.labs.pennmobile.databinding.FragmentSubletterPostedListingsBinding

class SubletterDraftListingsFragment : Fragment() {
class SubletterDraftListingsFragment(private val dataModel: SublettingViewModel) : Fragment() {
private var _binding: FragmentSubletterDraftListingsBinding? = null
private val binding get() = _binding!!
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -27,13 +28,15 @@ class SubletterDraftListingsFragment : Fragment() {

private fun navigateCreateNewListing() {
val mainActivity = activity as MainActivity
val fragment = NewListingsFragment()
val fragment = NewListingsFragment(dataModel)

val fragmentManager = mainActivity.supportFragmentManager
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment, "NEW_LISTING_FRAGMENT")
.addToBackStack(null)
.commitAllowingStateLoss()



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.SublettingViewModel

// TODO: Rename parameter arguments, choose names that match

Expand All @@ -22,19 +24,23 @@ class SubletterFragment : Fragment() {
lateinit var subletterPagerAdapter: SubletterPagerAdapter
private lateinit var mActivity: MainActivity
private lateinit var viewPager: ViewPager2
private lateinit var mStudentLife : StudentLife
private lateinit var dataModel : SublettingViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mActivity = activity as MainActivity
mActivity.closeKeyboard()
mStudentLife = MainActivity.studentLifeInstance
dataModel = SublettingViewModel(mActivity, mStudentLife)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val rootView = inflater.inflate(R.layout.fragment_subletter_view, container, false)
viewPager = rootView.findViewById(R.id.subletter_view_pager)
subletterPagerAdapter = SubletterPagerAdapter(this)
subletterPagerAdapter = SubletterPagerAdapter(this, dataModel)
viewPager.adapter = subletterPagerAdapter

val tabLayout: TabLayout = rootView.findViewById(R.id.subletter_tab_layout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@ import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.pennapps.labs.pennmobile.adapters.SubletterPagerAdapter
import com.pennapps.labs.pennmobile.adapters.SublettingPagerAdapter
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.SublettingViewModel
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior
import kotlinx.android.synthetic.main.fragment_dining_holder.view.appbar_home_holder

class SubletterHolderFragment : Fragment() {
lateinit var subletterPagerAdapter: SubletterPagerAdapter
private lateinit var mActivity: MainActivity
private lateinit var viewPager: ViewPager2
private lateinit var mStudentLife : StudentLife
private lateinit var dataModel : SublettingViewModel




override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mActivity = activity as MainActivity
mActivity.closeKeyboard()
mStudentLife = MainActivity.studentLifeInstance
dataModel = SublettingViewModel(mActivity, mStudentLife)

}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_subletting, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
subletterPagerAdapter = SubletterPagerAdapter(this)
subletterPagerAdapter = SubletterPagerAdapter(this, dataModel)
viewPager = view.findViewById(R.id.viewPager2)
viewPager.adapter = subletterPagerAdapter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.pennapps.labs.pennmobile.classes.SublettingViewModel
import com.pennapps.labs.pennmobile.databinding.FragmentSubletterPostedListingsBinding

class SubletterPostedListingsFragment : Fragment() {
class SubletterPostedListingsFragment(private val dataModel: SublettingViewModel) : Fragment() {
private var _binding: FragmentSubletterPostedListingsBinding? = null
private val binding get() = _binding!!
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -28,7 +29,8 @@ class SubletterPostedListingsFragment : Fragment() {

private fun navigateCreateNewListing() {
val mainActivity = context as MainActivity
val fragment = NewListingsFragment()

val fragment = NewListingsFragment(dataModel)

val fragmentManager = mainActivity.supportFragmentManager
fragmentManager.beginTransaction()
Expand All @@ -37,6 +39,8 @@ class SubletterPostedListingsFragment : Fragment() {
.addToBackStack(null)
.commitAllowingStateLoss()



}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.pennapps.labs.pennmobile.SubletterDraftListingsFragment
import com.pennapps.labs.pennmobile.SubletterPostedListingsFragment
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.SublettingViewModel

class SubletterPagerAdapter(fragment: Fragment, private val dataModel: SublettingViewModel) : FragmentStateAdapter(fragment) {

class SubletterPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 2
override fun createFragment(position: Int): Fragment {
return if (position == 0) {
SubletterPostedListingsFragment()
SubletterPostedListingsFragment(dataModel)
} else {
SubletterDraftListingsFragment()
SubletterDraftListingsFragment(dataModel)
}
}

Expand Down

0 comments on commit 4f5439b

Please sign in to comment.