diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewListingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewListingsFragment.kt index 3a65dba5..eef236c4 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewListingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewListingsFragment.kt @@ -48,6 +48,9 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment private var description: String? = null private lateinit var amenities: List + private lateinit var mActivity: MainActivity + + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -108,9 +111,22 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment endDate : String, beds: Int?, baths: Int?, amenities: List, 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) } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterDraftListingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterDraftListingsFragment.kt index cde5f547..4ff596f1 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterDraftListingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterDraftListingsFragment.kt @@ -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?) { @@ -27,7 +28,7 @@ class SubletterDraftListingsFragment : Fragment() { private fun navigateCreateNewListing() { val mainActivity = activity as MainActivity - val fragment = NewListingsFragment() + val fragment = NewListingsFragment(dataModel) val fragmentManager = mainActivity.supportFragmentManager fragmentManager.beginTransaction() @@ -35,5 +36,7 @@ class SubletterDraftListingsFragment : Fragment() { .addToBackStack(null) .commitAllowingStateLoss() + + } } \ No newline at end of file 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 622a90ac..dea4a7c0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterFragment.kt @@ -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 @@ -22,11 +24,15 @@ 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?, @@ -34,7 +40,7 @@ class SubletterFragment : Fragment() { // 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) 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 bd494808..4ef74352 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterHolderFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterHolderFragment.kt @@ -11,6 +11,8 @@ 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 @@ -18,12 +20,19 @@ 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?, @@ -31,7 +40,7 @@ class SubletterHolderFragment : Fragment() { 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 diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterPostedListingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterPostedListingsFragment.kt index 3d0ca8fe..25c1dc29 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterPostedListingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SubletterPostedListingsFragment.kt @@ -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?) { @@ -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() @@ -37,6 +39,8 @@ class SubletterPostedListingsFragment : Fragment() { .addToBackStack(null) .commitAllowingStateLoss() + + } } \ No newline at end of file diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SubletterPagerAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SubletterPagerAdapter.kt index 3475088c..d6d0eced 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SubletterPagerAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SubletterPagerAdapter.kt @@ -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) } }