TrendsDetailActivity.java 78.9 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
package com.yidianling.dynamic.trendsDetail;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ImageSpan;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.cxzapp.yidianling.trends.trendsDetail.AdViewPagerAdapter;
import com.google.gson.internal.LinkedTreeMap;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.ydl.webview.H5Params;
import com.ydl.webview.NewH5Activity;
import com.ydl.ydl_image.module.GlideApp;
import com.ydl.ydl_router.manager.YDLRouterManager;
import com.ydl.ydlcommon.actions.share.ShareActionCallBack;
import com.ydl.ydlcommon.actions.share.ShareMoreBean;
import com.ydl.ydlcommon.actions.share.ShareUtils;
import com.ydl.ydlcommon.base.BaseMvpActivity;
import com.ydl.ydlcommon.base.config.YDLConstants;
konghaorui committed
53
import com.ydl.ydlcommon.bean.StatusBarOptions;
konghaorui committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
import com.ydl.ydlcommon.data.http.BaseResponse;
import com.ydl.ydlcommon.router.IYDLRouterConstant;
import com.ydl.ydlcommon.ui.LogoLoadingView;
import com.ydl.ydlcommon.utils.BuryPointUtils;
import com.ydl.ydlcommon.utils.MoonUtil;
import com.ydl.ydlcommon.utils.ScreenUtil;
import com.ydl.ydlcommon.utils.SharedPreferencesEditor;
import com.ydl.ydlcommon.utils.StringUtils;
import com.ydl.ydlcommon.view.BaseViewHolder;
import com.ydl.ydlcommon.view.dialog.CommonDialog;
import com.ydl.ydlcommon.view.dialog.ListDialog;
import com.ydl.ydlcommon.view.dialog.NormalDialog;
import com.ydl.ydlcommon.view.dialog.YDLShareDialog;
import com.ydl.ydlcommon.view.widgets.MyScrollview;
import com.ydl.ydlcommon.view.widgets.RecyclerViewForScrollView;
import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.dynamic.DynamicConstants;
import com.yidianling.dynamic.R;
import com.yidianling.dynamic.R2;
import com.yidianling.dynamic.common.browsePictures.BrowsePicturesActivity2;
import com.yidianling.dynamic.common.emoji.EmoticonPickerView;
import com.yidianling.dynamic.common.emoji.IEmoticonSelectedListener;
import com.yidianling.dynamic.members.MembersActivity;
import com.yidianling.dynamic.model.CommentBean;
import com.yidianling.dynamic.model.Reply;
import com.yidianling.dynamic.model.TrendsDetailInfoBean;
import com.yidianling.dynamic.router.DynamicIn;
import com.yidianling.dynamic.thank.ThankActivity;
import com.yidianling.dynamic.topic.topicDetail.TopicDetailActivity;

import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import me.relex.circleindicator.CircleIndicator;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;


/**
 * Created by Jim on 2017/10/28 0028.
 * 动态详情
 */
@Route(path = "/trends/detail")
public class TrendsDetailActivity extends BaseMvpActivity<ITrendsDetailView, ITrendsDetailPresenterImpl> implements ITrendsDetailView, IEmoticonSelectedListener, SwipeRefreshLayout.OnRefreshListener, MyScrollview.ScrollViewListener {

    @BindView(R2.id.item_trend_info_title)
    TextView tvTrendInfoTitle;

    @BindView(R2.id.text_userName)
    TextView tvUserName;

    @BindView(R2.id.item_recommend_trend_user_head_iv)
    ImageView ivUserHead;

    @BindView(R2.id.img_sex)
    ImageView ivSex;

    @BindView(R2.id.text_time)
    TextView tvTime;

    @BindView(R2.id.item_recommend_from)
    TextView tvFrom;

    @BindView(R2.id.text_guanzhu)
    TextView tvGuanzhu;

    @BindView(R2.id.text_content)
    TextView tvContent;

    @BindView(R2.id.recy_ico_list)
    RecyclerView rcvZanListImag;

    @BindView(R2.id.item_recommend_trend_ad_rel)
    RelativeLayout relTrendAd;

    @BindView(R2.id.item_recommend_trend_ad_iv)
    ImageView ivAd;

    @BindView(R2.id.item_recommend_trend_ad_tv)
    TextView tvAdTitle;

    @BindView(R2.id.text_huati)
    TextView tvHuati;

    @BindView(R2.id.item_recommend_trend_readed_tv)
    TextView tvReadNum;

    @BindView(R2.id.item_recommend_trend_zannum_tv)
    TextView tvZanNum;

    @BindView(R2.id.text_talk_num)
    TextView tvCommentNum;

    @BindView(R2.id.talk_recyView)
    RecyclerViewForScrollView rcvCommentsList;

    @BindView(R2.id.lin_nullTip)
    LinearLayout linNullTip;

    @BindView(R2.id.lin_content)
    LinearLayout linContent;

    @BindView(R2.id.trend_detail_swl)
    SwipeRefreshLayout swl;

    @BindView(R2.id.rela_nullTip)
    RelativeLayout relNotExist;

    @BindView(R2.id.img_more)
    ImageView ivZanListMore;

    @BindView(R2.id.list_img)
    RecyclerViewForScrollView rcvContentImags;

    @BindView(R2.id.lin_zan_list1)
    LinearLayout linZanList;

    @BindView(R2.id.lin_comment)
    LinearLayout linComment;

    @BindView(R2.id.img_wennuan)
    ImageView ivLike;

    @BindView(R2.id.edit_content)
    EditText edCommentContent;

    @BindView(R2.id.trend_disscuss_send_lin)
    LinearLayout linCommentSend;

    @BindView(R2.id.trend_disscuss_bottom_img_lin)
    LinearLayout linBottomLikeShare;

    @BindView(R2.id.emoticon_picker_view)
    EmoticonPickerView mEmoticonPickerView;

    @BindView(R2.id.publish_emoji_iv)
    ImageView ivChooseEmoji;

    @BindView(R2.id.myScrollView)
    MyScrollview myScrollView;

    @BindView(R2.id.text_show_all)
    TextView tvShowAllComment;

    @BindView(R2.id.fl_ads)
    FrameLayout flAds;

    @BindView(R2.id.vp_ads)
    ViewPager vpAds;

    @BindView(R2.id.circle_indicator)
    CircleIndicator circleIndicator;

    @BindView(R2.id.tv_no_comments)
    TextView tvNoComments;

    @BindView(R2.id.iv_fm)
    ImageView iv_fm;

    @BindView(R2.id.ll_has_load)
    LinearLayout llHasLoad;

    @BindView(R2.id.v_loading)
    LogoLoadingView vLoading;

    private boolean isFirstLoad = true;

    public static final int RESULT_CODE = 10001;
    //键
    public static final String KEY_TREND_ID = "trend_id";
    public static final String KEY_COMMENT_COUNT = "comment_count";
    public static final String KEY_IS_COMMENT = "is_comment";
    public static final String KEY_POSITION = "position";
    public static final String KEY_IS_SPLASH = "is_splash";
    public static final String KEY_IS_SCROLL_TO_ZAN = "is_scroll_to_zan";
    public static final String KEY_IS_SCROLL_TO_COMMENT = "is_scroll_to_comment";
    public static final String KEY_LAST_ID = "last_id";
    public static final String KEY_TYPE = "type";
    private static final String ROUTER_PARAMS = "routerParam";
    public static final int SCROLL_TO_COMMENT = 1;
    public static final int SCROLL_TO_ZAN = 2;
    public static final int INIT_COMMENT_FLAG = 3;


    private final int zan_max_num = 7;
    private int commentCount;
    private int trendId; //动态id
    private int page;//评论列表页码
    private int lastId;//评论列表上一条id
    private int direction;//评论列表加载方向,1上加载,2下加载
    private boolean hasMore;//是否可以继续加载评论,服务端数据返回不准确所以加这个标志
    private int mPosition; //item位置
    private boolean isComment; //评论框是否去的焦点
    private int likeState; //用于返回当前页面的点赞状态
    private boolean isRefresh;
    private boolean isFromSplash;
    private boolean isScrollToZan;
    private boolean isScrollToComment;      //是否需要滚动到评论位置
    private int replierType; //回复评论类型
    private TrendsDetailInfoBean.TrendBody mTrendBody;
    private List<TrendsDetailInfoBean.ZanImg> zanMembers;
    private List<CommentBean> comments;
    private List<TrendsDetailInfoBean.IMage> contentImags;
    private CommonAdapter<TrendsDetailInfoBean.ZanImg> zanImgListAdapter;
    private CommonAdapter<CommentBean> commentListAdapter;
    private CommonAdapter<TrendsDetailInfoBean.IMage> imagsContentAdapter;
    private MyHandler uiHandler;
    private boolean isShowEmojiView;
    private boolean isTrendsBodyLoadError = false;
    private boolean isKeyboardShowed = true; // 是否显示键盘
    private boolean isCommentDataChanged = false;

    List<String> reportReasonsId;//举报内容id
    List<String> reportReasons;//举报内容列表

