@@ -174,55 +174,20 @@ class MainActivity : AppCompatActivity() {
174174 */
175175 private fun executeNavigationCommand (command : String ) {
176176
177- if ((command == resources.getString(R .string.navigate_to_grocery_list))) {
178- navToActivity(ActivityType .GROCERYLIST )
179-
180- } else if ((command == resources.getString(R .string.navigate_to_place_details))) {
181- navToActivity(ActivityType .PLACEDETAILS )
182-
183- } else if ((command == resources.getString(R .string.navigate_to_settings))) {
184- navToActivity(ActivityType .SETTINGS )
185-
186- } else if ((command == resources.getString(R .string.navigate_to_main_menu))) {
187- navToActivity(ActivityType .MAIN )
188-
189- } else {
190- viewModel.say(resources.getString(R .string.invalid_command))
191- }
177+ when (command) {
178+ resources.getString(R .string.navigate_to_grocery_list) ->
179+ navToActivity(this , ActivityType .GROCERYLIST )
192180
193- }
194-
195- /* *
196- * Handles navigation to next activity. Called either by button click or by execution of the
197- * voice command. If the called for activity is the current one, read out the activity name.
198- *
199- * @param activity: ActivityType, Enum specifying the activity
200- */
201- private fun navToActivity (activity : ActivityType ) {
181+ resources.getString(R .string.navigate_to_place_details) ->
182+ navToActivity(this , ActivityType .PLACEDETAILS )
202183
203- Log .println (Log .DEBUG , " navToActivity" , activity.toString())
184+ resources.getString(R .string.navigate_to_settings) ->
185+ navToActivity(this , ActivityType .SETTINGS )
204186
205- when (activity) {
206-
207- ActivityType .MAIN -> {
208- viewModel.say(resources.getString(R .string.main_menu))
209- }
210-
211- ActivityType .GROCERYLIST -> {
212- val intent = Intent (this , GroceryListActivity ::class .java)
213- this .startActivity(intent)
214- }
215-
216- ActivityType .PLACEDETAILS -> {
217- val intent = Intent (this , PlaceDetailsActivity ::class .java)
218- this .startActivity(intent)
219- }
220-
221- ActivityType .SETTINGS -> {
222- val intent = Intent (this , SettingsActivity ::class .java)
223- this .startActivity(intent)
224- }
225-
187+ resources.getString(R .string.navigate_to_main_menu) ->
188+ navToActivity(this , ActivityType .MAIN )
189+
190+ else -> viewModel.say(resources.getString(R .string.invalid_command))
226191 }
227192
228193 }
@@ -236,19 +201,19 @@ class MainActivity : AppCompatActivity() {
236201 // set up button to navigate to GroceryListActivity
237202 val groceryListButton: Button = findViewById<View >(R .id.grocery_list_bt) as Button
238203 groceryListButton.setOnClickListener { _ ->
239- navToActivity(ActivityType .GROCERYLIST )
204+ navToActivity(this , ActivityType .GROCERYLIST )
240205 }
241206
242207 // set up button to navigate to PlaceDetailsActivity
243208 val placeDetailsButton: Button = findViewById<View >(R .id.place_details_bt) as Button
244209 placeDetailsButton.setOnClickListener { _ ->
245- navToActivity(ActivityType .PLACEDETAILS )
210+ navToActivity(this , ActivityType .PLACEDETAILS )
246211 }
247212
248213 // set up button to navigate to SettingsActivity
249214 val settingsActivityButton: Button = findViewById<View >(R .id.settings_bt) as Button
250215 settingsActivityButton.setOnClickListener { _ ->
251- navToActivity(ActivityType .SETTINGS )
216+ navToActivity(this , ActivityType .SETTINGS )
252217 }
253218
254219 // set up voice Activation Button listener
0 commit comments