Skip to content

Commit

Permalink
Merge pull request #413 from skedgo/feature/20422-show-availability-info
Browse files Browse the repository at this point in the history
[20422] Handle and show availability info and disabling item if availability is MISSED_PREBOOKING_WINDOW
  • Loading branch information
MichaelReyes authored Feb 20, 2024
2 parents f8a1525 + 7b27bed commit e106bcc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class Trip implements ITimeRange {
private float caloriesCost;
@SerializedName("moneyCost")
private float mMoneyCost;
@SerializedName("moneyUSDCost")
private float moneyUsdCost;
@SerializedName("carbonCost")
private float mCarbonCost;
@SerializedName("hassleCost")
Expand Down Expand Up @@ -81,6 +83,8 @@ public class Trip implements ITimeRange {
@Nullable
@SerializedName("availability")
private String availability;
@Nullable
private String availabilityInfo;
@SerializedName("mainSegmentHashCode")
private long mainSegmentHashCode;
@SerializedName("hideExactTimes")
Expand All @@ -100,6 +104,7 @@ public Trip() {
mStartTimeInSecs = 0;
mEndTimeInSecs = 0;
mMoneyCost = UNKNOWN_COST;
moneyUsdCost = UNKNOWN_COST;
mCarbonCost = 0;
mHassleCost = 0;
}
Expand Down Expand Up @@ -208,6 +213,14 @@ public void setMoneyCost(final float moneyCost) {
this.mMoneyCost = moneyCost;
}

public float getMoneyUsdCost() {
return moneyUsdCost;
}

public void setMoneyUsdCost(float moneyUsdCost) {
this.moneyUsdCost = moneyUsdCost;
}

public float getCarbonCost() {
return mCarbonCost;
}
Expand Down Expand Up @@ -337,6 +350,11 @@ public Availability getAvailability() {
return com.skedgo.tripkit.routing.AvailabilityKt.toAvailability(availability);
}

@Nullable
public String getAvailabilityString() {
return availability;
}

/**
* Mutability is subject to deletion after we finish migrating to an immutable {@link Trip}.
*/
Expand All @@ -345,6 +363,10 @@ public void setAvailability(@NonNull Availability availability) {
this.availability = availability.getValue();
}

public void setAvailability(String availability) {
this.availability = availability;
}

public boolean queryIsLeaveAfter() {
return queryIsLeaveAfter;
}
Expand Down Expand Up @@ -508,6 +530,22 @@ public String getDisplayCost(String localizedFreeText) {
}
}

@Nullable
public String getDisplayCostUsd() {
if (moneyUsdCost == 0) {
return null;
} else if (moneyUsdCost == Trip.UNKNOWN_COST) {
return null;
} else {
// Use locale.
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.getDefault());
numberFormat.setRoundingMode(RoundingMode.CEILING);
numberFormat.setMaximumFractionDigits(0);
String value = numberFormat.format(moneyUsdCost);
return (currencySymbol != null ? currencySymbol : "$") + value;
}
}

