From 4e0b0bf55fdb67b26529450c06372487e8225060 Mon Sep 17 00:00:00 2001 From: vavali08 Date: Sun, 20 Oct 2024 13:44:44 -0400 Subject: [PATCH] various random ui tweaks/updates (images, text formatting, etc) --- .../Subletting/NewListingsFragment.kt | 73 +++++++++-- .../Subletting/SubletDetailsFragment.kt | 51 ++++++-- .../adapters/PostedSubletsListAdapter.kt | 27 +++- .../main/res/drawable/subletting_square.xml | 30 +++++ .../res/layout/fragment_sublet_details.xml | 76 +++++++++-- .../layout/fragment_subletter_new_listing.xml | 119 ++++++++++++++++-- .../main/res/layout/subletting_cardview.xml | 12 +- PennMobile/src/main/res/values/strings.xml | 5 + 8 files changed, 352 insertions(+), 41 deletions(-) create mode 100644 PennMobile/src/main/res/drawable/subletting_square.xml diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/NewListingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/NewListingsFragment.kt index ed424520..a502b476 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/NewListingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/NewListingsFragment.kt @@ -1,6 +1,7 @@ package com.pennapps.labs.pennmobile.Subletting import android.graphics.BitmapFactory +import android.media.Image import android.os.Bundle import android.util.Log import android.view.LayoutInflater @@ -68,6 +69,17 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment internal lateinit var imageIcon: ImageView internal lateinit var imageText: TextView + internal lateinit var moreImagesView: ImageView + internal lateinit var image1 :ImageView + internal lateinit var image2 : ImageView + internal lateinit var image3 : ImageView + internal lateinit var image4 : ImageView + internal lateinit var image5 : ImageView + + var imageCount = 0; + val imageParts = mutableListOf() + + @@ -143,6 +155,15 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment imageView = binding.mainImage imageIcon = binding.mainImageIcon imageText = binding.addPhotosText + moreImagesView = binding.addImage + image1 = binding.image1 + image2 = binding.image2 + image3 = binding.image3 + image4 = binding.image4 + image5 = binding.image5 + + val imageParts = mutableListOf() + val pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> @@ -155,12 +176,32 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment val inputStream = context?.contentResolver?.openInputStream(uri) val bitmap = BitmapFactory.decodeStream(inputStream) image = bitmap.toString() - imageView.setImageBitmap(bitmap) - imageIcon.visibility = View.GONE - imageText.visibility = View.GONE - multipartImage = MultipartUtil.createPartFromBitmap(bitmap) - + if (imageCount <= 5) { + if (imageCount == 0) { + imageView.setImageBitmap(bitmap) + imageIcon.visibility = View.GONE + imageText.visibility = View.GONE + } else if (imageCount == 1) { + image1.setImageBitmap(bitmap) + } else if (imageCount == 2) { + image2.setImageBitmap(bitmap) + } else if (imageCount == 3) { + image3.setImageBitmap(bitmap) + } else if (imageCount == 4) { + image4.setImageBitmap(bitmap) + } else { + image5.setImageBitmap(bitmap) + } + + multipartImage = MultipartUtil.createPartFromBitmap(bitmap) + if (multipartImage != null) { + imageParts.add(multipartImage!!) + } + } + + + imageCount++ inputStream?.close() } catch (e: IOException) { @@ -176,6 +217,19 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } + moreImagesView.setOnClickListener { + if (imageCount == 0) { + Toast.makeText(activity, "Please select main image first.", + Toast.LENGTH_LONG).show() + } else if (imageCount > 5) { + Toast.makeText(activity, "Image Limit Reached", Toast.LENGTH_LONG).show() + } + else { + pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) + } + + } + val dateRegex = Regex("""^(0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/\d{2}$""") @@ -273,13 +327,12 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment } } - if (multipartImage != null) { - val subletPart = MultipartUtil.createSubletPart(subletId) - dataModel.postImage(mActivity, subletId, subletPart, multipartImage!!) - } - + val subletPart = MultipartUtil.createSubletPart(subletId) + for (part in imageParts) { + dataModel.postImage(mActivity, subletId, subletPart, part) + } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletDetailsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletDetailsFragment.kt index 0cc5569c..7914b1fb 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletDetailsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletDetailsFragment.kt @@ -13,8 +13,14 @@ import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.Sublet +import com.pennapps.labs.pennmobile.classes.SubletImage import com.pennapps.labs.pennmobile.classes.SublettingViewModel import com.pennapps.labs.pennmobile.databinding.FragmentSubletDetailsBinding +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") +val outputFormatter = DateTimeFormatter.ofPattern("MMMM d, yyyy") class SubletDetailsFragment(private val dataModel: SublettingViewModel, private val subletNumber: Int) : Fragment() { private var _binding: FragmentSubletDetailsBinding? = null @@ -38,15 +44,46 @@ class SubletDetailsFragment(private val dataModel: SublettingViewModel, private binding.titleText.text = sublet.title binding.priceText.text = "$" + sublet.price.toString() binding.addressText.text = sublet.address - binding.datesText.text = sublet.startDate + " to " + sublet.endDate + + + + val startDate = LocalDate.parse(sublet.startDate, inputFormatter) + val endDate = LocalDate.parse(sublet.endDate, inputFormatter) + +// Format the dates to "Month Day, Year" + val formattedStartDate = startDate.format(outputFormatter) + val formattedEndDate = endDate.format(outputFormatter) + +// Set the formatted dates to the TextView + binding.datesText.text = "$formattedStartDate to $formattedEndDate" + //binding.datesText.text = sublet.startDate + " to " + sublet.endDate binding.descriptionText.text = sublet.description ?: "None" binding.amenitiesText.text = sublet.amenities?.joinToString(", ") ?: "No amenities available" - context?.let { - Glide.with(it) - .load(sublet.images?.get(0)?.imageUrl) - .centerCrop() // optional - adjust as needed - .transition(DrawableTransitionOptions.withCrossFade()) - .into(binding.subletImage) + + val images : List? = sublet.images + + val imageViews = listOf( + binding.image1, + binding.image2, + binding.image3, + binding.image4, + binding.image5, + binding.image6 + ) + + var count = 0 + if (images != null) { + while (count < sublet.images.size && count < imageViews.size) { + val imageUrl = sublet.images[count]?.imageUrl + context?.let { + Glide.with(it) + .load(imageUrl) + .centerCrop() + .transition(DrawableTransitionOptions.withCrossFade()) + .into(imageViews[count]) // Dynamically load into the right image view + } + count++ + } } binding.availableButton.setOnClickListener{ diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PostedSubletsListAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PostedSubletsListAdapter.kt index 6d98bcdd..f58b58ab 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PostedSubletsListAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PostedSubletsListAdapter.kt @@ -1,6 +1,7 @@ package com.pennapps.labs.pennmobile.adapters import android.content.Context +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -20,6 +21,11 @@ import com.pennapps.labs.pennmobile.classes.SublettingModel import com.pennapps.labs.pennmobile.classes.SublettingViewModel import kotlinx.android.synthetic.main.include_main.expandable_bottom_bar import kotlinx.android.synthetic.main.include_main.toolbar +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") +val outputFormatter = DateTimeFormatter.ofPattern("MMMM d, yyyy") class PostedSubletsListAdapter(private val dataModel: SublettingViewModel): RecyclerView.Adapter() { @@ -72,8 +78,27 @@ class PostedSubletsListAdapter(private val dataModel: SublettingViewModel): .commit() } + val startDate = LocalDate.parse(mSublettingCard.startDate, + inputFormatter + ) + val endDate = LocalDate.parse(mSublettingCard.endDate, + inputFormatter + ) + + val formattedStartDate = startDate.format(outputFormatter) + val formattedEndDate = endDate.format(outputFormatter) + Log.d("Formatted Date", formattedStartDate) + Log.e("Date", formattedEndDate) + + holder.listingDates.isSingleLine = false; - holder.listingDates.text = mSublettingCard.startDate + " to \n" + mSublettingCard.endDate + + holder.listingDates.text = buildString { + append(formattedStartDate) + append(" - ") + append(formattedEndDate) + } + } override fun getItemCount(): Int { diff --git a/PennMobile/src/main/res/drawable/subletting_square.xml b/PennMobile/src/main/res/drawable/subletting_square.xml new file mode 100644 index 00000000..b718caba --- /dev/null +++ b/PennMobile/src/main/res/drawable/subletting_square.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PennMobile/src/main/res/layout/fragment_sublet_details.xml b/PennMobile/src/main/res/layout/fragment_sublet_details.xml index 19a89995..f4dda427 100644 --- a/PennMobile/src/main/res/layout/fragment_sublet_details.xml +++ b/PennMobile/src/main/res/layout/fragment_sublet_details.xml @@ -26,7 +26,7 @@ android:fontFamily="@font/sf_pro_display_bold" android:text="Edit" android:textColor="@color/pennmobile_blue" - app:layout_constraintBottom_toBottomOf="@id/title_text" + app:layout_constraintBottom_toTopOf="@id/title_text" app:layout_constraintEnd_toStartOf="@id/delete_text" app:layout_constraintTop_toTopOf="parent" /> @@ -38,7 +38,7 @@ android:fontFamily="@font/sf_pro_display_bold" android:text="Delete" android:textColor="@color/pennmobile_blue" - app:layout_constraintBottom_toBottomOf="@id/title_text" + app:layout_constraintBottom_toTopOf="@id/title_text" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -46,27 +46,77 @@ android:id="@+id/title_text" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="26dp" + android:layout_marginStart="26sp" android:fontFamily="@font/sf_pro_display_bold" android:text="@string/title" android:textSize="26sp" - android:layout_marginEnd="36dp" + android:paddingRight="26sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/edit_text" /> - + app:layout_constraintTop_toBottomOf="@id/title_text"> + + + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/sublet_images" /> + + diff --git a/PennMobile/src/main/res/layout/fragment_subletter_new_listing.xml b/PennMobile/src/main/res/layout/fragment_subletter_new_listing.xml index b9eda388..e69a938f 100644 --- a/PennMobile/src/main/res/layout/fragment_subletter_new_listing.xml +++ b/PennMobile/src/main/res/layout/fragment_subletter_new_listing.xml @@ -74,6 +74,111 @@ app:layout_constraintStart_toStartOf="@id/main_image" app:layout_constraintTop_toTopOf="@id/main_image" /> + + + + + + + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/images_scroll_view" /> @@ -623,7 +728,7 @@ android:layout_height="wrap_content" android:layout_marginStart="26sp" android:fontFamily="@font/sf_pro_display_regular" - android:text="Accessibility Features" + android:text="@string/accessibility_features" android:textSize="16sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/security_check" /> @@ -634,7 +739,7 @@ android:layout_height="wrap_content" android:layout_marginStart="10sp" android:fontFamily="@font/sf_pro_display_regular" - android:text="Heating" + android:text="@string/heating" android:textSize="16sp" app:layout_constraintStart_toEndOf="@id/accessibility_check" app:layout_constraintTop_toBottomOf="@id/security_check" /> @@ -719,7 +824,7 @@ app:layout_constraintTop_toBottomOf="@id/button_layout" app:layout_constraintStart_toStartOf="parent" android:text="" - android:textSize="75dp"/> + android:textSize="75sp"/> diff --git a/PennMobile/src/main/res/layout/subletting_cardview.xml b/PennMobile/src/main/res/layout/subletting_cardview.xml index 18def14c..878ece7d 100644 --- a/PennMobile/src/main/res/layout/subletting_cardview.xml +++ b/PennMobile/src/main/res/layout/subletting_cardview.xml @@ -33,7 +33,7 @@ android:layout_width="fill_parent" android:layout_marginHorizontal="15dp" app:layout_constraintTop_toBottomOf="@id/subletting_cardview_image" - app:layout_constraintStart_toStartOf="@id/subletting_cardview_image" /> + app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" /> diff --git a/PennMobile/src/main/res/values/strings.xml b/PennMobile/src/main/res/values/strings.xml index 61829b5f..9fc6d728 100644 --- a/PennMobile/src/main/res/values/strings.xml +++ b/PennMobile/src/main/res/values/strings.xml @@ -280,4 +280,9 @@ Details Kitchen Appliances Furniture + Air Conditioning + Accessibility Features + End Date + Fitness Facilities + Heating