Skip to content

Commit

Permalink
Add gson to retrofit2
Browse files Browse the repository at this point in the history
  • Loading branch information
meiron03 committed Jan 26, 2025
1 parent ef768ce commit 27f467e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,55 @@ class MainActivity : AppCompatActivity() {
val studentLifeInstanceRf2: StudentLifeRf2
get() {
if (mStudentLifeRf2 == null) {
val gsonBuilder = GsonBuilder()

gsonBuilder.registerTypeAdapter(
object : TypeToken<MutableList<Contact?>?>() {}.type,
Serializer.DataSerializer<Any?>(),
)

gsonBuilder.registerTypeAdapter(
object : TypeToken<MutableList<Venue?>?>() {}.type,
Serializer.VenueSerializer(),
)
gsonBuilder.registerTypeAdapter(
DiningHall::class.java,
Serializer.MenuSerializer(),
)
// gets room
gsonBuilder.registerTypeAdapter(
object : TypeToken<LaundryRoom?>() {}.type,
Serializer.LaundryRoomSerializer(),
)

gsonBuilder.registerTypeAdapter(
object : TypeToken<MutableList<GSRLocation?>?>() {}.type,
Serializer.GsrLocationSerializer(),
)

gsonBuilder.registerTypeAdapter(
object : TypeToken<MutableList<FlingEvent?>?>() {}.type,
Serializer.FlingEventSerializer(),
)

// gets gsr reservations
gsonBuilder.registerTypeAdapter(
object : TypeToken<MutableList<GSRReservation?>?>() {}.type,
Serializer.GsrReservationSerializer(),
)
// gets user
gsonBuilder.registerTypeAdapter(
Account::class.java,
Serializer.UserSerializer(),
)
// gets posts
gsonBuilder.registerTypeAdapter(
object : TypeToken<MutableList<Post?>?>() {}.type,
Serializer.PostsSerializer(),
)

val gson = gsonBuilder.create()

val logging = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
Expand All @@ -380,7 +429,7 @@ class MainActivity : AppCompatActivity() {
.baseUrl("https://pennmobile.org/api/")
.client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build()
mStudentLifeRf2 = retrofit.create(StudentLifeRf2::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class OAuth2NetworkManager(
clientID,
)

if (response.isSuccessful) {
val t = response.body()!!
val t = response.body()

if (response.isSuccessful && t != null) {
val editor = sp.edit()
editor.putString(mActivity.getString(R.string.access_token), t.accessToken)
editor.putString(mActivity.getString(R.string.refresh_token), t.refreshToken)
Expand Down

0 comments on commit 27f467e

Please sign in to comment.