kotlin 1.4に合わせたリファクタ
This commit is contained in:
parent
ad41d614ec
commit
86597ce6ea
|
@ -326,7 +326,7 @@ class ActAppSetting : AsyncActivity(), ColorPickerDialogListener, View.OnClickLi
|
|||
override fun getCount() : Int = list.size
|
||||
override fun getItemId(position : Int) : Long = 0
|
||||
override fun getItem(position : Int) : Any = list[position]
|
||||
override fun getViewTypeCount() : Int = SettingType.values().maxBy { it.id } !!.id + 1
|
||||
override fun getViewTypeCount() : Int = SettingType.values().maxByOrNull { it.id } !!.id + 1
|
||||
|
||||
override fun getItemViewType(position : Int) : Int =
|
||||
when(val item = list[position]) {
|
||||
|
|
|
@ -609,7 +609,7 @@ class ColumnTask_Loading(
|
|||
client.request(path_base)
|
||||
}
|
||||
if(result != null) {
|
||||
val src = parseList(::MisskeyAntenna, parser, result.jsonArray)
|
||||
val src = parseList(::MisskeyAntenna, result.jsonArray)
|
||||
column.saveRange(bBottom = true, bTop = true, result = result, list = src)
|
||||
this.list_tmp = addAll(null, src)
|
||||
}
|
||||
|
|
|
@ -1091,15 +1091,13 @@ enum class ColumnType(
|
|||
result = TootApiResult()
|
||||
} else {
|
||||
result =
|
||||
client.searchTootsearch(column.search_query, column.idOld?.toLong())
|
||||
client.searchTootsearch(column.search_query, null)
|
||||
val jsonObject = result?.jsonObject
|
||||
if(jsonObject != null) {
|
||||
// max_id の更新
|
||||
column.idOld = EntityId.mayNull(
|
||||
TootApiClient.getTootsearchMaxId(
|
||||
jsonObject,
|
||||
column.idOld?.toLong()
|
||||
)?.toString()
|
||||
TootApiClient.getTootsearchMaxId(jsonObject,null)
|
||||
?.toString()
|
||||
)
|
||||
|
||||
// リストデータの用意
|
||||
|
|
|
@ -61,7 +61,7 @@ internal fun Column.loadAntennaInfo(client : TootApiClient, bForceReload : Boole
|
|||
|
||||
val jsonObject = result?.jsonObject
|
||||
if(jsonObject != null) {
|
||||
val data = parseItem(::MisskeyAntenna, parser, jsonObject)
|
||||
val data = parseItem(::MisskeyAntenna, jsonObject)
|
||||
if(data != null) {
|
||||
this.antenna_info = data
|
||||
client.publishApiProgress("") // カラムヘッダの再表示
|
||||
|
|
|
@ -711,7 +711,7 @@ internal class StatusButtons(
|
|||
status : TootStatus,
|
||||
target : CustomShareTarget
|
||||
) {
|
||||
val url = status.url ?: status.uri ?: return
|
||||
val url = status.url ?: status.uri
|
||||
|
||||
CustomShare.invoke(activity, url, target)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package jp.juggler.subwaytooter.api.entity
|
||||
|
||||
import jp.juggler.subwaytooter.api.TootParser
|
||||
import jp.juggler.util.JsonArray
|
||||
import jp.juggler.util.JsonObject
|
||||
|
||||
class MisskeyAntenna(parser:TootParser,src: JsonObject) :TimelineItem(){
|
||||
class MisskeyAntenna(src : JsonObject) :TimelineItem(){
|
||||
|
||||
private val timeCreatedAt:Long // "2020-02-19T09:08:41.929Z"
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ open class TootTag constructor(
|
|||
countWeekly = history?.sumBy { it.uses } ?: 0
|
||||
|
||||
accountDaily = history?.first()?.accounts ?: 0
|
||||
accountWeekly = history?.map { it.accounts }?.max() ?: accountDaily
|
||||
accountWeekly = history?.map { it.accounts }?.maxOrNull() ?: accountDaily
|
||||
}
|
||||
|
||||
class History(src : JsonObject) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import okio.Sink
|
|||
import okio.Source
|
||||
import okio.Timeout
|
||||
import java.nio.ByteBuffer
|
||||
import kotlin.jvm.Throws
|
||||
import kotlin.math.max
|
||||
|
||||
class ProgressResponseBody private constructor(
|
||||
|
@ -29,7 +30,7 @@ class ProgressResponseBody private constructor(
|
|||
|
||||
// please append this for OkHttpClient.Builder#addInterceptor().
|
||||
// ex) builder.addInterceptor( ProgressResponseBody.makeInterceptor() );
|
||||
fun makeInterceptor() : Interceptor = object:Interceptor{
|
||||
fun makeInterceptor() : Interceptor = object : Interceptor {
|
||||
override fun intercept(chain : Interceptor.Chain) : Response {
|
||||
val originalResponse = chain.proceed(chain.request())
|
||||
|
||||
|
@ -68,7 +69,62 @@ class ProgressResponseBody private constructor(
|
|||
Make WrappedBufferedSource to capture BufferedSource.readByteArray().
|
||||
*/
|
||||
|
||||
private var wrappedSource : BufferedSource? = null
|
||||
private val wrappedSource : BufferedSource by lazy {
|
||||
val originalSource = originalBody.source()
|
||||
|
||||
try {
|
||||
// if it is RealBufferedSource, I can access to source public field via reflection.
|
||||
val field_source = originalSource.javaClass.getField("source")
|
||||
|
||||
// If there is the method, create the wrapper.
|
||||
object : ForwardingBufferedSource(originalSource) {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun readByteArray() : ByteArray {
|
||||
/*
|
||||
RealBufferedSource.readByteArray() does:
|
||||
- buffer.writeAll(source);
|
||||
- return buffer.readByteArray(buffer.size());
|
||||
|
||||
We do same things using Reflection, with progress.
|
||||
*/
|
||||
|
||||
try {
|
||||
val contentLength = originalBody.contentLength()
|
||||
val buffer = originalSource.buffer
|
||||
val source = field_source.get(originalSource) as Source?
|
||||
?: throw IllegalArgumentException("source == null")
|
||||
|
||||
// same thing of Buffer.writeAll(), with counting.
|
||||
var nRead : Long = 0
|
||||
callback(0, max(contentLength, 1))
|
||||
while(true) {
|
||||
val delta = source.read(buffer, 8192)
|
||||
if(delta == - 1L) break
|
||||
nRead += delta
|
||||
if(nRead > 0) {
|
||||
callback(nRead, max(contentLength, nRead))
|
||||
}
|
||||
}
|
||||
// EOS時の進捗
|
||||
callback(nRead, max(contentLength, nRead))
|
||||
|
||||
return buffer.readByteArray()
|
||||
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.e("readByteArray() failed. ")
|
||||
return originalSource.readByteArray()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} catch(ex : Throwable) {
|
||||
log.e("can't access to RealBufferedSource#source field.")
|
||||
originalSource
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
then you can read response body's bytes() with progress callback.
|
||||
|
@ -88,68 +144,7 @@ class ProgressResponseBody private constructor(
|
|||
return originalBody.contentLength()
|
||||
}
|
||||
|
||||
override fun source() : BufferedSource {
|
||||
var ws = wrappedSource
|
||||
if(ws == null) {
|
||||
|
||||
val originalSource = originalBody.source()
|
||||
|
||||
ws = try {
|
||||
// if it is RealBufferedSource, I can access to source public field via reflection.
|
||||
val field_source = originalSource.javaClass.getField("source")
|
||||
|
||||
// If there is the method, create the wrapper.
|
||||
object : ForwardingBufferedSource(originalSource) {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun readByteArray() : ByteArray {
|
||||
/*
|
||||
RealBufferedSource.readByteArray() does:
|
||||
- buffer.writeAll(source);
|
||||
- return buffer.readByteArray(buffer.size());
|
||||
|
||||
We do same things using Reflection, with progress.
|
||||
*/
|
||||
|
||||
try {
|
||||
val contentLength = originalBody.contentLength()
|
||||
val buffer = originalSource.buffer
|
||||
val source = field_source.get(originalSource) as Source?
|
||||
?: throw IllegalArgumentException("source == null")
|
||||
|
||||
// same thing of Buffer.writeAll(), with counting.
|
||||
var nRead : Long = 0
|
||||
callback(0, max(contentLength, 1))
|
||||
while(true) {
|
||||
val delta = source.read(buffer, 8192)
|
||||
if(delta == - 1L) break
|
||||
nRead += delta
|
||||
if(nRead > 0) {
|
||||
callback(nRead, max(contentLength, nRead))
|
||||
}
|
||||
}
|
||||
// EOS時の進捗
|
||||
callback(nRead, max(contentLength, nRead))
|
||||
|
||||
return buffer.readByteArray()
|
||||
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.e("readByteArray() failed. ")
|
||||
return originalSource.readByteArray()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} catch(ex : Throwable) {
|
||||
log.e("can't access to RealBufferedSource#source field.")
|
||||
originalSource
|
||||
}
|
||||
wrappedSource = ws
|
||||
}
|
||||
return ws
|
||||
}
|
||||
override fun source() : BufferedSource = wrappedSource
|
||||
|
||||
// To avoid double buffering, We have to make ForwardingBufferedSource.
|
||||
internal open class ForwardingBufferedSource(
|
||||
|
|
Loading…
Reference in New Issue