Skip to content

Commit

Permalink
Fix issue with GSR booking timeout and added waiting UI
Browse files Browse the repository at this point in the history
  • Loading branch information
JSnipes29 committed Oct 2, 2023
1 parent c940002 commit 282a3da
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pennapps.labs.pennmobile

import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
Expand All @@ -14,7 +16,9 @@ import androidx.preference.PreferenceManager
import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.GSRBookingResult
import kotlinx.android.synthetic.main.gsr_details_book.*
import kotlinx.android.synthetic.main.gsr_details_book.view.*
import kotlinx.android.synthetic.main.loading_panel.*
import retrofit.Callback
import retrofit.RetrofitError
import retrofit.client.Response
Expand Down Expand Up @@ -90,6 +94,9 @@ class BookGsrFragment : Fragment() {
} else if (!emailEt.text.toString().matches("""[\w]+@(seas\.|sas\.|wharton\.|nursing\.)?upenn\.edu""".toRegex())) {
Toast.makeText(activity, "Please enter a valid Penn email", Toast.LENGTH_LONG).show()
} else {
submit.isClickable = false
submit.background.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY)
loading?.visibility = View.VISIBLE
bookGSR(Integer.parseInt(gsrID), gsrLocationCode, startTime, endTime, gid, roomId, roomName)
}
}
Expand Down Expand Up @@ -148,13 +155,15 @@ class BookGsrFragment : Fragment() {
Log.e("BookGsrFragment", "GSR booking failed with " + result.getError())
}
// go back to GSR fragment
loading?.visibility = View.GONE
activity?.onBackPressed()
}

override fun failure(error: RetrofitError) {
//If any error occurred displaying the error as toast
Log.e("BookGSRFragment", "Error booking gsr", error)
Toast.makeText(activity, "An error has occurred. Please try again.", Toast.LENGTH_LONG).show()
loading?.visibility = View.GONE
activity?.onBackPressed()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ class GsrTabbedFragment : Fragment() {
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_gsr_tabs, container, false)
val fragmentAdapter = activity?.supportFragmentManager?.let { GsrPagerAdapter(it) }
viewPager = view.gsr_viewpager
viewPager.adapter = fragmentAdapter

initAppBar(view)
tabLayout = view.gsr_tab_layout
tabLayout.setupWithViewPager(viewPager)

return view
}
Expand All @@ -43,6 +37,11 @@ class GsrTabbedFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val fragmentAdapter = activity?.supportFragmentManager?.let { GsrPagerAdapter(it) }
viewPager = view.gsr_viewpager
viewPager.adapter = fragmentAdapter
tabLayout = view.gsr_tab_layout
tabLayout.setupWithViewPager(viewPager)
//displays banner if not connected
if (!isOnline(context)) {
internetConnectionGSR?.setBackgroundColor(resources.getColor(R.color.darkRedBackground))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.*
import com.pennapps.labs.pennmobile.components.sneaker.Sneaker
import com.pennapps.labs.pennmobile.utils.Utils
import com.squareup.okhttp.OkHttpClient
import eightbitlab.com.blurview.RenderScriptBlur
import kotlinx.android.synthetic.main.custom_sneaker_view.view.*
import kotlinx.android.synthetic.main.fragment_dining_holder.*
import kotlinx.android.synthetic.main.include_main.*
import retrofit.RestAdapter
import retrofit.android.AndroidLog
import retrofit.client.OkClient
import retrofit.converter.GsonConverter
import java.util.Calendar
import java.util.concurrent.TimeUnit

class MainActivity : AppCompatActivity() {
private var tabShowed = false
Expand Down Expand Up @@ -331,8 +334,13 @@ class MainActivity : AppCompatActivity() {
// gets posts
gsonBuilder.registerTypeAdapter(object: TypeToken<MutableList<Post?>?>() {}.type, PostsSerializer())
val gson = gsonBuilder.create()
val okHttpClient = OkHttpClient()
okHttpClient.setConnectTimeout(35, TimeUnit.SECONDS) // Connection timeout
okHttpClient.setReadTimeout(35, TimeUnit.SECONDS) // Read timeout
okHttpClient.setWriteTimeout(35, TimeUnit.SECONDS) // Write timeout
val restAdapter = RestAdapter.Builder()
.setConverter(GsonConverter(gson))
.setClient(OkClient(okHttpClient))
.setEndpoint("https://pennmobile.org/api")
.build()
mStudentLife = restAdapter.create(StudentLife::class.java)
Expand Down
2 changes: 2 additions & 0 deletions PennMobile/src/main/res/layout/gsr_details_book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
android:id="@+id/submit_gsr"
android:text="@string/submit"
style="@style/submit_button" />

<include android:id="@+id/loading" layout="@layout/loading_panel" android:visibility="gone"/>
</RelativeLayout>

0 comments on commit 282a3da

Please sign in to comment.