Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/subletting' into subletting
Browse files Browse the repository at this point in the history
# Conflicts:
#	PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PostedSubletsListAdapter.kt
  • Loading branch information
trinif committed Oct 25, 2024
2 parents a9447fd + 4e0b0bf commit 2e48c09
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<MultipartBody.Part>()





Expand Down Expand Up @@ -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<MultipartBody.Part>()



val pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
Expand All @@ -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) {
Expand All @@ -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}$""")

Expand Down Expand Up @@ -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)

}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SubletImage>? = 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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.pennapps.labs.pennmobile.MainActivity
import com.pennapps.labs.pennmobile.R
import com.pennapps.labs.pennmobile.SublesseeDetailsFragment
import com.pennapps.labs.pennmobile.Subletting.SubletDetailsFragment
import com.pennapps.labs.pennmobile.Subletting.SubletDetailsHolderFragment
import com.pennapps.labs.pennmobile.classes.Sublet
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

class PostedSubletsListAdapter(private val dataModel: SublettingViewModel):
RecyclerView.Adapter<PostedSubletsListAdapter.SublettingCardViewHolder>() {
Expand Down
30 changes: 30 additions & 0 deletions PennMobile/src/main/res/drawable/subletting_square.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="75sp"
android:height="75sp"
android:viewportWidth="97.1"
android:viewportHeight="59.1"
>

<group>

<clip-path
android:pathData="M8.33974 0.05H88.7603C93.3386 0.05 97.05 3.76144 97.05 8.33974V50.7603C97.05 55.3386 93.3386 59.05 88.7603 59.05H8.33974C3.76144 59.05 0.05 55.3386 0.05 50.7603V8.33974C0.05 3.76144 3.76144 0.05 8.33974 0.05Z"
/>

<path
android:pathData="M0.05 0.05V59.05H97.05V0.05"
android:fillColor="#F6F7F8"
/>

</group>

<path
android:pathData="M8.33974 0.05H88.7603C93.3386 0.05 97.05 3.76144 97.05 8.33974V50.7603C97.05 55.3386 93.3386 59.05 88.7603 59.05H8.33974C3.76144 59.05 0.05 55.3386 0.05 50.7603V8.33974C0.05 3.76144 3.76144 0.05 8.33974 0.05Z"
android:strokeWidth="0.1"
android:strokeColor="#CACACA"
/>

</vector>
76 changes: 64 additions & 12 deletions PennMobile/src/main/res/layout/fragment_sublet_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand All @@ -38,35 +38,85 @@
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" />

<TextView
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" />



<ImageView
android:id="@+id/sublet_image"

<HorizontalScrollView
android:id="@+id/sublet_images"
android:layout_width="0dp"
android:layout_height="250sp"
android:layout_marginStart="26sp"
android:layout_marginTop="10sp"
android:layout_marginEnd="26sp"
android:layout_margin="26sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_text"
app:srcCompat="@drawable/subletting_house" />
app:layout_constraintTop_toBottomOf="@id/title_text">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView
android:id="@+id/image1"
android:layout_width="250sp"
android:layout_height="250sp"
android:layout_margin="10sp"
app:srcCompat="@drawable/subletting_house" />

<ImageView
android:id="@+id/image2"
android:layout_width="250sp"
android:layout_height="250sp"
android:layout_margin="10sp"
app:srcCompat="@drawable/subletting_house" />

<ImageView
android:id="@+id/image3"
android:layout_width="250sp"
android:layout_height="250sp"
android:layout_margin="10sp"
app:srcCompat="@drawable/subletting_house" />

<ImageView
android:id="@+id/image4"
android:layout_width="250sp"
android:layout_height="250sp"
android:layout_margin="10sp"
app:srcCompat="@drawable/subletting_house" />

<ImageView
android:id="@+id/image5"
android:layout_width="250sp"
android:layout_height="250sp"
android:layout_margin="10sp"
app:srcCompat="@drawable/subletting_house" />

<ImageView
android:id="@+id/image6"
android:layout_width="250sp"
android:layout_height="250sp"
android:layout_margin="10sp"
app:srcCompat="@drawable/subletting_house" />


</LinearLayout>

</HorizontalScrollView>

<TextView
android:id="@+id/price_text"
Expand All @@ -79,7 +129,7 @@
android:textColor="@color/dark_gray"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sublet_image" />
app:layout_constraintTop_toBottomOf="@+id/sublet_images" />

<TextView
android:id="@+id/address_text"
Expand Down Expand Up @@ -214,6 +264,8 @@
android:text=" "
android:textSize="75dp"/>



</androidx.constraintlayout.widget.ConstraintLayout>


Expand Down
Loading

0 comments on commit 2e48c09

Please sign in to comment.