aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-10-05 20:08:37 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-10-05 22:08:57 +0900
commit15d4b9e5d13c8e39a135866fe9cbda70d83d5056 (patch)
tree90f1e02c10c6da9c6b14aab7132380811acec976 /app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
parent9db537d339faa3ad44dfdcadb23f4c14bd8aceb4 (diff)
downloadSmileEssence-15d4b9e5d13c8e39a135866fe9cbda70d83d5056.tar.gz
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt323
1 files changed, 129 insertions, 194 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
index 228a000a..ca634d92 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
@@ -33,13 +33,9 @@ import android.text.method.LinkMovementMethod
import android.view.View
import android.widget.AbsListView
import android.widget.ListView
-import android.widget.TabHost
-import android.widget.TextView
-import com.android.volley.toolbox.NetworkImageView
import com.handmark.pulltorefresh.library.PullToRefreshBase
-import com.handmark.pulltorefresh.library.PullToRefreshListView
+import kotlinx.android.synthetic.main.dialog_user_detail.view.*
import net.lacolaco.smileessence.R
-import net.lacolaco.smileessence.activity.MainActivity
import net.lacolaco.smileessence.data.ImageCache
import net.lacolaco.smileessence.entity.RBinding
import net.lacolaco.smileessence.entity.User
@@ -53,30 +49,54 @@ import net.lacolaco.smileessence.view.ThreeStateButton
import net.lacolaco.smileessence.view.adapter.TimelineAdapter
class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener, PullToRefreshBase.OnRefreshListener2<ListView> {
- private lateinit var adapter: TimelineAdapter
- private lateinit var textViewScreenName: TextView
- private lateinit var textViewName: TextView
- private lateinit var textViewURL: TextView
- private lateinit var textViewLocate: TextView
- private lateinit var textViewFollowed: TextView
- private lateinit var textViewProtected: TextView
- private lateinit var textViewDescription: TextView
- private lateinit var textViewTweetCount: TextView
- private lateinit var textViewFriendCount: TextView
- private lateinit var textViewFollowerCount: TextView
- private lateinit var textViewFavoriteCount: TextView
- private lateinit var imageViewIcon: NetworkImageView
- private lateinit var imageViewHeader: NetworkImageView
- private lateinit var buttonFollow: ThreeStateButton
- private lateinit var listViewTimeline: PullToRefreshListView
- private lateinit var tabHost: TabHost
- private lateinit var observerBundle: UIObserverBundle
+ private val adapter by lazy { TimelineAdapter(activity, world) }
+ private val observerBundle by lazy { UIObserverBundle() }
private lateinit var user: User
override fun onClick(v: View) {
when (v.id) {
R.id.imageview_user_detail_menu -> {
- openUserMenu()
+ val v = view
+ val builder = AlertDialog.Builder(activity)
+ builder.setTitle("@" + user.screenName)
+ .setItems(R.array.user_commands) { dialog, which ->
+ // XXX
+ UIHandler().postDelayed({
+ if (this@UserDetailDialogFragment.isAdded) {
+ updateRelationship(v)
+ }
+ }, 1000)
+ when (which) {
+ 0 -> {
+ val text = String.format("@%s ", user.screenName)
+ world.postState.beginTransaction().insertText(0, text).moveCursor(text.length).commit()
+ world.notify(R.string.notice_add_to_reply)
+ }
+ 1 -> DialogHelper.showDialog(activity, SendMessageDialogFragment.newInstance(user))
+ 2 -> ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
+ Users.BlockTask(world.account, user.id)
+ .onDone { user -> world.notify(R.string.notice_block_succeeded) }
+ .onFail { ex -> world.notifyError(R.string.notice_block_failed) }
+ .execute()
+ }
+ 3 -> ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
+ Users.UnblockTask(world.account, user.id)
+ .onDone { user -> world.notify(R.string.notice_unblock_succeeded) }
+ .onFail { x -> world.notifyError(R.string.notice_unblock_failed) }
+ .execute()
+ }
+ 4 -> ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
+ Users.ReportForSpamTask(world.account, user.id)
+ .onDone { user -> world.notify(R.string.notice_r4s_succeeded) }
+ .onFail { ex -> world.notifyError(R.string.notice_r4s_failed) }
+ .execute()
+ }
+ 5 -> IntentUtils.openUri(activity, user.aclogTimelineURL)
+ else -> throw IllegalStateException()
+ }
+ }
+ val dialog = builder.create()
+ dialog.show()
}
R.id.imageview_user_detail_icon -> {
IntentUtils.openUri(activity, user.profileImageUrl!!)
@@ -94,7 +114,29 @@ class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener
IntentUtils.openUri(activity, String.format("%s/favorites", user.userHomeURL))
}
R.id.button_user_detail_follow -> {
- ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) { this.toggleFollowing() }
+ val v = view
+ ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
+ val account = world.account
+ val isFollowing = v.button_user_detail_follow.state == ThreeStateButton.STATE_ON
+ v.button_user_detail_follow.state = ThreeStateButton.STATE_LOCKED
+ if (isFollowing) {
+ Users.UnfollowTask(account, user.id)
+ .onDoneUI { result ->
+ world.notify(R.string.notice_unfollow_succeeded)
+ updateRelationship(v)
+ }
+ .onFail { x -> world.notifyError(R.string.notice_unfollow_failed) }
+ .execute()
+ } else {
+ Users.FollowTask(account, user.id)
+ .onDoneUI { result ->
+ world.notify(R.string.notice_follow_succeeded)
+ updateRelationship(v)
+ }
+ .onFail { x -> world.notifyError(R.string.notice_follow_failed) }
+ .execute()
+ }
+ }
}
}
}
@@ -129,20 +171,12 @@ class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener
.execute()
}
- // ------------------------ OVERRIDE METHODS ------------------------
-
- override fun onCreate(savedInstanceState: Bundle) {
- super.onCreate(savedInstanceState)
- observerBundle = UIObserverBundle()
- }
-
override fun onDestroy() {
- super.onDestroy()
observerBundle.detachAll()
+ super.onDestroy()
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
- val activity = activity as MainActivity
val found = User.fetch(arguments.getLong(KEY_USER_ID))
if (found == null) {
world.notify(R.string.notice_error_show_user)
@@ -151,42 +185,39 @@ class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener
user = found
val v = activity.layoutInflater.inflate(R.layout.dialog_user_detail, null)
- val menu = v.findViewById(R.id.imageview_user_detail_menu)
- menu.setOnClickListener(this)
- textViewScreenName = v.findViewById(R.id.textview_user_detail_screenname) as TextView
- textViewScreenName.setOnClickListener(this)
- textViewName = v.findViewById(R.id.textview_user_detail_name) as TextView
- textViewURL = v.findViewById(R.id.textview_user_detail_url) as TextView
- textViewLocate = v.findViewById(R.id.textview_user_detail_locate) as TextView
- textViewFollowed = v.findViewById(R.id.textview_user_detail_followed) as TextView
- textViewProtected = v.findViewById(R.id.texttview_user_detail_protected) as TextView
- textViewDescription = v.findViewById(R.id.textview_user_detail_description) as TextView
- textViewDescription.movementMethod = LinkMovementMethod.getInstance()
- textViewTweetCount = v.findViewById(R.id.textview_user_detail_tweet_count) as TextView
- textViewTweetCount.setOnClickListener(this)
- textViewFriendCount = v.findViewById(R.id.textview_user_detail_friend_count) as TextView
- textViewFriendCount.setOnClickListener(this)
- textViewFollowerCount = v.findViewById(R.id.textview_user_detail_follower_count) as TextView
- textViewFollowerCount.setOnClickListener(this)
- textViewFavoriteCount = v.findViewById(R.id.textview_user_detail_favorite_count) as TextView
- textViewFavoriteCount.setOnClickListener(this)
- imageViewIcon = v.findViewById(R.id.imageview_user_detail_icon) as NetworkImageView
- imageViewIcon.setOnClickListener(this)
- imageViewHeader = v.findViewById(R.id.imageview_user_detail_header) as NetworkImageView
- buttonFollow = v.findViewById(R.id.button_user_detail_follow) as ThreeStateButton
- buttonFollow.setOnClickListener(this)
- listViewTimeline = v.findViewById(R.id.listview_user_detail_timeline) as PullToRefreshListView
- listViewTimeline.setOnRefreshListener(this)
+ v.imageview_user_detail_menu.setOnClickListener(this)
+ v.textview_user_detail_screenname.setOnClickListener(this)
+ v.textview_user_detail_description.movementMethod = LinkMovementMethod.getInstance()
+ v.textview_user_detail_tweet_count.setOnClickListener(this)
+ v.textview_user_detail_friend_count.setOnClickListener(this)
+ v.textview_user_detail_follower_count.setOnClickListener(this)
+ v.textview_user_detail_favorite_count.setOnClickListener(this)
+ v.imageview_user_detail_icon.setOnClickListener(this)
+ v.button_user_detail_follow.setOnClickListener(this)
+ v.listview_user_detail_timeline.setOnRefreshListener(this)
+
+ v.tabhost.setup()
+ val tab1 = v.tabhost.newTabSpec("tab1").setContent(R.id.tab1).setIndicator(getString(R.string.user_detail_tab_info))
+ v.tabhost.addTab(tab1)
+ val tab2 = v.tabhost.newTabSpec("tab2").setContent(R.id.tab2).setIndicator(getString(R.string.user_detail_tab_timeline))
+ v.tabhost.addTab(tab2)
+ v.tabhost.currentTab = 0
- tabHost = v.findViewById(android.R.id.tabhost) as TabHost
- tabHost.setup()
- val tab1 = tabHost.newTabSpec("tab1").setContent(R.id.tab1).setIndicator(getString(R.string.user_detail_tab_info))
- tabHost.addTab(tab1)
- val tab2 = tabHost.newTabSpec("tab2").setContent(R.id.tab2).setIndicator(getString(R.string.user_detail_tab_timeline))
- tabHost.addTab(tab2)
- tabHost.currentTab = 0
+ updateUserDataBasic(v)
+ updateUserDataDetail(v)
- initUserData()
+ v.listview_user_detail_timeline.setAdapter(adapter)
+ executeUserTimelineTask(v, adapter)
+ updateRelationship(v)
+
+ observerBundle.attach(user) { changes ->
+ if (activity != null) {
+ if (changes.contains(RBinding.BASIC))
+ updateUserDataBasic(v)
+ if (changes.contains(RBinding.DETAIL))
+ updateUserDataDetail(v)
+ }
+ }
return AlertDialog.Builder(activity)
.setView(v)
@@ -194,153 +225,57 @@ class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener
.create()
}
- private fun executeUserTimelineTask(adapter: TimelineAdapter) {
+ private fun executeUserTimelineTask(v: View, adapter: TimelineAdapter) {
val account = world.account
- tabHost.tabWidget.getChildTabViewAt(1).visibility = View.GONE
+ v.tabhost.tabWidget.getChildTabViewAt(1).visibility = View.GONE
Timelines.UserTimelineTask(account, user.id)
.setCount(200)
.onFail { x -> world.notifyError(R.string.notice_error_get_user_timeline) }
.onDoneUI { tweets ->
adapter.addAll(tweets)
adapter.updateForce()
- tabHost.tabWidget.getChildTabViewAt(1).visibility = View.VISIBLE
+ v.tabhost.tabWidget.getChildTabViewAt(1).visibility = View.VISIBLE
}
.execute()
}
private val htmlDescription: String?
get() {
- val description = user.description
- if (TextUtils.isEmpty(description)) {
- return ""
- }
- var html = description
- html = html!!.replace("https?://[\\w/:%#$&?()~.=+-]+".toRegex(), "<a href=\"$0\">$0</a>")
+ var html = user.description
+ html = html.replace("https?://[\\w/:%#$&?()~.=+-]+".toRegex(), "<a href=\"$0\">$0</a>")
html = html.replace("@([a-zA-Z0-9_]+)".toRegex(), "<a href=\"https://twitter.com/$1\">$0</a>")
html = html.replace("\r\n".toRegex(), "<br />")
return html
}
- private fun updateUserDataBasic() {
- textViewName.text = user.name
- textViewScreenName.text = user.screenName
- textViewProtected.visibility = if (user.isProtected) View.VISIBLE else View.GONE
- imageViewIcon.setImageUrl(user.profileImageUrl, ImageCache.getImageLoader())
+ private fun updateUserDataBasic(v: View) {
+ v.textview_user_detail_name.text = user.name
+ v.textview_user_detail_screenname.text = user.screenName
+ v.texttview_user_detail_protected.visibility = if (user.isProtected) View.VISIBLE else View.GONE
+ v.imageview_user_detail_icon.setImageUrl(user.profileImageUrl, ImageCache.getImageLoader())
}
- private fun updateUserDataDetail() {
+ private fun updateUserDataDetail(v: View) {
if (TextUtils.isEmpty(user.location)) {
- textViewLocate.visibility = View.GONE
+ v.textview_user_detail_locate.visibility = View.GONE
} else {
- textViewLocate.text = user.location
- textViewLocate.visibility = View.VISIBLE
+ v.textview_user_detail_locate.text = user.location
+ v.textview_user_detail_locate.visibility = View.VISIBLE
}
if (TextUtils.isEmpty(user.url)) {
- textViewURL.visibility = View.GONE
+ v.textview_user_detail_url.visibility = View.GONE
} else {
- textViewURL.text = user.url
- textViewURL.visibility = View.VISIBLE
- }
- textViewDescription.text = Html.fromHtml(htmlDescription)
-
- textViewTweetCount.text = user.statusesCount.toString()
- textViewFriendCount.text = user.friendsCount.toString()
- textViewFollowerCount.text = user.followersCount.toString()
- textViewFavoriteCount.text = user.favoritesCount.toString()
-
- imageViewHeader.setImageUrl(user.profileBannerUrl, ImageCache.getImageLoader())
- }
-
- private fun initUserData() {
- updateUserDataBasic()
- updateUserDataDetail()
-
- val activity = activity as MainActivity
- adapter = TimelineAdapter(activity)
- listViewTimeline.setAdapter(adapter)
- executeUserTimelineTask(adapter)
- updateRelationship()
-
- observerBundle.attach(user) { changes ->
- if (getActivity() != null) {
- if (changes.contains(RBinding.BASIC))
- updateUserDataBasic()
- if (changes.contains(RBinding.DETAIL))
- updateUserDataDetail()
- }
+ v.textview_user_detail_url.text = user.url
+ v.textview_user_detail_url.visibility = View.VISIBLE
}
- }
-
- private fun openUserMenu() {
- val builder = AlertDialog.Builder(activity)
- builder.setTitle("@" + user.screenName)
- .setItems(R.array.user_commands) { dialog, which ->
- // XXX
- UIHandler().postDelayed({
- if (this@UserDetailDialogFragment.isAdded) {
- updateRelationship()
- }
- }, 1000)
- when (which) {
- 0 -> {
- val text = String.format("@%s ", user.screenName)
- world.postState.beginTransaction().insertText(0, text).moveCursor(text.length).commit()
- world.notify(R.string.notice_add_to_reply)
- }
- 1 -> DialogHelper.showDialog(activity, SendMessageDialogFragment.newInstance(user))
- 2 -> ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
- Users.BlockTask(world.account, user.id)
- .onDone { user -> world.notify(R.string.notice_block_succeeded) }
- .onFail { ex -> world.notifyError(R.string.notice_block_failed) }
- .execute()
- }
- 3 -> ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
- Users.UnblockTask(world.account, user.id)
- .onDone { user -> world.notify(R.string.notice_unblock_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_unblock_failed) }
- .execute()
- }
- 4 -> ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
- Users.ReportForSpamTask(world.account, user.id)
- .onDone { user -> world.notify(R.string.notice_r4s_succeeded) }
- .onFail { ex -> world.notifyError(R.string.notice_r4s_failed) }
- .execute()
- }
- 5 -> IntentUtils.openUri(activity, user.aclogTimelineURL)
- else -> throw IllegalStateException()
- }
- }
- val dialog = builder.create()
- dialog.show()
- }
+ v.textview_user_detail_description.text = Html.fromHtml(htmlDescription)
- private fun setFollowButtonState(isFollowing: Boolean) {
- if (activity != null) {
- buttonFollow.state = if (isFollowing) ThreeStateButton.STATE_ON else ThreeStateButton.STATE_OFF
- }
- }
+ v.textview_user_detail_tweet_count.text = user.statusesCount.toString()
+ v.textview_user_detail_friend_count.text = user.friendsCount.toString()
+ v.textview_user_detail_follower_count.text = user.followersCount.toString()
+ v.textview_user_detail_favorite_count.text = user.favoritesCount.toString()
- private fun toggleFollowing() {
- val account = world.account
- val isFollowing = buttonFollow.state == ThreeStateButton.STATE_ON
- buttonFollow.state = ThreeStateButton.STATE_LOCKED
- if (isFollowing) {
- Users.UnfollowTask(account, user.id)
- .onDoneUI { result ->
- world.notify(R.string.notice_unfollow_succeeded)
- updateRelationship()
- }
- .onFail { x -> world.notifyError(R.string.notice_unfollow_failed) }
- .execute()
- } else {
- Users.FollowTask(account, user.id)
- .onDoneUI { result ->
- world.notify(R.string.notice_follow_succeeded)
- updateRelationship()
- }
- .onFail { x -> world.notifyError(R.string.notice_follow_failed) }
- .execute()
- }
+ v.imageview_user_detail_header.setImageUrl(user.profileBannerUrl, ImageCache.getImageLoader())
}
private fun updateListView(absListView: AbsListView, adapter: TimelineAdapter, addedToTop: Boolean) {
@@ -359,19 +294,19 @@ class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener
}
}
- private fun updateRelationship() {
+ private fun updateRelationship(v: View) {
val account = world.account
if (user === account.user) {
- textViewFollowed.setText(R.string.user_detail_followed_is_me)
- buttonFollow.visibility = View.GONE
+ v.textview_user_detail_followed.setText(R.string.user_detail_followed_is_me)
+ v.button_user_detail_follow.visibility = View.GONE
} else {
- buttonFollow.state = ThreeStateButton.STATE_LOCKED
- textViewFollowed.setText(R.string.user_detail_loading)
+ v.button_user_detail_follow.state = ThreeStateButton.STATE_LOCKED
+ v.textview_user_detail_followed.setText(R.string.user_detail_loading)
Users.ShowFriendshipTask(account, user.id).onDoneUI { relationship ->
val isFollowing = relationship.isSourceFollowingTarget
val isFollowed = relationship.isSourceFollowedByTarget
- setFollowButtonState(isFollowing)
- textViewFollowed.setText(if (isFollowed) R.string.user_detail_followed else R.string.user_detail_not_followed)
+ v.button_user_detail_follow.state = if (isFollowing) ThreeStateButton.STATE_ON else ThreeStateButton.STATE_OFF
+ v.textview_user_detail_followed.setText(if (isFollowed) R.string.user_detail_followed else R.string.user_detail_not_followed)
}.execute()
}
}