mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-25 20:23:19 +00:00
Add new My Story privacy settings.
This commit is contained in:
@@ -55,11 +55,22 @@ fun Cursor.isNull(column: String): Boolean {
|
||||
return CursorUtil.isNull(this, column)
|
||||
}
|
||||
|
||||
inline fun <T> Cursor.readToList(mapper: (Cursor) -> T): List<T> {
|
||||
fun <T> Cursor.requireObject(column: String, serializer: LongSerializer<T>): T {
|
||||
return serializer.deserialize(CursorUtil.requireLong(this, column))
|
||||
}
|
||||
|
||||
fun <T> Cursor.requireObject(column: String, serializer: StringSerializer<T>): T {
|
||||
return serializer.deserialize(CursorUtil.requireString(this, column))
|
||||
}
|
||||
|
||||
inline fun <T> Cursor.readToList(predicate: (T) -> Boolean = { true }, mapper: (Cursor) -> T): List<T> {
|
||||
val list = mutableListOf<T>()
|
||||
use {
|
||||
while (moveToNext()) {
|
||||
list += mapper(this)
|
||||
val record = mapper(this)
|
||||
if (predicate(record)) {
|
||||
list += mapper(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
return list
|
||||
|
||||
@@ -7,6 +7,23 @@ import androidx.core.content.contentValuesOf
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteQueryBuilder
|
||||
|
||||
/**
|
||||
* Begins a transaction on the `this` database, runs the provided [block] providing the `this` value as it's argument
|
||||
* within the transaction, and then ends the transaction successfully.
|
||||
*
|
||||
* @return The value returned by [block] if any
|
||||
*/
|
||||
fun <T : SupportSQLiteDatabase, R> T.withinTransaction(block: (T) -> R): R {
|
||||
beginTransaction()
|
||||
try {
|
||||
val toReturn = block(this)
|
||||
setTransactionSuccessful()
|
||||
return toReturn
|
||||
} finally {
|
||||
endTransaction()
|
||||
}
|
||||
}
|
||||
|
||||
fun SupportSQLiteDatabase.getTableRowCount(table: String): Int {
|
||||
return this.query("SELECT COUNT(*) FROM $table").use {
|
||||
if (it.moveToFirst()) {
|
||||
@@ -224,4 +241,3 @@ class DeleteBuilderPart2(
|
||||
return db.delete(tableName, where, whereArgs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
core-util/src/main/java/org/signal/core/util/Serializer.kt
Normal file
13
core-util/src/main/java/org/signal/core/util/Serializer.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package org.signal.core.util
|
||||
|
||||
/**
|
||||
* Generic serialization interface for use with database and store operations.
|
||||
*/
|
||||
interface Serializer<T, R> {
|
||||
fun serialize(data: T): R
|
||||
fun deserialize(data: R): T
|
||||
}
|
||||
|
||||
interface StringSerializer<T> : Serializer<T, String>
|
||||
|
||||
interface LongSerializer<T> : Serializer<T, Long>
|
||||
Reference in New Issue
Block a user