aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2019-03-25 23:29:17 +0900
committerKazuki Yamaguchi <k@rhe.jp>2019-03-25 23:29:17 +0900
commitfedd5082d627a9f732887be26ce0a8f95eb5ca20 (patch)
tree23b705b29940c0fd952e170e7565d7da92103ca6 /app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
parentf783d6ab9afa579c91e73305ffdd66df60ce5efa (diff)
downloadSmileEssence-fedd5082d627a9f732887be26ce0a8f95eb5ca20.tar.gz
make everything a page
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt217
1 files changed, 0 insertions, 217 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
deleted file mode 100644
index 1f38817d..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
+++ /dev/null
@@ -1,217 +0,0 @@
-package net.lacolaco.smileessence.view.dialog
-
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import kotlinx.android.synthetic.main.dialog_status_detail.view.*
-import net.lacolaco.smileessence.R
-import net.lacolaco.smileessence.activity.MainActivity
-import net.lacolaco.smileessence.entity.Tweet
-import net.lacolaco.smileessence.twitter.*
-import net.lacolaco.smileessence.util.*
-import net.lacolaco.smileessence.view.DialogHelper
-import net.lacolaco.smileessence.view.Partials
-import net.lacolaco.smileessence.view.PopupMenu
-import net.lacolaco.smileessence.view.confirm
-
-class StatusDetailDialogFragment : StackableDialogFragment() {
- private lateinit var tweet: Tweet
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- val id = arguments!!.getLong(KEY_STATUS_ID)
- val found = Tweet.cached(id)
- if (found == null) {
- world.notifyError("Tweet id=$id not found")
- dismissAllowingStateLoss()
- // NB: It seems onCreateView() is called even if dismiss() is called.
- tweet = Tweet.placeHolder
- return
- }
- tweet = found
- }
-
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
- val view = inflater.inflate(R.layout.dialog_status_detail, container, false)
-
- val statusHeader = Partials.getTweetView(tweet, world, activity!!, view.detail_current_status)
- statusHeader.isClickable = false
-
- // XXX
- view.button_status_detail_favorite.isActivated = world.id in tweet.favoriters
- view.button_status_detail_retweet.isActivated = world.id in tweet.retweets
- updateViewButtons(view)
- setupViewMenu(view)
-
- if (tweet.inReplyToStatusId != null) {
- view.tweet_in_reply_to.visibility = View.VISIBLE
- view.detail_dialog_divider_top.visibility = View.VISIBLE
- val cached = Tweet.cached(tweet.inReplyToStatusId!!)
- if (cached != null)
- Partials.getTweetView(cached, world, activity!!, view.tweet_in_reply_to)
- else {
- Partials.getTweetView(Tweet.placeHolder, world, activity!!, view.tweet_in_reply_to)
- launchUi {
- try {
- val tweet = world.getTweetAsync(tweet.inReplyToStatusId!!, false).await()
- Partials.getTweetView(tweet, world, activity!!, view.tweet_in_reply_to)
- } catch (e: TwitterTaskException) {
- }
- }
- }
- } else {
- view.tweet_in_reply_to.visibility = View.GONE
- view.detail_dialog_divider_top.visibility = View.GONE
- }
- return view
- }
-
- private fun updateViewButtons(view: View) {
- view.button_status_detail_reply.setOnClickListener {
- val originalTweet = tweet.originalTweet
-
- val builder = StringBuilder()
- builder.append("@${originalTweet.user.screenName} ")
-
- originalTweet.entities.mentions
- .filter { it != world.user.screenName }
- .forEach { builder.append("@$it ") }
- val text = builder.toString()
- val selStart = originalTweet.user.screenName.length + 2 // "@" and " "
-
- (activity as MainActivity).openPostPageAndReplyTo(originalTweet, text)
- }
- view.button_status_detail_retweet.setOnClickListener {
- confirm(R.string.dialog_confirm_commands) {
- if (world.id in tweet.retweets) {
- launchUi {
- try {
- world.deleteTweetAsync(tweet.retweets[world.id]!!).await()
- world.notify(R.string.notice_status_delete_succeeded)
- updateViewButtons(view)
- } catch (e: TwitterTaskException) {
- world.notifyError(R.string.notice_status_delete_failed)
- }
- }
- } else {
- launchUi {
- try {
- world.retweetAsync(tweet.id).await()
- world.notify(R.string.notice_retweet_succeeded)
- updateViewButtons(view)
- } catch (e: TwitterTaskException) {
- world.notifyError(R.string.notice_retweet_failed)
- }
- }
- }
- }
- }
- view.button_status_detail_favorite.setOnClickListener {
- val favoriting = world.id !in tweet.favoriters
-
- launchUi {
- try {
- if (favoriting) {
- world.favoriteAsync(tweet.id).await()
- world.notify(R.string.notice_favorite_succeeded)
- } else {
- world.unfavoriteAsync(tweet.id).await()
- world.notify(R.string.notice_unfavorite_succeeded)
- }
- } catch (e: TwitterTaskException) {
- if (favoriting)
- world.notifyError(R.string.notice_favorite_failed)
- else
- world.notifyError(R.string.notice_unfavorite_failed)
- }
- }
- }
- if (tweet.originalTweet.user === world.user)
- view.button_status_detail_delete.visibility = View.VISIBLE
- else
- view.button_status_detail_delete.visibility = View.GONE
- view.button_status_detail_delete.setOnClickListener {
- confirm(R.string.dialog_confirm_commands) {
- launchBg {
- try {
- world.deleteTweetAsync(tweet.originalTweet.id).await()
- world.notify(R.string.notice_status_delete_succeeded)
- } catch (e: TwitterTaskException) {
- world.notifyError(R.string.notice_status_delete_failed)
- }
- }
- dismiss()
- }
- }
- view.button_status_detail_menu.setOnClickListener {
- val popup = PopupMenu(activity!!, view.button_status_detail_menu)
- popup.add(R.string.command_status_add_to_reply) {
- val text = String.format("@%s ", tweet.originalTweet.user.screenName)
- (activity as MainActivity).openPostPageAndAppendText(text)
- world.notify(R.string.notice_add_to_reply)
- }
- popup.add(R.string.command_status_open_in_browser) {
- browse("https://twitter.com/${tweet.originalTweet.user.screenName}/status/${tweet.originalTweet.id}")
- }
- popup.add(R.string.command_status_copy_text_to_clipboard) {
- SystemServiceHelper.copyToClipboard(activity!!, "tweet text", tweet.originalTweet.text)
- world.notify(R.string.notice_copy_clipboard)
- }
- popup.add(R.string.command_status_copy_url_to_clipboard) {
- SystemServiceHelper.copyToClipboard(activity!!, "tweet url", "https://twitter.com/${tweet.originalTweet.user.screenName}/status/${tweet.originalTweet.id}")
- world.notify(R.string.notice_copy_clipboard)
- }
- popup.show()
- }
- }
-
- private fun setupViewMenu(view: View) {
- val addUserItem = { screenName: String, title: String ->
- view.embedded_menu_items.add("@$screenName", title) {
- val ref = ref(activity as MainActivity)
- launchUi {
- try {
- val user = world.getUserAsync(screenName).await()
- DialogHelper.showDialog(ref.get(), UserDetailDialogFragment.newInstance(user))
- } catch (e: TwitterTaskException) {
- world.notifyError(R.string.notice_error_show_user)
- }
- }
- }
- }
- if (tweet.user !== tweet.originalTweet.user)
- addUserItem(tweet.user.screenName, "RT by")
- for (screenName in tweet.entities.mentions.distinct().minus(tweet.user.screenName))
- addUserItem(screenName, "Mention")
- for (hashtag in tweet.entities.hashtags)
- view.embedded_menu_items.add("#$hashtag", "Hashtag") {
- // XXX
- (activity as MainActivity).openPostPageAndAppendText(" #$hashtag")
- }
- for (url in tweet.entities.urlsExpanded)
- view.embedded_menu_items.add(url, "URL") {
- activity!!.browse(url)
- }
- for (url in tweet.entities.mediaUrls)
- view.embedded_menu_items.add(url, "Media") {
- activity!!.browse(url)
- }
- if (view.embedded_menu_items.childCount == 0) {
- view.detail_dialog_divider_bottom.visibility = View.GONE
- view.embedded_menu_items.visibility = View.GONE
- }
- }
-
- companion object {
- private const val KEY_STATUS_ID = "status_id"
-
- fun newInstance(tweet: Tweet): StatusDetailDialogFragment {
- val obj = StatusDetailDialogFragment()
- val args = Bundle()
- args.putLong(KEY_STATUS_ID, tweet.id)
- obj.arguments = args
- return obj
- }
- }
-}