2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter
|
|
|
|
|
|
|
|
import android.graphics.PorterDuff
|
|
|
|
import android.view.View
|
|
|
|
import android.widget.Button
|
|
|
|
import android.widget.ImageButton
|
|
|
|
import android.widget.ImageView
|
|
|
|
import android.widget.PopupWindow
|
|
|
|
|
|
|
|
import jp.juggler.subwaytooter.action.Action_Follow
|
|
|
|
import jp.juggler.subwaytooter.action.Action_Toot
|
2018-01-10 16:47:35 +01:00
|
|
|
import jp.juggler.subwaytooter.action.NOT_CROSS_ACCOUNT
|
2018-01-04 19:52:25 +01:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootNotification
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootStatus
|
|
|
|
import jp.juggler.subwaytooter.table.SavedAccount
|
|
|
|
import jp.juggler.subwaytooter.table.UserRelation
|
|
|
|
import jp.juggler.subwaytooter.util.LogCategory
|
|
|
|
|
|
|
|
internal class StatusButtons(
|
|
|
|
private val activity : ActMain,
|
|
|
|
private val column : Column,
|
2018-01-14 22:47:42 +01:00
|
|
|
private val bSimpleList : Boolean,
|
|
|
|
|
|
|
|
private val btnConversation : ImageButton,
|
|
|
|
private val btnReply : ImageButton,
|
|
|
|
private val btnBoost : Button,
|
|
|
|
private val btnFavourite : Button,
|
|
|
|
private val llFollow2 : View,
|
|
|
|
private val btnFollow2 : ImageButton,
|
|
|
|
private val ivFollowedBy2 : ImageView,
|
|
|
|
private val btnMore : ImageButton
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
) : View.OnClickListener, View.OnLongClickListener {
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
val log = LogCategory("StatusButtons")
|
|
|
|
}
|
|
|
|
|
|
|
|
private val access_info : SavedAccount
|
|
|
|
private var relation : UserRelation? = null
|
|
|
|
private var status : TootStatus? = null
|
|
|
|
private var notification : TootNotification? = null
|
|
|
|
|
|
|
|
var close_window : PopupWindow? = null
|
|
|
|
|
|
|
|
init {
|
|
|
|
this.access_info = column.access_info
|
|
|
|
|
2018-01-18 19:09:36 +01:00
|
|
|
btnBoost.setOnClickListener(this)
|
|
|
|
btnBoost.setOnLongClickListener(this)
|
|
|
|
btnFavourite.setOnClickListener(this)
|
|
|
|
btnFavourite.setOnLongClickListener(this)
|
|
|
|
btnFollow2.setOnClickListener(this)
|
|
|
|
btnFollow2.setOnLongClickListener(this)
|
|
|
|
btnMore.setOnClickListener(this)
|
|
|
|
btnConversation.setOnClickListener(this)
|
|
|
|
btnConversation.setOnLongClickListener(this)
|
|
|
|
btnReply.setOnClickListener(this)
|
|
|
|
btnReply.setOnLongClickListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fun bind(status : TootStatus, notification : TootNotification?) {
|
|
|
|
this.status = status
|
|
|
|
this.notification = notification
|
|
|
|
|
|
|
|
val color_normal = Styler.getAttributeColor(activity, R.attr.colorImageButton)
|
|
|
|
val color_accent = Styler.getAttributeColor(activity, R.attr.colorImageButtonAccent)
|
2018-01-17 18:39:16 +01:00
|
|
|
val fav_icon_attr =
|
|
|
|
if(access_info.isNicoru(status.account)) R.attr.ic_nicoru else R.attr.btn_favourite
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
// ブーストボタン
|
2018-01-04 19:52:25 +01:00
|
|
|
when {
|
2018-01-17 18:39:16 +01:00
|
|
|
TootStatus.VISIBILITY_DIRECT == status.visibility -> setButton(
|
|
|
|
btnBoost,
|
|
|
|
false,
|
|
|
|
color_accent,
|
|
|
|
R.attr.ic_mail,
|
|
|
|
""
|
|
|
|
)
|
2018-05-08 07:18:28 +02:00
|
|
|
// マストドン2.4.0から非公開トゥートもブーストできるようになった
|
|
|
|
// TootStatus.VISIBILITY_PRIVATE == status.visibility -> setButton(
|
|
|
|
// btnBoost,
|
|
|
|
// false,
|
|
|
|
// color_accent,
|
|
|
|
// R.attr.ic_lock,
|
|
|
|
// ""
|
|
|
|
// )
|
2018-01-17 18:39:16 +01:00
|
|
|
activity.app_state.isBusyBoost(access_info, status) -> setButton(
|
|
|
|
btnBoost,
|
|
|
|
false,
|
|
|
|
color_normal,
|
|
|
|
R.attr.btn_refresh,
|
|
|
|
"?"
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
else -> {
|
2018-01-17 18:39:16 +01:00
|
|
|
setButton(
|
|
|
|
btnBoost,
|
|
|
|
true,
|
2018-01-18 19:09:36 +01:00
|
|
|
if(status.reblogged) color_accent else color_normal,
|
2018-01-17 18:39:16 +01:00
|
|
|
R.attr.btn_boost,
|
|
|
|
status.reblogs_count?.toString() ?: ""
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
when {
|
2018-01-17 18:39:16 +01:00
|
|
|
activity.app_state.isBusyFav(access_info, status) -> setButton(
|
|
|
|
btnFavourite,
|
|
|
|
false,
|
|
|
|
color_normal,
|
|
|
|
R.attr.btn_refresh,
|
|
|
|
"?"
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
else -> {
|
2018-01-17 18:39:16 +01:00
|
|
|
setButton(
|
|
|
|
btnFavourite,
|
|
|
|
true,
|
2018-01-18 19:09:36 +01:00
|
|
|
if(status.favourited) color_accent else color_normal,
|
2018-01-17 18:39:16 +01:00
|
|
|
fav_icon_attr,
|
|
|
|
status.favourites_count?.toString() ?: ""
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val account = status.account
|
|
|
|
|
2018-01-17 18:39:16 +01:00
|
|
|
this.relation = if(! Pref.bpShowFollowButtonInButtonBar(activity.pref)) {
|
2018-01-04 19:52:25 +01:00
|
|
|
llFollow2.visibility = View.GONE
|
|
|
|
null
|
|
|
|
} else {
|
|
|
|
llFollow2.visibility = View.VISIBLE
|
|
|
|
val relation = UserRelation.load(access_info.db_id, account.id)
|
|
|
|
Styler.setFollowIcon(activity, btnFollow2, ivFollowedBy2, relation, account)
|
|
|
|
relation
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:39:16 +01:00
|
|
|
private fun setButton(
|
|
|
|
b : Button,
|
|
|
|
enabled : Boolean,
|
|
|
|
color : Int,
|
|
|
|
icon_attr : Int,
|
|
|
|
text : String
|
|
|
|
) {
|
2018-01-04 19:52:25 +01:00
|
|
|
val d = Styler.getAttributeDrawable(activity, icon_attr).mutate()
|
|
|
|
d.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
|
|
|
|
b.setCompoundDrawablesRelativeWithIntrinsicBounds(d, null, null, null)
|
|
|
|
b.text = text
|
|
|
|
b.setTextColor(color)
|
|
|
|
b.isEnabled = enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onClick(v : View) {
|
|
|
|
|
|
|
|
close_window?.dismiss()
|
|
|
|
close_window = null
|
|
|
|
|
|
|
|
val status = this.status ?: return
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
when(v) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-17 18:39:16 +01:00
|
|
|
btnConversation -> Action_Toot.conversation(
|
|
|
|
activity,
|
|
|
|
activity.nextPosition(column),
|
|
|
|
access_info,
|
|
|
|
status
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-17 18:39:16 +01:00
|
|
|
btnReply -> if(! access_info.isPseudo) {
|
2018-01-04 19:52:25 +01:00
|
|
|
Action_Toot.reply(activity, access_info, status)
|
|
|
|
} else {
|
|
|
|
Action_Toot.replyFromAnotherAccount(activity, access_info, status)
|
|
|
|
}
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
btnBoost -> {
|
|
|
|
if(access_info.isPseudo) {
|
|
|
|
Action_Toot.boostFromAnotherAccount(activity, access_info, status)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// トグル動作
|
2018-04-20 12:43:09 +02:00
|
|
|
val bSet = ! status.reblogged
|
2018-01-14 22:47:42 +01:00
|
|
|
|
|
|
|
Action_Toot.boost(
|
|
|
|
activity,
|
|
|
|
access_info,
|
|
|
|
status,
|
2018-05-08 07:59:28 +02:00
|
|
|
access_info.getFullAcct(status.account),
|
2018-01-14 22:47:42 +01:00
|
|
|
NOT_CROSS_ACCOUNT,
|
2018-04-20 12:43:09 +02:00
|
|
|
when {
|
|
|
|
! bSimpleList -> null
|
|
|
|
// 簡略表示なら結果をトースト表示
|
|
|
|
bSet -> activity.boost_complete_callback
|
|
|
|
else -> activity.unboost_complete_callback
|
|
|
|
},
|
|
|
|
bSet = bSet
|
2018-01-14 22:47:42 +01:00
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
btnFavourite -> {
|
|
|
|
if(access_info.isPseudo) {
|
|
|
|
Action_Toot.favouriteFromAnotherAccount(activity, access_info, status)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// トグル動作
|
2018-04-20 12:43:09 +02:00
|
|
|
val bSet = ! status.favourited
|
2018-01-14 22:47:42 +01:00
|
|
|
|
|
|
|
Action_Toot.favourite(
|
|
|
|
activity,
|
|
|
|
access_info,
|
|
|
|
status,
|
|
|
|
NOT_CROSS_ACCOUNT,
|
2018-04-20 12:43:09 +02:00
|
|
|
when {
|
|
|
|
! bSimpleList -> null
|
|
|
|
// 簡略表示なら結果をトースト表示
|
|
|
|
bSet -> activity.favourite_complete_callback
|
|
|
|
else -> activity.unfavourite_complete_callback
|
|
|
|
},
|
|
|
|
bSet = bSet
|
2018-01-14 22:47:42 +01:00
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
btnFollow2 -> {
|
2018-05-08 10:25:02 +02:00
|
|
|
val accountRef = status.accountRef
|
2018-05-18 19:08:46 +02:00
|
|
|
val account = accountRef.get()
|
2018-01-04 19:52:25 +01:00
|
|
|
val relation = this.relation ?: return
|
|
|
|
|
|
|
|
when {
|
|
|
|
access_info.isPseudo -> {
|
|
|
|
// 別アカでフォロー
|
|
|
|
Action_Follow.followFromAnotherAccount(
|
|
|
|
activity,
|
|
|
|
activity.nextPosition(column),
|
|
|
|
access_info,
|
|
|
|
account
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
relation.blocking || relation.muting -> {
|
|
|
|
// 何もしない
|
|
|
|
}
|
|
|
|
|
|
|
|
relation.getFollowing(account) || relation.getRequested(account) -> {
|
|
|
|
// フォロー解除
|
|
|
|
Action_Follow.follow(
|
|
|
|
activity,
|
|
|
|
activity.nextPosition(column),
|
|
|
|
access_info,
|
2018-05-08 10:25:02 +02:00
|
|
|
accountRef,
|
2018-01-10 16:47:35 +01:00
|
|
|
bFollow = false,
|
|
|
|
callback = activity.unfollow_complete_callback
|
2018-01-04 19:52:25 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
// フォロー
|
|
|
|
Action_Follow.follow(
|
|
|
|
activity,
|
|
|
|
activity.nextPosition(column),
|
|
|
|
access_info,
|
2018-05-08 10:25:02 +02:00
|
|
|
accountRef,
|
2018-01-17 18:39:16 +01:00
|
|
|
bFollow = true,
|
|
|
|
callback = activity.follow_complete_callback
|
2018-01-04 19:52:25 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 10:25:02 +02:00
|
|
|
btnMore -> DlgContextMenu(activity, column, status.accountRef, status, notification).show()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onLongClick(v : View) : Boolean {
|
|
|
|
|
|
|
|
close_window?.dismiss()
|
|
|
|
close_window = null
|
|
|
|
|
|
|
|
val status = this.status ?: return true
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
when(v) {
|
|
|
|
btnConversation -> Action_Toot.conversationOtherInstance(
|
2018-01-17 18:39:16 +01:00
|
|
|
activity, activity.nextPosition(column), status
|
|
|
|
)
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
btnBoost -> Action_Toot.boostFromAnotherAccount(
|
2018-01-17 18:39:16 +01:00
|
|
|
activity, access_info, status
|
|
|
|
)
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
btnFavourite -> Action_Toot.favouriteFromAnotherAccount(
|
2018-01-17 18:39:16 +01:00
|
|
|
activity, access_info, status
|
|
|
|
)
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
btnReply -> Action_Toot.replyFromAnotherAccount(
|
2018-01-17 18:39:16 +01:00
|
|
|
activity, access_info, status
|
|
|
|
)
|
|
|
|
|
2018-01-14 22:47:42 +01:00
|
|
|
btnFollow2 -> Action_Follow.followFromAnotherAccount(
|
2018-01-17 18:39:16 +01:00
|
|
|
activity, activity.nextPosition(column), access_info, status.account
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|