@Nullable
public String getDisplayCarbonCost() {
if (mCarbonCost > 0) {
Expand Down Expand Up @@ -595,6 +633,15 @@ public void setQueryTime(long queryTime) {
this.queryTime = queryTime;
}

@Nullable
public String getAvailabilityInfo() {
return availabilityInfo;
}

public void setAvailabilityInfo(@Nullable String availabilityInfo) {
this.availabilityInfo = availabilityInfo;
}

public String getTripUuid() {
if (saveURL != null) {
Uri uri = Uri.parse(saveURL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ final class RouteContract {
static final String COL_SOURCES = "sources";
static final String COL_SUBSCRIBE_URL = "subscribeURL";
static final String COL_UNSUBSCRIBE_URL = "unsubscribeURL";
static final String COL_AVAILABILITY = "availability";
static final String COL_AVAILABILITY_INFO = "availabilityInfo";
static final String COL_MONEY_USD_COST = "moneyUSDCost";

private RouteContract() {
}
Expand Down Expand Up @@ -80,6 +83,9 @@ static void createTables(SQLiteDatabase database) {
final DatabaseField sources = new DatabaseField(COL_SOURCES, "text");
final DatabaseField subscribeUrl = new DatabaseField(COL_SUBSCRIBE_URL, "text");
final DatabaseField unSubscribeUrl = new DatabaseField(COL_UNSUBSCRIBE_URL, "text");
final DatabaseField availability = new DatabaseField(COL_AVAILABILITY, "text");
final DatabaseField availabilityInfo = new DatabaseField(COL_AVAILABILITY_INFO, "text");
final DatabaseField moneyUsdCost = new DatabaseField(COL_MONEY_USD_COST, "real");
final DatabaseTable tripGroups = new DatabaseTable(
TABLE_TRIP_GROUPS,
new DatabaseField[]{
Expand All @@ -100,7 +106,7 @@ static void createTables(SQLiteDatabase database) {
caloriesCost, moneyCost, carbonCost, hassleCost, weightedScore,
updateUrl, progressUrl, plannedUrl, tempUrl,
queryIsLeaveAfter, logUrl, shareUrl, mainSegmentHashCode, isHideExactTimes,
queryTime, subscribeUrl, unSubscribeUrl
queryTime, subscribeUrl, unSubscribeUrl, availability, availabilityInfo, moneyUsdCost
},
UniqueIndices.of(TABLE_TRIPS, id, groupId, uuid),
"CREATE TRIGGER deleteSegments AFTER DELETE ON " + TABLE_TRIPS + " BEGIN " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.widget.Toast;

public class RouteDatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 11;
private static final int DATABASE_VERSION = 12;

public RouteDatabaseHelper(Context context, String name) {
super(context, name, null, DATABASE_VERSION);
Expand Down Expand Up @@ -83,6 +83,15 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// ignored if the column exists
}
}
if(newVersion > 11) {
try {
db.execSQL("ALTER TABLE trips ADD COLUMN availability TEXT");
db.execSQL("ALTER TABLE trips ADD COLUMN availabilityInfo TEXT");
db.execSQL("ALTER TABLE trips ADD COLUMN moneyUSDCost REAL");
} catch (SQLiteException ex) {
// ignored if the column exists
}
}
} else {
RoutingStatusContract.INSTANCE.create(db);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ open class RouteStore(private val databaseHelper: SQLiteOpenHelper, private val
values.put(COL_QUERY_IS_LEAVE_AFTER, if (trip.queryIsLeaveAfter()) 1 else 0)
values.put(COL_SUBSCRIBE_URL, trip.subscribeURL)
values.put(COL_UNSUBSCRIBE_URL, trip.unsubscribeURL)
values.put(COL_AVAILABILITY, trip.availabilityString)
values.put(COL_AVAILABILITY_INFO, trip.availabilityInfo)
values.put(COL_MONEY_USD_COST, trip.moneyUsdCost)
database.beginTransaction()
try {
database.update(TABLE_TRIPS, values, "$COL_UUID = ?", arrayOf(oldTripUuid))
Expand Down Expand Up @@ -257,6 +260,9 @@ open class RouteStore(private val databaseHelper: SQLiteOpenHelper, private val
val isNotifable = groupCursor.getInt(groupCursor.getColumnIndex(COL_IS_NOTIFIABLE)) == 1
val subscribeUrl = tripCursor.getString(tripCursor.getColumnIndex(COL_SUBSCRIBE_URL))
val unSubscribeUrl = tripCursor.getString(tripCursor.getColumnIndex(COL_UNSUBSCRIBE_URL))
val availability = tripCursor.getString(tripCursor.getColumnIndex(COL_AVAILABILITY))
val availabilityInfo = tripCursor.getString(tripCursor.getColumnIndex(COL_AVAILABILITY_INFO))
val moneyUSDCost = tripCursor.getFloat(tripCursor.getColumnIndex(COL_MONEY_USD_COST))

val trip = Trip()
trip.id = id
Expand All @@ -283,6 +289,9 @@ open class RouteStore(private val databaseHelper: SQLiteOpenHelper, private val
trip.isFavourite(isNotifable)
trip.subscribeURL = subscribeUrl
trip.unsubscribeURL = unSubscribeUrl
trip.setAvailability(availability)
trip.availabilityInfo = availabilityInfo
trip.moneyUsdCost = moneyUSDCost
return trip
}

Expand Down Expand Up @@ -401,6 +410,9 @@ open class RouteStore(private val databaseHelper: SQLiteOpenHelper, private val
values.put(COL_QUERY_TIME, trip.queryTime)
values.put(COL_SUBSCRIBE_URL, trip.subscribeURL)
values.put(COL_UNSUBSCRIBE_URL, trip.unsubscribeURL)
values.put(COL_AVAILABILITY, trip.availabilityString)
values.put(COL_AVAILABILITY_INFO, trip.availabilityInfo)
values.put(COL_MONEY_USD_COST, trip.moneyUsdCost)
database.insertWithOnConflict(TABLE_TRIPS, null, values, SQLiteDatabase.CONFLICT_REPLACE)
}

Expand Down

0 comments on commit e106bcc

Please sign in to comment.