    //记录当前回复的是帖子还是评论
    private int type = 1;//业务类型:1回复动态,2盖楼
    private int id;//当前要回复的id
    private String toContent;//当前要回复的动态
    private String toUsername;//当前要回复的用户名
    private TrendsDetailActivity.ItemLikeActionCallBack mItemLikeCallBack;
    private ArrayList<String> returnCommentsData; //当在该页面执行评论操作后的返回给上一个Activity的评论变化数据

    private long stopTime = 0;
    private boolean isSendComment = false;
    private Disposable subscribe;
    private Runnable showEmojiRunnable;
    private Runnable showTextRunnable;

konghaorui committed
300 301 302 303 304 305
    @NotNull
    @Override
    public StatusBarOptions getStatusViewOptions() {
        return new StatusBarOptions(true,true);
    }

konghaorui committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
    public static Intent newIntent(Activity activity, int trendId, boolean isScrollToZan) {
        Intent intent = new Intent(activity, TrendsDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_TREND_ID, trendId);
        bundle.putBoolean(KEY_IS_SCROLL_TO_ZAN, isScrollToZan);
        intent.putExtra(YDLConstants.BUNDLE, bundle);
        return intent;
    }

    public static Intent newIntent(Activity activity, int trendId, boolean isScrollToZan, int lastId) {
        Intent intent = new Intent(activity, TrendsDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_TREND_ID, trendId);
        bundle.putBoolean(KEY_IS_SCROLL_TO_ZAN, isScrollToZan);
        bundle.putInt(KEY_LAST_ID, lastId);
        intent.putExtra(YDLConstants.BUNDLE, bundle);
        return intent;
    }

    public static Intent newIntent(Activity activity, int trendId) {
        Intent intent = new Intent(activity, TrendsDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_TREND_ID, trendId);
        intent.putExtra(YDLConstants.BUNDLE, bundle);
        return intent;
    }

    public static void start(Activity activity, int trendId, int key_type, int id, String replyHint, boolean key_is_comment) {
        Intent intent = new Intent(activity, TrendsDetailActivity.class);
        Bundle bundle = new Bundle();

        bundle.putInt(KEY_TREND_ID, trendId);
        bundle.putInt(KEY_TYPE, key_type);
        bundle.putInt("id", id);
        bundle.putString("replyHint", replyHint);
        bundle.putBoolean(KEY_IS_COMMENT, key_is_comment);

        intent.putExtra("bundle", bundle);
        activity.startActivity(intent);
    }

