1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2025-02-07 06:04:23 +01:00

アカウント追加時に非対応のPixelfedサーバを指定すると勝手にアカウント作成ダイアログを開いてしまうのを修正

This commit is contained in:
tateisu 2019-11-25 00:28:37 +09:00
parent 5fd43462c9
commit 28133651ec
3 changed files with 69 additions and 60 deletions

View File

@ -57,7 +57,6 @@ class ActAbout : AppCompatActivity() {
) )
} }
override fun onCreate(savedInstanceState : Bundle?) { override fun onCreate(savedInstanceState : Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
App1.setActivityTheme(this) App1.setActivityTheme(this)

View File

@ -23,14 +23,18 @@ import kotlin.math.min
class MyAppGlideModule : AppGlideModule() { class MyAppGlideModule : AppGlideModule() {
companion object{ companion object{
private val svgSig = "<svg".toByteArray(Charsets.UTF_8) private val svgSig = "<svg".toByteArray(Charsets.UTF_8)
private fun findBytes(data:ByteArray,dataSize:Int = data.size,key:ByteArray):Int{ private fun findBytes(data:ByteArray,dataSize:Int = data.size,key:ByteArray):Int{
fun check(start:Int):Boolean{ fun check(start:Int):Boolean{
for(j in key.indices){ for(j in key.indices){
if( data[start+j] != key[j] ) return false if( data[start+j] != key[j] ) return false
} }
return true return true
} }
for(i in 0 .. dataSize - key.size){ for(i in 0 .. dataSize - key.size){
if(check(i)) return i if(check(i)) return i
} }
@ -41,13 +45,13 @@ class MyAppGlideModule : AppGlideModule() {
// Decodes an SVG internal representation from an [InputStream]. // Decodes an SVG internal representation from an [InputStream].
inner class SvgDecoder : ResourceDecoder<InputStream, SVG> { inner class SvgDecoder : ResourceDecoder<InputStream, SVG> {
@Throws(IOException::class)
override fun handles(source : InputStream, options : Options) : Boolean { override fun handles(source : InputStream, options : Options) : Boolean {
val size = min(source.available(),1024) val size = min(source.available(),1024)
if(size<=0) return false if(size<=0) return false
val buf = ByteArray(size) val buf = ByteArray(size)
val nRead = source.read(buf,0,size) val nRead = source.read(buf,0,size)
val isSvg = -1 != findBytes(buf,nRead,svgSig) return -1 != findBytes(buf,nRead, svgSig)
return isSvg
} }

View File

@ -31,14 +31,37 @@ object Action_Account {
) { dialog, instance, action -> ) { dialog, instance, action ->
TootTaskRunner(activity).run(instance, object : TootTask { TootTaskRunner(activity).run(instance, object : TootTask {
override fun background(client : TootApiClient) : TootApiResult? = when(action) { override fun background(client : TootApiClient) : TootApiResult? {
LoginForm.Action.Existing -> client.authentication1(Pref.spClientName(activity)) return when(action) {
LoginForm.Action.Create -> client.createUser1(Pref.spClientName(activity)) LoginForm.Action.Existing -> client.authentication1(
Pref.spClientName(
LoginForm.Action.Pseudo, LoginForm.Action.Token -> { activity
val (ti, ri) = TootInstance.get(client) )
if(ti != null) ri?.data = ti )
ri LoginForm.Action.Create -> client.createUser1(Pref.spClientName(activity))
LoginForm.Action.Pseudo, LoginForm.Action.Token -> {
val (ti, ri) = TootInstance.get(client)
if(ti != null) ri?.data = ti
ri
}
}
}
private fun handleError(result : TootApiResult) {
val error = result.error ?: "(no error information)"
if(error.contains("SSLHandshakeException")
&& (Build.VERSION.RELEASE.startsWith("7.0")
|| Build.VERSION.RELEASE.startsWith("7.1")
&& ! Build.VERSION.RELEASE.startsWith("7.1.")
)
) {
AlertDialog.Builder(activity)
.setMessage(error + "\n\n" + activity.getString(R.string.ssl_bug_7_0))
.setNeutralButton(R.string.close, null)
.show()
} else {
showToast(activity, true, "$error ${result.requestInfo}".trim())
} }
} }
@ -46,31 +69,32 @@ object Action_Account {
result ?: return // cancelled. result ?: return // cancelled.
when(val data = result.data) { val error = result.error
val data = result.data
// ブラウザ用URLが生成された (LoginForm.Action.Existing) if(error == null && data != null) {
is String -> { when(action) {
val intent = Intent() LoginForm.Action.Existing -> if(data is String) {
intent.data = data.toUri() // ブラウザ用URLが生成された (LoginForm.Action.Existing)
activity.startAccessTokenUpdate(intent) val intent = Intent()
dialog.dismissSafe() intent.data = data.toUri()
} activity.startAccessTokenUpdate(intent)
dialog.dismissSafe()
// インスタンスを確認できた (LoginForm.Action.Create) return
is JSONObject -> { }
createAccount(
activity, LoginForm.Action.Create -> if(data is JSONObject) {
instance, // インスタンスを確認できた
data, createAccount(
dialog activity,
) instance,
} data,
dialog
// インスタンス情報を取得した( Pseudo, Token ) )
is TootInstance -> { return
when(action) { }
LoginForm.Action.Pseudo -> addPseudoAccount( LoginForm.Action.Pseudo -> if(data is TootInstance) {
addPseudoAccount(
activity, activity,
instance, instance,
instanceInfo = data instanceInfo = data
@ -80,8 +104,10 @@ object Action_Account {
activity.addColumn(pos, a, ColumnType.LOCAL) activity.addColumn(pos, a, ColumnType.LOCAL)
dialog.dismissSafe() dialog.dismissSafe()
} }
}
LoginForm.Action.Token -> DlgTextInput.show(
LoginForm.Action.Token -> if(data is TootInstance) {
DlgTextInput.show(
activity, activity,
activity.getString(R.string.access_token_or_api_token), activity.getString(R.string.access_token_or_api_token),
null, null,
@ -109,30 +135,10 @@ object Action_Account {
} }
} }
) )
// never happen
else -> {
}
}
}
else -> {
val error = result.error ?: "(no error information)"
if(error.contains("SSLHandshakeException")
&& (Build.VERSION.RELEASE.startsWith("7.0")
|| Build.VERSION.RELEASE.startsWith("7.1")
&& ! Build.VERSION.RELEASE.startsWith("7.1.")
)
) {
AlertDialog.Builder(activity)
.setMessage(error + "\n\n" + activity.getString(R.string.ssl_bug_7_0))
.setNeutralButton(R.string.close, null)
.show()
} else {
showToast(activity, true, "$error ${result.requestInfo}".trim())
} }
} }
} }
handleError(result)
} }
}) })
} }
@ -253,7 +259,7 @@ object Action_Account {
) { ) {
activity.post_helper.closeAcctPopup() activity.post_helper.closeAcctPopup()
val db_id = activity.currentPostTarget?.db_id ?: -1L val db_id = activity.currentPostTarget?.db_id ?: - 1L
if(db_id != - 1L) { if(db_id != - 1L) {
ActPost.open(activity, ActMain.REQUEST_CODE_POST, db_id, initial_text = initial_text) ActPost.open(activity, ActMain.REQUEST_CODE_POST, db_id, initial_text = initial_text)
} else { } else {