Skip to content

Commit

Permalink
URGENT FIX !! App closes when clicking directions buttons
Browse files Browse the repository at this point in the history
-launching activity from model was a bad idea
-replicate startActivityForResult pattern in activity model and activity
  -but in trip model and trip fragment
  • Loading branch information
nackko committed May 7, 2019
1 parent 29d955c commit 505ae28
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class TripDetailsFragment : Fragment() {
}
})

fragmentModel.lastStartActivityIntent.observe(this, Observer {
it?.let { intent ->
fragmentModel.clearLastStartActivityRequest()
startActivity(intent)
}
})

inflatedView.findViewById<View>(R.id.trip_details_directions_loc_to_a).setOnClickListener {
fragmentModel.locToStationADirectionsFabClick()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ class TripFragmentViewModel(app: Application,
private val aToBGoogleMapDirectionsIntent = MutableLiveData<Intent>()
private val bToDestGoogleMapDirectionsIntent = MutableLiveData<Intent>()

private val lastStartActData = MutableLiveData<Intent>()
val lastStartActivityIntent: LiveData<Intent>
get() = lastStartActData

fun requestStartActivity(intent: Intent) {
lastStartActData.value = intent
}

fun clearLastStartActivityRequest() {
lastStartActData.value = null
}

val locToStationAText: LiveData<String>
get() = locToStationADurationString

Expand Down Expand Up @@ -196,15 +208,15 @@ class TripFragmentViewModel(app: Application,
}

fun locToStationADirectionsFabClick() {
getApplication<Application>().startActivity(locToAGoogleMapDirectionsIntent.value)
lastStartActData.value = locToAGoogleMapDirectionsIntent.value
}

fun stationAToStationBDirectionsFabClick() {
getApplication<Application>().startActivity(aToBGoogleMapDirectionsIntent.value)
lastStartActData.value = aToBGoogleMapDirectionsIntent.value
}

fun stationBTofinalDestinationDirectionsFabClick() {
getApplication<Application>().startActivity(bToDestGoogleMapDirectionsIntent.value)
lastStartActData.value = bToDestGoogleMapDirectionsIntent.value
}

private fun recalculateTripTotal(statBToFinal: Int?, statAToStatB: Int?, locToA: Int?) {
Expand Down

0 comments on commit 505ae28

Please sign in to comment.