aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-10-10 18:15:41 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-10-10 18:22:33 +0900
commit901356520a22c1160b08b972416085c317579fde (patch)
tree8220a237de8f711cbd21e42f62c3e18d86b2cd00 /app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
parent25404ac5fa085fad902973ac59d6b831ed7f57b7 (diff)
downloadSmileEssence-901356520a22c1160b08b972416085c317579fde.tar.gz
coroutine-ify2017-10-10
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.kt92
1 files changed, 58 insertions, 34 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
index 3fcd40d1..d2784cdf 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
@@ -16,9 +16,12 @@ import net.lacolaco.smileessence.command.CommandOpenURL
import net.lacolaco.smileessence.command.CommandOpenUserDetail
import net.lacolaco.smileessence.entity.Tweet
import net.lacolaco.smileessence.preference.UserPreferenceHelper
-import net.lacolaco.smileessence.twitter.task.TweetReactions
-import net.lacolaco.smileessence.twitter.task.Tweets
+import net.lacolaco.smileessence.twitter.TwitterTaskException
+import net.lacolaco.smileessence.twitter.task.*
import net.lacolaco.smileessence.util.SystemServiceHelper
+import net.lacolaco.smileessence.util.bg
+import net.lacolaco.smileessence.util.launchBg
+import net.lacolaco.smileessence.util.launchUi
import net.lacolaco.smileessence.view.DialogHelper
import net.lacolaco.smileessence.view.Partials
import net.lacolaco.smileessence.view.adapter.TimelineAdapter
@@ -53,12 +56,16 @@ class StatusDetailDialogFragment : StackableDialogFragment() {
if (tweet.inReplyToStatusId != -1L) {
view.detail_dialog_divider_top.visibility = View.VISIBLE
view.listview_status_detail_reply_to.visibility = View.VISIBLE
- Tweet.fetchTask(tweet.inReplyToStatusId, world.account)
- .onDoneUI { replyTo ->
- adapter.add(replyTo)
- adapter.update()
- }
- .execute()
+
+ bg {
+ val inreply = try {
+ world.getTweetAsync(tweet.inReplyToStatusId, false).await()
+ } catch (e: Exception) {
+ return@bg
+ }
+ adapter.add(inreply)
+ adapter.update()
+ }
} else {
view.detail_dialog_divider_top.visibility = View.GONE
view.listview_status_detail_reply_to.visibility = View.GONE
@@ -114,43 +121,60 @@ class StatusDetailDialogFragment : StackableDialogFragment() {
val account = world.account
confirm({
if (tweet.isRetweetedBy(account.userId)) {
- Tweets.DestroyTask(account, tweet.getRetweetIdBy(account.userId))
- .onDone { t -> world.notify(R.string.notice_status_delete_succeeded) }
- .onFail { e -> world.notifyError(R.string.notice_status_delete_failed) }
- .onFinishUI { updateViewReactions(view) }
- .execute()
+ launchUi {
+ try {
+ world.deleteTweetAsync(tweet.getRetweetIdBy(account.userId)).await()
+ world.notify(R.string.notice_status_delete_succeeded)
+ updateViewButtons(view)
+ } catch (e: TwitterTaskException) {
+ world.notifyError(R.string.notice_status_delete_failed)
+ }
+ }
} else {
- TweetReactions.RetweetTask(account, tweet.id)
- .onDone { x -> world.notify(R.string.notice_retweet_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_retweet_failed) }
- .onFinishUI { updateViewReactions(view) }
- .execute()
+ launchUi {
+ try {
+ world.retweetAsync(tweet.getRetweetIdBy(account.userId)).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 account = world.account
- if (tweet.isFavoritedBy(account.userId)) {
- TweetReactions.UnfavoriteTask(account, tweet.id)
- .onDone { x -> world.notify(R.string.notice_unfavorite_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_unfavorite_failed) }
- .onFinishUI { updateViewReactions(view) }
- .execute()
- } else {
- TweetReactions.FavoriteTask(account, tweet.id)
- .onDone { x -> world.notify(R.string.notice_favorite_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_favorite_failed) }
- .onFinishUI { updateViewReactions(view) }
- .execute()
+ val favoriting = !tweet.isFavoritedBy(account.userId)
+
+ 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)
+ }
}
}
view.button_status_detail_delete.visibility = if (tweet.originalTweet.user === world.account.user) View.VISIBLE else View.GONE
view.button_status_detail_delete.setOnClickListener {
confirm({
- Tweets.DestroyTask(world.account, tweet.originalTweet.id)
- .onDone { t -> world.notify(R.string.notice_status_delete_succeeded) }
- .onFail { e -> world.notifyError(R.string.notice_status_delete_failed) }
- .execute()
+ 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()
})
}