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
|
2021-06-28 09:09:00 +02:00
|
|
|
import jp.juggler.subwaytooter.*
|
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.TootStatus
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootVisibility
|
|
|
|
import jp.juggler.subwaytooter.dialog.pickAccount
|
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.PostCompleteCallback
|
|
|
|
import jp.juggler.subwaytooter.util.PostImpl
|
|
|
|
import jp.juggler.util.hideKeyboard
|
|
|
|
import jp.juggler.util.launchMain
|
|
|
|
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
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
if (!PrefB.bpQuickPostBar(pref)) {
|
|
|
|
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 =
|
|
|
|
when (val resId = Styler.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
|
|
|
|
|
|
|
PostImpl(
|
|
|
|
activity = this,
|
|
|
|
account = account,
|
2021-06-28 09:09:00 +02:00
|
|
|
content = etQuickPost.text.toString().trim { it <= ' ' },
|
2021-06-23 06:14:25 +02:00
|
|
|
spoilerText = null,
|
2021-06-28 09:09:00 +02:00
|
|
|
visibilityArg = when (quickPostVisibility) {
|
2021-06-23 06:14:25 +02:00
|
|
|
TootVisibility.AccountSetting -> account.visibility
|
2021-06-28 09:09:00 +02:00
|
|
|
else -> quickPostVisibility
|
2021-06-23 06:14:25 +02:00
|
|
|
},
|
|
|
|
bNSFW = false,
|
|
|
|
inReplyToId = null,
|
|
|
|
attachmentListArg = null,
|
|
|
|
enqueteItemsArg = null,
|
|
|
|
pollType = null,
|
|
|
|
pollExpireSeconds = 0,
|
|
|
|
pollHideTotals = false,
|
|
|
|
pollMultipleChoice = false,
|
|
|
|
scheduledAt = 0L,
|
|
|
|
scheduledId = null,
|
|
|
|
redraftStatusId = null,
|
2022-03-15 12:39:37 +01:00
|
|
|
editStatusId = null,
|
2021-06-23 06:14:25 +02:00
|
|
|
emojiMapCustom = App1.custom_emoji_lister.getMap(account),
|
|
|
|
useQuoteToot = false,
|
|
|
|
callback = object : PostCompleteCallback {
|
|
|
|
override fun onScheduledPostComplete(targetAccount: SavedAccount) {}
|
|
|
|
override fun onPostComplete(targetAccount: SavedAccount, status: TootStatus) {
|
2021-06-28 09:09:00 +02:00
|
|
|
etQuickPost.setText("")
|
2021-06-23 06:14:25 +02:00
|
|
|
postedAcct = targetAccount.acct
|
|
|
|
postedStatusId = status.id
|
|
|
|
postedReplyId = status.in_reply_to_id
|
|
|
|
postedRedraftId = null
|
|
|
|
refreshAfterPost()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).run()
|
|
|
|
}
|