Skip to content

Commit

Permalink
working on saved sublets
Browse files Browse the repository at this point in the history
  • Loading branch information
trinif committed Sep 29, 2024
1 parent 2df9fbb commit ba8b878
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.pennapps.labs.pennmobile
import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -98,7 +99,16 @@ class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position:
}
dataModel.addSavedSublet(sublet) */
dataModel.addSavedSublet(mActivity, sublet.id!!)
/* dataModel.addSavedSublet(mActivity, newSublet) { postedSublet ->
if (postedSublet != null) {
Log.i("MainActivity", "Posted sublet ID: ${postedSublet.id}")
subletId = postedSublet.id!!
} else {
// Handle failure to post sublet
Log.e("MainActivity", "Failed to post sublet")
}
} */
dataModel.addSavedSublet(mActivity, sublet)
Toast.makeText(context, "This property has been saved", Toast.LENGTH_LONG).show()
mActivity.supportFragmentManager.beginTransaction()
.replace(((view as ViewGroup).parent as View).id, SublesseeSavedFragment())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ Observable<List<Sublet>> getSublets(
@POST("/sublet/properties/{sublet_id}/favorites")
void addFavoriteSublet(
@Header("Authorization") String bearerToken,
@Body SubletRequest sublets,
@Path("sublet_id") int id,
@Body Sublet sublet,
Callback<Sublet> callback);

@Headers({"Content-Type: application/json"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ class SublesseeViewModel(private val activity: Activity, private val studentLife
return savedSublets.value?.get(position) ?: Sublet() // Provide a default value if needed
} */

fun addSavedSublet(mActivity: MainActivity, id: Int) {
fun addSavedSublet(mActivity: MainActivity, sublet: Sublet) {
val context = activity.applicationContext
val sp = PreferenceManager.getDefaultSharedPreferences(activity)

savedSubletIds.add(id)
//savedSubletIds.add(id)

OAuth2NetworkManager(mActivity).getAccessToken {

val bearerToken =
"Bearer " + sp.getString(context.getString(R.string.access_token), "").toString()


studentLife.addFavoriteSublet(bearerToken, SubletRequest(ArrayList(savedSubletIds)), id, object : Callback<Sublet> {
studentLife.addFavoriteSublet(bearerToken, sublet, object : Callback<Sublet> {
override fun success(t: Sublet?, response: Response?) {
Log.i("Sublessee View Model", "sublet added")
}
Expand Down

0 comments on commit ba8b878

Please sign in to comment.