Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fdb35b5b authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

TableLogBuffer: Default columnPrefix to "".

Most uses of TableLogBuffer are setting columnPrefix to "", so we should
make that the default and save most people from writing it explicitly.

This also removes the `columnPrefix = ""` in all the status-bar-related
code. Future CL(s) will remove it from other places.

Bug: N/A
Flag: EXEMPT refactor
Test: Dump TableLogBuffers with and without column prefixes -> verify
they look the same

Change-Id: I8fbe2b7dbf35f45ece10a23d5c20da3e5d7b7772
parent c7bd665f
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -25,34 +25,34 @@ interface TableLogBufferBase {
     *
     * For Java overloading.
     */
    fun logChange(prefix: String, columnName: String, value: String?) {
    fun logChange(prefix: String = "", columnName: String, value: String?) {
        logChange(prefix, columnName, value, isInitial = false)
    }

    /** Logs a String? change. */
    fun logChange(prefix: String, columnName: String, value: String?, isInitial: Boolean)
    fun logChange(prefix: String = "", columnName: String, value: String?, isInitial: Boolean)

    /**
     * Logs a Boolean change.
     *
     * For Java overloading.
     */
    fun logChange(prefix: String, columnName: String, value: Boolean) {
    fun logChange(prefix: String = "", columnName: String, value: Boolean) {
        logChange(prefix, columnName, value, isInitial = false)
    }

    /** Logs a Boolean change. */
    fun logChange(prefix: String, columnName: String, value: Boolean, isInitial: Boolean)
    fun logChange(prefix: String = "", columnName: String, value: Boolean, isInitial: Boolean)

    /**
     * Logs an Int? change.
     *
     * For Java overloading.
     */
    fun logChange(prefix: String, columnName: String, value: Int?) {
    fun logChange(prefix: String = "", columnName: String, value: Int?) {
        logChange(prefix, columnName, value, isInitial = false)
    }

    /** Logs an Int? change. */
    fun logChange(prefix: String, columnName: String, value: Int?, isInitial: Boolean)
    fun logChange(prefix: String = "", columnName: String, value: Int?, isInitial: Boolean)
}
+6 −6
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ interface Diffable<T> {
 */
fun <T : Diffable<T>> Flow<T>.logDiffsForTable(
    tableLogBuffer: TableLogBuffer,
    columnPrefix: String,
    columnPrefix: String = "",
    initialValue: T,
): Flow<T> {
    // Fully log the initial value to the table.
@@ -87,7 +87,7 @@ fun <T : Diffable<T>> Flow<T>.logDiffsForTable(
/** See [logDiffsForTable(TableLogBuffer, String, T)]. */
fun Flow<Boolean>.logDiffsForTable(
    tableLogBuffer: TableLogBuffer,
    columnPrefix: String,
    columnPrefix: String = "",
    columnName: String,
    initialValue: Boolean,
): Flow<Boolean> {
@@ -106,7 +106,7 @@ fun Flow<Boolean>.logDiffsForTable(
/** See [logDiffsForTable(TableLogBuffer, String, T)]. */
fun Flow<Int>.logDiffsForTable(
    tableLogBuffer: TableLogBuffer,
    columnPrefix: String,
    columnPrefix: String = "",
    columnName: String,
    initialValue: Int,
): Flow<Int> {
@@ -125,7 +125,7 @@ fun Flow<Int>.logDiffsForTable(
/** See [logDiffsForTable(TableLogBuffer, String, T)]. */
fun Flow<Int?>.logDiffsForTable(
    tableLogBuffer: TableLogBuffer,
    columnPrefix: String,
    columnPrefix: String = "",
    columnName: String,
    initialValue: Int?,
): Flow<Int?> {
@@ -144,7 +144,7 @@ fun Flow<Int?>.logDiffsForTable(
/** See [logDiffsForTable(TableLogBuffer, String, T)]. */
fun Flow<String?>.logDiffsForTable(
    tableLogBuffer: TableLogBuffer,
    columnPrefix: String,
    columnPrefix: String = "",
    columnName: String,
    initialValue: String?,
): Flow<String?> {
@@ -163,7 +163,7 @@ fun Flow<String?>.logDiffsForTable(
/** See [logDiffsForTable(TableLogBuffer, String, T)]. */
fun <T> Flow<List<T>>.logDiffsForTable(
    tableLogBuffer: TableLogBuffer,
    columnPrefix: String,
    columnPrefix: String = "",
    columnName: String,
    initialValue: List<T>,
): Flow<List<T>> {
+4 −3
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ class TableLogBuffer(
     *   the separator token for parsing, so it can't be present in any part of the column name.
     */
    @Synchronized
    fun <T : Diffable<T>> logDiffs(columnPrefix: String, prevVal: T, newVal: T) {
    fun <T : Diffable<T>> logDiffs(columnPrefix: String = "", prevVal: T, newVal: T) {
        val row = tempRow
        row.timestamp = systemClock.currentTimeMillis()
        row.columnPrefix = columnPrefix
@@ -136,6 +136,7 @@ class TableLogBuffer(
    /**
     * Logs change(s) to the buffer using [rowInitializer].
     *
     * @param columnPrefix see [logDiffs].
     * @param rowInitializer a function that will be called immediately to store relevant data on
     *   the row.
     * @param isInitial true if this change represents the starting value for a particular column
@@ -145,9 +146,9 @@ class TableLogBuffer(
     */
    @Synchronized
    fun logChange(
        columnPrefix: String,
        columnPrefix: String = "",
        isInitial: Boolean = false,
        rowInitializer: (TableRowLogger) -> Unit
        rowInitializer: (TableRowLogger) -> Unit,
    ) {
        val row = tempRow
        row.timestamp = systemClock.currentTimeMillis()
+1 −6
Original line number Diff line number Diff line
@@ -81,12 +81,7 @@ constructor(
                awaitClose { observer.isListening = false }
            }
            .distinctUntilChanged()
            .logDiffsForTable(
                logger,
                columnPrefix = "",
                columnName = "isAirplaneMode",
                initialValue = false,
            )
            .logDiffsForTable(logger, columnName = "isAirplaneMode", initialValue = false)
            .stateIn(
                scope,
                started = SharingStarted.WhileSubscribed(),
+0 −1
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ constructor(
            .distinctUntilChanged()
            .logDiffsForTable(
                logger,
                columnPrefix = "",
                columnName = "isAirplaneModeIconVisible",
                initialValue = false,
            )
Loading