@@ -218,12 +218,25 @@ class PlaceDetailsActivity : AppCompatActivity(), PlaceDetailsItemCallback {
218218
219219 }
220220
221+ /* *
222+ * Requests a response from the user by reading out the question and activating voice control
223+ * once the question has been read fully.
224+ *
225+ * @param question: String, the question to ask the user
226+ */
221227 private suspend fun requestResponse (question : String ) {
222228 viewModel.sayAndAwait(question)
223229 viewModel.setSpeechRecognitionListener(STTInputType .ANSWER )
224230 viewModel.handleSpeechBegin()
225231 }
226232
233+ /* *
234+ * Called when the user has given a response to an item quesion.Depending on the previous
235+ * command and the given response, the action is executed.
236+ *
237+ * @param command: String, the command preceding the response
238+ * @param response: String, the response given by the user
239+ */
227240 private fun executeItemCommand (command : String , response : String ) {
228241
229242 if (response != resources.getString(R .string.cancel)) {
@@ -252,6 +265,13 @@ class PlaceDetailsActivity : AppCompatActivity(), PlaceDetailsItemCallback {
252265
253266 }
254267
268+ /* *
269+ * Requests the ViewModel to add a new Place Details Item to the favorites by name. If no
270+ * Place Details Item exists for the given item name, this is stated. If the item is already a
271+ * favorite, this, too is stated.
272+ *
273+ * @param storeName: String, the name of the item to be added to favorites
274+ */
255275 private fun addToFavorites (storeName : String ) {
256276
257277 val placeDetailsItem = findPlaceByName(storeName)
@@ -272,6 +292,13 @@ class PlaceDetailsActivity : AppCompatActivity(), PlaceDetailsItemCallback {
272292
273293 }
274294
295+ /* *
296+ * Requests the ViewModel to remove a Place Details Item from the favorites by name. If no
297+ * Place Details Item exists for the given item name, this is stated. If the item is not a
298+ * favorite, this, too is stated.
299+ *
300+ * @param storeName: String, the name of the item to be removed from favorites
301+ */
275302 private fun removeFromFavorites (storeName : String ) {
276303
277304 Log .println (Log .DEBUG , " rmFav" , " 1" )
@@ -298,6 +325,11 @@ class PlaceDetailsActivity : AppCompatActivity(), PlaceDetailsItemCallback {
298325
299326 }
300327
328+ /* *
329+ * Handles voice commands for which a list of place detail items must be read out loud.
330+ *
331+ * @param command: String, the command given by the user
332+ */
301333 private fun executeListCommand (command : String ) {
302334
303335 Log .println (Log .DEBUG , " exec" , command)
@@ -331,6 +363,10 @@ class PlaceDetailsActivity : AppCompatActivity(), PlaceDetailsItemCallback {
331363
332364 }
333365
366+ /* *
367+ * Reads today's Opening Hours for a given store name out loud. If the store name does not
368+ * correspond to a place details item on the list, state this.
369+ */
334370 private fun stateOpeningHours (storeName : String ) {
335371
336372 val placeDetailsItem = findPlaceByName(storeName)
@@ -351,6 +387,11 @@ class PlaceDetailsActivity : AppCompatActivity(), PlaceDetailsItemCallback {
351387
352388 }
353389
390+ /* *
391+ * Checks whether a store is currently open, based on its opening Hours and the current time.
392+ *
393+ * @param openingHours: List<String> the opening hours of a store
394+ */
354395 private fun isOpen (openingHours : List <String >): Boolean {
355396
356397 val dayOfWeek = Math .floorMod(Calendar .getInstance().get(Calendar .DAY_OF_WEEK ) - 2 , 7 )
@@ -517,20 +558,33 @@ class PlaceDetailsActivity : AppCompatActivity(), PlaceDetailsItemCallback {
517558
518559 }
519560
520- private fun deletePlaceDetailsItem (response : String ) {
561+ /* *
562+ * Checks if the desired Place Details Item exist in the list and deletes it. If it does not
563+ * exist, states this.
564+ *
565+ * @param itemName: name to be deleted
566+ */
567+ private fun deletePlaceDetailsItem (itemName : String ) {
521568
522- val placeDetailsItem = findPlaceByName(response )
569+ val placeDetailsItem = findPlaceByName(itemName )
523570
524571 if (placeDetailsItem != null ) {
525572 deletePlaceDetailsItem(placeDetailsItem, placeDetailsItemList.indexOf(placeDetailsItem))
526573 } else {
527574 viewModel.say(
528- resources.getString(R .string.STORENAME_is_not_on_the_list , response )
575+ resources.getString(R .string.STORENAME_is_not_on_the_list , itemName )
529576 )
530577 }
531578
532579 }
533580
581+ /* *
582+ * Searches the list for a Place Detail Item by its name.
583+ *
584+ * @param storeName: String, the name of the place to be deleted
585+ *
586+ * @return The Place Details Item if it exists, else null
587+ */
534588 private fun findPlaceByName (storeName : String ): PlaceDetailsItem ? {
535589 return placeDetailsItemList.find { it.storeName.lowercase() == storeName }
536590 }
0 commit comments