aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java423
1 files changed, 0 insertions, 423 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java
deleted file mode 100644
index c8d62fa8..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.view.dialog;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.os.Bundle;
-import android.text.Html;
-import android.text.TextUtils;
-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 net.lacolaco.smileessence.R;
-import net.lacolaco.smileessence.activity.MainActivity;
-import net.lacolaco.smileessence.data.Account;
-import net.lacolaco.smileessence.data.ImageCache;
-import net.lacolaco.smileessence.entity.RBinding;
-import net.lacolaco.smileessence.entity.User;
-import net.lacolaco.smileessence.twitter.task.Timelines;
-import net.lacolaco.smileessence.twitter.task.Users;
-import net.lacolaco.smileessence.util.IntentUtils;
-import net.lacolaco.smileessence.util.UIHandler;
-import net.lacolaco.smileessence.util.UIObserverBundle;
-import net.lacolaco.smileessence.view.DialogHelper;
-import net.lacolaco.smileessence.view.ThreeStateButton;
-import net.lacolaco.smileessence.view.adapter.TimelineAdapter;
-
-public class UserDetailDialogFragment extends StackableDialogFragment implements View.OnClickListener,
- PullToRefreshBase.OnRefreshListener2<ListView> {
-
- // ------------------------------ FIELDS ------------------------------
-
- private static final String KEY_USER_ID = "userID";
- private TimelineAdapter adapter;
- private TextView textViewScreenName;
- private TextView textViewName;
- private TextView textViewURL;
- private TextView textViewLocate;
- private TextView textViewFollowed;
- private TextView textViewProtected;
- private TextView textViewDescription;
- private TextView textViewTweetCount;
- private TextView textViewFriendCount;
- private TextView textViewFollowerCount;
- private TextView textViewFavoriteCount;
- private NetworkImageView imageViewIcon;
- private NetworkImageView imageViewHeader;
- private ThreeStateButton buttonFollow;
- private PullToRefreshListView listViewTimeline;
- private TabHost tabHost;
- private UIObserverBundle observerBundle;
- private User user;
-
- // --------------------- GETTER / SETTER METHODS ---------------------
-
- public long getUserID() {
- return getArguments().getLong(KEY_USER_ID);
- }
-
- public void setUserID(long userID) {
- Bundle args = new Bundle();
- args.putLong(KEY_USER_ID, userID);
- setArguments(args);
- }
-
- // ------------------------ INTERFACE METHODS ------------------------
-
-
- // --------------------- Interface OnClickListener ---------------------
-
- @Override
- public void onClick(final View v) {
- switch (v.getId()) {
- case R.id.imageview_user_detail_menu: {
- openUserMenu();
- break;
- }
- case R.id.imageview_user_detail_icon: {
- IntentUtils.openUri(getActivity(), user.getProfileImageUrlOriginal());
- break;
- }
- case R.id.textview_user_detail_screenname:
- case R.id.textview_user_detail_tweet_count: {
- IntentUtils.openUri(getActivity(), user.getUserHomeURL());
- break;
- }
- case R.id.textview_user_detail_friend_count: {
- IntentUtils.openUri(getActivity(), String.format("%s/following", user.getUserHomeURL()));
- break;
- }
- case R.id.textview_user_detail_follower_count: {
- IntentUtils.openUri(getActivity(), String.format("%s/followers", user.getUserHomeURL()));
- break;
- }
- case R.id.textview_user_detail_favorite_count: {
- IntentUtils.openUri(getActivity(), String.format("%s/favorites", user.getUserHomeURL()));
- break;
- }
- case R.id.button_user_detail_follow: {
- ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), this::toggleFollowing);
- break;
- }
- }
- }
-
- // --------------------- Interface OnRefreshListener2 ---------------------
-
- @Override
- public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) {
- Account currentAccount = getWorld().getAccount();
- new Timelines.UserTimelineTask(currentAccount, getUserID())
- .setCount(200)
- .setSinceId(adapter.getTopID())
- .onFail(x -> getWorld().notifyError(R.string.notice_error_get_user_timeline))
- .onDoneUI(tweets -> {
- adapter.addAll(tweets);
- updateListView(refreshView.getRefreshableView(), adapter, true);
- refreshView.onRefreshComplete();
- })
- .execute();
- }
-
- @Override
- public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) {
- Account currentAccount = getWorld().getAccount();
- new Timelines.UserTimelineTask(currentAccount, getUserID())
- .setCount(200)
- .setMaxId(adapter.getLastID() - 1)
- .onFail(x -> getWorld().notifyError(R.string.notice_error_get_user_timeline))
- .onDoneUI(tweets -> {
- adapter.addAll(tweets);
- updateListView(refreshView.getRefreshableView(), adapter, false);
- refreshView.onRefreshComplete();
- })
- .execute();
- }
-
- // ------------------------ OVERRIDE METHODS ------------------------
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- user = User.fetch(getUserID());
- observerBundle = new UIObserverBundle();
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- observerBundle.detachAll();
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- MainActivity activity = (MainActivity) getActivity();
- if (user == null) {
- getWorld().notify(R.string.notice_error_show_user);
- return new DisposeDialog(activity);
- }
-
- View v = activity.getLayoutInflater().inflate(R.layout.dialog_user_detail, null);
- View menu = v.findViewById(R.id.imageview_user_detail_menu);
- menu.setOnClickListener(this);
- textViewScreenName = (TextView) v.findViewById(R.id.textview_user_detail_screenname);
- textViewScreenName.setOnClickListener(this);
- textViewName = (TextView) v.findViewById(R.id.textview_user_detail_name);
- textViewURL = (TextView) v.findViewById(R.id.textview_user_detail_url);
- textViewLocate = (TextView) v.findViewById(R.id.textview_user_detail_locate);
- textViewFollowed = (TextView) v.findViewById(R.id.textview_user_detail_followed);
- textViewProtected = (TextView) v.findViewById(R.id.texttview_user_detail_protected);
- textViewDescription = (TextView) v.findViewById(R.id.textview_user_detail_description);
- textViewDescription.setMovementMethod(LinkMovementMethod.getInstance());
- textViewTweetCount = (TextView) v.findViewById(R.id.textview_user_detail_tweet_count);
- textViewTweetCount.setOnClickListener(this);
- textViewFriendCount = (TextView) v.findViewById(R.id.textview_user_detail_friend_count);
- textViewFriendCount.setOnClickListener(this);
- textViewFollowerCount = (TextView) v.findViewById(R.id.textview_user_detail_follower_count);
- textViewFollowerCount.setOnClickListener(this);
- textViewFavoriteCount = (TextView) v.findViewById(R.id.textview_user_detail_favorite_count);
- textViewFavoriteCount.setOnClickListener(this);
- imageViewIcon = (NetworkImageView) v.findViewById(R.id.imageview_user_detail_icon);
- imageViewIcon.setOnClickListener(this);
- imageViewHeader = (NetworkImageView) v.findViewById(R.id.imageview_user_detail_header);
- buttonFollow = (ThreeStateButton) v.findViewById(R.id.button_user_detail_follow);
- buttonFollow.setOnClickListener(this);
- listViewTimeline = (PullToRefreshListView) v.findViewById(R.id.listview_user_detail_timeline);
- listViewTimeline.setOnRefreshListener(this);
-
- tabHost = (TabHost) v.findViewById(android.R.id.tabhost);
- tabHost.setup();
- TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1").setContent(R.id.tab1).setIndicator(getString(R.string.user_detail_tab_info));
- tabHost.addTab(tab1);
- TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2").setContent(R.id.tab2).setIndicator(getString(R.string.user_detail_tab_timeline));
- tabHost.addTab(tab2);
- tabHost.setCurrentTab(0);
-
- initUserData();
-
- return new AlertDialog.Builder(activity)
- .setView(v)
- .setCancelable(true)
- .create();
- }
-
- private void executeUserTimelineTask(final TimelineAdapter adapter) {
- Account account = getWorld().getAccount();
- tabHost.getTabWidget().getChildTabViewAt(1).setVisibility(View.GONE);
- new Timelines.UserTimelineTask(account, user.getId())
- .setCount(200)
- .onFail(x -> getWorld().notifyError(R.string.notice_error_get_user_timeline))
- .onDoneUI(tweets -> {
- adapter.addAll(tweets);
- adapter.updateForce();
- tabHost.getTabWidget().getChildTabViewAt(1).setVisibility(View.VISIBLE);
- })
- .execute();
- }
-
- private String getHtmlDescription() {
- String description = user.getDescription();
- if (TextUtils.isEmpty(description)) {
- return "";
- }
- String html = description;
- html = html.replaceAll("https?://[\\w/:%#$&?()~.=+-]+", "<a href=\"$0\">$0</a>");
- html = html.replaceAll("@([a-zA-Z0-9_]+)", "<a href=\"https://twitter.com/$1\">$0</a>");
- html = html.replaceAll("\r\n", "<br />");
- return html;
- }
-
- private void updateUserDataBasic() {
- textViewName.setText(user.getName());
- textViewScreenName.setText(user.getScreenName());
- textViewProtected.setVisibility(user.isProtected() ? View.VISIBLE : View.GONE);
- imageViewIcon.setImageUrl(user.getProfileImageUrlOriginal(), ImageCache.getImageLoader());
- }
-
- private void updateUserDataDetail() {
- if (TextUtils.isEmpty(user.getLocation())) {
- textViewLocate.setVisibility(View.GONE);
- } else {
- textViewLocate.setText(user.getLocation());
- textViewLocate.setVisibility(View.VISIBLE);
- }
- if (TextUtils.isEmpty(user.getUrl())) {
- textViewURL.setVisibility(View.GONE);
- } else {
- textViewURL.setText(user.getUrl());
- textViewURL.setVisibility(View.VISIBLE);
- }
- textViewDescription.setText(Html.fromHtml(getHtmlDescription()));
-
- textViewTweetCount.setText(String.valueOf(user.getStatusesCount()));
- textViewFriendCount.setText(String.valueOf(user.getFriendsCount()));
- textViewFollowerCount.setText(String.valueOf(user.getFollowersCount()));
- textViewFavoriteCount.setText(String.valueOf(user.getFavoritesCount()));
-
- imageViewHeader.setImageUrl(user.getProfileBannerUrl(), ImageCache.getImageLoader());
- }
-
- private void initUserData() {
- updateUserDataBasic();
- updateUserDataDetail();
-
- MainActivity activity = (MainActivity) getActivity();
- adapter = new 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();
- }
- });
- }
-
- private void openUserMenu() {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setTitle("@" + user.getScreenName())
- .setItems(R.array.user_commands, (dialog, which) -> {
- // XXX
- new UIHandler().postDelayed(() -> {
- if (UserDetailDialogFragment.this.isAdded()) {
- updateRelationship();
- }
- }, 1000);
- switch (which) {
- case 0:
- String text = String.format("@%s ", user.getScreenName());
- getWorld().getPostState().beginTransaction().insertText(0, text).moveCursor(text.length()).commit();
- getWorld().notify(R.string.notice_add_to_reply);
- break;
- case 1:
- DialogHelper.showDialog(getActivity(), SendMessageDialogFragment.newInstance(user));
- break;
- case 2:
- ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), () ->
- new Users.BlockTask(getWorld().getAccount(), user.getId())
- .onDone(user -> getWorld().notify(R.string.notice_block_succeeded))
- .onFail(ex -> getWorld().notifyError(R.string.notice_block_failed))
- .execute());
- break;
- case 3:
- ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), () ->
- new Users.UnblockTask(getWorld().getAccount(), user.getId())
- .onDone(user -> getWorld().notify(R.string.notice_unblock_succeeded))
- .onFail(x -> getWorld().notifyError(R.string.notice_unblock_failed))
- .execute());
- break;
- case 4:
- ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), () ->
- new Users.ReportForSpamTask(getWorld().getAccount(), user.getId())
- .onDone(user -> getWorld().notify(R.string.notice_r4s_succeeded))
- .onFail(ex -> getWorld().notifyError(R.string.notice_r4s_failed))
- .execute());
- break;
- case 5:
- IntentUtils.openUri(getActivity(), user.getAclogTimelineURL());
- break;
- default:
- throw new IllegalStateException();
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
-
- private void setFollowButtonState(boolean isFollowing) {
- MainActivity mainActivity = (MainActivity) getActivity();
- if (mainActivity != null) {
- buttonFollow.setState(isFollowing ? ThreeStateButton.STATE_ON : ThreeStateButton.STATE_OFF);
- }
- }
-
- private void toggleFollowing() {
- Account account = getWorld().getAccount();
- Boolean isFollowing = buttonFollow.getState() == ThreeStateButton.STATE_ON;
- buttonFollow.setState(ThreeStateButton.STATE_LOCKED);
- if (isFollowing) {
- new Users.UnfollowTask(account, user.getId())
- .onDoneUI(result -> {
- getWorld().notify(R.string.notice_unfollow_succeeded);
- updateRelationship();
- })
- .onFail(x ->
- getWorld().notifyError(R.string.notice_unfollow_failed))
- .execute();
- } else {
- new Users.FollowTask(account, user.getId())
- .onDoneUI(result -> {
- getWorld().notify(R.string.notice_follow_succeeded);
- updateRelationship();
- })
- .onFail(x -> getWorld().notifyError(R.string.notice_follow_failed))
- .execute();
- }
- }
-
- private void updateListView(AbsListView absListView, TimelineAdapter adapter, boolean addedToTop) {
- int before = adapter.getCount();
- adapter.notifyDataSetChanged(); // synchronized call (not adapter#updateForce())
- int after = adapter.getCount();
- int increments = after - before;
- if (increments > 0) {
- if (addedToTop) {
- absListView.setSelection(increments + 1);
- absListView.smoothScrollToPositionFromTop(increments, 0);
- absListView.setSelection(increments);
- } else {
- absListView.smoothScrollToPositionFromTop(before, 0);
- }
- }
- }
-
- private void updateRelationship() {
- Account account = getWorld().getAccount();
- if (user == account.getUser()) {
- textViewFollowed.setText(R.string.user_detail_followed_is_me);
- buttonFollow.setVisibility(View.GONE);
- } else {
- buttonFollow.setState(ThreeStateButton.STATE_LOCKED);
- textViewFollowed.setText(R.string.user_detail_loading);
- new Users.ShowFriendshipTask(account, user.getId()).onDoneUI(relationship -> {
- boolean isFollowing = relationship.isSourceFollowingTarget();
- boolean isFollowed = relationship.isSourceFollowedByTarget();
- setFollowButtonState(isFollowing);
- textViewFollowed.setText(isFollowed ? R.string.user_detail_followed : R.string.user_detail_not_followed);
- }).execute();
- }
- }
-}