Skip to content

Commit

Permalink
Merge pull request #401 from skedgo/feature/20162-next-up-card
Browse files Browse the repository at this point in the history
[20162] Next Up item card feature on home
  • Loading branch information
MichaelReyes authored Dec 27, 2023
2 parents d4589b9 + cead111 commit 4939569
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,44 @@ package com.skedgo.tripkit.routing
import android.content.Context
import android.content.SharedPreferences


object GetOffAlertCache {

private const val PREF_KEY = "KEY_GET_OFF_ALERTS"
private const val PREF_KEY_TRIP_ID = "KEY_TRIP_ID"
private const val PREF_KEY_TRIP_GROUP_ID = "KEY_TRIP_GROUP_ID"
private lateinit var sharedPreferences: SharedPreferences
var onTripAlertStateChanged: () -> Unit = {}

fun init(context: Context) {
sharedPreferences = context.getSharedPreferences(PREF_KEY, Context.MODE_PRIVATE)
}

fun setTripAlertOnState(tripUuid: String, onState: Boolean) {
fun setTripAlertOnState(tripUuid: String, tripGroupId: String, onState: Boolean) {
if (onState) {
//As per adrian, only one trip can have alerts on, so will need to clear first to make sure no other trips has alerts on
sharedPreferences.edit().apply {
clear()
putBoolean(tripUuid, onState).apply()
putBoolean(tripUuid, onState)
putString(PREF_KEY_TRIP_ID, tripUuid)
putString(PREF_KEY_TRIP_GROUP_ID, tripGroupId)
}.apply()
//sharedPreferences.edit().putBoolean(tripUuid, onState).apply()
onTripAlertStateChanged.invoke()
} else {
sharedPreferences.edit().remove(tripUuid).apply()
sharedPreferences.edit().apply {
remove(tripUuid)
remove(PREF_KEY_TRIP_ID)
remove(PREF_KEY_TRIP_GROUP_ID)
}.apply()
onTripAlertStateChanged.invoke()
}
}

fun isTripAlertStateOn(tripUuid: String): Boolean = sharedPreferences.getBoolean(tripUuid, false)
fun isTripAlertStateOn(tripUuid: String): Boolean =
sharedPreferences.getBoolean(tripUuid, false)

fun getTripId(): String = sharedPreferences.getString(PREF_KEY_TRIP_ID, "").orEmpty()

fun getTripAlertGroupId(): String? = sharedPreferences.getString(PREF_KEY_TRIP_GROUP_ID, null)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.skedgo.tripkit.common.util.TripSegmentUtils
import org.joda.time.DateTime
import java.util.concurrent.TimeUnit
import com.skedgo.tripkit.common.model.TransportMode
import org.joda.time.format.DateTimeFormat

val TIME_FORMATTER = DateTimeFormat.forPattern("hh:mm a")

/**
* Gets a start date-time with time-zone.
Expand All @@ -15,6 +18,9 @@ val Trip.startDateTime: DateTime
from.dateTimeZone
)

val Trip.startTimeString: String
get() = startDateTime.toString(TIME_FORMATTER)

/**
* Get an end date-time with time-zone.
*/
Expand All @@ -24,6 +30,9 @@ val Trip.endDateTime: DateTime
to?.dateTimeZone
)

val Trip.endTimeString: String
get() = endDateTime.toString(TIME_FORMATTER)

/**
* Gets a query date-time with time-zone based on from location
*/
Expand Down

0 comments on commit 4939569

Please sign in to comment.