MSP検索を開く導線を削除
This commit is contained in:
parent
e7bbae83af
commit
d034c98a09
|
@ -294,7 +294,7 @@ class ActMain : AppCompatActivity(),
|
||||||
|
|
||||||
val arActText = ActivityResultHandler(log) { r ->
|
val arActText = ActivityResultHandler(log) { r ->
|
||||||
when (r.resultCode) {
|
when (r.resultCode) {
|
||||||
ActText.RESULT_SEARCH_MSP -> searchFromActivityResult(r.data, ColumnType.SEARCH_MSP)
|
// ActText.RESULT_SEARCH_MSP -> searchFromActivityResult(r.data, ColumnType.SEARCH_MSP)
|
||||||
// ActText.RESULT_SEARCH_TS -> searchFromActivityResult(r.data, ColumnType.SEARCH_TS)
|
// ActText.RESULT_SEARCH_TS -> searchFromActivityResult(r.data, ColumnType.SEARCH_TS)
|
||||||
ActText.RESULT_SEARCH_NOTESTOCK -> searchFromActivityResult(
|
ActText.RESULT_SEARCH_NOTESTOCK -> searchFromActivityResult(
|
||||||
r.data,
|
r.data,
|
||||||
|
|
|
@ -24,8 +24,7 @@ class ActText : AppCompatActivity() {
|
||||||
|
|
||||||
internal val log = LogCategory("ActText")
|
internal val log = LogCategory("ActText")
|
||||||
|
|
||||||
internal const val RESULT_SEARCH_MSP = RESULT_FIRST_USER + 1
|
// internal const val RESULT_SEARCH_MSP = RESULT_FIRST_USER + 1
|
||||||
|
|
||||||
// internal const val RESULT_SEARCH_TS = RESULT_FIRST_USER + 2
|
// internal const val RESULT_SEARCH_TS = RESULT_FIRST_USER + 2
|
||||||
internal const val RESULT_SEARCH_NOTESTOCK = RESULT_FIRST_USER + 3
|
internal const val RESULT_SEARCH_NOTESTOCK = RESULT_FIRST_USER + 3
|
||||||
|
|
||||||
|
|
|
@ -378,9 +378,9 @@ class SideMenuAdapter(
|
||||||
Item(),
|
Item(),
|
||||||
Item(title = R.string.toot_search),
|
Item(title = R.string.toot_search),
|
||||||
|
|
||||||
Item(icon = R.drawable.ic_search, title = R.string.mastodon_search_portal) {
|
// Item(icon = R.drawable.ic_search, title = R.string.mastodon_search_portal) {
|
||||||
addColumn(defaultInsertPosition, SavedAccount.na, ColumnType.SEARCH_MSP, "")
|
// addColumn(defaultInsertPosition, SavedAccount.na, ColumnType.SEARCH_MSP, "")
|
||||||
},
|
// },
|
||||||
// Item(icon = R.drawable.ic_search, title = R.string.tootsearch) {
|
// Item(icon = R.drawable.ic_search, title = R.string.tootsearch) {
|
||||||
// addColumn(defaultInsertPosition, SavedAccount.na, ColumnType.SEARCH_TS, "")
|
// addColumn(defaultInsertPosition, SavedAccount.na, ColumnType.SEARCH_TS, "")
|
||||||
// },
|
// },
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package jp.juggler.subwaytooter.search
|
package jp.juggler.subwaytooter.search
|
||||||
|
|
||||||
import jp.juggler.subwaytooter.*
|
import android.content.Context
|
||||||
import jp.juggler.subwaytooter.column.addWithFilterStatus
|
import jp.juggler.subwaytooter.R
|
||||||
import jp.juggler.subwaytooter.api.TootApiClient
|
import jp.juggler.subwaytooter.api.TootApiClient
|
||||||
import jp.juggler.subwaytooter.api.TootApiResult
|
import jp.juggler.subwaytooter.api.TootApiResult
|
||||||
import jp.juggler.subwaytooter.api.TootParser
|
import jp.juggler.subwaytooter.api.TootParser
|
||||||
|
@ -9,10 +9,11 @@ import jp.juggler.subwaytooter.api.entity.EntityId
|
||||||
import jp.juggler.subwaytooter.api.entity.ServiceType
|
import jp.juggler.subwaytooter.api.entity.ServiceType
|
||||||
import jp.juggler.subwaytooter.column.ColumnTask_Loading
|
import jp.juggler.subwaytooter.column.ColumnTask_Loading
|
||||||
import jp.juggler.subwaytooter.column.ColumnTask_Refresh
|
import jp.juggler.subwaytooter.column.ColumnTask_Refresh
|
||||||
import jp.juggler.subwaytooter.pref.PrefS
|
import jp.juggler.subwaytooter.column.addWithFilterStatus
|
||||||
import jp.juggler.subwaytooter.pref.put
|
import jp.juggler.util.JsonArray
|
||||||
import jp.juggler.util.*
|
import jp.juggler.util.JsonObject
|
||||||
import okhttp3.Request
|
import jp.juggler.util.cast
|
||||||
|
import jp.juggler.util.notEmpty
|
||||||
|
|
||||||
object MspHelper {
|
object MspHelper {
|
||||||
private const val mspTokenUrl = "https://msearch.fediverse.media/api/v1.0.1/utoken"
|
private const val mspTokenUrl = "https://msearch.fediverse.media/api/v1.0.1/utoken"
|
||||||
|
@ -24,80 +25,86 @@ object MspHelper {
|
||||||
private fun getNextId(array: JsonArray, old: String?) =
|
private fun getNextId(array: JsonArray, old: String?) =
|
||||||
array.lastOrNull().cast<JsonObject>()?.string("msp_id")?.notEmpty() ?: old
|
array.lastOrNull().cast<JsonObject>()?.string("msp_id")?.notEmpty() ?: old
|
||||||
|
|
||||||
private suspend fun TootApiClient.search(query: String, maxId: String?): TootApiResult? {
|
@Suppress("unused", "RedundantSuspendModifier", "UNUSED_PARAMETER")
|
||||||
|
private suspend fun TootApiClient.search(
|
||||||
|
context: Context,
|
||||||
|
query: String,
|
||||||
|
maxId: String?,
|
||||||
|
): TootApiResult? {
|
||||||
|
return TootApiResult(context.getString(R.string.msp_discontinued))
|
||||||
|
|
||||||
// ユーザトークンを読む
|
// // ユーザトークンを読む
|
||||||
var user_token: String? = PrefS.spMspUserToken(pref)
|
// var user_token: String? = PrefS.spMspUserToken(pref)
|
||||||
|
//
|
||||||
for (nTry in 0 until 3) {
|
// for (nTry in 0 until 3) {
|
||||||
if (callback.isApiCancelled()) return null
|
// if (callback.isApiCancelled()) return null
|
||||||
|
//
|
||||||
// ユーザトークンがなければ取得する
|
// // ユーザトークンがなければ取得する
|
||||||
if (user_token == null || user_token.isEmpty()) {
|
// if (user_token == null || user_token.isEmpty()) {
|
||||||
|
//
|
||||||
callback.publishApiProgress("get MSP user token...")
|
// callback.publishApiProgress("get MSP user token...")
|
||||||
|
//
|
||||||
val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
// val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
||||||
if (result.error != null) return result
|
// if (result.error != null) return result
|
||||||
|
//
|
||||||
if (!sendRequest(result) {
|
// if (!sendRequest(result) {
|
||||||
Request.Builder()
|
// Request.Builder()
|
||||||
.url(mspTokenUrl + "?apikey=" + mspApiKey.encodePercent())
|
// .url(mspTokenUrl + "?apikey=" + mspApiKey.encodePercent())
|
||||||
.build()
|
// .build()
|
||||||
}) return result
|
// }) return result
|
||||||
|
//
|
||||||
val r2 = parseJson(result) { json ->
|
// val r2 = parseJson(result) { json ->
|
||||||
val error = json.string("error")
|
// val error = json.string("error")
|
||||||
if (error == null) {
|
// if (error == null) {
|
||||||
null
|
// null
|
||||||
} else {
|
// } else {
|
||||||
val type = json.string("type")
|
// val type = json.string("type")
|
||||||
"error: $type $error"
|
// "error: $type $error"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
val jsonObject = r2?.jsonObject ?: return r2
|
// val jsonObject = r2?.jsonObject ?: return r2
|
||||||
user_token = jsonObject.jsonObject("result")?.string("token")
|
// user_token = jsonObject.jsonObject("result")?.string("token")
|
||||||
if (user_token?.isEmpty() != false) {
|
// if (user_token?.isEmpty() != false) {
|
||||||
return result.setError("Can't get MSP user token. response=${result.bodyString}")
|
// return result.setError("Can't get MSP user token. response=${result.bodyString}")
|
||||||
} else {
|
// } else {
|
||||||
pref.edit().put(PrefS.spMspUserToken, user_token).apply()
|
// pref.edit().put(PrefS.spMspUserToken, user_token).apply()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// ユーザトークンを使って検索APIを呼び出す
|
// // ユーザトークンを使って検索APIを呼び出す
|
||||||
val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
// val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
||||||
if (result.error != null) return result
|
// if (result.error != null) return result
|
||||||
|
//
|
||||||
if (!sendRequest(result) {
|
// if (!sendRequest(result) {
|
||||||
val url = StringBuilder()
|
// val url = StringBuilder()
|
||||||
.append(mspSearchUrl)
|
// .append(mspSearchUrl)
|
||||||
.append("?apikey=").append(mspApiKey.encodePercent())
|
// .append("?apikey=").append(mspApiKey.encodePercent())
|
||||||
.append("&utoken=").append(user_token.encodePercent())
|
// .append("&utoken=").append(user_token.encodePercent())
|
||||||
.append("&q=").append(query.encodePercent())
|
// .append("&q=").append(query.encodePercent())
|
||||||
.append("&max=").append(maxId?.encodePercent() ?: "")
|
// .append("&max=").append(maxId?.encodePercent() ?: "")
|
||||||
|
//
|
||||||
Request.Builder().url(url.toString()).build()
|
// Request.Builder().url(url.toString()).build()
|
||||||
}) return result
|
// }) return result
|
||||||
|
//
|
||||||
var isUserTokenError = false
|
// var isUserTokenError = false
|
||||||
val r2 = parseJson(result) { json ->
|
// val r2 = parseJson(result) { json ->
|
||||||
val error = json.string("error")
|
// val error = json.string("error")
|
||||||
if (error == null) {
|
// if (error == null) {
|
||||||
null
|
// null
|
||||||
} else {
|
// } else {
|
||||||
// ユーザトークンがダメなら生成しなおす
|
// // ユーザトークンがダメなら生成しなおす
|
||||||
val detail = json.string("detail")
|
// val detail = json.string("detail")
|
||||||
if ("utoken" == detail) {
|
// if ("utoken" == detail) {
|
||||||
isUserTokenError = true
|
// isUserTokenError = true
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
val type = json.string("type")
|
// val type = json.string("type")
|
||||||
"API returns error: $type $error"
|
// "API returns error: $type $error"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (r2 == null || !isUserTokenError) return r2
|
// if (r2 == null || !isUserTokenError) return r2
|
||||||
}
|
// }
|
||||||
return TootApiResult("MSP user token retry exceeded.")
|
// return TootApiResult("MSP user token retry exceeded.")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseList(parser: TootParser, root: JsonArray) =
|
private fun parseList(parser: TootParser, root: JsonArray) =
|
||||||
|
@ -110,7 +117,11 @@ object MspHelper {
|
||||||
listTmp = java.util.ArrayList()
|
listTmp = java.util.ArrayList()
|
||||||
TootApiResult()
|
TootApiResult()
|
||||||
} else {
|
} else {
|
||||||
client.search(column.searchQuery, column.idOld?.toString())?.also { result ->
|
client.search(
|
||||||
|
context,
|
||||||
|
column.searchQuery,
|
||||||
|
column.idOld?.toString()
|
||||||
|
)?.also { result ->
|
||||||
result.jsonArray?.let { root ->
|
result.jsonArray?.let { root ->
|
||||||
column.idOld = EntityId.mayNull(getNextId(root, null))
|
column.idOld = EntityId.mayNull(getNextId(root, null))
|
||||||
listTmp = addWithFilterStatus(null, parseList(parser, root))
|
listTmp = addWithFilterStatus(null, parseList(parser, root))
|
||||||
|
@ -128,7 +139,11 @@ object MspHelper {
|
||||||
listTmp = ArrayList()
|
listTmp = ArrayList()
|
||||||
TootApiResult(context.getString(R.string.end_of_list))
|
TootApiResult(context.getString(R.string.end_of_list))
|
||||||
} else {
|
} else {
|
||||||
client.search(q, old)?.also { result ->
|
client.search(
|
||||||
|
context,
|
||||||
|
q,
|
||||||
|
old
|
||||||
|
)?.also { result ->
|
||||||
result.jsonArray?.let { root ->
|
result.jsonArray?.let { root ->
|
||||||
column.idOld = EntityId.mayNull(getNextId(root, column.idOld?.toString()))
|
column.idOld = EntityId.mayNull(getNextId(root, column.idOld?.toString()))
|
||||||
listTmp = addWithFilterStatus(listTmp, parseList(parser, root))
|
listTmp = addWithFilterStatus(listTmp, parseList(parser, root))
|
||||||
|
|
|
@ -1154,4 +1154,5 @@
|
||||||
<string name="unfollow_hashtag_of">\"%1$s\"のフォロー解除</string>
|
<string name="unfollow_hashtag_of">\"%1$s\"のフォロー解除</string>
|
||||||
<string name="conversation_with_reference">会話と参照</string>
|
<string name="conversation_with_reference">会話と参照</string>
|
||||||
<string name="tootsearch_discontinued">Tootsearchは2022/12/25にサービス終了しました。</string>
|
<string name="tootsearch_discontinued">Tootsearchは2022/12/25にサービス終了しました。</string>
|
||||||
|
<string name="msp_discontinued">マストドン検索ポータルはサービス終了しました。</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1163,4 +1163,5 @@
|
||||||
<string name="unfollow_hashtag_of">Unfollow %1$s</string>
|
<string name="unfollow_hashtag_of">Unfollow %1$s</string>
|
||||||
<string name="conversation_with_reference">conversation + reference</string>
|
<string name="conversation_with_reference">conversation + reference</string>
|
||||||
<string name="tootsearch_discontinued">Tootsearch service discontinued on 2022/12/25.</string>
|
<string name="tootsearch_discontinued">Tootsearch service discontinued on 2022/12/25.</string>
|
||||||
|
<string name="msp_discontinued">Mastodon Search Portal service was discontinued.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue