Skip to content

Commit

Permalink
Code cleanup, ui fixes, and added padding to end of rv for fragment_s…
Browse files Browse the repository at this point in the history
…ubletter_posted_listings.xml to fix the cutoff issue (needs more investigation tho).
  • Loading branch information
meiron03 committed Apr 21, 2024
1 parent 64a8485 commit f648ac2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class SubletterPostedListingsFragment() : Fragment() {

//api manager
private lateinit var mStudentLife: StudentLife

private lateinit var mActivity: MainActivity

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -40,17 +39,12 @@ class SubletterPostedListingsFragment() : Fragment() {
mActivity = activity as MainActivity
mActivity.closeKeyboard()
dataModel = SublettingViewModel(mActivity, mStudentLife)

val bundle = Bundle()
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
_binding = FragmentSubletterPostedListingsBinding.inflate(inflater, container, false)
binding.postedAddListingButton.setOnClickListener{
navigateCreateNewListing()
}
return binding.root
}

Expand All @@ -60,17 +54,33 @@ class SubletterPostedListingsFragment() : Fragment() {
newLayoutManager = GridLayoutManager(context, 2, LinearLayoutManager.VERTICAL, false)
sublettingRecyclerView.layoutManager = newLayoutManager


dataModel.getPostedSublets(mActivity)
myAdapter = PostedSubletsListAdapter(dataModel)
dataModel.postedSubletsList.observe(viewLifecycleOwner, { sublets ->
dataModel.postedSubletsList.observe(viewLifecycleOwner) { sublets ->
binding.listingsRefreshLayout.isRefreshing = false

sublettingList = sublets
myAdapter.notifyDataSetChanged()
})

if (sublets.size > 0) {
binding.postedHouseImage.visibility = View.GONE
binding.postedNoListingsText.visibility = View.GONE
} else {
binding.postedHouseImage.visibility = View.VISIBLE
binding.postedNoListingsText.visibility = View.VISIBLE
}
}

sublettingRecyclerView.adapter = myAdapter

}
binding.listingsRefreshLayout.setOnRefreshListener {
dataModel.getPostedSublets(mActivity)
}

binding.postedAddListingButton.setOnClickListener{
navigateCreateNewListing()
}
}

private fun navigateCreateNewListing() {
val mainActivity = context as MainActivity
Expand All @@ -85,4 +95,8 @@ class SubletterPostedListingsFragment() : Fragment() {
.commitAllowingStateLoss()
}

override fun onDestroy() {
super.onDestroy()
_binding = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,5 @@ class SublettingFragment : Fragment() {
tab.text = "Sublessee"
}
}.attach()


}


private fun initAppBar(view: View) {
(view.appbar_home_holder.layoutParams as CoordinatorLayout.LayoutParams).behavior = ToolbarBehavior()
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ class PostedSubletsListAdapter(private val dataModel: SublettingViewModel):
private lateinit var mActivity: MainActivity

class SublettingCardViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {

var listingImage = itemView.findViewById<ImageView>(R.id.subletting_cardview_image)
var listingTitle = itemView.findViewById<TextView>(R.id.subletting_cardview_title)
var listingPrice = itemView.findViewById<TextView>(R.id.subletting_cardview_price)
var listingRooms = itemView.findViewById<TextView>(R.id.subletting_cardview_rooms)
var listingDates = itemView.findViewById<TextView>(R.id.subletting_cardview_dates)


var listingImage: ImageView = itemView.findViewById(R.id.subletting_cardview_image)
var listingTitle: TextView = itemView.findViewById(R.id.subletting_cardview_title)
var listingPrice: TextView = itemView.findViewById(R.id.subletting_cardview_price)
var listingRooms: TextView = itemView.findViewById(R.id.subletting_cardview_rooms)
var listingDates: TextView = itemView.findViewById(R.id.subletting_cardview_dates)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SublettingCardViewHolder {
Expand All @@ -47,21 +44,17 @@ class PostedSubletsListAdapter(private val dataModel: SublettingViewModel):
}

override fun onBindViewHolder(holder: SublettingCardViewHolder, position: Int) {

var mSublettingCard: Sublet = dataModel.getSublet(position) // dataModel.getSblet(position)
//holder.listingImage.setImageResource(mSublettingCard.listingImage!!)
val mSublettingCard: Sublet = dataModel.getSublet(position) // dataModel.getSublet(position)

Glide.with(mContext) // Use mContext here instead of context
.load(mSublettingCard.images?.get(0)?.imageUrl) // Access the first image URL from the list
.centerCrop() // optional - adjust as needed
.transition(DrawableTransitionOptions.withCrossFade())
.into(holder.listingImage)


holder.listingTitle.text = mSublettingCard.title

var price = "$" + mSublettingCard.price.toString()

val price = "$" + mSublettingCard.price.toString()
holder.listingPrice.text = price

val rooms = mSublettingCard.beds.toString() + " bd | " +
Expand All @@ -75,11 +68,11 @@ class PostedSubletsListAdapter(private val dataModel: SublettingViewModel):
.addToBackStack(null)
.commit()
}
holder.listingDates.setSingleLine(false);

holder.listingDates.isSingleLine = false;
holder.listingDates.text = mSublettingCard.startDate + " to \n" + mSublettingCard.endDate
}


override fun getItemCount(): Int {
return dataModel.postedSubletsList.value?.size ?: 0
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">


<ImageView
android:id="@+id/posted_house_image"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -38,29 +36,33 @@
android:radius="30sp"
android:text="@string/add_listing"
android:textColor="@color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/listings_refresh_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/posted_add_listing_button"
app:layout_constraintVertical_bias="1.0">
app:layout_constraintTop_toBottomOf="@+id/posted_add_listing_button"
app:layout_constraintVertical_bias="0.0">


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/posted_sublets_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"/>

app:layout_constraintTop_toTopOf="@+id/posted_add_listing_button"
android:paddingBottom="50dp"/>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion PennMobile/src/main/res/layout/subletting_cardview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/subletting_cardview_item"
android:layout_width="200dp"
android:layout_height="340dp"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardElevation="5dp"
app:cardPreventCornerOverlap="true"
Expand Down

0 comments on commit f648ac2

Please sign in to comment.