mirror of
https://github.com/tateisu/SubwayTooter
synced 2025-02-04 04:37:40 +01:00
検索結果のページングに対応
This commit is contained in:
parent
bcee7f0ec8
commit
ac8abbfa32
@ -1981,7 +1981,7 @@ class Column(
|
||||
fireShowColumnStatus()
|
||||
}
|
||||
|
||||
internal fun startGap(gap : TootGap?) {
|
||||
internal fun startGap(gap : TimelineItem?) {
|
||||
|
||||
if(gap == null) {
|
||||
showToast(context, true, "gap is null")
|
||||
|
@ -9,18 +9,40 @@ import jp.juggler.subwaytooter.api.entity.*
|
||||
import jp.juggler.util.*
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class ColumnTask_Gap(
|
||||
columnArg : Column,
|
||||
private val gap : TootGap
|
||||
private val gap : TimelineItem
|
||||
) : ColumnTask(columnArg, ColumnTaskType.GAP) {
|
||||
|
||||
companion object {
|
||||
internal val log = LogCategory("CT_Gap")
|
||||
}
|
||||
|
||||
private var max_id : EntityId? = gap.max_id
|
||||
private var since_id : EntityId? = gap.since_id
|
||||
private var max_id : EntityId? = (gap as? TootGap)?.max_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? {
|
||||
ctStarted.set(true)
|
||||
@ -43,8 +65,8 @@ class ColumnTask_Gap(
|
||||
try {
|
||||
return (columnTypeProcMap[column.column_type] ?: columnTypeProcMap[Column.TYPE_HOME])
|
||||
.gap(this, client)
|
||||
}catch(ex:Throwable){
|
||||
return TootApiResult( ex.withCaption("gap loading failed.") )
|
||||
} catch(ex : Throwable) {
|
||||
return TootApiResult(ex.withCaption("gap loading failed."))
|
||||
} finally {
|
||||
try {
|
||||
column.updateRelation(client, list_tmp, column.who_account, parser)
|
||||
@ -767,4 +789,44 @@ class ColumnTask_Gap(
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -949,8 +949,17 @@ val columnTypeProcMap = SparseArray<ColumnTypeProc>().apply {
|
||||
if(tmp != null) {
|
||||
list_tmp = ArrayList()
|
||||
addAll(list_tmp, tmp.hashtags)
|
||||
if(tmp.hashtags.isNotEmpty()){
|
||||
addOne(list_tmp,TootSearchGap(TootSearchGap.SearchType.Hashtag))
|
||||
}
|
||||
addAll(list_tmp, tmp.accounts)
|
||||
if(tmp.accounts.isNotEmpty()){
|
||||
addOne(list_tmp,TootSearchGap(TootSearchGap.SearchType.Account))
|
||||
}
|
||||
addAll(list_tmp, tmp.statuses)
|
||||
if(tmp.statuses.isNotEmpty()){
|
||||
addOne(list_tmp,TootSearchGap(TootSearchGap.SearchType.Status))
|
||||
}
|
||||
return@add result
|
||||
}
|
||||
}
|
||||
@ -981,7 +990,9 @@ val columnTypeProcMap = SparseArray<ColumnTypeProc>().apply {
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
},
|
||||
gap = { client ->
|
||||
getSearchGap(client)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package jp.juggler.subwaytooter
|
||||
|
||||
import android.util.SparseArray
|
||||
import jp.juggler.subwaytooter.api.TootApiClient
|
||||
import jp.juggler.subwaytooter.api.TootApiResult
|
||||
import jp.juggler.subwaytooter.api.TootParser
|
||||
import jp.juggler.subwaytooter.api.entity.*
|
||||
import jp.juggler.subwaytooter.api.syncAccountByAcct
|
||||
|
@ -504,6 +504,7 @@ internal class ItemViewHolder(
|
||||
is TootNotification -> showNotification(item)
|
||||
|
||||
is TootGap -> showGap()
|
||||
is TootSearchGap -> showSearchGap(item)
|
||||
is TootDomainBlock -> showDomainBlock(item)
|
||||
is TootList -> showList(item)
|
||||
|
||||
@ -1026,6 +1027,15 @@ internal class ItemViewHolder(
|
||||
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(
|
||||
iconId : Int,
|
||||
text : Spannable
|
||||
@ -1837,6 +1847,7 @@ internal class ItemViewHolder(
|
||||
is TootConversationSummary -> openConversationSummary()
|
||||
|
||||
is TootGap -> column.startGap(item)
|
||||
is TootSearchGap -> column.startGap(item)
|
||||
|
||||
is TootDomainBlock -> {
|
||||
val domain = item.domain
|
||||
|
@ -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))
|
||||
}
|
@ -923,5 +923,8 @@
|
||||
<string name="bottom">下</string>
|
||||
<string name="switch_button_color">スイッチボタンの色</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>
|
||||
|
@ -916,5 +916,8 @@
|
||||
<string name="bottom">Bottom</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="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>
|
Loading…
x
Reference in New Issue
Block a user