That fuck shit the fascists are using
at master 50 lines 1.8 kB view raw
1package org.tm.archive.logsubmit 2 3import android.app.Application 4import org.signal.core.util.logging.Scrubber 5import org.signal.paging.PagedDataSource 6import org.tm.archive.database.LogDatabase 7 8/** 9 * Retrieves logs to show in the [SubmitDebugLogActivity]. 10 * 11 * @param prefixLines A static list of lines to show before all of the lines retrieved from [LogDatabase] 12 * @param untilTime Only show logs before this time. This is our way of making sure the set of logs we show on this screen doesn't grow. 13 */ 14class LogDataSource( 15 application: Application, 16 private val prefixLines: List<LogLine>, 17 private val untilTime: Long 18) : 19 PagedDataSource<Long, LogLine> { 20 21 val logDatabase = LogDatabase.getInstance(application) 22 23 override fun size(): Int { 24 return prefixLines.size + logDatabase.logs.getLogCountBeforeTime(untilTime) 25 } 26 27 override fun load(start: Int, length: Int, totalSize: Int, cancellationSignal: PagedDataSource.CancellationSignal): List<LogLine> { 28 if (start + length < prefixLines.size) { 29 return prefixLines.subList(start, start + length) 30 } else if (start < prefixLines.size) { 31 return prefixLines.subList(start, prefixLines.size) + 32 logDatabase.logs.getRangeBeforeTime(0, length - (prefixLines.size - start), untilTime).map { convertToLogLine(it) } 33 } else { 34 return logDatabase.logs.getRangeBeforeTime(start - prefixLines.size, length, untilTime).map { convertToLogLine(it) } 35 } 36 } 37 38 override fun load(key: Long?): LogLine? { 39 throw UnsupportedOperationException("Not implemented!") 40 } 41 42 override fun getKey(data: LogLine): Long { 43 return data.id 44 } 45 46 private fun convertToLogLine(raw: String): LogLine { 47 val scrubbed: String = Scrubber.scrub(raw).toString() 48 return SimpleLogLine(scrubbed, LogStyleParser.parseStyle(scrubbed), LogLine.Placeholder.NONE) 49 } 50}