1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2025-02-09 16:48:47 +01:00

検索結果のページングに対応

This commit is contained in:
tateisu 2019-08-12 13:36:42 +09:00
parent bcee7f0ec8
commit ac8abbfa32
8 changed files with 114 additions and 9 deletions

View File

@ -1981,7 +1981,7 @@ class Column(
fireShowColumnStatus() fireShowColumnStatus()
} }
internal fun startGap(gap : TootGap?) { internal fun startGap(gap : TimelineItem?) {
if(gap == null) { if(gap == null) {
showToast(context, true, "gap is null") showToast(context, true, "gap is null")

View File

@ -9,18 +9,40 @@ import jp.juggler.subwaytooter.api.entity.*
import jp.juggler.util.* import jp.juggler.util.*
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import java.util.*
import kotlin.collections.ArrayList
class ColumnTask_Gap( class ColumnTask_Gap(
columnArg : Column, columnArg : Column,
private val gap : TootGap private val gap : TimelineItem
) : ColumnTask(columnArg, ColumnTaskType.GAP) { ) : ColumnTask(columnArg, ColumnTaskType.GAP) {
companion object { companion object {
internal val log = LogCategory("CT_Gap") internal val log = LogCategory("CT_Gap")
} }
private var max_id : EntityId? = gap.max_id private var max_id : EntityId? = (gap as? TootGap)?.max_id
private var since_id : EntityId? = gap.since_id private var since_id : EntityId? = (gap as? TootGap)?.since_id
private val countTag: Int
private val countAccount: Int
private val countStatus: Int
init{
var countTag =0
var countAccount =0
var countStatus = 0
if( gap is TootSearchGap){
columnArg.list_data.forEach {
when(it){
is TootTag -> ++countTag
is TootAccountRef -> ++countAccount
is TootStatus -> ++countStatus
}
}
}
this.countTag = countTag
this.countAccount = countAccount
this.countStatus = countStatus
}
override fun doInBackground(vararg unused : Void) : TootApiResult? { override fun doInBackground(vararg unused : Void) : TootApiResult? {
ctStarted.set(true) ctStarted.set(true)
@ -43,8 +65,8 @@ class ColumnTask_Gap(
try { try {
return (columnTypeProcMap[column.column_type] ?: columnTypeProcMap[Column.TYPE_HOME]) return (columnTypeProcMap[column.column_type] ?: columnTypeProcMap[Column.TYPE_HOME])
.gap(this, client) .gap(this, client)
}catch(ex:Throwable){ } catch(ex : Throwable) {
return TootApiResult( ex.withCaption("gap loading failed.") ) return TootApiResult(ex.withCaption("gap loading failed."))
} finally { } finally {
try { try {
column.updateRelation(client, list_tmp, column.who_account, parser) column.updateRelation(client, list_tmp, column.who_account, parser)
@ -767,4 +789,44 @@ class ColumnTask_Gap(
return result return result
} }
fun getSearchGap(client:TootApiClient):TootApiResult? {
if( gap !is TootSearchGap ) return null
// https://mastodon2.juggler.jp/api/v2/search?q=gargron&type=accounts&offset=5
val typeKey = when( gap.type ) {
TootSearchGap.SearchType.Hashtag -> "hashtags"
TootSearchGap.SearchType.Account -> "accounts"
TootSearchGap.SearchType.Status -> "statuses"
}
val offset = when( gap.type ) {
TootSearchGap.SearchType.Hashtag -> countTag
TootSearchGap.SearchType.Account -> countAccount
TootSearchGap.SearchType.Status -> countStatus
}
var path = String.format(
Locale.JAPAN,
Column.PATH_SEARCH_V2,
column.search_query.encodePercent()
)
if(column.search_resolve) path += "&resolve=1"
path += "&type=$typeKey&offset=$offset"
val result = client.request(path)
val jsonObject = result?.jsonObject
if(jsonObject != null) {
val tmp = parser.resultsV2(jsonObject)
if(tmp != null) {
list_tmp = ArrayList()
addAll(list_tmp, tmp.hashtags)
addAll(list_tmp, tmp.accounts)
addAll(list_tmp, tmp.statuses)
if(list_tmp?.isNotEmpty() == true) {
addOne(list_tmp, TootSearchGap(gap.type))
}
}
}
return result
}
} }

View File

@ -949,8 +949,17 @@ val columnTypeProcMap = SparseArray<ColumnTypeProc>().apply {
if(tmp != null) { if(tmp != null) {
list_tmp = ArrayList() list_tmp = ArrayList()
addAll(list_tmp, tmp.hashtags) addAll(list_tmp, tmp.hashtags)
if(tmp.hashtags.isNotEmpty()){
addOne(list_tmp,TootSearchGap(TootSearchGap.SearchType.Hashtag))
}
addAll(list_tmp, tmp.accounts) addAll(list_tmp, tmp.accounts)
if(tmp.accounts.isNotEmpty()){
addOne(list_tmp,TootSearchGap(TootSearchGap.SearchType.Account))
}
addAll(list_tmp, tmp.statuses) addAll(list_tmp, tmp.statuses)
if(tmp.statuses.isNotEmpty()){
addOne(list_tmp,TootSearchGap(TootSearchGap.SearchType.Status))
}
return@add result return@add result
} }
} }
@ -981,7 +990,9 @@ val columnTypeProcMap = SparseArray<ColumnTypeProc>().apply {
result result
} }
},
gap = { client ->
getSearchGap(client)
} }
) )

View File

@ -1,8 +1,6 @@
package jp.juggler.subwaytooter package jp.juggler.subwaytooter
import android.util.SparseArray
import jp.juggler.subwaytooter.api.TootApiClient import jp.juggler.subwaytooter.api.TootApiClient
import jp.juggler.subwaytooter.api.TootApiResult
import jp.juggler.subwaytooter.api.TootParser import jp.juggler.subwaytooter.api.TootParser
import jp.juggler.subwaytooter.api.entity.* import jp.juggler.subwaytooter.api.entity.*
import jp.juggler.subwaytooter.api.syncAccountByAcct import jp.juggler.subwaytooter.api.syncAccountByAcct

View File

@ -504,6 +504,7 @@ internal class ItemViewHolder(
is TootNotification -> showNotification(item) is TootNotification -> showNotification(item)
is TootGap -> showGap() is TootGap -> showGap()
is TootSearchGap -> showSearchGap(item)
is TootDomainBlock -> showDomainBlock(item) is TootDomainBlock -> showDomainBlock(item)
is TootList -> showList(item) is TootList -> showList(item)
@ -1026,6 +1027,15 @@ internal class ItemViewHolder(
btnSearchTag.text = activity.getString(R.string.read_gap) btnSearchTag.text = activity.getString(R.string.read_gap)
} }
private fun showSearchGap(item:TootSearchGap){
llSearchTag.visibility = View.VISIBLE
btnSearchTag.text = activity.getString(when(item.type){
TootSearchGap.SearchType.Hashtag -> R.string.read_more_hashtag
TootSearchGap.SearchType.Account -> R.string.read_more_account
TootSearchGap.SearchType.Status -> R.string.read_more_status
})
}
private fun showReply( private fun showReply(
iconId : Int, iconId : Int,
text : Spannable text : Spannable
@ -1837,6 +1847,7 @@ internal class ItemViewHolder(
is TootConversationSummary -> openConversationSummary() is TootConversationSummary -> openConversationSummary()
is TootGap -> column.startGap(item) is TootGap -> column.startGap(item)
is TootSearchGap -> column.startGap(item)
is TootDomainBlock -> { is TootDomainBlock -> {
val domain = item.domain val domain = item.domain

View File

@ -0,0 +1,17 @@
package jp.juggler.subwaytooter.api.entity
class TootSearchGap(val type: SearchType ) :TimelineItem(){
enum class SearchType{
Hashtag,
Account,
Status
}
override fun getOrderId() : EntityId {
return EntityId.DEFAULT
}
// constructor(max_id : Long, since_id : Long) : this(EntityIdLong(max_id), EntityIdLong(since_id))
}

View File

@ -923,5 +923,8 @@
<string name="bottom"></string> <string name="bottom"></string>
<string name="switch_button_color">スイッチボタンの色</string> <string name="switch_button_color">スイッチボタンの色</string>
<string name="max_toot_chars">投稿の最大文字数(0:デフォルト。サーバがmax_toot_charsを提供する場合はこの設定は無視されます)</string> <string name="max_toot_chars">投稿の最大文字数(0:デフォルト。サーバがmax_toot_charsを提供する場合はこの設定は無視されます)</string>
<string name="read_more_hashtag">ハッシュタグをもっと読む</string>
<string name="read_more_account">アカウントをもっと読む</string>
<string name="read_more_status">投稿をもっと読む</string>
</resources> </resources>

View File

@ -916,5 +916,8 @@
<string name="bottom">Bottom</string> <string name="bottom">Bottom</string>
<string name="switch_button_color">Switch button color</string> <string name="switch_button_color">Switch button color</string>
<string name="max_toot_chars">maximum character count in status (0:default. if server provides max_toot_chars, this setting is ignored.)</string> <string name="max_toot_chars">maximum character count in status (0:default. if server provides max_toot_chars, this setting is ignored.)</string>
<string name="read_more_hashtag">Read more hashtags</string>
<string name="read_more_account">Read more accounts</string>
<string name="read_more_status">Read more toots</string>
</resources> </resources>