    public static void start(Context activity, int trendId, boolean isSplash, boolean isComment, boolean isScrollToZan, boolean isScrollToComment, int lastId) {
        Intent intent = new Intent(activity, TrendsDetailActivity.class);
        Bundle bundle = new Bundle();

        bundle.putInt(KEY_TREND_ID, trendId);
        bundle.putBoolean(KEY_IS_SPLASH, isSplash);
        bundle.putBoolean(KEY_IS_COMMENT, isComment);
        bundle.putBoolean(KEY_IS_SCROLL_TO_ZAN, isScrollToZan);
        bundle.putBoolean(KEY_IS_SCROLL_TO_COMMENT, isScrollToComment);
        bundle.putInt(KEY_LAST_ID, lastId);

        intent.putExtra("bundle", bundle);
        if (activity instanceof Activity) {
        } else {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        activity.startActivity(intent);
    }

    public static void startForResult(Fragment fragment, int trendId, int commentCount, boolean isComment, int position, int requestCode) {
        Intent intent = new Intent(fragment.getActivity(), TrendsDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_TREND_ID, trendId);
        bundle.putInt(KEY_COMMENT_COUNT, commentCount);
        bundle.putBoolean(KEY_IS_COMMENT, isComment);
        bundle.putInt(KEY_POSITION, position);
        intent.putExtra("bundle", bundle);
        fragment.startActivityForResult(intent, requestCode);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
konghaorui committed
380
        setContentView(R.layout.dynamic_activity_trend_details);
konghaorui committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
        ButterKnife.bind(this);
        initDatas();
        initViews();
        onRefresh();
        if (isComment) {
            reply("", 1, trendId, "", 0);
        }

        initNetLossView();
    }

    private void initNetLossView() {
        vLoading.setListener(new LogoLoadingView.LogoLoadingListener() {
            @Override
            public void onDataResetClick() {
                vLoading.setViewType(LogoLoadingView.TYPE_LOADING, null);
                onRefresh();
            }

            @Override
            public void onBackClick() {
                finish();
            }
        });
    }

    /**
     * 获取路由传递的参数
     */
    private void getParam(){
        if (null == getIntent() || !getIntent().hasExtra(ROUTER_PARAMS)){
            return;
        }
        //路由传递的入参
        String json = getIntent().getStringExtra(ROUTER_PARAMS);
        try {
            JSONObject jsonObject = new JSONObject(json);
            //详情页ID
            trendId = jsonObject.getInt(IYDLRouterConstant.EXTRA_ID);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void showLoadingView(String message) {
        if (!swl.isRefreshing()) {
            dismissProgressDialog();
            if (isFirstLoad) {
                vLoading.setViewType(LogoLoadingView.TYPE_LOADING, null);
            }else {
                showProgressDialog(message);
            }
        }
    }

    @Override
    public void hideRefreshProgress() {
        if (swl.isRefreshing()) {
            swl.setRefreshing(false);
        }
    }

    @Override
    public void hideLoadingView() {
        dismissProgressDialog();

        vLoading.setVisibility(View.GONE);
        llHasLoad.setVisibility(View.VISIBLE);
    }

    @Override
    public void showTrendsBodyContent(TrendsDetailInfoBean.TrendBody trendBody) {
        isTrendsBodyLoadError = false;
        mTrendBody = trendBody;
        if (mTrendBody != null) {
            commentCount = mTrendBody.replyCounter;
            fillContent();
        }
    }

    private List<TrendsDetailInfoBean.Ad> mAdList;

    @Override
    public void showAds(List<TrendsDetailInfoBean.Ad> adList) {
        if (adList.size() > 0) {
            if (adList.size() > 4) {
                mAdList = adList.subList(0, 4);
            } else {
                mAdList = adList;
            }
            LogUtil.d("ad content: " + adList.toString());
            flAds.setVisibility(View.VISIBLE);
            AdViewPagerAdapter adapter = new AdViewPagerAdapter(this, mAdList);
            vpAds.setAdapter(adapter);
            circleIndicator.setViewPager(vpAds);
            if (mAdList.size() <= 1) {
                circleIndicator.setVisibility(View.INVISIBLE);
            }
            resetAdBannerTimer();
        }
    }

    @Override
    public void showSilencedDialog(String tips, String url) {
        CommonDialog.create(this)
                .setMessage(tips)
konghaorui committed
492
                .setLeftOnclick(TrendsDetailActivity.this.getString(R.string.dynamic_details), new View.OnClickListener() {
konghaorui committed
493 494 495 496 497 498 499
                    @Override
                    public void onClick(View v) {
                        String realUrl = TextUtils.isEmpty(url) ? DynamicConstants.HELP_URL  : url;
                        H5Params params = new H5Params(realUrl, "");
                        NewH5Activity.start(TrendsDetailActivity.this, params);
                    }
                })
konghaorui committed
500
                .setRightClick(TrendsDetailActivity.this.getString(R.string.dynamic_approval), null)
konghaorui committed
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
                .show();
    }

    private void resetAdBannerTimer() {
        if (subscribe != null) {
            subscribe.dispose();
        }
        subscribe = Observable.interval(4000, TimeUnit.MILLISECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(aLong -> vpAds.setCurrentItem(getNextItem(), true), Throwable::printStackTrace);
    }

    private int getNextItem() {
        return (vpAds.getCurrentItem() + 1) % mAdList.size();
    }

    @Override
    public void showTrendsNotExsitView() {
        isTrendsBodyLoadError = true;
        linContent.setVisibility(View.GONE);
        linComment.setVisibility(GONE);
        relNotExist.setVisibility(View.VISIBLE);
    }

    @Override
    public void showTrendsLoadErrorView() {
        isTrendsBodyLoadError = true;

        //如果是第一次加载且加载失败的情况下,才会展示网络开小差
        if (isFirstLoad) {
            linContent.setVisibility(View.GONE);
            linComment.setVisibility(GONE);
            llHasLoad.setVisibility(View.GONE);
            vLoading.setVisibility(View.VISIBLE);
            vLoading.setViewType(LogoLoadingView.TYPE_NET_LOSS, "哎呦,网络开小差了");
        }
    }

    //显示点赞用户列表
    @Override
    public void showZanList(List<TrendsDetailInfoBean.ZanImg> zanImgList) {
        if (zanImgList != null && zanImgList.size() > 0) {
            zanImgListAdapter.setDatas(zanImgList);
            zanImgListAdapter.notifyDataSetChanged();
            linZanList.setVisibility(View.VISIBLE);
            ivZanListMore.setVisibility(View.VISIBLE);
        }
    }

    //显示评论数据
    @Override
    public void showCommentsList(List<CommentBean> commentsBean) {
        if (page == 1) {
            commentListAdapter.clearHeaderViews();
            commentListAdapter.getDatas().clear();
            commentListAdapter.notifyDataSetChanged();
        }
        if (commentsBean != null && commentsBean.size() > 0) {
            commentListAdapter.addDatas(commentsBean);
            hasMore = true;
        } else {
            hasMore = false;
            commentListAdapter.notifyItemChanged(commentListAdapter.getDatas().size() - 1);
        }
        isShowNoCommentView(false);
        if (isScrollToComment) {
            Runnable scrollToCommentRunnable = new MyRunnable(this, SCROLL_TO_COMMENT);
            uiHandler.postDelayed(scrollToCommentRunnable, 200);
        }
        if (isFirstLoad) {
            vLoading.setVisibility(View.GONE);
            llHasLoad.setVisibility(View.VISIBLE);
            isFirstLoad = false;
        }
    }

    private void scrollToComment() {
        myScrollView.smoothScrollTo(0, rcvCommentsList.getTop());
        isScrollToComment = false;
    }


    @Override
    public void showCommentsLoadError() {
        isShowNoCommentView(true);
        if (commentListAdapter.getDatas() != null && commentListAdapter.getDatas().size() > 0) {
            linNullTip.setVisibility(GONE);
        } else {
            linNullTip.setVisibility(VISIBLE);
konghaorui committed
590
            tvNoComments.setText(this.getString(R.string.dynamic_trend_comments_load_error));
konghaorui committed
591 592 593 594
        }
    }

    private void setZanBackground(boolean isSelect) {
konghaorui committed
595
        Drawable drawable = getResources().getDrawable(isSelect ? R.drawable.dynamic_icon_warm_sel : R.drawable.dynamic_icon_warm_nor);
konghaorui committed
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//这句一定要加
        tvZanNum.setCompoundDrawables(drawable, null, null, null);
    }

    //帖子已赞
    @Override
    public void showLikedView() {
        BuryPointUtils.getInstance().createMap()
                .put("warmth_dynamic_name", mTrendBody.title)
                .put("warmth_dynamic_ID", mTrendBody.id + "")
                .put("warmth_category", mTrendBody.topicTitle)
                .put("warmth_way", "动态详情页面")
                .burryPoint("Warmth_dynamic");
        int length = zanImgListAdapter.getDatas().size() > 7 ? 7 : zanImgListAdapter.getDatas().size();
        likeState = 1;
konghaorui committed
611
        ivLike.setImageResource(R.drawable.dynamic_newsfeed_like_sel);
konghaorui committed
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
        startAnimation(ivLike);
        LogUtil.d("uid: " + DynamicIn.INSTANCE.getUserInfo().getUid());
        if (!isZanListContainUser() && DynamicIn.INSTANCE.isLogin() && length < 7) {
            zanImgListAdapter.addData(0, new TrendsDetailInfoBean.ZanImg(DynamicIn.INSTANCE.getUserInfo().getHead(), Integer.valueOf(DynamicIn.INSTANCE.getUserInfo().getUid())));
        }
        mTrendBody.zanCount += 1;
        tvZanNum.setText(String.valueOf(mTrendBody.zanCount));
        setZanBackground(true);
        showZanList();
    }

    //帖子未赞
    @Override
    public void showUnLikeView() {
        LogUtil.d("showUnLikeView");
        int length = zanImgListAdapter.getDatas().size() > 7 ? 7 : zanImgListAdapter.getDatas().size();
        likeState = 2;
konghaorui committed
629
        ivLike.setImageResource(R.drawable.dynamic_newsfeed_like);
konghaorui committed
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
        startAnimation(ivLike);
        mTrendBody.zanCount -= 1;
        tvZanNum.setText(String.valueOf(mTrendBody.zanCount));
        setZanBackground(false);
        LogUtil.d("uid: " + DynamicIn.INSTANCE.getUserInfo().getUid());
        for (int i = 0; i < length; i++) {
            if (zanImgListAdapter.getDatas().get(i).uid == Integer.valueOf(DynamicIn.INSTANCE.getUserInfo().getUid())) {
                LogUtil.d("user head index: " + i + " data size: " + zanImgListAdapter.getDatas().size());
                zanImgListAdapter.removeData(i);
                break;
            }
        }
        if (zanImgListAdapter.getDatas().size() <= 0) {
            linZanList.setVisibility(View.GONE);
            ivZanListMore.setVisibility(View.GONE);
        }
    }

    //回复点赞
    @Override
    public void showCommentsItemLikeStatus(int status) {
        mItemLikeCallBack.callBack(status);
    }

    @Override
    public void showFousChangeView() {
        tvGuanzhu.setText("已关注");
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(() -> tvGuanzhu.setVisibility(View.GONE));
            }
        }, 1000);

    }

    @Override
    public void showReportContentView(BaseResponse response, int answerId, String commentContent) {
        try {
            LinkedTreeMap<String, String> reportReasonsmaps =
                    (LinkedTreeMap<String, String>) response.data;
            if (reportReasonsmaps == null)
                return;
            reportReasonsId = new ArrayList<>();
            reportReasons = new ArrayList<>();
            for (Map.Entry<String, String> entry : reportReasonsmaps.entrySet()) {
                reportReasonsId.add(entry.getKey());
                reportReasons.add(entry.getValue());
            }
            showReportReason(1, answerId, commentContent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void refreshCommentListAfterComment(BaseResponse<Reply> replyBaseResponse, int type, String content, String replyContent, String toName) {
        page = 1;
        lastId = 0;
        fetchTrendsDetailsInfo();
        replyReset();
//        mTrendBody.reply_count += 1;
//        tvCommentNum.setText(mTrendBody.reply_count + "个评论");
//        isCommentDataChanged = true;
//        Long time = System.currentTimeMillis();
//        Date date = new Date(time);
//        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
//        String time_str = "今天 " + sdf.format(date);
//        commentListAdapter.addData(0, new CommentBean(Integer.valueOf(replyBaseResponse.data.id), DynamicIn.INSTANCE.getUserInfo().getUid(),
//                DynamicIn.INSTANCE.getUserInfo().getNick_name(), content, DynamicIn.INSTANCE.getUserInfo().getHead(), mTrendBody.id, 0, 0, toName, toContent, time_str, DynamicIn.INSTANCE.getUserInfo().getGender(), DynamicIn.INSTANCE.getUserInfo().getUser_type(), 2));
//        isShowNoCommentView(false);
//        myScrollView.smoothScrollTo(0, rcvCommentsList.getTop());
    }

    //删除评论或者动态
    @Override
    public void showDeleteReplyOrTrendView(BaseResponse<Object> response, int type, int position) {
        LogUtil.d("delete position: " + position);
        if (type == 1) {    //移除评论
            isCommentDataChanged = true;
            mTrendBody.replyCounter -= 1;
            tvCommentNum.setText(mTrendBody.replyCounter + "个评论");
            commentListAdapter.removeData(position);
            isShowNoCommentView(false);
        } else if (type == 2) {     //移除动态
            SharedPreferencesEditor.putString("trend_state", "success");
            setResultForActivity();
            finish();
        }
    }


    @Override
    public void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }


    public void isShowNoCommentView(boolean isDataLoadError) {
        if (commentListAdapter.getDatas() != null && commentListAdapter.getDatas().size() > 0) {
            linNullTip.setVisibility(GONE);
        } else {
            linNullTip.setVisibility(VISIBLE);
konghaorui committed
733
            tvNoComments.setText(isDataLoadError ? this.getString(R.string.dynamic_trend_comments_load_error) : this.getString(R.string.dynamic_trend_waitting_for_comment));
konghaorui committed
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
        }
    }

    @Override
    protected int layoutResId() {
        return 0;
    }

    @Override
    protected void initDataAndEvent() {

    }

    private interface ItemLikeActionCallBack {
        void callBack(int result);
    }


    private void browsePicAction(int position) {
        Intent intent = new Intent();
        intent.setClass(TrendsDetailActivity.this, BrowsePicturesActivity2.class);
        intent.putExtra("position", position);
        intent.putExtra("browse_type", "browse");
        Bundle bd = new Bundle();
        ArrayList<String> imgList = new ArrayList<String>();
        for (TrendsDetailInfoBean.IMage iMage : mTrendBody.bigAttach) {
            imgList.add(iMage.url);
        }
        intent.putStringArrayListExtra("allTrendImages", imgList);
        intent.putExtra("trend_id", mTrendBody.id);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        TrendsDetailActivity.this.startActivity(intent);
    }

    private void initViews() {
        if (isScrollToComment) {
            tvShowAllComment.setVisibility(VISIBLE);
            tvShowAllComment.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    lastId = 0;
                    page = 1;
                    tvShowAllComment.setVisibility(GONE);
                    isScrollToComment = false;
                    fetchTrendsDetailsInfo();
                }
            });
        }
        swl.setOnRefreshListener(this);
konghaorui committed
783
        swl.setColorSchemeResources(R.color.dynamic_main_theme);
konghaorui committed
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
        vpAds.getLayoutParams().height = ScreenUtil.getDisplayWidth() * 19 / 66;
        vpAds.requestLayout();
        vpAds.setOnTouchListener((v, event) -> {
            swl.setEnabled(false);
            switch (event.getAction()) {
                case MotionEvent.ACTION_UP:
                    swl.setEnabled(true);
                    break;
            }
            return false;
        });
        myScrollView.setScrollViewListener(this);
        initImageContentRcv();
        initZanListImagRcv();
        initCommentListRcv();
        initEditCommentView();
        LogUtil.d("trend id " + trendId);
    }

