스팀 앱 - 개발 중: 사용자 히스토리 화면 개선 중

스팀 앱 - 개발 중: 사용자 히스토리 화면 개선 중

2024. 08. 03 (토) | Written by @dorian-mobileapp

히스토리 화면을 개선 중입니다. 항목들의 타입이 다양한데요. 그 중 일부를 사용자가 이해할 수 있는 텍스트로 변환을 구현했습니다.


AccountHistoryItem.getUserReadableContent() 메소드

AccountHistoryItem 객체의 content 필드(Map<String, Any> 타입)를 사용자가 이해 가능한 텍스트로 변환해 주는 메소드입니다. 이 객체의 type 값에 따라 각기 다른 메소드들을 호출하게 했습니다.

fun AccountHistoryItem.getUserReadableContent(): String {
    return when (type) {
        "vote" -> getVoteContent()
        "transfer" -> getTransferContent()
        "curation_reward" -> getCurationRewardContent()
        "claim_reward_balance" -> getClaimRewardBalance()
        "comment" -> getCommentContent()
        else -> content.toString()
    }
}

AccountHistoryItem 객체의 type별로 호출할 메소드들은 아래와 같습니다.

fun AccountHistoryItem.getVoteContent(): String {
    if (type != "vote") {
        return ""
    }

    val voter = content.read("voter", "")
    val author = content.read("author", "")
    val permlink = content.read("permlink", "")
    val weight = content.read("weight", 0.0) / 100.0
    return "@${voter} votes @${author}/${permlink}. (${weight}%)"
}

fun AccountHistoryItem.getTransferContent(): String {
    if (type != "transfer") {
        return ""
    }

    val from = content.read("from", "")
    val to = content.read("to", "")
    val memo = content.read("memo", "")
    val amount = content.read("amount", "0.0 STEEM")
    return "@${from} to @${to}: ${amount}\n\n${memo}"
}

fun AccountHistoryItem.getCurationRewardContent(): String {
    if (type != "curation_reward") {
        return ""
    }

    val curator = content.read("curator", "")
    val reward = content.read("reward", "")
    val commentAuthor = content.read("comment_author", "")
    val commentPermlink = content.read("comment_permlink", "")
    return "${reward} from @${commentAuthor}/${commentPermlink}"
}

fun AccountHistoryItem.getClaimRewardBalance(): String {
    if (type != "claim_reward_balance") {
        return ""
    }

    val account = content.read("account", "")
    val rewardSteem = content.read("reward_steem", "")
    val rewardSbd = content.read("reward_sbd", "")
    val rewardVests = content.read("reward_vests", "")
    return "Claimed ${rewardSteem}, ${rewardSbd}, ${rewardVests}"
}

fun AccountHistoryItem.getCommentContent(): String {
    if (type != "comment") {
        return ""
    }

    // val parentAuthor = content.read("parent_author", "")
    // val parentPermlink = content.read("parent_permlink", "")
    val author = content.read("author", "")
    val permlink = content.read("permlink", "")
    val title = content.read("title", "")
    // val body = content.read("body", "")
    // val jsonMetadata = content.read("json_metadata", "")
    return "@${author} commented @${author}/${permlink}${
        when (title.isNotEmpty()) {
            true -> "\n\n${title}"
            else -> ""
        }
    }"
}

AccountHistoryItemListViewHolder 클래스

사용자 히스토리 항목을 업데이트 하는 이 클래스에서 AccountHistoryItem 객체의 getUserReadableContent() 메소드를 호출합니다.

inner class AccountHistoryItemListViewHolder(
    val binding: LayoutAccountHistoryItemBinding
) : RecyclerView.ViewHolder(binding.root) {
    fun bind(accountHistoryItem: AccountHistoryItem, position: Int) {
        binding.apply {
            textHistoryItemType.text = accountHistoryItem.type
            textHistoryItemContent.text = accountHistoryItem.getUserReadableContent()
            textHistoryItemTime.text = accountHistoryItem.localTime
            root.setBackgroundColor(when (position.isOdd()) {
                true -> Color.rgb(0xEE, 0xEE, 0xEE)
                else -> Color.WHITE
            })
        }
    }
}

Layout provided by Steemit Enhancer hommage by ayogom


Posted through the ECblog app (https://blog.etain.club)
Sort:  

안녕하세요.
SteemitKorea팀에서 제공하는 'steemit-enhancer'를 사용해 주셔서 감사합니다. 개선 사항이 있으면 언제나 저에게 연락을 주시면 되고, 관심이 있으신 분들은 https://cafe.naver.com/steemitkorea/425 에서 받아보실 수 있습니다. 사용시 @응원해 가 포함이 되며, 악용시에는 모든 서비스에서 제외될 수 있음을 알려드립니다.

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.


안녕하세요.
이 글은 SteemitKorea팀(@ayogom)님께서 저자이신 @dorian-mobileapp님을 응원하는 글입니다.
소정의 보팅을 해드렸습니다 ^^ 항상 좋은글 부탁드립니다
SteemitKorea팀에서는 보다 즐거운 steemit 생활을 위해 노력하고 있습니다.
이 글은 다음날 다시 한번 포스팅을 통해 소개 될 예정입니다. 감사합니다!

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.

Upvoted! Thank you for supporting witness @jswit.

Coin Marketplace

STEEM 0.19
TRX 0.17
JST 0.033
BTC 63989.15
ETH 2749.61
USDT 1.00
SBD 2.66