app / sg.edu.ntu.scse.cz2006.gymbuddies / CarparkAndSearchResultActivity

CarparkAndSearchResultActivity

class CarparkAndSearchResultActivity : AppCompatActivity, OnMapReadyCallback

Activity for showing both carpark and search results

Author
Kenneth Soh

Since
2019-10-14

Constructors

<init>

Activity for showing both carpark and search results

CarparkAndSearchResultActivity()

Properties

autoExpandFlag

Boolean Flag for determining if the bottom sheet should auto expand when shown

var autoExpandFlag: Boolean

backStack

Boolean Flag for enabling custom backstack handling for gym details

var backStack: Boolean

backStackCp

Boolean Flag for enabling custom backstack handling for carpark details

var backStackCp: Boolean

coordinates

LatLng? Coordinates of the selected gym for gym directions

var coordinates: LatLng?

flagReviewing

Boolean Flag to signify if the user is currently reviewing the gym and the gym review dialog is active

var flagReviewing: Boolean

gpsPerm

Boolean Flag to signify if we have GPS/Location Permission

var gpsPerm: Boolean

gymDetailFavListener

ListenerRegistration? Firebase Firestore Listener for Gym Favourites data. This is used to handle real time updates to the favourites count of the gym

var gymDetailFavListener: ListenerRegistration?

mMap

GoogleMap The Google Map Object

lateinit var mMap: GoogleMap

selectedGymUid

String? UID of the selected gym

var selectedGymUid: String?

state

Int Current state of the activity. Can be either STATE_SEARCH, STATE_CARPARK or STATE_UNKNOWN

var state: Int

Functions

callSearchTask

Internal function to perform gym searching and filtering

fun callSearchTask(param: GymSearchBy): Unit

displayCarpark

Displays the carpark information on the carpark bottom sheet

fun displayCarpark(cp: Pair<CarPark, Float>): Unit

doCarpark

This function is used to initialize the various view elements if state is STATE_CARPARK

fun doCarpark(): Unit

doSearch

This function is used to initialize the relevant view elements when state is STATE_SEARCH

fun doSearch(): Unit

errorAndExit

Internal function to display and error message and exit this activity if there is an error

fun errorAndExit(errorMessage: String): Unit

getPeakCarparks

Internal function used to get all HDB carparks as per data from https://www.hdb.gov.sg/cs/infoweb/car-parks/short-term-parking/short-term-parking-charges

fun getPeakCarparks(): HashMap<String, String>

onBackPressed

Internal lifecycle function called when the back button is pressed on the device We override it to properly handle the backstack changes if needed

fun onBackPressed(): Unit

onCreate

Internal lifecycle function that is called when the activity is created

fun onCreate(savedInstanceState: Bundle?): Unit

onMapReady

Internal lifecycle function that is called when the map is prepared and initalized and ready for use

fun onMapReady(p0: GoogleMap): Unit

onOptionsItemSelected

Internal lifecycle function for when a menu item is selected

fun onOptionsItemSelected(item: MenuItem): Boolean

onPause

Internal lifecycle function for pausing an activity

fun onPause(): Unit

onRequestPermissionsResult

Internal lifecycle function that executes when we receive permission grant/deny details We use this for the location permission

fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray): Unit

onResume

Internal lifecycle function for resuming an activity

fun onResume(): Unit

onSearchResult

Function that executes and updates the map and relevant data when search completes

fun onSearchResult(result: ArrayList<FavGymObject>): Unit

processCarpark

Function used to process and retrieve the nearest 10 carparks from the selected gym

fun processCarpark(results: ArrayList<Pair<CarPark, Float>>, gym: GymShell): Unit

setGymStatus

Internal function to set the logged in user's gym review status This will determine if the user has a review for that particular gym or not. If there is, the view review layout is used, otherwise the create new review layout is used

fun setGymStatus(hasReview: Boolean, message: String?, rating: Float): Unit

setupCpControls

Internal function to setup carpark details bottom sheet

fun setupCpControls(): Unit

setupGymDetailsControls

Initialize method for setting up the gym details bottom sheet

fun setupGymDetailsControls(): Unit

showCpDetails

Internal function called to hide the favourites list bottom sheet and display the gym details bottom sheet

fun showCpDetails(): Unit

showGymDetails

Internal function called to hide the favourites list bottom sheet and display the gym details bottom sheet

fun showGymDetails(): Unit

submitReview

Internal function to submit review for the selected gym

fun submitReview(bar: MaterialRatingBar, reviewMessage: TextInputEditText): Unit

unselectCpDetails

Internal function called to hide the gym details bottom sheet and redisplay the favourites list bottom sheet

fun unselectCpDetails(): Unit

unselectGymDetails

Internal function called to hide the gym details bottom sheet and redisplay the favourites list bottom sheet

fun unselectGymDetails(): Unit

updateGymDetails

Updates the data in the gym details bottom sheet

fun updateGymDetails(gym: GymShell?): Unit

updateGymRatings

Internal function to update gym ratings for a selected gym

fun updateGymRatings(): Unit

updateResultsLayoutHeight

Internal function to update the layout height of the results sheet This will either be to the height of the items or to half of the device screen if there are too many items

fun updateResultsLayoutHeight(): Unit

zoomToMyLocation

Internal method to zoom the map to the user's current location

fun zoomToMyLocation(lastLocation: LatLng, zoom: Float = 15f): Unit

Companion Object Properties

RC_LOC_SEARCH

Location permission request code for search

const val RC_LOC_SEARCH: Int

STATE_CARPARK

Activity is currently in gym nearby carpark state

const val STATE_CARPARK: Int

STATE_SEARCH

Activity is currently in gym searching state

const val STATE_SEARCH: Int

STATE_UNKNOWN

Activity is currently in an unknown state and will throw an error

const val STATE_UNKNOWN: Int

TAG

Internal tag for logging purposes

const val TAG: String