    private void initEditCommentView() {
        edCommentContent.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    linCommentSend.setVisibility(View.VISIBLE);
                    linBottomLikeShare.setVisibility(View.GONE);
                } else {
                    linCommentSend.setVisibility(View.GONE);
                    linBottomLikeShare.setVisibility(View.VISIBLE);
                    hideEmojiLayout();
                    hideInputMethod();
                    replyReset();
                }
            }
        });
        edCommentContent.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                hideEmojiLayout();
konghaorui committed
823
                ivChooseEmoji.setImageResource(R.drawable.dynamic_edict_ico_emoji);
konghaorui committed
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
                return false;
            }
        });
        edCommentContent.addTextChangedListener(new TextWatcher() {
            private int start;
            private int count;

            @Override
            public void onTextChanged(CharSequence arg0, int start, int before, int count) {
                this.start = start;
                this.count = count;
                String editable = edCommentContent.getText().toString();
                String str = StringUtils.StringFilter(editable.toString());
                if (!editable.equals(str)) {
                    edCommentContent.setText(str);
                    edCommentContent.setSelection(str.length()); //光标置后
                }

            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int start, int count, int after) {
            }


            @Override
            public void afterTextChanged(Editable arg0) {
                edCommentContent.removeTextChangedListener(this);
                MoonUtil.replaceEmoticons(TrendsDetailActivity.this, arg0, start, count);
                int editEnd = edCommentContent.getSelectionEnd();
                edCommentContent.removeTextChangedListener(this);
                while (StringUtils.counterChars(arg0.toString()) > 5000 && editEnd > 0) {
                    arg0.delete(editEnd - 1, editEnd);
                    editEnd--;
                }
                edCommentContent.setSelection(editEnd);
                edCommentContent.addTextChangedListener(this);
            }

        });
    }

    private void initDatas() {
        page = 1;
        direction = 0;
        isRefresh = false;
        likeState = 0;
        replierType = 0;
        uiHandler = new MyHandler(this);
        contentImags = new ArrayList<>();
        zanMembers = new ArrayList<>();
        comments = new ArrayList<>();

        Bundle bundle = getIntent().getBundleExtra(YDLConstants.BUNDLE);
        if (null != bundle){
            lastId = bundle.getInt(KEY_LAST_ID, 0);
            isFromSplash = bundle.getBoolean(KEY_IS_SPLASH, false);
            trendId = bundle.getInt(KEY_TREND_ID, 0);
            commentCount = bundle.getInt(KEY_COMMENT_COUNT, 0);
            mPosition = bundle.getInt(KEY_POSITION, 0);
            isComment = bundle.getBoolean(KEY_IS_COMMENT, false);
            isScrollToZan = bundle.getBoolean(KEY_IS_SCROLL_TO_ZAN, false);
            isScrollToComment = bundle.getBoolean(KEY_IS_SCROLL_TO_COMMENT, false);
            if ((id = bundle.getInt("id", 0)) == 0) {
                id = trendId;
            }
            type = bundle.getInt(KEY_TYPE, 1);
            toUsername = bundle.getString("replyHint");
        }
        getParam();
        showEmojiRunnable = new ShowEmojiRunnable(this, mEmoticonPickerView);
        showTextRunnable = new ShowTextRunnable(this, edCommentContent);
    }

    private void initCommentListRcv() {
        LinearLayoutManager linlayoutmanager2 = new LinearLayoutManager(this);
        rcvCommentsList.setLayoutManager(linlayoutmanager2);
        rcvCommentsList.getItemAnimator().setChangeDuration(0);
konghaorui committed
902
        commentListAdapter = new CommonAdapter<CommentBean>(this, R.layout.dynamic_item_talk_list, comments) {
konghaorui committed
903 904 905
            @Override
            public void convert(BaseViewHolder holder, int position, CommentBean data, int dataState) {
                if (lastId == data.getId() && isScrollToComment) {
konghaorui committed
906
                    holder.setBackgroundColor(R.id.lin_body, TrendsDetailActivity.this.getResources().getColor(R.color.dynamic_fffaec));
konghaorui committed
907
                } else {
konghaorui committed
908
                    holder.setBackgroundColor(R.id.lin_body, TrendsDetailActivity.this.getResources().getColor(R.color.dynamic_white));
konghaorui committed
909 910 911 912
                }
                holder.setHeadImageWithUrl(R.id.item_recommend_trend_user_head_iv, data.getHeader());       //头像
                holder.setText(R.id.text_userName, data.getName());         //用户名
                holder.setText(R.id.text_time, data.getTime_str()); //发布时间
konghaorui committed
913 914
                holder.setImageResource(R.id.img_comment_sex, data.getGender() == 1 ? R.drawable.dynamic_male : R.drawable.dynamic_female);
                holder.setImageResource(R.id.img_comment_zan, data.getIs_zan() == 1 ? R.drawable.dynamic_reply_zan_sel : R.drawable.dynamic_reply_zan);
konghaorui committed
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
                showCommentItemContent(holder, data);
                //咨询师标志
                holder.setVisibility(R.id.iv_shang, data.getUser_type() == 2 ? VISIBLE : View.GONE) //赏
                        .setVisibility(R.id.text_zixunshi, data.getUser_type() == 2 ? VISIBLE : GONE)
                        .setVisibility(R.id.text_chat, data.getUser_type() == 2 ? VISIBLE : GONE)
                        .setVisibility(R.id.text_confide, data.getIsAvailable() == 1 && data.getIsOpenListen() == 1 ? VISIBLE : GONE)
                        .setOnClickListener(R.id.text_confide, v -> {
                            NewH5Activity.start(TrendsDetailActivity.this, new H5Params(data.getListenLinkUrl(), "开始倾诉"));
                        })
                        .setOnClickListener(R.id.text_chat, v -> {
                            if (!DynamicIn.INSTANCE.isLogin()) {
                                startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
//                                startActivity(new Intent(TrendsDetailActivity.this, ChooseLoginWayActivity.class));
                                return;
                            } else {
                                BuryPointUtils.getInstance().createMap()
                                        .put("expert_entrance", "动态详情")
                                        .put("expert_ID", data.getDoctor_id())
                                        .put("expert_name", data.getName() == null ? "" : data.getName())
                                        .burryPoint("Chat_click");
                                getPresenter().getExpert(TrendsDetailActivity.this, data.getUid());
                            }
                        })
                        .setOnClickListener(R.id.iv_shang, v -> {
                            if (!DynamicIn.INSTANCE.isLogin()) {
                                //未登录则跳转登录页面
                                startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
//                                startActivity(new Intent(TrendsDetailActivity.this, ChooseLoginWayActivity.class));
                                return;
                            }
                            BuryPointUtils.getInstance().createMap()
                                    .put("reward_expert_ID", data.getDoctor_id())
                                    .put("reward_expert_name", data.getName())
                                    .put("reward_dynamic_name", mTrendBody.title)
                                    .put("reward_dynamic_ID", mTrendBody.id)
                                    .put("reward_dynamic_type", mTrendBody.topicTitle)
                                    .burryPoint("Reward");
                            Intent intent = new Intent(TrendsDetailActivity.this, ThankActivity.class);
                            intent.putExtra("answerId", data.getId());
                            startActivity(intent);
                        });
                if (position == commentListAdapter.getItemCount() - 1) {       //显示加载更多进度条
                    LogUtil.d("position: " + position + " data size: " + commentListAdapter.getItemCount());
                    holder.setVisibility(R.id.item_trend_load_more_tv, View.VISIBLE);
                    if (hasMore && isHasMore()) {
                        holder.setText(R.id.item_trend_load_more_tv, "点击加载更多");
                        holder.setOnClickListener(R.id.item_trend_load_more_tv, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (hasMore && isHasMore()) {
                                    page++;
//                                    lastId = comments.get(comments.size() - 1).getId();
                                    lastId = commentListAdapter.getDatas().get(commentListAdapter.getDatas().size() - 1).getId();
//                                    fetchTrendsDetailsInfo();
//                                    getPresenter().fetchTrendsDetails(trendId);
                                    getPresenter().fetchCommentsDatas(page);
                                } else {
                                    holder.setClickable(R.id.item_trend_load_more_tv, false);
                                }
                            }
                        });
                    } else {
                        String hint = "<font color='#B6B6B6'>" + "没有更多了" + "</font>";
                        holder.setText(R.id.item_trend_load_more_tv, Html.fromHtml(hint));
                        holder.setClickable(R.id.item_trend_load_more_tv, false);
                    }
                } else {
                    holder.setVisibility(R.id.item_trend_load_more_tv, View.GONE);
                }
                holder.setOnClickListener(R.id.lin_body, v -> {
                    reply(data.getName(), 2, data.getId(), data.getContent(), data.getUser_type());
                });
                holder.setOnLongClickListener(R.id.lin_body, v -> {
                    showDialog(holder.getItemView(), position, data);
                    return true;
                });
                holder.setOnClickListener(R.id.img_comment_discuss, v -> {
                    reply(data.getName(), 2, data.getId(), data.getContent(), data.getUser_type());
                });
                holder.setOnClickListener(R.id.img_comment_zan, v -> {
                    BuryPointUtils.getInstance().createMap()
                            .put("appreciate_replier_ID", data.getUser_type() == 2 ? data.getDoctor_id() : data.getUid())
                            .put("appreciate_replier_name", data.getName())
                            .put("appreciate_replier_type", data.getUser_type())
                            .burryPoint("appreciate");
                    mItemLikeCallBack = new TrendsDetailActivity.ItemLikeActionCallBack() {
                        @Override
                        public void callBack(int result) {
                            switch (result) {
                                case 1:         //已赞
konghaorui committed
1005
                                    holder.setImageResource(R.id.img_comment_zan, R.drawable.dynamic_reply_zan_sel);
konghaorui committed
1006 1007 1008
                                    startAnimation(holder.getView(R.id.img_comment_zan));
                                    break;
                                case 2:         //未赞
konghaorui committed
1009
                                    holder.setImageResource(R.id.img_comment_zan, R.drawable.dynamic_reply_zan);
konghaorui committed
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
                                    startAnimation(holder.getView(R.id.img_comment_zan));
                                    break;
                            }
                        }
                    };
                    doLikeAction(3, data.getId());
                });
                holder.setOnClickListener(R.id.item_trend_user_head_rel, v -> {
                    if (2 == data.getUser_type()) {//1用户2专家3助理
                        BuryPointUtils.getInstance().createMap()
                                .put("expert_entrance", "动态详情")
                                .put("expert_ID", data.getDoctor_id())
                                .put("expert_name", data.getName())
                                .burryPoint("Expert_particulars");
                        String url = DynamicIn.INSTANCE.getExpertHost() + data.getDoctor_id();
                        H5Params h5Params = new H5Params(url, null);
                        h5Params.setShareData(data.getShare_data());
                        LogUtil.d("share data: " + data.getShare_data());
                        NewH5Activity.start(TrendsDetailActivity.this, h5Params);
                    } else {
                        if (TextUtils.isEmpty(data.getUid()) || TextUtils.equals("0", data.getUid())) {
                            return;
                        }
                        Intent intent = new Intent(TrendsDetailActivity.this, MembersActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putString("user_id", data.getUid());
                        intent.putExtra("bundle", bundle);
                        startActivity(intent);
                    }
                });
            }

            private void showCommentItemContent(BaseViewHolder holder, CommentBean data) {
                boolean isToContentEmpty = TextUtils.isEmpty(data.getTo_content());
                holder.setVisibility(R.id.lin_reply, !isToContentEmpty ? VISIBLE : GONE);     //ToContent的布局
                if (!isToContentEmpty) {     //评论内容
                    holder.setVisibility(R.id.text_all, data.getTo_content().trim().length() > 30 ? VISIBLE : GONE);
                    MoonUtil.identifyFaceExpression(TrendsDetailActivity.this, holder.getView(R.id.text_comment_content), data.getContent(), ImageSpan.ALIGN_BOTTOM);
                    MoonUtil.SetItemDicussContent(TrendsDetailActivity.this, holder.getView(R.id.text_reply), data.getTo_content().trim().length() > 30 ? data.getTo_content().substring(0, 30) + "..." : data.getTo_content(), data.getTo_name(), "", ImageSpan.ALIGN_BOTTOM);
                    holder.setOnClickListener(R.id.text_all, v -> {
                        MoonUtil.SetItemDicussContent(TrendsDetailActivity.this, holder.getView(R.id.text_reply), data.getTo_content(), data.getTo_name(), "", ImageSpan.ALIGN_BOTTOM);
                        holder.setVisibility(R.id.text_all, GONE);
                    });
                    holder.setOnClickListener(R.id.text_reply, v -> {
                        reply(data.getTo_name(), 2, data.getId(), data.getContent(), data.getUser_type());
                    });
                } else {
                    MoonUtil.identifyFaceExpression(TrendsDetailActivity.this, holder.getView(R.id.text_comment_content), data.getContent(), ImageSpan.ALIGN_BOTTOM);
                }
            }
        };
        rcvCommentsList.getItemAnimator().setChangeDuration(0);
        rcvCommentsList.setAdapter(commentListAdapter);
    }

    private boolean isFirst = true;

    private void initImageContentRcv() {
        LinearLayoutManager linlayoutmanager1 = new LinearLayoutManager(this);
        rcvContentImags.setLayoutManager(linlayoutmanager1);
konghaorui committed
1070
        imagsContentAdapter = new CommonAdapter<TrendsDetailInfoBean.IMage>(this, R.layout.dynamic_item_image, contentImags) {
konghaorui committed
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
            @Override
            public void convert(BaseViewHolder holder, int position, TrendsDetailInfoBean.IMage data, int dataState) {
                GlideApp.with(TrendsDetailActivity.this)
                        .load(data.url)
                        .fitCenter()
                        .into((ImageView) holder.getView(R.id.img_img));
                holder.setOnClickListener(R.id.img_img, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        browsePicAction(position);
                    }
                });
            }
        };
        rcvContentImags.setAdapter(imagsContentAdapter);
    }

    private void initZanListImagRcv() {
        LinearLayoutManager horizontallinManager = new LinearLayoutManager(TrendsDetailActivity.this);
        horizontallinManager.setOrientation(LinearLayoutManager.HORIZONTAL);
konghaorui committed
1091
        zanImgListAdapter = new CommonAdapter<TrendsDetailInfoBean.ZanImg>(this, R.layout.dynamic_item_circleimg, zanMembers) {
konghaorui committed
1092 1093 1094
            @Override
            public void convert(BaseViewHolder holder, int position, TrendsDetailInfoBean.ZanImg data, int dataState) {
                if (position == zan_max_num) {
konghaorui committed
1095
                    holder.setImageResource(R.id.img_ico, R.drawable.dynamic_newsfeed_zan_more);
konghaorui committed
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
                } else if (position > zan_max_num) {
                    //多余图片不展示
                } else {
                    holder.setHeadImageWithUrl(R.id.img_ico, data.head);
                }
                holder.setOnClickListener(R.id.img_ico, v -> {
                    H5Params h5Params = new H5Params(DynamicConstants.Companion.getTRENDS_ZAN_LIST_H5() + "/" + trendId, null);
                    NewH5Activity.start(TrendsDetailActivity.this, h5Params);
                });
            }
        };
        rcvZanListImag.setLayoutManager(horizontallinManager);
        rcvZanListImag.setAdapter(zanImgListAdapter);
    }


    @OnClick({R2.id.item_recommend_trend_ad_rel, R2.id.publish_emoji_iv, R2.id.trend_disscuss_send_tv, R2.id.image_back, R2.id.img_wennuan, R2.id.image_right, R2.id.img_share, R2.id.item_recommend_trend_user_head_iv, R2.id.text_huati, R2.id.text_guanzhu, R2.id.lin_zan_list1})
    public void doClick(View v) {
        if (v.getId() == R.id.trend_disscuss_send_tv) {
            LogUtil.d("click send comment");
            if (DynamicIn.INSTANCE.isLogin()) {
                if (TextUtils.isEmpty(edCommentContent.getText().toString())) {
                    ToastUtil.toastShort("评论内容不能为空");
                    return;
                }
                sendComment(type, id, edCommentContent.getText().toString(), toContent, toUsername);
            } else {
                startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
//                    startActivity(new Intent(this, ChooseLoginWayActivity.class));
            }
        } else if (v.getId() == R.id.publish_emoji_iv) {
            //点击发送表情
            toggleEmojiLayout();
        } else if (v.getId() == R.id.image_right) {
            try {
                share();
            } catch (Exception e) {
                LogUtil.e("share error: " + e);
            }
        } else if (v.getId() == R.id.image_back) {
            if (isFromSplash) {
                startActivity(DynamicIn.INSTANCE.mainIntent(this));
                finish();
            }
            setResultForActivity();
            this.finish();
        } else if (v.getId() == R.id.img_wennuan) {
            doLikeAction(2, trendId);
        } else if (v.getId() == R.id.edit_content) {

        } else if (v.getId() == R.id.item_recommend_trend_user_head_iv) {
            if (TextUtils.isEmpty(mTrendBody.uid) || TextUtils.equals("0", mTrendBody.uid)) {
                return;
            }
            LogUtil.d("start memberActivity uid: " + mTrendBody.uid);
            Intent intent = new Intent();
            intent.setClass(this, MembersActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("user_id", mTrendBody.uid);
            intent.putExtra("bundle", bundle);
            startActivity(intent);
        } else if (v.getId() == R.id.text_huati) {
            gotoTopicPage();
        } else if (v.getId() == R.id.text_guanzhu) {
            getPresenter().focus(mTrendBody.uid);
        } else if (v.getId() == R.id.lin_zan_list1) {
            H5Params h5Params = new H5Params(DynamicConstants.Companion.getTRENDS_ZAN_LIST_H5() + "/" + trendId, null);
            NewH5Activity.start(TrendsDetailActivity.this, h5Params);
        } else if (v.getId() == R.id.item_recommend_trend_ad_rel) {//内容AD点击事件
            gotoAd();
        } else if (v.getId() == R.id.img_share) {
            share();
        }

    }

    private void sendComment(int type, int id, String content, String toContent, String toName) {
        if (mTrendBody == null) {
            return;
        }
        if (TextUtils.isEmpty(DynamicIn.INSTANCE.getUserInfo().getPhone())) {
            CommonDialog.create(this)
                    .setLeftOnclick("忍痛放弃", null)
                    .setRightClick("果断绑定", v -> {
                        startActivity(DynamicIn.INSTANCE.inputPhoneIntent(this, DynamicConstants.BIND_PHONE_ACTION));
                    })
                    .setMessage("\n" + DynamicConstants.Companion.getBIND_PHONE()+ "\n")
                    .show();
            return;
        }

        if (!isSendComment) {
            if (replierType == 0) {
                BuryPointUtils.getInstance().createMap()
                        .put("dynamic_name", mTrendBody.title)
                        .put("dynamic_ID", mTrendBody.id + "")
                        .put("dynamic_type", mTrendBody.topicTitle)
                        .burryPoint("Comment_dynamic");
            } else {
                BuryPointUtils.getInstance().createMap()
                        .put("replier_ID", id)
                        .put("replier_name", toName)
                        .put("replier_type", replierType == 2 ? "专家" : "用户")
                        .burryPoint("Reply_dynamic");
            }
            isSendComment = true;
            Runnable initCommentFlagRunnable = new MyRunnable(this, INIT_COMMENT_FLAG);
            uiHandler.postDelayed(initCommentFlagRunnable, 1000);
            getPresenter().commitOrReply(type, String.valueOf(id), content, toContent, toName);
        }
    }

    private void initCommentFlag() {
        isSendComment = false;
    }

    private void gotoTopicPage() {
        Intent intent = new Intent();
        intent.setClass(TrendsDetailActivity.this, TopicDetailActivity.class);
        intent.putExtra("topic_id", mTrendBody.topicId + "");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    private void doLikeAction(int type, int id) {
        if (!DynamicIn.INSTANCE.isLogin()) {
            startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
//            startActivity(new Intent(this, ChooseLoginWayActivity.class));
        } else {
            getPresenter().doLikeAction(type, id);
        }
    }

    private void fetchTrendsDetailsInfo() {
        getPresenter().fetchTrendsDetails(trendId);
    }

    private void showZanList() {
        linZanList.setVisibility(View.VISIBLE);
        ivZanListMore.setVisibility(View.VISIBLE);
    }

    private boolean isZanListContainUser() {
        boolean isContainUser = false;
        if (zanImgListAdapter.getDatas() == null || !DynamicIn.INSTANCE.isLogin()) {
            isContainUser = false;
        } else {
            int length = zanImgListAdapter.getDatas().size() > zan_max_num ? zan_max_num : zanImgListAdapter.getDatas().size();
            for (int i = 0; i < length; i++) {
                if (Integer.valueOf(DynamicIn.INSTANCE.getUserInfo().getUid()) == zanImgListAdapter.getDatas().get(i).uid) {
                    isContainUser = true;
                    break;
                }
            }
        }
        return isContainUser;
    }

    //重置当前评论类型
    private void replyReset() {
        this.type = 1;
        this.id = trendId;
        this.toUsername = "";
        this.toContent = "";
        edCommentContent.setText("");
        edCommentContent.setHint("发表评论");
        hideInputMethod();
        edCommentContent.clearFocus();
    }


    private void reply(String toName, int type, int id, String toContent, int replierType) {
        this.replierType = replierType;
        this.type = type;
        this.id = id;
        this.toContent = toContent;
        this.toUsername = toName;
        hideEmojiLayout();
konghaorui committed
1279
        ivChooseEmoji.setImageResource(R.drawable.dynamic_edict_ico_emoji);
konghaorui committed
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
        edCommentContent.setFocusable(true);
        edCommentContent.setFocusableInTouchMode(true);
        edCommentContent.requestFocus();
        if (!TextUtils.isEmpty(toName)) {
            edCommentContent.setHint("回复" + toName);
        } else {
            edCommentContent.setHint("发表评论");
        }
        uiHandler.postDelayed(showTextRunnable, 200);
    }


    // 隐藏表情布局
    @SuppressLint("WrongConstant")
    private void hideEmojiLayout() {
        uiHandler.removeCallbacks(showEmojiRunnable);

        if (mEmoticonPickerView != null) {
            mEmoticonPickerView.setVisibility(View.GONE);
        }
        isShowEmojiView = false;
    }

    // 显示表情布局
    private void showEmojiLayout() {
        hideInputMethod();
        edCommentContent.requestFocus();
        uiHandler.postDelayed(showEmojiRunnable, 100);
        mEmoticonPickerView.show(this);
        isShowEmojiView = true;
    }

    private void hideInputMethod() {
        isKeyboardShowed = false;
        uiHandler.removeCallbacks(showTextRunnable);
        @SuppressLint("WrongConstant") InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(edCommentContent.getWindowToken(), 0);
    }

    // 点击表情,切换到表情布局
    @SuppressLint("WrongConstant")
    private void toggleEmojiLayout() {
        if (mEmoticonPickerView == null || mEmoticonPickerView.getVisibility() == View.GONE) {
            showEmojiLayout();
konghaorui committed
1324
            ivChooseEmoji.setImageResource(R.drawable.dynamic_edict_ico_key);
konghaorui committed
1325 1326 1327
        } else {
            hideEmojiLayout();
            showInputMethod(edCommentContent);
konghaorui committed
1328
            ivChooseEmoji.setImageResource(R.drawable.dynamic_edict_ico_emoji);
konghaorui committed
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
        }
    }

    // 显示键盘布局
    private void showInputMethod(EditText editTextMessage) {
        editTextMessage.requestFocus();
        //如果已经显示,则继续操作时不需要把光标定位到最后
        if (!isKeyboardShowed) {
            editTextMessage.setSelection(editTextMessage.getText().length());
            isKeyboardShowed = true;
        }
        @SuppressLint("WrongConstant") InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editTextMessage, 0);
    }

    /**
     * 举报
     */
    public void showReportReason(final int ttype, final int answerId, final String answerContent) {
        if (reportReasons == null || reportReasons.size() <= 0) {
            getPresenter().fetchReportReasonContent(answerId, answerContent);
            return;
        }
        int itemTextColor = Color.RED;
        ListDialog.Builder builder1 = new ListDialog.Builder(this, reportReasons, itemTextColor);
        builder1.SetLastStr("取消");
        builder1.SetLastButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder1.SetOnItemClickLister(new ListDialog.Builder.OnItemClickLister() {
            @Override
            public void onItemClick(Dialog dialog, View view, int position) {
                dialog.dismiss();
                if (!DynamicIn.INSTANCE.isLogin()) {
                    //未登录则跳转登录页面
                    startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
                    return;
                }
                getPresenter().report(trendId, ttype, Integer.valueOf(reportReasonsId.get(position)), answerId, answerContent);
            }

            @Override
            public void onItemLongClick(Dialog dialog, View view, int position) {

            }
        });
        builder1.create().show();
    }

    private boolean isHasMore() {
        LogUtil.d("comment count: " + commentCount + " comment size: " + commentListAdapter.getDatas().size());
        return commentCount > commentListAdapter.getDatas().size();
    }

    private void fillContent() {
        linComment.setVisibility(VISIBLE);
        linContent.setVisibility(View.VISIBLE);
        relNotExist.setVisibility(View.GONE);
        linNullTip.setVisibility(mTrendBody.replyCounter > 0 ? GONE : VISIBLE);
        tvGuanzhu.setVisibility(mTrendBody.is_focused == 1 || mTrendBody.uid.equals("0") || TextUtils.equals(mTrendBody.uid, DynamicIn.INSTANCE.getUserInfo().getUid()) ? View.GONE : View.VISIBLE);
konghaorui committed
1392
        ivLike.setImageResource(mTrendBody.isZan == 1 ? R.drawable.dynamic_newsfeed_like_sel : R.drawable.dynamic_newsfeed_like);
konghaorui committed
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
        if (!TextUtils.isEmpty(mTrendBody.content)) {
            MoonUtil.identifyFaceExpression(this, tvContent, mTrendBody.content, ImageSpan.ALIGN_BOTTOM);
            tvContent.setVisibility(View.VISIBLE);
        } else {
            tvContent.setVisibility(View.GONE);
        }
        tvUserName.setText(mTrendBody.name);
        tvTime.setText(mTrendBody.timeStr + "-");    //发布时间
        tvFrom.setText(mTrendBody.from); //来源

        if (TextUtils.isEmpty(mTrendBody.title)) {
            tvTrendInfoTitle.setVisibility(GONE);
        } else {
            tvTrendInfoTitle.setVisibility(VISIBLE);
            tvTrendInfoTitle.setText(mTrendBody.title);  //标题
        }

        tvReadNum.setText(mTrendBody.visitCount);  //阅读量
        tvZanNum.setText(String.valueOf(mTrendBody.zanCount));  //点赞数量
        setZanBackground(mTrendBody.isZan == 1);
        tvHuati.setText("#" + mTrendBody.topicTitle + "#");
        tvCommentNum.setText(mTrendBody.replyCounter + "个评论");
konghaorui committed
1415
        ivSex.setImageResource(mTrendBody.gender == 2 ? R.drawable.dynamic_female : R.drawable.dynamic_male);
konghaorui committed
1416 1417
        GlideApp.with(this)
                .load(mTrendBody.header)
konghaorui committed
1418 1419
                .placeholder(R.drawable.dynamic_head_place_hold_pic)
                .error(R.drawable.dynamic_head_place_hold_pic)
konghaorui committed
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
                .circleCrop()
                .skipMemoryCache(true)
                .into(ivUserHead);//头像
        LogUtil.d("multitext_type: " + mTrendBody.multitextType);
        if (mTrendBody.multitextType.equals("2") || mTrendBody.multitextType.equals("3")) {
            fillImageContent();
        } else if (mTrendBody.multitextType.equals("4")) {
            fillAdContent();
        }
        if (isScrollToZan) {
            Runnable scrollToZanRunnable = new MyRunnable(this, SCROLL_TO_ZAN);
            uiHandler.postDelayed(scrollToZanRunnable, 400);
        }
    }

    private void scrollToZan() {
        myScrollView.smoothScrollTo(0, linZanList.getTop() - ScreenUtil.screenHeight / 2);
        isScrollToZan = false;
    }

    private void fillAdContent() {
        relTrendAd.setVisibility(View.VISIBLE);
        rcvContentImags.setVisibility(View.GONE);
        tvAdTitle.setText(mTrendBody.ext.title);
        GlideApp.with(this)
                .load(mTrendBody.ext.cover)
konghaorui committed
1446
                .placeholder(R.drawable.dynamic_default_img)
konghaorui committed
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
                .centerCrop()
                .into(ivAd);
        iv_fm.setVisibility((null != mTrendBody && null != mTrendBody.ext && mTrendBody.ext.url.contains("fm/detail")) ? View.VISIBLE : View.GONE);
    }

    private void fillImageContent() {
        rcvContentImags.setVisibility(View.VISIBLE);
        relTrendAd.setVisibility(View.GONE);
        contentImags = mTrendBody.bigAttach;
        imagsContentAdapter.clearData();
        imagsContentAdapter.setDatas(contentImags);
        imagsContentAdapter.notifyDataSetChanged();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (uiHandler != null) {
            uiHandler.removeCallbacksAndMessages(null);
        }
        if (subscribe != null) {
            subscribe.dispose();
        }
    }

    @NonNull
    @Override
    public ITrendsDetailPresenterImpl createPresenter() {
        return new ITrendsDetailPresenterImpl();
    }

    @Override
    public void onBackPressed() {
        setResultForActivity();
//        overridePendingTransition(R.anim.activity_close_enter_anim, R.anim.activity_close_exit_anim);
        this.finish();
    }

    private void setResultForActivity() {
        if (isTrendsBodyLoadError || mTrendBody == null) {
            return;
        }
        LogUtil.d("pos: " + mPosition + " likestate: " + likeState + " reply_count: " + mTrendBody.replyCounter + " zancount: " + mTrendBody.zanCount);
        Intent i = new Intent();
        i.putExtra("position", mPosition);
        i.putExtra("like_state", likeState);
        i.putExtra("comment_count", mTrendBody.replyCounter);
        i.putExtra("like_count", mTrendBody.zanCount);
//        returnCommentsData.add(DynamicIn.INSTANCE.getUserInfo().nickName+"/"+content+"/"+toName);
        LogUtil.d("isCommentDataChanged: " + isCommentDataChanged);
        if (isCommentDataChanged && commentListAdapter.getDatas().size() > 0) {
            returnCommentsData = new ArrayList<>();
            for (int j = 0; j < (commentListAdapter.getDatas().size() > 6 ? 6 : commentListAdapter.getDatas().size()); j++) {
                CommentBean commentBean = commentListAdapter.getDatas().get(j);
                LogUtil.d("retrun comment name: " + commentBean.getName() + " content: " + commentBean.getContent() + " to name: " + commentBean.getTo_name());
                if (TextUtils.isEmpty(commentBean.getTo_name())) {
                    returnCommentsData.add(commentBean.getName() + "/" + commentBean.getContent());
                } else {
                    returnCommentsData.add(commentBean.getName() + "/" + commentBean.getContent() + "/" + commentBean.getTo_name());
                }
            }
            i.putStringArrayListExtra("comment_datas", returnCommentsData);
        }
        setResult(RESULT_CODE, i);
    }

    @Override
    public void onRefresh() {
        isScrollToComment = false;
        tvShowAllComment.setVisibility(View.GONE);
        page = 1;
        lastId = 0;
        swl.setRefreshing(true);
        fetchTrendsDetailsInfo();
    }

    private void gotoAd() {
        if (YDLRouterManager.Companion.router(mTrendBody.ext.url)) {
            return;
        }
        Map<String, String> map = StringUtils.IsHttpReturn(mTrendBody.ext.url);
        String jumpType = map.get("jump_type");
        LogUtil.d("jumpType: " + jumpType);
        if ("url".equals(jumpType)) {
            String realUrl = map.get("url");
            String urlPage = map.get("url_page");
            if ("experts_search".equals(urlPage)) {
                startActivity(DynamicIn.INSTANCE.expertSearchIntent(TrendsDetailActivity.this, 0, 0, false));
            } else if ("test_detail".equals(urlPage)) {
                String[] strs = realUrl.split("/");
                String containsId = strs[strs.length - 1];
                try {
                    int id = Integer.parseInt(containsId.replaceAll("[^0-9]*", ""));
//                    OuterEmptyImp.jumpToTestDetailActivity(TrendsDetailActivity.this, id);
//                    startActivity(DynamicIn.INSTANCE.testDetailIntent(this, id));
                    DynamicIn.INSTANCE.testDetailH5(id);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            } else if ("test_result".equals(urlPage)) {
                String[] strs = realUrl.split("/");
                strs = strs[strs.length - 1].split("&");
                String containsId = strs[0];
                try {
                    int id = Integer.parseInt(containsId.replaceAll("[^0-9]*", ""));
//                    OuterEmptyImp.jumpToTestResultActivity(this, id);
//                    startActivity(DynamicIn.INSTANCE.testResultIntent(this, id));
                    DynamicIn.INSTANCE.testResultH5(id);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            } else if ("test".equals(urlPage)) {
                String[] strs = realUrl.split("/");
                strs = strs[strs.length - 1].split("&");
                String containsId = strs[0];
                if (!DynamicIn.INSTANCE.isLogin()) {
                    startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
                    return;
                }
//                RetrofitUtils.fetchTestDetail(new Command.FetchTestDetailCommand(containsId))
//                        .subscribeOn(Schedulers.io())
//                        .observeOn(AndroidSchedulers.mainThread())
//                        .subscribe(testDetailBaseResponse -> {
////                            OuterEmptyImp.jumpToTestAnswerActivity(this,testDetailBaseResponse.data);
//                            startActivity(DynamicIn.INSTANCE.testAnswerIntent(this));
////                                        TestAnswerActivity.Companion.start(this, testDetailBaseResponse.data),
//                        }, throwble -> {
//                            throwble.printStackTrace();
//                        });
                DynamicIn.INSTANCE.testDetailH5(Integer.valueOf(containsId));
            } else if (realUrl.contains("fm/detail")) {
                //因为ios已经做了,就是这么判断的,所以后续改吧
                String id = realUrl.substring(realUrl.lastIndexOf("/") + 1);
                if (!TextUtils.isEmpty(id)) {
                    startActivity(DynamicIn.INSTANCE.fmDetailIntent(this, Integer.valueOf(id)));
                }
            } else {
                H5Params h5Params = new H5Params(realUrl, null);
                NewH5Activity.start(getMContext(), h5Params);
            }
        } else if ("native".equals(jumpType)) {
            String nativePage = map.get("native_page");
            if ("listen".equals(nativePage)) {
//                Intent intent = new Intent(mContext, PhoneCallActivity.class);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                mContext.startActivity(intent);
//                OuterEmptyImp.jumpToPhoneCallActivity(TrendsDetailActivity.this);
                startActivity(DynamicIn.INSTANCE.phoneCallIntent(this));
            } else if ("fm".equals(nativePage)) {
                String fmId = map.get("id");
                int fm_idi = Integer.valueOf(fmId);
//                OuterEmptyImp.jumpToFMDetailActivity(getMContext(),Integer.valueOf(map.get("id")));
                startActivity(DynamicIn.INSTANCE.fmDetailIntent(this, fm_idi));

            }
        }
    }

    //分享
    public void share() {
        if (mTrendBody == null) {
            return;
        }
        List<ShareMoreBean> shareMoreBeanList = new ArrayList<>();
        if (mTrendBody.is_self == 1) {
            //自己的帖子
//            shareMoreBeanList.add(new ShareMoreBean(R.drawable.pop_delete, getString(R.string.delete), () -> {
//                //删除
//                deleteDialog(2, mTrendBody.id, 0);//
//            }));
            YDLShareDialog dialog = YDLShareDialog.Companion.style2(this, mTrendBody.title, DynamicConstants.Companion.getTRENF_INFO_SHARE_H5()+ trendId, mTrendBody.content, "http://static.ydlcdn.com/v1/images/logo320.png");
            dialog.setCallBack(type -> {
                if (2 == type) {
                    //删除
                    deleteDialog(2, mTrendBody.id, 0);
                } else if (4 == type) {
                    backHome();
                }
            });
            dialog.show(getFragmentManager(), "lose");
        } else {
            //别人帖子
            YDLShareDialog dialog = YDLShareDialog.Companion.style3(this, mTrendBody.title, DynamicConstants.Companion.getTRENF_INFO_SHARE_H5()+ trendId, mTrendBody.content, "http://static.ydlcdn.com/v1/images/logo320.png");
            dialog.setCallBack(type -> {
                if (3 == type) {
                    if (!DynamicIn.INSTANCE.isLogin()) {
                        //未登录则跳转登录页面
                        startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
                        return;
                    }
                    //举报
                    if (!DynamicIn.INSTANCE.isLogin()) {
                        startActivity(DynamicIn.INSTANCE.loginWayIntent(TrendsDetailActivity.this));
                        return;
                    }
                    showReportReason(1, 0, null);
                } else if (4 == type) {
                    backHome();
                }
            });
            dialog.show(getFragmentManager(), "lose");
        }
//        ShareUtils.INSTANCE.share(this, mTrendBody.title, DynamicConstants.TRENF_INFO_SHARE_H5 + trendId, mTrendBody.content, "http://static.ydlcdn.com/v1/images/logo320.png", shareMoreBeanList);
        ShareUtils.INSTANCE.setCallBack(new ShareActionCallBack() {
            @Override
            public void onShareFailed(@NotNull SHARE_MEDIA share_media, @NotNull Throwable throwable) {
                BuryPointUtils.getInstance().createMap()
                        .put("share_where", share_media.toString())
                        .put("share_what", trendId + (mTrendBody != null ? mTrendBody.title : ""))
                        .put("share_succeed", false)
                        .burryPoint("Share");
                LogUtil.d("Share Failed: " + share_media);
            }

            @Override
            public void onShareSuccessed(@NotNull SHARE_MEDIA share_media) {
                LogUtil.d("share successed: " + share_media);
                BuryPointUtils.getInstance().createMap()
                        .put("share_where", share_media.toString())
                        .put("share_what", trendId + (mTrendBody != null ? mTrendBody.title : ""))
                        .put("share_succeed", true)
                        .burryPoint("Share");
            }

        });
    }

    private void backHome() {
        Intent intent = DynamicIn.INSTANCE.mainIntent(this);
        Bundle bundle = new Bundle();
        bundle.putInt("selectTab", 0);
        intent.putExtra("bundle", bundle);
        startActivity(intent);
    }

    /**
     * 删除提示
     *
     * @param type
     * @param id
     * @param position 删除帖子的位置
     */
    public void deleteDialog(final int type, final int id, final int position) {
        NormalDialog.Builder builder = new NormalDialog.Builder(this);
        builder.setTitle("");
        builder.setMessage("覆水难收啊,陛下,真的删除吗?");
        builder.setPositiveButton("删了吧",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        getPresenter().delTrendsReply(type, id, position);
                    }
                });
        builder.setNegativeButton("我纠结了",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        builder.create().show();
    }

    /**
     * 长按评论弹出dialog
     *
     * @param view1
     * @param positionm 位置
     */
    public void showDialog(final View view1, final int positionm, CommentBean commentData) {

        String uid = "-2";
        try {
            uid = DynamicIn.INSTANCE.getUserInfo().getUid();
        } catch (Exception e) {
        }

        final boolean isSelf = TextUtils.equals(commentData.getUid(), uid);

        //自己的回复
        List<String> dialogDatas = new ArrayList<String>();
        if (isSelf) {
            dialogDatas.add("复制");
            dialogDatas.add("删除");
        } else { //ta人的回复
            dialogDatas.add("回复");
            dialogDatas.add("举报");
        }
        dialogDatas.add("取消");
        ListDialog.Builder builder1 = new ListDialog.Builder(TrendsDetailActivity.this, dialogDatas, Color.BLACK);
        builder1.SetOnItemClickLister(new ListDialog.Builder.OnItemClickLister() {
            @Override
            public void onItemClick(Dialog dialog, View view, int position) {
                switch (position) {
                    case 0:
                        if (isSelf) {
                            //复制
                            @SuppressLint("WrongConstant") ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                            // 将文本内容放到系统剪贴板里。
                            TextView textCommentContent = (TextView) view1.findViewById(R.id.text_comment_content);
                            String word = textCommentContent.getText().toString();
                            if (word.indexOf(":") != -1) {
                                word = word.substring(word.indexOf(":") + 1);
                            }
                            cm.setText(word);
                            ToastUtil.toastShort("复制成功");
                        } else {
                            reply(commentData.getName(), 2, commentData.getId(), commentData.getContent(), commentData.getUser_type());
                        }
                        break;
                    case 1:
                        if (isSelf) {
                            deleteDialog(1, commentData.getId(), positionm);//删除
                        } else {
                            showReportReason(1, commentData.getId(), commentData.getContent());
                        }
                        break;
                }
                dialog.dismiss();
            }

            @Override
            public void onItemLongClick(Dialog dialog, View view, int position) {
            }
        });
        builder1.create().show();
    }

    @Override
    public void onEmojiSelected(String key) {
        if (key.equals("/DEL")) {
            edCommentContent.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
        } else {
            int start = edCommentContent.getSelectionStart() > 0 ? edCommentContent.getSelectionStart() : 0;
            int end = edCommentContent.getSelectionEnd() > 0 ? edCommentContent.getSelectionEnd() : 0;
            edCommentContent.getText().replace(start, end, key);
        }

    }

    @Override
    public void onStickerSelected(String categoryName, String stickerName) {

    }

    @Override
    public void onScrollChanged(MyScrollview scrollView, int x, int y, int oldx, int oldy) {
        hideEmojiLayout();
        hideInputMethod();
konghaorui committed
1797
        ivChooseEmoji.setImageResource(R.drawable.dynamic_edict_ico_key);
konghaorui committed
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886
        edCommentContent.clearFocus();
    }

    private void startAnimation(ImageView imgView) {
        PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 1.5f, 1f);
        PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 1.5f, 1f);
        ObjectAnimator.ofPropertyValuesHolder(imgView, scaleX, scaleY).setDuration(500).start();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //所有友盟分享,都必须复写这里,保证返回到分享界面时,能够回调友盟的接口。
        //友盟分享必须重写
//        InnerEmptyImp.UMShareOnActivityResult();
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    static class MyHandler extends Handler {
        WeakReference<Context> mActivity;

        public MyHandler(Context activity) {
            mActivity = new WeakReference<Context>(activity);
        }
    }

    static class MyRunnable implements Runnable {
        WeakReference<TrendsDetailActivity> mActivity;
        int flag = -1;

        public MyRunnable(TrendsDetailActivity activity, int scrollPlace) {
            mActivity = new WeakReference<TrendsDetailActivity>(activity);
            this.flag = scrollPlace;
        }

        @Override
        public void run() {
            if (mActivity.get() == null) {
                return;
            }
            if (flag == SCROLL_TO_ZAN) {
                mActivity.get().scrollToZan();
            } else if (flag == SCROLL_TO_COMMENT) {
                mActivity.get().scrollToComment();
            } else if (flag == INIT_COMMENT_FLAG) {
                mActivity.get().initCommentFlag();
            }
        }
    }

    static class ShowEmojiRunnable implements Runnable {
        WeakReference<TrendsDetailActivity> mActivity;
        WeakReference<EmoticonPickerView> mEmoticonPickerView;

        public ShowEmojiRunnable(TrendsDetailActivity activity, EmoticonPickerView emoticonPickerView) {
            mActivity = new WeakReference<TrendsDetailActivity>(activity);
            mEmoticonPickerView = new WeakReference<EmoticonPickerView>(emoticonPickerView);
        }

        @Override
        public void run() {
            if (mEmoticonPickerView.get() != null) {
                mEmoticonPickerView.get().setVisibility(View.VISIBLE);
            }
        }
    }

    static class ShowTextRunnable implements Runnable {
        WeakReference<TrendsDetailActivity> mActivity;
        WeakReference<EditText> edCommentContent;

        public ShowTextRunnable(TrendsDetailActivity activity, EditText edCommentContent) {
            mActivity = new WeakReference<TrendsDetailActivity>(activity);
            this.edCommentContent = new WeakReference<EditText>(edCommentContent);
        }

        @Override
        public void run() {
            if (mActivity.get() != null && edCommentContent.get() != null) {
                mActivity.get().showInputMethod(edCommentContent.get());
            }
        }

    }


    private boolean judgeIsSlienced() {
        if (DynamicIn.INSTANCE.getUserInfo() != null && DynamicIn.INSTANCE.getUserInfo().is_silenced() == 2) {
            CommonDialog.create(this)
konghaorui committed
1887
                    .setMessage(TrendsDetailActivity.this.getString(R.string.dynamic_silence_content))
konghaorui committed
1888 1889 1890 1891 1892 1893
                    .setLeftOnclick(TrendsDetailActivity.this.getString(R.string.platform_appeal), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            DynamicIn.INSTANCE.startChat(TrendsDetailActivity.this, "14");
                        }
                    })
konghaorui committed
1894
                    .setRightClick(TrendsDetailActivity.this.getString(R.string.dynamic_approval), null)
konghaorui committed
1895 1896 1897 1898 1899 1900 1901
                    .show();
            return true;
        }
        return false;
    }

}