2021-06-28 09:09:00 +02:00
|
|
|
package jp.juggler.subwaytooter.actmain
|
2021-06-23 06:14:25 +02:00
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
import android.text.InputType
|
|
|
|
import android.view.View
|
|
|
|
import android.view.inputmethod.EditorInfo
|
|
|
|
import android.widget.TextView
|
|
|
|
import androidx.core.view.GravityCompat
|
2022-05-29 15:38:21 +02:00
|
|
|
import jp.juggler.subwaytooter.ActMain
|
|
|
|
import jp.juggler.subwaytooter.App1
|
|
|
|
import jp.juggler.subwaytooter.R
|
2022-03-15 12:39:37 +01:00
|
|
|
import jp.juggler.subwaytooter.actpost.CompletionHelper
|
2021-06-23 06:14:25 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootVisibility
|
|
|
|
import jp.juggler.subwaytooter.dialog.pickAccount
|
2023-01-13 13:22:25 +01:00
|
|
|
import jp.juggler.subwaytooter.getVisibilityIconId
|
2021-11-06 04:00:29 +01:00
|
|
|
import jp.juggler.subwaytooter.pref.PrefB
|
2022-03-15 12:39:37 +01:00
|
|
|
import jp.juggler.subwaytooter.table.SavedAccount
|
2021-06-23 06:14:25 +02:00
|
|
|
import jp.juggler.subwaytooter.util.PostImpl
|
2022-05-29 15:38:21 +02:00
|
|
|
import jp.juggler.subwaytooter.util.PostResult
|
2023-01-13 13:22:25 +01:00
|
|
|
import jp.juggler.util.coroutine.launchAndShowError
|
|
|
|
import jp.juggler.util.coroutine.launchMain
|
|
|
|
import jp.juggler.util.ui.hideKeyboard
|
2021-06-23 06:14:25 +02:00
|
|
|
import org.jetbrains.anko.imageResource
|
|
|
|
|
|
|
|
// 簡易投稿入力のテキスト
|
2021-06-28 09:09:00 +02:00
|
|
|
val ActMain.quickPostText: String
|
|
|
|
get() = etQuickPost.text.toString()
|
2021-06-23 06:14:25 +02:00
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
fun ActMain.initUIQuickPost() {
|
|
|
|
etQuickPost.typeface = ActMain.timelineFont
|
2021-06-24 04:31:34 +02:00
|
|
|
|
2023-01-13 13:22:25 +01:00
|
|
|
if (!PrefB.bpQuickPostBar.invoke(pref)) {
|
2021-06-28 09:09:00 +02:00
|
|
|
llQuickPostBar.visibility = View.GONE
|
2021-06-24 04:31:34 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
if (PrefB.bpDontUseActionButtonWithQuickPostBar(pref)) {
|
|
|
|
etQuickPost.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
|
|
|
etQuickPost.imeOptions = EditorInfo.IME_ACTION_NONE
|
2021-06-24 04:31:34 +02:00
|
|
|
// 最後に指定する必要がある?
|
2021-06-28 09:09:00 +02:00
|
|
|
etQuickPost.maxLines = 5
|
|
|
|
etQuickPost.isVerticalScrollBarEnabled = true
|
|
|
|
etQuickPost.isScrollbarFadingEnabled = false
|
2021-06-24 04:31:34 +02:00
|
|
|
} else {
|
2021-06-28 09:09:00 +02:00
|
|
|
etQuickPost.inputType = InputType.TYPE_CLASS_TEXT
|
|
|
|
etQuickPost.imeOptions = EditorInfo.IME_ACTION_SEND
|
|
|
|
etQuickPost.setOnEditorActionListener(TextView.OnEditorActionListener { _, actionId, _ ->
|
2021-06-24 04:31:34 +02:00
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
btnQuickToot.performClick()
|
|
|
|
return@OnEditorActionListener true
|
|
|
|
}
|
|
|
|
false
|
|
|
|
})
|
|
|
|
// 最後に指定する必要がある?
|
2021-06-28 09:09:00 +02:00
|
|
|
etQuickPost.maxLines = 1
|
2021-06-24 04:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
completionHelper.attachEditText(
|
|
|
|
llFormRoot,
|
2021-06-28 09:09:00 +02:00
|
|
|
etQuickPost,
|
2021-06-24 04:31:34 +02:00
|
|
|
true,
|
|
|
|
object : CompletionHelper.Callback2 {
|
|
|
|
override fun onTextUpdate() {}
|
|
|
|
|
|
|
|
override fun canOpenPopup(): Boolean {
|
|
|
|
return !drawer.isDrawerOpen(GravityCompat.START)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
showQuickPostVisibility()
|
2021-06-24 04:31:34 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
fun ActMain.showQuickPostVisibility() {
|
|
|
|
btnQuickPostMenu.imageResource =
|
2023-01-13 13:22:25 +01:00
|
|
|
when (val resId = getVisibilityIconId(false, quickPostVisibility)) {
|
2021-06-23 06:14:25 +02:00
|
|
|
R.drawable.ic_question -> R.drawable.ic_description
|
|
|
|
else -> resId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
fun ActMain.toggleQuickPostMenu() {
|
2021-06-23 06:14:25 +02:00
|
|
|
dlgQuickTootMenu.toggle()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun ActMain.performQuickPost(account: SavedAccount?) {
|
|
|
|
if (account == null) {
|
|
|
|
val a = if (tabletViews != null && !PrefB.bpQuickTootOmitAccountSelection(pref)) {
|
|
|
|
// タブレットモードでオプションが無効なら
|
|
|
|
// 簡易投稿は常にアカウント選択する
|
|
|
|
null
|
|
|
|
} else {
|
|
|
|
currentPostTarget
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a != null && !a.isPseudo) {
|
|
|
|
performQuickPost(a)
|
|
|
|
} else {
|
|
|
|
// アカウントを選択してやり直し
|
|
|
|
launchMain {
|
|
|
|
pickAccount(
|
|
|
|
bAllowPseudo = false,
|
|
|
|
bAuto = true,
|
|
|
|
message = getString(R.string.account_picker_toot)
|
|
|
|
)?.let { performQuickPost(it) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
etQuickPost.hideKeyboard()
|
2021-06-23 06:14:25 +02:00
|
|
|
|
2022-05-29 15:38:21 +02:00
|
|
|
launchAndShowError {
|
|
|
|
val postResult = PostImpl(
|
|
|
|
activity = this@performQuickPost,
|
|
|
|
account = account,
|
|
|
|
content = etQuickPost.text.toString().trim { it <= ' ' },
|
|
|
|
spoilerText = null,
|
|
|
|
visibilityArg = when (quickPostVisibility) {
|
|
|
|
TootVisibility.AccountSetting -> account.visibility
|
|
|
|
else -> quickPostVisibility
|
|
|
|
},
|
|
|
|
bNSFW = false,
|
|
|
|
inReplyToId = null,
|
|
|
|
attachmentListArg = null,
|
|
|
|
enqueteItemsArg = null,
|
|
|
|
pollType = null,
|
|
|
|
pollExpireSeconds = 0,
|
|
|
|
pollHideTotals = false,
|
|
|
|
pollMultipleChoice = false,
|
|
|
|
scheduledAt = 0L,
|
|
|
|
scheduledId = null,
|
|
|
|
redraftStatusId = null,
|
|
|
|
editStatusId = null,
|
|
|
|
emojiMapCustom = App1.custom_emoji_lister.getMapNonBlocking(account),
|
|
|
|
useQuoteToot = false,
|
2022-05-31 16:39:22 +02:00
|
|
|
lang = account.lang,
|
2022-05-29 15:38:21 +02:00
|
|
|
).runSuspend()
|
|
|
|
|
|
|
|
if (postResult is PostResult.Normal) {
|
|
|
|
etQuickPost.setText("")
|
|
|
|
postedAcct = postResult.targetAccount.acct
|
|
|
|
postedStatusId = postResult.status.id
|
|
|
|
postedReplyId = postResult.status.in_reply_to_id
|
|
|
|
postedRedraftId = null
|
|
|
|
refreshAfterPost()
|
2021-06-23 06:14:25 +02:00
|
|
|
}
|
2022-05-29 15:38:21 +02:00
|
|
|
}
|
2021-06-23 06:14:25 +02:00
|
|
|
}
|